好友
阅读权限10
听众
最后登录1970-1-1
|
1.程序截图
(程序图标)
(程序截图)
2.程序说明
本程序基于.NET 4.0制作,可以计算课程学分以及达标所需学分
课程数据存于txt文件
types.txt用于存放课程类别,课程类别.txt用于存放各类别的课程数据,格式:课程名+空格+学分(实验学分) tips:实验学分可空
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)
完全原创,有需自取,有免费热心万分感谢 |
免费评分
-
查看全部评分
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|