学生成绩管理系统课程设计源程序.docx
《学生成绩管理系统课程设计源程序.docx》由会员分享,可在线阅读,更多相关《学生成绩管理系统课程设计源程序.docx(47页珍藏版)》请在冰点文库上搜索。
学生成绩管理系统课程设计源程序
关于About.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Reflection;
namespace学生成绩管理系统
{
publicpartialclassAbout:
Form
{
publicAbout()
{
InitializeComponent();
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
this.Close();
}
privatevoidAbout_Load(objectsender,EventArgse)
{
}
}
}
添加课程信息AddCourse.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMySql.Data.MySqlClient;
namespace学生成绩管理系统
{
publicpartialclassAddCourse:
Form
{
publicAddCourse()
{
InitializeComponent();
}
privatevoidbtnExit_Click(objectsender,EventArgse)
{
this.Close();
}
privatevoidbtnAddCourse_Click(objectsender,EventArgse)
{
stringmyConnectionString="Database=student;DataSource=localhost;UserId=root;Password=k6smile20xq";
MySqlConnectionmycn=newMySqlConnection(myConnectionString);
mycn.Open();
stringsql;
Coursecourse=newCourse();
course.Cno=txtCno.Text;
course.Cname=txtCname.Text;
try
{
sql="selectcount(*)fromcoursewherecno='"+txtCno.Text+"'";
MySqlCommandmycm=newMySqlCommand(sql,mycn);
MySqlDataReadermsdr=mycm.ExecuteReader();
msdr.Read();
intstuCount=msdr.GetInt32("count(*)");
msdr.Close();
if(stuCount==0&&txtCname.Text!
=""&&txtCno.Text!
="")
{
sql="insertintocourse(cno,cname)values('"+course.Cno+"','"+course.Cname+"')";
MySqlCommandmycm1=newMySqlCommand(sql,mycn);
try
{
mycm1.ExecuteNonQuery();
}
catch(Exceptionexception)
{
MessageBox.Show(exception.Message);
return;
}
finally
{
mycn.Close();
}
MessageBox.Show("添加成功!
");
}
elseif(stuCount>=1&&txtCno.Text!
=""&&txtCname.Text!
="")
{
//这里需要关闭资源
MessageBox.Show("该课程的信息已存在,请重新输入!
");
}
else
{
//这里需要关闭资源
MessageBox.Show("请输入要添加的信息");
msdr.Close();
mycn.Close();
}
}
catch(Exceptiona)
{
Console.WriteLine(a.ToString());
}
finally
{
txtCno.Text="";
txtCname.Text="";
}
}
privatevoidAddCourse_Load(objectsender,EventArgse)
{
}
}
}
添加学生信息AddStudent.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMySql.Data.MySqlClient;
usingSystem.IO;
namespace学生成绩管理系统
{
publicpartialclassAddStudent:
Form
{
publicAddStudent()
{
InitializeComponent();
}
privatevoidAddStudent_Load(objectsender,EventArgse)
{
}
privatevoidbtnCancel_Click(objectsender,EventArgse)
{
this.Close();
}
privatevoidbtnAddStudent_Click(objectsender,EventArgse)
{
stringmyConnectionString="Database=student;DataSource=localhost;UserId=root;Password=k6smile20xq";
MySqlConnectionmycn=newMySqlConnection(myConnectionString);
mycn.Open();
stringsql;
//intstuNum=Selectcount(id)from
Studentstu=newStudent();
stu.Sno=txtSno.Text;
stu.Sname=txtName.Text;
stu.Age=txtAge.Text;
stu.ClassName=txtClassName.Text;
stu.Password=txtPassword.Text;
stu.Id=txtId.Text;
if(rbStuGirl.Checked)stu.Sex="女?
";
elseif(rbStuBoy.Checked)stu.Sex="男D";
//if(rbStuGirl.Checked)stu.Sex="girl";
//elseif(rbStuBoy.Checked)stu.Sex="boy";
try
{
sql="selectcount(*)fromstudentwheresno='"+txtSno.Text+"'";
MySqlCommandmycm=newMySqlCommand(sql,mycn);
MySqlDataReadermsdr=mycm.ExecuteReader();
msdr.Read();
intstuCount=msdr.GetInt32("count(*)");
msdr.Close();
if(stuCount==0&&txtSno.Text!
=""&&txtName.Text!
=""&&txtAge.Text!
=""&&txtClassName.Text!
=""&&txtPassword.Text!
=""&&txtId.Text!
="")
{
sql="insertintostudent(sno,sname,sex,age,classname,password,id)values('"+stu.Sno+"','"+stu.Sname+"','"+stu.Sex+"','"+stu.Age+"','"+stu.ClassName+"','"+stu.Password+"','"+stu.Id+"')";
Console.WriteLine(sql);
MySqlCommandmycm1=newMySqlCommand(sql,mycn);
try
{
mycm1.ExecuteNonQuery();
}catch(Exceptionexception)
{
MessageBox.Show(exception.Message);
return;
}
finally
{
msdr.Close();
mycn.Close();
}
MessageBox.Show("添?
¨?
加¨?
成¨?
功|!
ê?
");
}
elseif(stuCount>=1&&txtSno.Text!
=""&&txtName.Text!
=""&&txtAge.Text!
=""&&txtClassName.Text!
=""&&txtPassword.Text!
=""&&txtId.Text!
="")
{
//这里需要关闭资源
MessageBox.Show("该学生的信息已存在");
}
else
{
//这里需要关闭资源
MessageBox.Show("请输入要添加的信息");
msdr.Close();
mycn.Close();
}
}
catch(Exceptiona)
{
Console.WriteLine(a.ToString());
}finally
{
txtSno.Text="";
txtName.Text="";
txtAge.Text="";
txtClassName.Text="";
txtPassword.Text="";
txtId.Text="";
}
}
}
}
主窗口程序AdminWindou.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespace学生成绩管理系统
{
publicpartialclassAdminWindow:
Form
{
publicAdminWindow()
{
InitializeComponent();
}
privatevoidAdminWindow_Load(objectsender,EventArgse)
{
}
privatevoid查询学生信息ToolStripMenuItem2_Click(objectsender,EventArgse)
{
newSearchStudent().ShowDialog();
}
privatevoid添加学生信息ToolStripMenuItem3_Click(objectsender,EventArgse)
{
newAddStudent().ShowDialog();
}
privatevoid修改学生信息ToolStripMenuItem3_Click(objectsender,EventArgse)
{
newUpdateStudent().ShowDialog();
}
privatevoid删除学生信息ToolStripMenuItem3_Click(objectsender,EventArgse)
{
newDeleteStudent().ShowDialog();
}
privatevoid查询课程信息ToolStripMenuItem2_Click(objectsender,EventArgse)
{
newSearchCourse().ShowDialog();
}
privatevoid添加课程信息ToolStripMenuItem3_Click(objectsender,EventArgse)
{
newAddCourse().ShowDialog();
}
privatevoid修改学生信息ToolStripMenuItem3_Click(objectsender,EventArgse)
{
newUpdateCourse().ShowDialog();
}
privatevoid删除课程信息ToolStripMenuItem3_Click(objectsender,EventArgse)
{
newDeleteCourse().ShowDialog();
}
privatevoid关于ToolStripMenuItem2_Click(objectsender,EventArgse)
{
newAbout().ShowDialog();
}
privatevoid退出系统ToolStripMenuItem2_Click(objectsender,EventArgse)
{
Application.Exit();
}
privatevoid排名ToolStripMenuItem1_Click(objectsender,EventArgse)
{
newCourseRank().ShowDialog();
}
privatevoid查询学生成绩ToolStripMenuItem2_Click(objectsender,EventArgse)
{
newScoreSearch().ShowDialog();
}
privatevoid各班平均分ToolStripMenuItem2_Click(objectsender,EventArgse)
{
newClassAvg().ShowDialog();
}
privatevoid各科平均分ToolStripMenuItem2_Click(objectsender,EventArgse)
{
newCourseAvg().ShowDialog();
}
}
}
班级平均成绩查询ClassAvg.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMySql.Data.MySqlClient;
namespace学生成绩管理系统
{
publicpartialclassClassAvg:
Form
{
publicClassAvg()
{
InitializeComponent();
}
privatevoidClassAvg_Load(objectsender,EventArgse)
{
}
privatevoidbtnsearch_Click(objectsender,EventArgse)
{
stringbjmc=txtbjmc.Text;
using(MySqlConnectionconn=newMySqlConnection(@"Database=student;DataSource=localhost;UserId=root;Password=k6smile20xq"))
{
conn.Open();
using(MySqlCommandcmd=conn.CreateCommand())
{
cmd.CommandText=@"selectavg(score)fromscoreinfi
whereclassname=@bjmc";
cmd.Parameters.Add(newMySqlParameter("bjmc",bjmc));
stringbjavg=Convert.ToString(cmd.ExecuteScalar());
txtbjavg.Text=bjavg;
}
}
}
privatevoidbtncancle_Click(objectsender,EventArgse)
{
this.Close();
}
}
}
单科平均成绩CourseAvg.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMySql.Data.MySqlClient;
namespace学生成绩管理系统
{
publicpartialclassCourseAvg:
Form
{
publicCourseAvg()
{
InitializeComponent();
}
privatevoidbtnquery_Click(objectsender,EventArgse)
{
stringcourseid=txtcourseid.Text;
stringcoursename=txtcoursename.Text;
using(MySqlConnectionconn=newMySqlConnection(@"Database=student;DataSource=localhost;UserId=root;Password=k6smile20xq"))
{
conn.Open();
using(MySqlCommandcmd=conn.CreateCommand())
{
cmd.CommandText=@"selectavg(score)asavgfromscoreinfi
wherecname=@coursename";
cmd.Parameters.Add(newMySqlParameter("coursename",coursename));
/*DataSetdataset=newDataSet();
MySqlDataAdapteradapter=newMySqlDataAdapter(cmd);
adapter.Fill(dataset);
DataTabletable=dataset.Tables[0];
for(inti=0;i
{
DataRowrow=table.Rows[i];
txtavg.Text=Convert.ToString(row["avg"]);
}*/
txtavg.Text=Convert.ToString(cmd.ExecuteScalar());
}
}
}
privatevoidCourseAvg_Load(objectsender,EventArgse)
{
}
privatevoidbtnexit_Click(objectsender,EventArgse)
{
this.Close();
}
}
}
单科成绩排名CourseRank.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMySql.Data.MySqlClient;
namespace学生成绩管理系统
{
publicpartialclassCourseRank:
Form
{
publicCourseRank()
{
InitializeComponent();
}
privatevoidForm1_Load(objectsender,EventArgse)
{
//this