实体类:Student
using System;
using System.Collections.Generic;
using System.Text;
namespace 成绩管理系统
{
class Student : IComparable<Student>
{
private string stuName;//学生姓名
public string StuName
{
get { return stuName; }
// set { stuName = value; }
}
private int mathScore;//高数成绩
public int MathScore
{
get { return mathScore; }
set { mathScore = value; }
}
private int englishScore;//英语成绩
public int EnglishScore
{
get { return englishScore; }
set { englishScore = value; }
}
private int specScore;//专业成绩
public int SpecScore
{
get { return specScore; }
set { specScore = value; }
}
private int totalScore1;
public int TotalScore1
{
get { return totalScore1=mathScore+englishScore+specScore; }
set { totalScore1 = value; }
}
public Student(string name, int math, int english, int spec)
{
this.stuName = name;
this.mathScore = math;
this.englishScore = english;
this.specScore = spec;
}
//计算成绩的方法
public int TotalScore()
{
int sum = mathScore + englishScore + specScore;
return sum;
}
//实现泛型借口中的方法
public int CompareTo(Student other)
{
return this.TotalScore().CompareTo(other.TotalScore());
}
//重写String的方法
public override string ToString()
{
return base.ToString();
}
}
}
实体类:Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace 成绩管理系统
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
#region 窗体加载
private void frmLogin_Load(object sender, EventArgs e)
{
this.skinEngine1.SkinFile = "SportsOrange.ssk";
}
#endregion
#region 登陆检测
private void btnOk_Click(object sender, EventArgs e)
{
bool flag = false;
StreamReader sr = new StreamReader(@"Administrator.txt", Encoding.UTF8);
string uname, upwd;
while (sr.Peek() != -1)
{
uname = sr.ReadLine();
upwd = sr.ReadLine();
if (uname.Equals(this.txtName.Text.Trim()) && upwd.Equals(this.txtPwd.Text.Trim()))
{
flag = true;
break;
}
sr.ReadLine();
}
sr.Close();
if (flag == false)
{
MessageBox.Show("用户名或密码错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
this.progressBar1.Maximum = 50;
this.progressBar1.Value = 0;
Timer timer = new Timer();
timer.Interval = 1000;
timer.Tick += new EventHandler(timer1_Tick);
timer.Start();
for (int i = 0; i < 50; i++)
{
this.progressBar1.Value++;
}
}
}
#endregion
#region 时间计算
private void timer1_Tick(object sender, EventArgs e)
{
if (this.progressBar1.Value == this.progressBar1.Maximum)
{
((Timer)sender).Stop();
this.Hide();
Form2 frm = new Form2();
frm.Show();
}
}
#endregion
#region 退出
private void btnQuit_Click(object sender, EventArgs e)
{
if (MessageBox.Show("你真的要退出么?", "退出提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Application.Exit();
}
}
#endregion
}
}
实体类:Form2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 成绩管理系统
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
List<Student> listStu = new List<Student>();//泛型
private void Form2_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
this.skinEngine1.SkinFile = "SportsOrange.ssk";
}
#region 验证数据是否合法
private bool IsValidate()
{
//验证姓名
string strname = this.txtSname.Text.Trim();
if (strname.Length == 0)
{
MessageBox.Show("姓名不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.txtSname.Focus();
return false;
}
else
{
foreach(Student s in listStu)
{
if (txtSname.Text==s.StuName)
{
MessageBox.Show("姓名已经存在!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.txtSname.Focus();
this.txtSname.SelectAll();
return false;
}
}
}
//验证高数成绩
string strmath = this.txtSmath.Text.Trim();
if (strmath.Length == 0)
{
MessageBox.Show("高数成绩不能为空!", "数据错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.txtSmath.Focus();
return false;
}
try
{
int math = int.Parse(strmath);
if (math < 0 || math > 100)
{
MessageBox.Show("高数成绩输入不再范围内!", "数据错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.txtSmath.Focus();
this.txtSmath.SelectAll();
return false;
}
}
catch (FormatException e)
{
MessageBox.Show("高数成绩只能是整数!", "数据错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.txtSmath.Focus();
this.txtSmath.SelectAll();
return false;
}
//验证英语成绩
string strEnglish = this.txtSenglish.Text.Trim();
if (strEnglish.Length == 0)
{
MessageBox.Show("英语成绩不能为空!", "数据错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.txtSenglish.Focus();
return false;
}
try
{
int english = int.Parse(strEnglish);
if (english < 0 || english > 100)
{
MessageBox.Show("英语成绩输入不再范围内!", "数据错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.txtSenglish.Focus();
this.txtSenglish.SelectAll();
return false;
}
}
catch (FormatException e)
{
MessageBox.Show("英语成绩只能是整数!", "数据错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.txtSenglish.Focus();
this.txtSenglish.SelectAll();
return false;