我的GitHub网址
数据库技术
在本次设计中,用SQL Server建了六个表用来存储基本信息,分别为Tb_Student (学生信息表)、Tb_Course(课程信息表)、Tb_Course2(选修课程表)、Tb_ScoreSt(学生成绩表)、Tb_Slogin(学生登录表)、Tb_Admin(管理员信息表)。建立一个存储过程,Change_Student实现对学生表增加、更新信息、删除信息。建立一个触发器Slogin,监听学生信息表,如果有新的学生信息插入,则自动给学生登录表添加学生以及默认密码000.。一个视图,用于查看学生成绩(选修和非选修结合)。
C#技术
采用Visual Studio 2015新建项目Windows窗体应用程序,进行界面设计,本程序主要用到了Button、DataGridView、Label、Menustrip、TextBox、RadioButton。
引用using System.Data.SqlClient来进行数据库连接,要存取数据源内的属性,首先要建立程序和数据源之间的连接,利用Connection对象提供与数据源的连接。使用Command对象可以访问用于返回数据、修改数据,运行存储过程以及发送或检索参数信息的数据库命令,调用DataAdapter对象的Fill()方法填充DataSet对象等。
功能需求描述
(1)系统应符合班级管理制度的规定,满足班级日常管理的需要。
(2)基于现有成绩,可展示某学年某学期的成绩,以及对应的获得绩点。
(3)数据录入时,要保证数据的真实性以及合理性,不可出现无关数据。
(4)通过学校给于的综合测评计算方法,在数据库端实现相应的存储过程,方便每个学期结束时,统计德育分总和,品行表现分,学业成绩以及综合成绩和排名情况。
(5)按照奖学金分发的流程,实现自动对奖学金进行评定,减轻工作负担,评定后不合理处可以更改。
(6)操作简单,易懂,方便,能及时按需求进行增、删、改、查。
(7)实现后台的监控功能。
系统运行环境
系统在Windows10开发环境下,利用Visual Studio 2015 开发工具,并使用SQL Server2012作为数据库管理系统,来现班级管理系统的各个功能。
系统功能结构图及功能模块简介
主要表的结构
数据库名称为课设,共有6个表,只展示一个,完整项目可以到我的GitHub查看。
Tb_Student(学生信息表),用于保存学生的基本信息,
前端界面设计
详细界面设计在GitHub中可以看到
视图
用于学生查看个人成绩,由于选修课程表和非选修课程表表结构有差异,因此创建虚字段视图,用union all将数据连接起来
create view ScoreSearch
as
select S.Sno as SNO,C.Cno as CNO,Cname as CNAME,Cyear as CYEAR,Cterm as CTERM,Ccredit as CCREDIT,Cnature as CNATURE,Score as SCORE
from Tb_Course C,Tb_ScoreSt S
where C.Cno=S.Cno
union all
select C2.Sno_C AS SNO,C2.Cno as CNO,Cname as CNAME,Cyear as CYEAR,Cterm as CTERM ,Ccredit as CCREDIT , null as CNATURE, CScore as SCORE
from Tb_Course2 C2,Tb_Student S2
where C2.Sno_C=S2.Sno
存储过程
本系统的存储过程主要用于学生信息更新或者添加时候,避免前端设计时候的语句重复性,造成运行缓慢,因此写到数据库端
create procedure Insert_Student @Sno char(16),@Sname varchar(8),@Ssex char(2) ,@Saddress varchar(50),@Stell char(11),@Sqq char(16) ,@rtn int output
as
declare @tmpSno char(16),@tmpSname varchar(8),@tmpSsex char(2) ,@tmpSaddress varchar(50),@tmpStell char(11),@tmpSqq char(16)if exists(select * from Tb_Student where Sno=@Sno)if @@OPTIONS=0delete from Tb_Student where Sno=@Snoelse if @@OPTIONS=1begin select @tmpSno=Sno,@tmpSname=Sname,@tmpSsex=Ssex,@tmpSaddress=Saddress,@tmpStell=Stell,@tmpSqq=Sqqfrom Tb_Studentwhere Sno=@Snoif (@tmpSno=@Sno and @tmpSname=@Sname and @tmpSsex=@Ssex and @tmpSaddress=@Saddress and @tmpStell=@Stell and @tmpSqq=@Sqq )beginset @rtn=0endelse beginupdate Tb_Student set Sno=@Sno,Sname=@Sname,Ssex=@Ssex,Saddress=@Saddress,Stell=@Stell,Sqq=@Sqqwhere Sno=@Snoset @rtn=2endendelsebegininsert into Tb_Student(Sno,Sname,Ssex,Saddress,Stell,Sqq) values(@Sno,@Sname,@Ssex,@Saddress,@Stell ,@Sqq)set @rtn=1 --没有相同的数据,进行插入处理end
触发器
触发器用于管理员添加一个学生个人信息后,向学生登录信息表中添加账户姓名以及默认密码
create trigger Slogin
on Tb_Student
for insert
as
declare @sno char(16),@sname varchar(8);
begin select @sno=Sno,@sname=Sname from insertedinsert into Tb_SLogin values (@sno,@sname,'000')
end
登陆界面
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.Data.SqlClient;using System.Text.RegularExpressions;namespace WindowsFormsApplication1
{public partial class Login : Form
{
//静态变量传参,限定修改密码时候只能修改自己的static public string IDnew;static public string name;static public string pass;static public string welcome;public Login(){//Login.ID = null;InitializeComponent();}private void btnLogin_Click(object sender, EventArgs e){string strsql_query = "";if (IDBox.Text != string.Empty && passwdBox.Text != string.Empty){string ID2 = IDBox.Text.Trim().ToString();string passwd = passwdBox.Text.Trim().ToString();string strcon = "Data Source=(local);Initial Catalog=课设;Integrated Security=True";SqlConnection conn = new SqlConnection(strcon);conn.Open();if (stuButton.Checked){strsql_query = string.Format("select * from Tb_SLogin where Sno='{0}' and Spassword='{1}'", ID2, passwd);}else if (adminButton.Checked){strsql_query = string.Format("select * from Tb_Admin where id='{0}' and Password='{1}'", ID2, passwd);}SqlCommand cmd_query = new SqlCommand(strsql_query, conn);SqlDataReader dr = cmd_query.ExecuteReader();if (dr.HasRows){dr.Read();if (stuButton.Checked){Login.name = dr["Sname"].ToString();welcome = "欢迎 " + name + " 同学登录本系统";}else if (adminButton.Checked){Login.name = dr["id"].ToString();}dr.Close();if (stuButton.Checked){StudentPage stu = new StudentPage();pass = passwd;IDnew = ID2;MessageBox.Show(welcome);stu.Show();}else{adminPage main = new adminPage();main.Show();}Visible = false;}else{MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);passwdBox.Focus();}}else{MessageBox.Show("用户名或密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);}}private void reBtn_Click(object sender, EventArgs e){IDBox.Text = "";passwdBox.Text = "";}private void Login_Load(object sender, EventArgs e)//光标TAB换行{IDBox.TabIndex = 0;passwdBox.TabIndex = 1;}public void clear_passwd_ID(Login l){l.passwdBox.Text = "";l.IDBox.Text = "";}}
}
学生个人界面
namespace WindowsFormsApplication1
{public partial class StudentPage : Form{// bool One = false;Login login = new Login();SCoreSt scst;PasswordChange pc;public StudentPage(){InitializeComponent();this.IsMdiContainer = false;}public void CloseFrom(){}private void 注销ToolStripMenuItem_Click(object sender, EventArgs e){DialogResult r = MessageBox.Show("确定注销吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);if (r == DialogResult.Yes){Login login = new Login();login.Visible = true;login.clear_passwd_ID(login);Close();}}private void 退出ToolStripMenuItem_Click(object sender, EventArgs e){DialogResult r = MessageBox.Show("确定退出吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);if (r == DialogResult.Yes){Close();}}private void 成绩查询ToolStripMenuItem_Click(object sender, EventArgs e){this.CloseFrom();scst = new SCoreSt();scst.Show();}private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e){this.CloseFrom();pc = new PasswordChange();pc.Show(); }private void btnChange_Click(object sender, EventArgs e){int clickTimes;object tag = this.btnChange.Tag;if (tag == null){clickTimes = 0;}else{clickTimes = Convert.ToInt32(tag);}this.btnChange.Tag = ++clickTimes;if ((clickTimes % 2) == 1){string word = "保存";btnChange.Text = word.ToString();SaddressBox.ReadOnly = false;StellBox.ReadOnly = false;SqqBox.ReadOnly = false;}else{//SnoBox.ReadOnly = false;string a = SnoBox.Text.Trim().ToString();//SnameBox.ReadOnly = false;string b = SnameBox.Text.Trim().ToString();//SexBox.ReadOnly = false;string c = SexBox.Text.Trim().ToString();//Char[] cc = c.ToCharArray();//由于数据库端对于Ssex列添加check('男','女')的约束,导致存储时出现问题,于是将该约束删去。string d = SaddressBox.Text.Trim().ToString();string g = StellBox.Text.Trim().ToString();string f = SqqBox.Text.Trim().ToString();string sql = "Insert_Student";string strcon2 = "Data Source=(local);Initial Catalog=课设;Integrated Security=True";//存储过程调用及传参SqlConnection conStr = new SqlConnection(strcon2);SqlCommand INs = new SqlCommand(sql, conStr);INs.CommandType = CommandType.StoredProcedure;INs.Parameters.Add("@Sno", SqlDbType.Char).Value = a;INs.Parameters.Add("@Sname", SqlDbType.VarChar).Value = b;INs.Parameters.Add("@Ssex", SqlDbType.Char).Value = c;INs.Parameters.Add("@Saddress", SqlDbType.VarChar).Value = d;INs.Parameters.Add("@Stell", SqlDbType.Char).Value = g;INs.Parameters.Add("@Sqq", SqlDbType.Char).Value = f;INs.Parameters.Add("@rtn", SqlDbType.Int).Value = 2;conStr.Open();SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter(INs);DataTable DT = new DataTable();SqlDataAdapter1.Fill(DT);conStr.Close();MessageBox.Show("修改成功!");string word = "修改";btnChange.Text = word.ToString();SaddressBox.ReadOnly = true;StellBox.ReadOnly = true;SqqBox.ReadOnly = true;}}private void StudentPage_Load(object sender, EventArgs e){string Sno = Login.IDnew;//MessageBox.Show(Sno);//测试有没有传过来string strcon = "Data Source=(local);Initial Catalog=课设;Integrated Security=True";SqlConnection conn = new SqlConnection(strcon);conn.Open();SnoBox.Text = Login.IDnew;string strsql1 = string.Format("select Sname from Tb_Student where Sno='{0}'", Sno);SqlCommand SNAME = new SqlCommand(strsql1, conn);SnameBox.Text = SNAME.ExecuteScalar().ToString().Trim();string strsql2 = string.Format("select Ssex from Tb_Student where Sno='{0}'", Sno);SqlCommand SEX = new SqlCommand(strsql2, conn);SexBox.Text = SEX.ExecuteScalar().ToString().Trim();string strsql3 = string.Format("select Saddress from Tb_Student where Sno='{0}'", Sno);SqlCommand SAD = new SqlCommand(strsql3, conn);SaddressBox.Text = SAD.ExecuteScalar().ToString().Trim();string strsql4 = string.Format("select Stell from Tb_Student where Sno='{0}'", Sno);SqlCommand STEL = new SqlCommand(strsql4, conn);StellBox.Text = STEL.ExecuteScalar().ToString().Trim();string strsql5 = string.Format("select Sqq from Tb_Student where Sno='{0}'", Sno);SqlCommand SQQ = new SqlCommand(strsql5,conn);SqqBox.Text = SQQ.ExecuteScalar().ToString().Trim();conn.Close();}}
}