吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 9451|回复: 21
收起左侧

[原创工具] 【原创】学分计算器

  [复制链接]
fissssssh 发表于 2019-3-5 17:14
1.程序截图
1.png (程序图标)
2.png (程序截图)
2.程序说明
本程序基于.NET 4.0制作,可以计算课程学分以及达标所需学分
课程数据存于txt文件
types.txt用于存放课程类别,课程类别.txt用于存放各类别的课程数据,格式:课程名+空格+学分(实验学分) tips:实验学分可空
3.png 4.png
3.程序下载
程序下载: PointCalc.rar (26.64 KB, 下载次数: 14)
4.源码及下载
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace PointCalc
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public struct Course
        {
            public string name;
            public double point;
            public double? point2;

            public override string ToString()
            {
                return point2 == null ? name + " " + point : name + " " + point + "(" + point2 + ")";
            }
        }

        double allPoint = 0;
        double allPoint2 = 0;
        List<Course> courses = new List<Course>();
        FileStream fs;
        StreamReader sr;
        string content;

        private void Form1_Load(object sender, EventArgs e)
        {
            fs = new FileStream("types.txt", FileMode.OpenOrCreate, FileAccess.Read);
            sr = new StreamReader(fs, Encoding.Default);
            content = sr.ReadLine();
            while (content != null)
            {
                comboBox1.Items.Add(content);
                content = sr.ReadLine();
            }
            sr.Close();
            fs.Close();
            if (comboBox1.Items.Count != 0)
                comboBox1.SelectedIndex = 0;
            toolStripStatusLabel1.Text = "";
        }

        private void checkBox_CheckedChanged(object sender, EventArgs e)
        {
            content = (sender as CheckBox).Text;
            int index = int.Parse(content.Substring(0, content.IndexOf('.'))) - 1;
            if ((sender as CheckBox).Checked)
            {
                allPoint += courses[index].point;
                if (courses[index].point2 != null)
                    allPoint2 += (double)courses[index].point2;
            }
            else
            {
                allPoint -= courses[index].point;
                if (courses[index].point2 != null)
                    allPoint2 -= (double)courses[index].point2;
            }
            Updata();
        }

        private void Updata()
        {
            label1.Text = "当前学分:" + allPoint.ToString("f1");
            label2.Text = "当前括号学分:" + allPoint2.ToString("f1");
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            label1.Text = "当前学分:0";
            label2.Text = "当前括号学分:0";
            courses.Clear();
            fs = new FileStream(comboBox1.SelectedItem.ToString() + ".txt", FileMode.Open, FileAccess.Read);
            sr = new StreamReader(fs, Encoding.Default);
            content = sr.ReadLine();
            while (content != null)
            {
                string[] infos = content.Split(' ');
                Course course = new Course();
                course.name = infos[0];
                if (infos[1].Contains('('))
                {
                    course.point = double.Parse(infos[1].Substring(0, infos[1].IndexOf('(')));
                    var temp = infos[1].Substring(infos[1].IndexOf('('));
                    course.point2 = double.Parse(temp.Substring(1, temp.Length - 2));

                }
                else
                {
                    course.point = int.Parse(infos[1]);
                }
                courses.Add(course);
                content = sr.ReadLine();
            }
            sr.Close();
            fs.Close();
            RefreshPanel();
            toolStripStatusLabel1.Text = "";
        }

        private void RefreshPanel()
        {
            flowLayoutPanel1.Controls.Clear();
            for (int i = 0; i < courses.Count; ++i)
            {
                AddCheckBox(courses[i], i);
            }
        }

        private void AddCheckBox(Course course, int i)
        {
            CheckBox checkbox = new CheckBox();
            checkbox.Text = i + 1 + "." + course.ToString();
            checkbox.Size = new Size(210, 16);
            checkbox.CheckedChanged += checkBox_CheckedChanged;
            checkbox.CheckedChanged += Calc;
            checkbox.ContextMenuStrip = contextMenuStrip1;
            this.flowLayoutPanel1.Controls.Add(checkbox);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string newType;
            Form2 form2 = new Form2();
            if (form2.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            newType = form2.result;

            fs = new FileStream("types.txt", FileMode.Append, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs, Encoding.Default);
            sw.WriteLine(newType);
            comboBox1.Items.Add(newType);
            sw.Close();
            fs.Close();

            fs = new FileStream(newType + ".txt", FileMode.Create, FileAccess.Write);
            fs.Close();

            comboBox1.SelectedIndex = comboBox1.Items.Count - 1;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Course newCourse;
            Form3 form3 = new Form3();
            if (form3.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            newCourse = form3.course;

            fs = new FileStream(comboBox1.SelectedItem.ToString() + ".txt", FileMode.Append, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs, Encoding.Default);
            sw.WriteLine(newCourse.ToString());
            sw.Close();
            fs.Close();
            AddCheckBox(newCourse, courses.Count);
            courses.Add(newCourse);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("确定删除?", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dialogResult != DialogResult.OK)
                return;
            File.Delete(comboBox1.SelectedItem.ToString() + ".txt");
            int oldIndex = comboBox1.SelectedIndex;
            comboBox1.Items.RemoveAt(comboBox1.SelectedIndex);
            fs = new FileStream("types.txt", FileMode.Create, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs, Encoding.Default);
            foreach (var item in comboBox1.Items)
            {
                sw.WriteLine(item.ToString());
            }
            sw.Close();
            fs.Close();
            comboBox1.SelectedIndex = oldIndex - 1;
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            content = (((sender as ToolStripMenuItem).GetCurrentParent() as ContextMenuStrip).SourceControl as CheckBox).Text;
            courses.RemoveAt(int.Parse(content.Substring(0, content.IndexOf('.'))) - 1);
            fs = new FileStream(comboBox1.SelectedItem.ToString() + ".txt", FileMode.Create, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs, Encoding.Default);
            foreach (var item in courses)
            {
                sw.WriteLine(item.ToString());
            }
            sw.Close();
            fs.Close();
            RefreshPanel();
        }

        private void Calc(object sender, EventArgs e)
        {
            double needPoint = 0;
            double needPoint2 = 0;
            if (!string.IsNullOrEmpty(textBox1.Text))
            {
                double goalPoint = double.Parse(textBox1.Text);
                if (goalPoint > allPoint)
                    needPoint = goalPoint - allPoint;
            }
            else
                return;
            if (!string.IsNullOrEmpty(textBox1.Text))
            {
                double goalPoint2 = double.Parse(textBox2.Text);
                if (goalPoint2 > allPoint2)
                    needPoint2 = goalPoint2 - allPoint2;
            }
            if (needPoint == 0 && needPoint2 == 0)
            {
                toolStripStatusLabel1.Text = string.Format("学分已足够!");
                toolStripStatusLabel1.ForeColor = Color.Green;
            }
            else
            {
                toolStripStatusLabel1.Text = string.Format("距离目标学分还差:{0:N1}({1:N1})", needPoint, needPoint2);
                toolStripStatusLabel1.ForeColor = Color.Red;
            }
        }
    }
}

源码下载: 学分计算器.rar (356.96 KB, 下载次数: 10)

完全原创,有需自取,有免费热心万分感谢

点评

过来支持老铁技术贴  发表于 2019-3-7 07:52

免费评分

参与人数 5吾爱币 +10 热心值 +5 收起 理由
无间孤独行者 + 1 + 1 我很赞同!
speed2017 + 1 + 1 很实用!
jnez112358 + 1 + 1 谢谢@Thanks!
云在天 + 6 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
tangfangxi + 1 + 1 我很赞同!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

pikachu888 发表于 2019-3-5 17:51
我怎么觉得用Excel算比这个更快更方便...txt文档还得有格式
pulinstan 发表于 2019-3-6 17:46
jeffkorn 发表于 2019-3-6 18:42 来自手机
感觉好冷门的样子,打代码很辛苦,支持楼主一下!
gaosongling 发表于 2019-3-6 20:55
        我很赞同
hicodecn 发表于 2019-3-6 21:05
谢谢楼主了
wujingli 发表于 2019-3-6 23:47
可以很好
jnez112358 发表于 2019-3-7 09:21
学习中,谢
wwwww1986528 发表于 2019-3-7 12:21
感谢楼主了,,纯支持了。。涌不上了
所以你就辣么浪 发表于 2019-3-7 12:31 来自手机
谢谢分享
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 17:17

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表