首页 学生学籍管理系统代码

学生学籍管理系统代码

举报
开通vip

学生学籍管理系统代码学生学籍管理系统代码 学生学籍管理系统详细代码 本文为学生学籍管理系统的各个模块效果图和详细代码; 登录模块: 登录模块代码: 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; n...

学生学籍管理系统代码
学生学籍管理系统代码 学生学籍管理系统详细代码 本文为学生学籍管理系统的各个模块效果图和详细代码; 登录模块: 登录模块代码: 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; namespace StuIFMS { public partial class Form1 : Form { public Color temp;//存储临时的按钮颜色 public Form1() { InitializeComponent(); } private void button3_Click(object sender, EventArgs e) { Application.Exit(); } public User CurrentUser; private void button2_Click(object sender, EventArgs e) { MessageBox.Show("学生/教师用自己的学号/教师编号登录~,如过 没有注册则点击“注册”进行注册~", "提示"); } private void button1_Click(object sender, EventArgs e) { bool UserExit = false, KeyRight = false; //声明上下文集合 DataClasses1DataContext myDataContext = new DataClasses1DataContext(); //把用户 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 里所有内容提取到User集合里 //排查输入错误 //用户名为空 if (textBox1.Text == "") MessageBox.Show("用户名不能为空~", "提示"); //用户名不为空 else { //密码为空 if (textBox2.Text == "") MessageBox.Show("密码不能为空", "提示"); //密码不为空 else { //学生身份登录 if (radioButton1.Checked==true) { var User = from user in myDataContext.UsersTable where user.Identity == "学生" select user; foreach (var stu in User) { if (stu.UerID == textBox1.Text) { UserExit = true; if (stu.Password == textBox2.Text) { KeyRight = true; CurrentUser = new User(textBox1.Text, textBox2.Text, radioButton1.Text); } } } if (UserExit == false) MessageBox.Show("用户名不存在~"); else { if (KeyRight == false) MessageBox.Show("密码错误~"); else { //MessageBox.Show("登录成功"); MainForm fm = new MainForm(CurrentUser); fm.FormClosed += new FormClosedEventHandler(fm_FormClosed); this.Hide(); fm.Initial(CurrentUser,0); fm.Show(); } } } //教师登录 else { var User1 = from teacher in myDataContext.UsersTable where teacher.Identity == "教师" select teacher; foreach (var teac in User1) { if (teac.UerID == textBox1.Text) { UserExit = true; if (teac.Password == textBox2.Text) { KeyRight = true; // 记录 混凝土 养护记录下载土方回填监理旁站记录免费下载集备记录下载集备记录下载集备记录下载 登录用户用户名身份信息 CurrentUser = new User(textBox1.Text, textBox2.Text, radioButton2.Text); } } } if (UserExit == false) MessageBox.Show("用户名不存在"); else { if (KeyRight == false) MessageBox.Show("密码错误"); else { //登录教师界面 //MessageBox.Show("登录成功~"); MainForm fm = new MainForm(CurrentUser); fm.Initial(CurrentUser,1); this.Hide(); fm.Show(); } } } } } } void fm_FormClosed(object sender, FormClosedEventArgs e) { this.Close(); } //注册按钮实现 private void button4_Click(object sender, EventArgs e) { LogForm fm = new LogForm(); fm.ShowDialog(); } //鼠标进去按钮事件 private void button1_MouseEnter(object sender, EventArgs e) { temp = button1.BackColor; button1.BackColor = System.Drawing.Color.Pink; } //鼠标离开按钮的事件 private void button1_MouseLeave(object sender, EventArgs e) { button1.BackColor = temp; } private void button3_MouseEnter(object sender, EventArgs e) { temp = button3.BackColor; button3.BackColor = System.Drawing.Color.Pink; } //鼠标离开事件 private void button3_MouseLeave(object sender, EventArgs e) { button3.BackColor = temp; } private void button4_MouseEnter(object sender, EventArgs e) { temp = button4.BackColor; button4.BackColor = Color.Orange; } private void button4_MouseLeave(object sender, EventArgs e) { button4.BackColor = temp; } private void button2_MouseEnter(object sender, EventArgs e) { temp = button2.BackColor; button2.BackColor = Color.Pink; } private void button2_MouseLeave(object sender, EventArgs e) { button2.BackColor = temp; } } } 注册模块代码: 代码: 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; namespace StuIFMS { public partial class LogForm : Form { public LogForm() { InitializeComponent(); } private void textBox1_TextChanged(object sender, EventArgs e) { checkBox1.Checked = false; textBox2.Enabled = false; bool isRegeisted=false;//帐号是否被注册标记 bool isexited=false;//帐号是否存在标记 //提取出用户数据表里所有用户资料 DataClasses1DataContext myDataContext = new DataClasses1DataContext(); var UsersQuery = from User in myDataContext.UsersTable select User; //文本数据发生变化时候,检查输入是否可以申请 //学生身份申请帐号 if (radioButton1.Checked == true) { //在用户表里检查该学生帐号是否被注册了 foreach (var user in UsersQuery) { //学生用户帐号已经被注册 if (user.UerID == textBox1.Text && user.Identity == radioButton1.Text) isRegeisted = true; } //检出该学号被注册了 if (isRegeisted == true) checkBox1.Text = "已注册的号码"; //MessageBox.Show("该学号已经被注册了~"); //帐号没有被注册,在学生表里检查该学号存在与否 else { DataClasses2DataContext myDataContext2 = new DataClasses2DataContext(); //从学生表里提取所有数据 var StuQuery = from Stud in myDataContext2.StudentsTable select Stud; foreach (var stu in StuQuery) { //学号被找到了,说明该学号存在且没有被注册,可 以注册该学号 if (stu.StudentN == textBox1.Text) isexited = true; } if (isexited == false) //MessageBox.Show("该学号不存在~"); checkBox1.Text = "不存在的学号"; else { //checkBox1打勾,说明可用 checkBox1.Checked = true; checkBox1.Text = ""; textBox2.Enabled = true; } } } //教师注册 else { //检查用户表看帐号有没有被注册 foreach (var user in UsersQuery) { //教师帐号已经被注册了 if (textBox1.Text == user.UerID && radioButton2.Text == user.Identity) isRegeisted = true; } //被注册的处理 if (isRegeisted == true) checkBox1.Text = "帐号被注册"; else { //未被注册的帐号,到教师信息表里查找该教师编号是否 存在 DataClasses3DataContext TeacherDataContext = new DataClasses3DataContext(); //取出教师信息表里的所有数据,放到集合里 var TeacherQuery = from teac in TeacherDataContext.TeachersTable select teac; foreach (var teacher in TeacherQuery) { //查找到存在这个教师编号 if (teacher.TeacherN == textBox1.Text) isexited = true; } //不存在这个编号的老师的处理 if (isexited == false) checkBox1.Text = "不存在的编号"; else { //checkBox1打勾,说明可用 checkBox1.Checked = true; checkBox1.Text = ""; textBox2.Enabled = true; } } } } //密码输入按钮 private void textBox2_TextChanged(object sender, EventArgs e) { textBox3.Enabled = false; checkBox2.Checked = false; //检查密码 规范 编程规范下载gsp规范下载钢格栅规范下载警徽规范下载建设厅规范下载 ,密码长度为6-16字符 if (textBox2.Text.ToString() == "") checkBox2.Text = "密码非空!"; else { if (textBox2.Text.Contains(" ")) checkBox2.Text = "密码不能包含空格"; else { if (textBox2.Text.Length > 16 || textBox2.Text.Length < 6) "; checkBox2.Text = "密码长度6-16~ else { //密码格式正确,checkedBox打勾且激活textBox3 checkBox2.Text = ""; checkBox2.Checked = true; textBox3.Enabled = true; } } } } //验证密码的文本改变事件 private void textBox3_TextChanged(object sender, EventArgs e) { button1.Enabled = false; checkBox3.Checked = false; //检验密码和验证密码是否相等 if (textBox2.Text != textBox3.Text) checkBox3.Text = "密码确认失败~"; //密码和确认密码相同,可以注册,激活注册按钮,同时把 checkBox3打勾 else { button1.Enabled = true; checkBox3.Checked = true; checkBox3.Text = ""; } } //帮助按钮实现 private void button2_Click(object sender, EventArgs e) { MessageBox.Show("师生只能通过自己的唯一学号/教师编号注册, "); 如果发现自己帐号被非法注册,请联系管理员~", "注册帮助 } //注册按钮的实现 private void button1_Click(object sender, EventArgs e) { //检测数据填写状态,确定是否有了注册需要的足够满足格式的数 据 if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked) { //满足条件,将数据写到数据库的UsersTable里 DataClasses1DataContext myDataContext = new DataClasses1DataContext(); //分注册身份进行建立不同表格行 UsersTable temptable = new UsersTable { UerID = textBox1.Text, Password = textBox2.Text }; if (radioButton1.Checked) temptable.Identity = radioButton1.Text; else temptable.Identity = radioButton2.Text; try { myDataContext.UsersTable.InsertOnSubmit(temptable); myDataContext.SubmitChanges(); //button1.Enabled = false; MessageBox.Show("注册成功~请牢记你的密码~"); //清空各个内容 textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; checkBox1.Checked = false; checkBox1.Text = ""; checkBox2.Checked = false; checkBox3.Checked = false; checkBox2.Text = ""; checkBox3.Text = ""; } catch (Exception ex) { MessageBox.Show("异常" + ex.Message); } } } //屏蔽掉点击事件,使得点击无效 private void checkBox1_Click(object sender, EventArgs e) { if (checkBox1.Checked) checkBox1.Checked = false; else checkBox1.Checked = true; } //屏蔽掉点击事件,使得点击无效 private void checkBox2_Click(object sender, EventArgs e) { if (checkBox2.Checked) checkBox2.Checked = false; else checkBox2.Checked = true; } //屏蔽掉点击事件,使得点击无效 private void checkBox3_Click(object sender, EventArgs e) { if (checkBox3.Checked) checkBox3.Checked = false; else checkBox3.Checked = true; } private void label2_Click(object sender, EventArgs e) { } private void label1_Click(object sender, EventArgs e) { } //屏蔽掉点击事件,使得点击无效 private void radioButton1_Click(object sender, EventArgs e) { //检测学生帐号是否被注册 checkBox1.Checked = false; textBox2.Enabled = false; bool isRegeisted = false;//帐号是否被注册标记 bool isexited = false;//帐号是否存在标记 //提取出用户数据表里所有用户资料 DataClasses1DataContext myDataContext = new DataClasses1DataContext(); var UsersQuery = from User in myDataContext.UsersTable select User; //在用户表里检查该学生帐号是否被注册了 foreach (var user in UsersQuery) { //学生用户帐号已经被注册 ") if (user.UerID == textBox1.Text && user.Identity =="学生 isRegeisted = true; } //检出该学号被注册了 if (isRegeisted == true) checkBox1.Text = "已注册的号码"; //MessageBox.Show("该学号已经被注册了~"); //帐号没有被注册,在学生表里检查该学号存在与否 else { DataClasses2DataContext myDataContext2 = new DataClasses2DataContext(); //从学生表里提取所有数据 var StuQuery = from Stud in myDataContext2.StudentsTable select Stud; foreach (var stu in StuQuery) { //学号被找到了,说明该学号存在且没有被注册,可以注 册该学号 if (stu.StudentN == textBox1.Text) isexited = true; } if (isexited == false) //MessageBox.Show("该学号不存在~"); checkBox1.Text = "不存在的学号"; else { //checkBox1打勾,说明可用 checkBox1.Checked = true; checkBox1.Text = ""; textBox2.Enabled = true; } } } //屏蔽掉点击事件,使得点击无效 private void radioButton2_Click(object sender, EventArgs e) { checkBox1.Checked = false; textBox2.Enabled = false; bool isRegeisted = false;//帐号是否被注册标记 bool isexited = false;//帐号是否存在标记 //提取出用户数据表里所有用户资料 DataClasses1DataContext myDataContext = new DataClasses1DataContext(); var UsersQuery = from User in myDataContext.UsersTable select User; //教师注册 //检查用户表看帐号有没有被注册 foreach (var user in UsersQuery) { //教师帐号已经被注册了 if (textBox1.Text == user.UerID && user.Identity=="教师") isRegeisted = true; } //被注册的处理 if (isRegeisted == true) checkBox1.Text = "帐号被注册"; else { //未被注册的帐号,到教师信息表里查找该教师编号是否 存在 DataClasses3DataContext TeacherDataContext = new DataClasses3DataContext(); //取出教师信息表里的所有数据,放到集合里 var TeacherQuery = from teac in TeacherDataContext.TeachersTable select teac; foreach (var teacher in TeacherQuery) { //查找到存在这个教师编号 if (teacher.TeacherN == textBox1.Text) isexited = true; } //不存在这个编号的老师的处理 if (isexited == false) checkBox1.Text = "不存在的编号"; else { //checkBox1打勾,说明可用 checkBox1.Checked = true; checkBox1.Text = ""; textBox2.Enabled = true; } } } //检测学生帐号输入是否正确 private void radioButton1_CheckedChanged(object sender, EventArgs e) { } //检测教师帐号是否存在 private void radioButton2_CheckedChanged(object sender, EventArgs e) { } } } 主界面模块: 教师登录效果 学生登录效果: 详细代码: 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; namespace StuIFMS { public partial class MainForm : Form { private User currentuser; public MainForm(User current) { InitializeComponent(); currentuser = current; } //初始化窗体 方法 快递客服问题件处理详细方法山木方法pdf计算方法pdf华与华方法下载八字理论方法下载 ,为不同身份用户提供不同功能的主界面,同时在窗体 里显示用户名和身份 public bool Initial(User currentuser,int i) { bool result = true; if(i==1) { //教师用户登录 //显示用户信息 label2.Text=currentuser.GetUserID(); label4.Text=currentuser.GetIdentity(); //初始化menustrip 学生信息录入ToolStripMenuItem.Enabled=true; 学生信息修改删除ToolStripMenuItem.Enabled=true; 学生成绩录入ToolStripMenuItem.Enabled=true; 学生成绩修改删除ToolStripMenuItem.Enabled=true; 计算总分和排名ToolStripMenuItem.Enabled=true; 添加帐号ToolStripMenuItem.Enabled=true; 考试管理ToolStripMenuItem.Enabled = true; if (currentuser.GetUserID() == "SuperMan") { 删除帐号ToolStripMenuItem.Enabled = true; 帐号检测ToolStripMenuItem.Enabled = true; } } else { //显示学生用户信息 label2.Text=currentuser.GetUserID(); label4.Text=currentuser.GetIdentity(); } return result; } //修改帐号密码的功能实现 private void 修改帐号ToolStripMenuItem_Click(object sender, EventArgs e) { //User current = new User(label2.Text, "", label4.Text); ChangePForm Changeform = new ChangePForm(currentuser); Changeform.ShowDialog(); } private void 添加帐号ToolStripMenuItem_Click(object sender, EventArgs e) { AddUserForm fm = new AddUserForm(); fm.ShowDialog(); } private void 删除帐号ToolStripMenuItem_Click(object sender, EventArgs e) { DeleUserForm fm = new DeleUserForm(); fm.ShowDialog(); } private void 帐号检测ToolStripMenuItem_Click(object sender, EventArgs e) { CheckForm fm = new CheckForm(); fm.ShowDialog(); } private void 学生信息查询ToolStripMenuItem_Click(object sender, EventArgs e) { CheckStudentsForm fm = new CheckStudentsForm(currentuser); fm.ShowDialog(); } private void 学生信息录入ToolStripMenuItem_Click(object sender, EventArgs e) { StudentIFForm fm = new StudentIFForm(); fm.ShowDialog(); } private void 学生信息修改删除ToolStripMenuItem_Click(object sender, EventArgs e) { StuChanForm fm = new StuChanForm(); fm.ShowDialog(); } private void 学生成绩查询ToolStripMenuItem_Click(object sender, EventArgs e) { ScoreCheckForm fm = new ScoreCheckForm(currentuser); fm.ShowDialog(); } private void 学生成绩录入ToolStripMenuItem_Click(object sender, EventArgs e) { ScoreInForm fm = new ScoreInForm(); fm.ShowDialog(); } private void 学生成绩修改删除ToolStripMenuItem_Click(object sender, EventArgs e) { ScorChanForm fm = new ScorChanForm(); fm.ShowDialog(); } private void 计算总分和排名ToolStripMenuItem_Click(object sender, EventArgs e) { //计算总分 TotallForm fm = new TotallForm(); fm.ShowDialog(); } private void 考试管理ToolStripMenuItem_Click(object sender, EventArgs e) { //考试管理模块实现 TestForm fm = new TestForm(); fm.ShowDialog(); } } } 学生信息查询模块: 学生登录效果截图: (该学生信息未录入) 教师登录效果截图: 代码: 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; namespace StuIFMS { public partial class CheckStudentsForm : Form { //传递进来用户信息 private User currentuser; public CheckStudentsForm(User myuser) { InitializeComponent(); currentuser = myuser; if (currentuser.GetIdentity() == "学生") { button2.Visible = false; } else { button1.Visible = false; } } //查询按钮的实现 private void button1_Click(object sender, EventArgs e) { DataClasses2DataContext mydata = new DataClasses2DataContext(); var myself=from user in mydata.StudentsTable.ToArray() where user.StudentN == currentuser.GetUserID() select user; dataGridView1.DataSource = myself.ToArray(); dataGridView1.Columns[0].Visible = false; } //查询全部按钮的实现 private void button2_Click(object sender, EventArgs e) { DataClasses2DataContext mydata = new DataClasses2DataContext(); dataGridView1.DataSource = mydata.StudentsTable; dataGridView1.Columns[0].Visible = false; } } } 学生信息录入模块: 代码: 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; namespace StuIFMS { public partial class StudentIFForm : Form { public StudentIFForm() { InitializeComponent(); } //输入学号时候事件 private void textBox1_Leave(object sender, EventArgs e) { checkBox1.Text = ""; checkBox1.Checked = false; if (textBox1.Text == "") //没有输入或者输入后删除了 checkBox1.Text = "请输入输入学号"; else { //文本框里有内容 //内容为数字 if (textBox1.Text.All(x => x >= '0' && x <= '9')) { //判断是否是11位数 if (textBox1.Text.Length == 11) { //满足格式要求,查询学生表进一步判断是否存在的 学号 DataClasses2DataContext mydata = new DataClasses2DataContext(); var Stu = from stu in mydata.StudentsTable.ToArray() where stu.StudentN == textBox1.Text select stu; if (Stu.Count()==0) { checkBox1.Checked = true; checkBox1.Text = ""; } else { checkBox1.Text = "已存在学号"; ; } } else checkBox1.Text = "学号11位"; } //文本含有非数字 else checkBox1.Text = "学号为数字"; } } //姓名格式判定 private void textBox2_Leave(object sender, EventArgs e) { checkBox2.Checked = false; checkBox2.Text = ""; //没有输入姓名 if (textBox2.Text == "") checkBox2.Text = "请输入姓名"; //输入了,判段 else { if (textBox2.Text.IndexOfAny("~!@#$%^&*()-=_+/*-+.<>,./?[]{}\\';:|".ToArray())>=0) checkBox2.Text = "非法输入!"; else { //判断长度 if (textBox2.Text.Length > 6) checkBox2.Text = "长度<1-6>"; else { checkBox2.Text = ""; checkBox2.Checked = true; } } } } private void comboBox1_Leave(object sender, EventArgs e) { } //屏蔽鼠标点击事件 private void checkBox1_Click(object sender, EventArgs e) { if (checkBox1.Checked) checkBox1.Checked = false; else checkBox1.Checked = true; } private void checkBox2_Click(object sender, EventArgs e) { if (checkBox2.Checked) checkBox2.Checked = false; else checkBox2.Checked = true; } private void checkBox3_Click(object sender, EventArgs e) { if (checkBox3.Checked) checkBox3.Checked = false; else checkBox3.Checked = true; } private void checkBox4_Click(object sender, EventArgs e) { if (checkBox4.Checked) checkBox4.Checked = false; else checkBox4.Checked = true; } private void button1_Click(object sender, EventArgs e) { //添加按钮的实现 //检测checkBox状态 if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked && checkBox4.Checked) { //条件满足,可以添加 StudentsTable temp = new StudentsTable { StudentN = textBox1.Text, Name = textBox2.Text, Adress = textBox3.Text, ClassN = Convert.ToInt32(comboBox1.SelectedItem.ToString()) }; if (radioButton1.Checked) temp.Sex = "男"; else temp.Sex = "女"; //添加学生信息 DataClasses2DataContext mydata = new DataClasses2DataContext(); mydata.StudentsTable.InsertOnSubmit(temp); if (MessageBox.Show("确认要添加该学生到数据库吗,", "提示 ", MessageBoxButtons.OKCancel) == DialogResult.OK) { mydata.SubmitChanges(); MessageBox.Show("添加成功~","提示"); //清空各个数据,为下次录入准备 textBox1.Text = ""; textBox2.Text = ""; comboBox1.SelectedItem = null; textBox3.Text = ""; checkBox1.Checked = false; checkBox2.Checked = false; checkBox3.Checked = false; checkBox4.Checked = false; checkBox1.Text = ""; checkBox2.Text = ""; checkBox3.Text = ""; checkBox4.Text = ""; } } else { //条件不足,不能添加 MessageBox.Show("条件不足,不能添加~", "提示"); } } private void button2_Click(object sender, EventArgs e) { //取消按钮实现 this.Close(); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { //检测是否选择班级,班级默认为1-6班 checkBox4.Text = ""; checkBox4.Checked = false; if (comboBox1.SelectedItem == null) //没有选择 checkBox4.Text = "选择班级"; else { checkBox4.Checked = true; checkBox4.Text = ""; } } private void textBox3_Leave(object sender, EventArgs e) { //检测地址是否有错误 checkBox3.Checked = false; checkBox3.Text = ""; if (textBox3.Text == "") checkBox3.Text = "请输入地址"; else { //检测地址合法性 if (textBox3.Text.IndexOfAny("~@!#$%^&*()_-=+-*/+.".ToArray()) >= 0) checkBox3.Text = "地址含非法字符"; else { checkBox3.Text = ""; checkBox3.Checked = true; } } } //改变性别事件 private void radioButton1_Click(object sender, EventArgs e) { //检测学号是否存在 checkBox1.Text = ""; checkBox1.Checked = false; if (textBox1.Text == "") //没有输入或者输入后删除了 checkBox1.Text = "请输入输入学号"; else { //文本框里有内容 //内容为数字 if (textBox1.Text.All(x => x >= '0' && x <= '9')) { //判断是否是11位数 if (textBox1.Text.Length == 11) { //满足格式要求,查询学生表进一步判断是否存在的 学号 DataClasses2DataContext mydata = new DataClasses2DataContext(); var Stu = from stu in mydata.StudentsTable.ToArray() where stu.StudentN == textBox1.Text select stu; if (Stu.Count() == 0) { checkBox1.Checked = true; checkBox1.Text = ""; } else { "; checkBox1.Text = "已存在学号 } } else checkBox1.Text = "学号11位"; } //文本含有非数字 else checkBox1.Text = "学号为数字"; } } private void radioButton2_CheckedChanged(object sender, EventArgs e) { //检测学号是否存在 checkBox1.Text = ""; checkBox1.Checked = false; if (textBox1.Text == "") //没有输入或者输入后删除了 checkBox1.Text = "请输入输入学号"; else { //文本框里有内容 //内容为数字 if (textBox1.Text.All(x => x >= '0' && x <= '9')) { //判断是否是11位数 if (textBox1.Text.Length == 11) { //满足格式要求,查询学生表进一步判断是否存在的 学号 DataClasses2DataContext mydata = new DataClasses2DataContext(); var Stu = from stu in mydata.StudentsTable.ToArray() where stu.StudentN == textBox1.Text select stu; if (Stu.Count() == 0) { checkBox1.Checked = true; checkBox1.Text = ""; } else { checkBox1.Text = "已存在学号"; } } else checkBox1.Text = "学号11位"; } //文本含有非数字 else checkBox1.Text = "学号为数字"; } } } } 学生信息修改删除模块: 代码: 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; namespace StuIFMS { public partial class StuChanForm : Form { public StuChanForm() { InitializeComponent(); } public void refresh() { comboBox1.Items.Clear(); comboBox1.Text = ""; textBox1.Text = ""; textBox2.Text = ""; comboBox2.Text = ""; var StuQuery = from stu in mydata.StudentsTable select stu; comboBox1.Sorted = true; foreach (var stu in StuQuery) { //添加用户名列表到comboBox1 comboBox1.Items.Add(stu.StudentN); } } DataClasses2DataContext mydata = new DataClasses2DataContext(); private void StuChanForm_Load(object sender, EventArgs e) { refresh(); } private void StuChanForm_FormClosing(object sender, FormClosingEventArgs e) { } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { //选定改变时候更新下面相应的信息 if (comboBox1.SelectedItem != null) { //有选择的时候,显示学生信息 var StuQuery = from stu in mydata.StudentsTable.ToArray() select stu; foreach (var stu in StuQuery) { if (stu.StudentN == comboBox1.SelectedItem.ToString()) //找到该学生,显示信息 { textBox1.Text = stu.Name; textBox2.Text = stu.Adress; if (stu.Sex == "男") radioButton1.Checked = true; else radioButton2.Checked = true; comboBox2.SelectedIndex = stu.ClassN - 1; comboBox2.Text = comboBox2.SelectedItem.ToString(); } } } } private void button1_Click(object sender, EventArgs e) { //删除按钮的实现,从数据库中删除选定学号的学生 if (comboBox1.Items == null) MessageBox.Show("没有可删除选择~"); else { if (comboBox1.SelectedItem == null) MessageBox.Show("没有选择~"); else { var StuQuery = from stu in mydata.StudentsTable.ToArray() where stu.StudentN == comboBox1.SelectedItem.ToString() select stu; mydata.StudentsTable.DeleteOnSubmit(StuQuery.ElementAt(0)); if (MessageBox.Show("删除数据不可恢复,继续", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) //保存结果 mydata.SubmitChanges(); //刷新内容 refresh(); } } } private void button2_Click(object sender, EventArgs e) { //修改按钮实现 if (comboBox1.Items == null) MessageBox.Show("数据库里没有内容!", "提示"); else { if (comboBox1.SelectedItem == null) MessageBox.Show("没有选择学生!"); else { //选择学生了,提取修改内容,找到学生表里的指定编号 的学生,将数据修改了 if (textBox1.Text == "" || textBox2.Text == "" || comboBox2.SelectedItem == null) //信息不完整 MessageBox.Show("信息不完整,请填写完整再修改~ "); else { //各个信息不为空,检查姓名,地址格式 if (textBox1.Text.IndexOfAny(" ~!@#$%^&*()_-+=/*-+,./;'[]\\<>?:\"|".ToArray()) >= 0) MessageBox.Show("姓名中包含非法字符~"); else { if (textBox2.Text.IndexOfAny("~!@#$%^&*()_+-=[]{}\\|:\",./;<>?'".ToArray()) >= 0) MessageBox.Show("地址中有非法字符~"); else { //姓名地址合法,修改数据库学生表 var StuQuery = from stu in mydata.StudentsTable.ToArray() where stu.StudentN == comboBox1.SelectedItem.ToString() select stu; StuQuery.ElementAt(0).Name = textBox1.Text; StuQuery.ElementAt(0).Adress = textBox2.Text; if (radioButton1.Checked) StuQuery.ElementAt(0).Sex = "男"; else StuQuery.ElementAt(0).Sex = "女"; StuQuery.ElementAt(0).ClassN = Convert.ToInt32(comboBox2.SelectedItem.ToString()); //保存修改 if (MessageBox.Show("修改数据将写进数据 库,确定修改,", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) mydata.SubmitChanges(); //刷新数据 refresh(); } } } } } } } } 成绩查询模块: 代码: 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; namespace StuIFMS { public partial class ScoreCheckForm : Form { private User current; public ScoreCheckForm(User curr) { current = curr; InitializeComponent(); } private void ScoreCheckForm_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { //查询按钮的实现,学生只能查到自己的成绩,教师能查到所有人的成绩 DataClasses4DataContext mydata = new DataClasses4DataContext(); //教师查询所有的学生成绩 var ScoreQuery = from stu in mydata.ScoreTable select stu; if (ScoreQuery.Count() > 0) { //先把数据源给它才能设置 dataGridView1.DataSource = ScoreQuery; dataGridView1.Columns[0].Visible = false; dataGridView1.Show(); } else { MessageBox.Show("抱歉~数据还没有录入"); } } } } 成绩录入模块: 代码: 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; namespace StuIFMS { public partial class ScoreInForm : Form { public ScoreInForm() { InitializeComponent(); textBox1.Select(); } private void button2_Click(object sender, EventArgs e) { //取消按钮的实现 this.Close(); } private void textBox1_Leave(object sender, EventArgs e) { bool isexist = false; label3.Text = ""; //输入文本检测 if (textBox1.Text == "") checkBox1.Text = "输入学号"; else { if (textBox1.Text.All(x => x >= '0' && x <= '9')) //输入为数字 { if (textBox1.Text.Length != 11) checkBox1.Text = "长度错误"; else { //查表,检测学生是否存在 DataClasses2DataContext mydata = new DataClasses2DataContext(); var StuQuery = from stu in mydata.StudentsTable select stu; foreach (var stu in StuQuery) { if (stu.StudentN == textBox1.Text) { isexist = true; label3.Text = stu.Name; comboBox1.Enabled = true; } } //根据学生存在与否更新消息 if (isexist) { checkBox1.Checked = true; checkBox1.Text = ""; } else checkBox1.Text = "学号不存在"; } } else { checkBox1.Text = "格式错误~"; } } } private void comboBox1_Leave(object sender, EventArgs e) { bool isexist = false; checkBox2.Checked = false; checkBox2.Text = ""; if (comboBox1.SelectedItem == null) checkBox2.Text = "请选择"; else { if (checkBox1.Checked) { //如果学号已经填写的话,检测该学号学生该门科目有没 有录入 DataClasses4DataContext mydata = new DataClasses4DataContext(); var StuQuery = from stu in mydata.ScoreTable.ToArray() select stu; foreach (var stu in StuQuery) { if (stu.StudentN == textBox1.Text) isexist = true; } if (isexist) { foreach (var stu in StuQuery) { if (stu.StudentN == textBox1.Text) { //找到该学生,查看其该门课程成绩是否录 入 if (comboBox1.SelectedItem.ToString() == "组 成原理") { if (stu.组成原理 != null) { checkBox2.Text = "成绩已存在"; } else { checkBox2.Checked = true; checkBox2.Text = ""; } } if (comboBox1.SelectedItem.ToString() == "软 件工程") { if (stu.软件工程 != null) checkBox2.Text = "成绩已存在"; else { checkBox2.Checked = true; checkBox2.Text = ""; } } if (comboBox1.SelectedItem.ToString() == "英 语") { if (stu.英语 != null) checkBox2.Text = "成绩已存在"; else { checkBox2.Text = ""; checkBox2.Checked = true; } } if (comboBox1.SelectedItem.ToString() == "操 作系统") { if (stu.操作系统 != null) checkBox2.Text = "成绩已存在"; else { checkBox2.Text = ""; checkBox2.Checked = true; } } if (comboBox1.SelectedItem.ToString() == "毛概") { if (stu.毛概 != null) checkBox2.Text = "成绩已存在"; else { checkBox2.Text = ""; checkBox2.Checked = true; } } } } } else { //该学生学号在学生表里存在,但是没有出现在成绩表里,新建一条记录 checkBox2.Text = ""; checkBox2.Checked = true; } } else checkBox2.Text = "请输入学号~"; } } private void textBox2_Leave(object sender, EventArgs e) { checkBox3.Text = ""; checkBox3.Checked = false; //判断成绩输入是否符合格式需求 if (textBox2.Text == "") checkBox3.Text = "输入成绩"; else { if (textBox2.Text.All(x => x >= '0' && x <= '9')) { if (textBox2.Text.Length > 0 && textBox2.Text.Length <= 3) { //长度符合1-3位数,判断大小是否是0-100 if (Convert.ToInt32(textBox2.Text) >= 0 && Convert.ToInt32(textBox2.Text) <= 100) { //分数输入正确,可以录入 button1.Enabled = true; checkBox3.Text = ""; checkBox3.Checked = true; } else { checkBox3.Text = "分数<0-100>"; } } else { checkBox3.Text = "长度<1-3>"; } } else { checkBox3.Text = "格式错误"; } } } private void checkBox1_Click(object sender, EventArgs e) { if (checkBox1.Checked) checkBox1.Checked = false; else checkBox1.Checked = true; } private void checkBox2_Click(object sender, EventArgs e) { if (checkBox2.Checked) checkBox2.Checked = false; else checkBox2.Checked = true; } private void checkBox3_Click(object sender, EventArgs e) { if (checkBox3.Checked) checkBox3.Checked = false; else checkBox3.Checked = true; } private void button1_Click(object sender, EventArgs e) { bool isexist = false; //录入按钮的实现 //检查标志信息,查看是否可以录入 DataClasses4DataContext mydata = new DataClasses4DataContext(); if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked) { var ScoreQuery = from scor in mydata.ScoreTable select scor; foreach (var scor in ScoreQuery) { if (scor.StudentN == textBox1.Text) { //有该学生记录,不需要增加一条记录 isexist = true; if (comboBox1.SelectedItem.ToString() == "组成原理") { scor.组成原理 = Convert.ToInt32(textBox2.Text); } if (comboBox1.SelectedItem.ToString() == "软件工程") { scor.软件工程 = Convert.ToInt32(textBox2.Text); } if (comboBox1.SelectedItem.ToString() == "英语") { scor.英语 = Convert.ToInt32(textBox2.Text); } if (comboBox1.SelectedItem.ToString() == "操作系统") { scor.操作系统= Convert.ToInt32(textBox2.Text); } ") if (comboBox1.SelectedItem.ToString() == "毛概 { scor.毛概 = Convert.ToInt32(textBox2.Text); } if (MessageBox.Show("确认录入该分数吗,", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { mydata.SubmitChanges(); } } } if (isexist == false) { //向表里增加一条记录 ScoreTable scor = new ScoreTable { StudentN = textBox1.Text, Name = label3.Text }; if (comboBox1.SelectedItem.ToString() == "组成原理") { scor.组成原理 = Convert.ToInt32(textBox2.Text); } if (comboBox1.SelectedItem.ToString() == "软件工程") { scor.软件工程 = Convert.ToInt32(textBox2.Text); } if (comboBox1.SelectedItem.ToString() == "英语") { scor.英语 = Convert.ToInt32(textBox2.Text); } if (comboBox1.SelectedItem.ToString() == "操作系统") { scor.操作系统 = Convert.ToInt32(textBox2.Text); } if (comboBox1.SelectedItem.ToString() == "毛概") { scor.毛概 = Convert.ToInt32(textBox2.Text); } mydata.ScoreTable.InsertOnSubmit(scor); if (MessageBox.Show("您确定要录入吗,", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { mydata.SubmitChanges(); } } } else { //有信息不完整 MessageBox.Show("信息不完整~请完整后再录入~", "提示"); } } } } 成绩修改模块: 代码: 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; namespace StuIFMS { public partial class ScorChanForm : Form { public ScorChanForm() { InitializeComponent(); } //学号输入检测 private void textBox1_Leave(object sender, EventArgs e) { bool isexist = false; label3.Text = ""; //输入文本检测 if (textBox1.Text == "") checkBox1.Text = "输入学号"; else { if (textBox1.Text.All(x => x >= '0' && x <= '9')) //输入为数字 { if (textBox1.Text.Length != 11) checkBox1.Text = "长度错误"; else { //查表,检测学生是否存在 DataClasses4DataContext mydata = new DataClasses4DataContext(); var StuQuery = from stu in mydata.ScoreTable select stu; foreach (var stu in StuQuery) { if (stu.StudentN == textBox1.Text) { isexist = true; label3.Text = stu.Name; comboBox1.Enabled = true; } } //根据学生存在与否更新消息 if (isexist) { checkBox1.Checked = true; checkBox1.Text = ""; } else "; checkBox1.Text = "学号不存在 } } else { checkBox1.Text = "格式错误~"; } } } private void comboBox1_Leave(object sender, EventArgs e) { } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { //选择科目事件 //bool isexist = false; checkBox2.Checked = false; checkBox2.Text = ""; textBox2.Text = ""; if (comboBox1.SelectedItem == null) checkBox2.Text = "请选择"; else { //选择了科目,检测是否满足删除修改的条件 if (checkBox1.Checked) { //学号已经选好了 DataClasses4DataContext mydata = new DataClasses4DataContext(); var ScorQuery = from sc in mydata.ScoreTable select sc; foreach (var stu in ScorQuery) { if (stu.StudentN == textBox1.Text) { //找到该学生,查找选定成绩是否存在,存在的话显示成绩 if (comboBox1.SelectedItem.ToString() == "组成原理") { if (stu.组成原理 != null) { textBox2.Text = stu.组成原理.ToString(); checkBox2.Checked = true; checkBox2.Text = ""; } else { checkBox2.Text = "成绩不存在"; } } if (comboBox1.SelectedItem.ToString() == "软件工程") { if (stu.软件工程 != null) { textBox2.Text = stu.软件工程.ToString(); checkBox2.Checked = true; checkBox2.Text = ""; } else { checkBox2.Text = "成绩不存在"; } } if (comboBox1.SelectedItem.ToString() == "英语") { if (stu.英语 != null) { textBox2.Text = stu.英语.ToString(); checkBox2.Checked = true; checkBox2.Text = ""; } else { checkBox2.Text = "成绩不存在"; } } if (comboBox1.SelectedItem.ToString() == "操作系统") { if (stu.操作系统 != null) { textBox2.Text = stu.操作系统.ToString(); checkBox2.Checked = true; checkBox2.Text = ""; } else { checkBox2.Text = "成绩不存在"; } } if (comboBox1.SelectedItem.ToString() == "毛概") { if (stu.毛概 != null) { textBox2.Text = stu.毛概.ToString(); checkBox2.Checked = true; checkBox2.Text = ""; } else { checkBox2.Text = "成绩不存在"; } } } } } } } private void textBox2_TextChanged(object sender, EventArgs e) { checkBox3.Text = ""; checkBox3.Checked = false; //判断成绩输入是否符合格式需求 if (textBox2.Text == "") checkBox3.Text = "输入成绩"; else { if (textBox2.Text.All(x => x >= '0' && x <= '9')) { if (textBox2.Text.Length > 0 && textBox2.Text.Length <= 3) { //长度符合1-3位数,判断大小是否是0-100 if (Convert.ToInt32(textBox2.Text) >= 0 && Convert.ToInt32(textBox2.Text) <= 100) { //分数输入正确,可以录入 button1.Enabled = true; checkBox3.Text = ""; checkBox3.Checked = true; } else { checkBox3.Text = "分数<0-100>"; } } else { checkBox3.Text = "长度<1-3>"; } } else { checkBox3.Text = "格式错误"; } } } private void checkBox1_Click(object sender, EventArgs e) { if (checkBox1.Checked) checkBox1.Checked = false; else checkBox1.Checked = true; } private void checkBox2_Click(object sender, EventArgs e) { if (checkBox2.Checked) checkBox2.Checked = false; else checkBox2.Checked = true; } private void checkBox3_Click(object sender, EventArgs e) { if (checkBox3.Checked) checkBox3.Checked = false; else checkBox3.Checked = true; } private void button1_Click(object sender, EventArgs e) { //修改按钮的实现 if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked) { //各项条件满足,可以修改 DataClasses4DataContext mydata = new DataClasses4DataContext(); var ScorQuery = from sc in mydata.ScoreTable select sc; foreach (var stu in ScorQuery) { //找到该学生 if (stu.StudentN == textBox1.Text) { //找到该项目 if (stu.StudentN == textBox1.Text) { //找到该学生,查找选定成绩是否存在,存在的话 显示成绩 if (comboBox1.SelectedItem.ToString() == "组成原 理") { stu.组成原理 = Convert.ToInt32(textBox2.Text); } if (comboBox1.SelectedItem.ToString() == "软件工 程") { stu.软件工程 = Convert.ToInt32(textBox2.Text); } if (comboBox1.SelectedItem.ToString() == "英语") { stu.英语 = Convert.ToInt32(textBox2.Text); } if (comboBox1.SelectedItem.ToString() == "操作系 统") { stu.操作系统 = Convert.ToInt32(textBox2.Text); } if (comboBox1.SelectedItem.ToString() == "毛概") { stu.毛概 = Convert.ToInt32(textBox2.Text); } if (MessageBox.Show("确认修改该学生的成绩, ","提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { mydata.SubmitChanges(); } } } } } else { MessageBox.Show("信息不完整,无法修改"); } } private void button2_Click(object sender, EventArgs e) { //删除按钮的实现 if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked) { //各项条件满足,可以修改 DataClasses4DataContext mydata = new DataClasses4DataContext(); var ScorQuery = from sc in mydata.ScoreTable select sc; foreach (var stu in ScorQuery) { //找到该学生 if (stu.StudentN == textBox1.Text) { //找到该项目 if (stu.StudentN == textBox1.Text) { //找到该学生,查找选定成绩是否存在,存在的话 显示成绩 if (comboBox1.SelectedItem.ToString() == "组成原理") { stu.总分 -= stu.组成原理; stu.组成原理 = null; } if (comboBox1.SelectedItem.ToString() == "软件工程") { stu.总分 -= stu.软件工程; stu.软件工程 = null; } if (comboBox1.SelectedItem.ToString() == "英语") { -= stu.英语; stu.总分 stu.英语 = null; } if (comboBox1.SelectedItem.ToString() == "操作系统") { stu.总分 -= stu.操作系统; stu.操作系统 = null; } if (comboBox1.SelectedItem.ToString() == "毛概") { stu.总分 -= stu.毛概; stu.毛概 = null; } if (MessageBox.Show("确认要删除该项成绩吗,", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { mydata.SubmitChanges(); textBox2.Text = ""; } } } } } else { MessageBox.Show("信息不完整,无法修改"); } } } } 总分和排名: 计算总分: 代码: 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; namespace StuIFMS { public partial class TotallForm : Form { public TotallForm() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { DataClasses4DataContext mydata = new DataClasses4DataContext(); dataGridView1.DataSource = mydata.ScoreTable; dataGridView1.Columns[0].Visible = false; } private void button1_Click(object sender, EventArgs e) { //计算总分 DataClasses4DataContext mydata = new DataClasses4DataContext(); var ScoreQuery = from stu in mydata.ScoreTable select stu; foreach (var stu in ScoreQuery) { stu.总分 = 0; //把非空的成绩加起来 if (stu.操作系统 != null) stu.总分 += stu.操作系统; if (stu.毛概 != null) stu.总分 += stu.毛概; if (stu.软件工程 != null) stu.总分 += stu.软件工程; if (stu.英语 != null) stu.总分 += stu.英语; if (stu.组成原理 != null) stu.总分 += stu.组成原理; } mydata.SubmitChanges(); dataGridView1.DataSource = mydata.ScoreTable; } } } 考试管理模块: 查看考试: 添加考试: 修改考试: 详细代码: 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.OleDb; namespace StuIFMS { public partial class TestForm : Form { public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { //初始化,屏蔽所有的控件 dataGridView1.Visible = false; label1.Visible = false; label2.Visible = false; label3.Visible = false; label4.Visible = false; textBox1.Visible = false; comboBox1.Visible = false; comboBox2.Visible = false; dateTimePicker1.Visible = false; button5.Visible = false; button6.Visible = false; button4.Visible = false; } private void button1_Click(object sender, EventArgs e) { //查看考试按钮的实现 dataGridView1.Visible = true; DataClasses5DataContext mydata = new DataClasses5DataContext(); dataGridView1.DataSource = mydata.TestTable; dataGridView1.Columns[0].Visible = false; label1.Visible = false; label2.Visible = false; label3.Visible = false; comboBox1.Visible = false; textBox1.Visible = false; dateTimePicker1.Visible = false; label4.Visible = false; button5.Visible = false; button6.Visible = false; comboBox2.Visible = false; button4.Visible = false; } private void button2_Click(object sender, EventArgs e) { //添加考试的实现 label1.Visible = true; label2.Visible = true; label3.Visible = true; label4.Visible = false; comboBox1.Visible = true; textBox1.Visible = true; dateTimePicker1.Visible = true; button5.Visible = true; button6.Visible = false; comboBox2.Visible = false; button4.Visible = false; textBox1.Text = ""; button4.Visible = false; } private void button3_Click(object sender, EventArgs e) { //修改删除按钮的实现 label1.Visible = true; label2.Visible = true; label3.Visible = true; label4.Visible = true; comboBox1.Visible = true; textBox1.Visible = true; dateTimePicker1.Visible = true; button5.Visible = false; button6.Visible = true; comboBox2.Visible = true; button4.Visible = true; } private void button5_Click(object sender, EventArgs e) { if (comboBox1.SelectedItem != null && textBox1.Text != "" && dateTimePicker1.Text != null) { bool isexist = false; //条件满足,增加 DataClasses5DataContext mydata = new DataClasses5DataContext(); var TestQuery = from test in mydata.TestTable select test; foreach (var test in TestQuery) { if (test.考试科目 == comboBox1.SelectedItem.ToString() && test.考试时间 == dateTimePicker1.Text && test.考试地点 == textBox1.Text) { isexist = true; } } if (isexist) MessageBox.Show("此考试已经存在了~~"); else { TestTable temp = new TestTable { = dateTimePicker1.Text, 考试时间 考试地点 = textBox1.Text, 考试科目 = comboBox1.SelectedItem .ToString() }; mydata.TestTable.InsertOnSubmit(temp); if (MessageBox.Show("确定要添加吗,", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { mydata.SubmitChanges(); //更新考试查询 if (dataGridView1.Visible == true) { dataGridView1.DataSource = mydata.TestTable; dataGridView1.Columns[0].Visible = false; } } } } } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { textBox1.Text = ""; //考试选项修改事件的实现,及时更新信息,如果该科目有考试被选 定,则在文本框里显示选择的考试 if (comboBox2.Items == null) { //没有考试 textBox1.Text = ""; } else { if (comboBox2.SelectedItem == null) //没有选择考试 textBox1.Text = ""; else { //选择了一门考试,查找考试表,将考试地点显示出来 DataClasses5DataContext mydata = new DataClasses5DataContext(); var Test = from test in mydata.TestTable select test; foreach (var test in Test) { if (test.考试科目 == comboBox1.SelectedItem.ToString() && test.考试时间 == comboBox2.SelectedItem.ToString()) textBox1.Text = test.考试地点; } } } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { comboBox2.Items.Clear();//清空 //修改时候科目选择改变时候 if (comboBox2.Visible == true) { //检验是否是修改,把该门课程的所有考试添加到里面,一共修 改 DataClasses5DataContext mydata = new DataClasses5DataContext(); var TestQuery = from test in mydata.TestTable select test; if (comboBox1.SelectedItem != null) { foreach (var test in TestQuery) { if (test.考试科目 == comboBox1.SelectedItem.ToString()) { comboBox2.Items.Add(test.考试时间); // textBox1.Text = test.考试时间; } } } } } private void button6_Click(object sender, EventArgs e) { //修改按钮的实现 if (comboBox2.SelectedItem != null && comboBox1.SelectedItem != null && textBox1.Text != null && dateTimePicker1.Text != null) { //找到那个考试。修改之 DataClasses5DataContext mydata = new DataClasses5DataContext(); var TestQuery = from test in mydata.TestTable select test; foreach (var test in TestQuery) { try { if (test.考试科目 == comboBox1.SelectedItem.ToString() && test.考试时间 == comboBox2.SelectedItem.ToString()) { //找到该考试,修改掉在数据库里的记录 test.考试时间 = dateTimePicker1.Text; test.考试地点 = textBox1.Text; if (MessageBox.Show("确认修改吗,", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { mydata.SubmitChanges(); //更新显示 dataGridView1.DataSource = TestQuery; //清空显示 comboBox2.Items.Clear(); textBox1.Text = ""; } } } catch (Exception ex) { MessageBox.Show("异常" + ex.Message); } } } else { MessageBox.Show("信息不完整,请完整后操作~", "提示"); } } private void button4_Click(object sender, EventArgs e) { //删除考试按钮的实现 //选择了考试科目和考试 //int i = comboBox2.SelectedIndex; if (comboBox2.SelectedItem != null && comboBox1.SelectedItem != null) { //在考试表里找到该考试,删除之 DataClasses5DataContext mydata = new DataClasses5DataContext(); var TestQuery = from test in mydata.TestTable select test; foreach (var test in TestQuery) { if (test.考试科目 == comboBox1.SelectedItem.ToString() && test.考试时间 == comboBox2.SelectedItem.ToString()) { //找到了该考试,删除它 if (MessageBox.Show("删除考试将不可恢复~确定删 除吗", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) { mydata.TestTable.DeleteOnSubmit(test); //更新数据库 mydata.SubmitChanges(); //更新显示框 if (dataGridView1.Visible) { dataGridView1.DataSource = mydata.TestTable; dataGridView1.Columns[0].Visible = false; } //在考试选择框里删除它 comboBox2.Items.Remove(test.考试时间); comboBox2.Text = ""; textBox1.Text = ""; } } } } } } } 密码修改: 代码: 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; namespace StuIFMS { public partial class ChangePForm : Form { private User CurrentUser; public ChangePForm(User current) { InitializeComponent(); CurrentUser = current; this.textBox3.Select(); } private void ChangePForm_Load(object sender, EventArgs e) { label2.Text = CurrentUser.GetUserID(); } //新密码textBox1文本改变时间 private void textBox1_TextChanged(object sender, EventArgs e) { checkBox1.Text = ""; checkBox2.Text = ""; checkBox1.Checked = false; if (textBox2.Enabled == false) { //判断新密码格式是否正确,更新checkbox1状态 if (textBox1.Text == "" || textBox1.Text.Contains(" ")) checkBox1.Text = "含有空格!"; else { //密码不含空格,检验密码长度 if (textBox1.Text.Length > 16 || textBox1.Text.Length < 6) //密码格式不正确 checkBox1.Text = "长度<6-16>"; else { //密码格式正确,激活确认密码按钮 textBox2.Enabled = true; checkBox1.Checked=true; checkBox1.Text = ""; } } } //确认已经可以用了,排除密码确认正确后改动新密码而确认密码 信息没法及时更新的情况 else { //先检查新密码格式是否正确 if (textBox1.Text == "" || textBox1.Text.Contains(" ")) { checkBox2.Checked = false; checkBox1.Text = "含有空格!"; } else { if (textBox1.Text.Length > 16 || textBox1.Text.Length < 6) checkBox1.Text = "长度<6-16>"; else { //新密码格式正确,检测确认密码是否和新密码相同, 不同则更新checkBox2消息 if (textBox1.Text != textBox2.Text) { checkBox2.Text = "确认错误~"; checkBox2.Checked = false; checkBox1.Text = ""; checkBox2.Checked = false; checkBox1.Checked = true; } else { checkBox1.Checked = true; checkBox2.Checked = true; checkBox2.Text = ""; checkBox1.Text = ""; } } } } } //旧密码文本改变事件 private void textBox3_TextChanged(object sender, EventArgs e) { textBox1.Enabled = false; checkBox3.Checked = false; checkBox3.Text = ""; //查找用户表 //DataClasses1DataContext myDataContext = new DataClasses1DataContext(); //找到该登录用户 if (textBox3.Text == CurrentUser.GetPassword()) { textBox1.Enabled = true; checkBox3.Checked = true; checkBox3.Text = ""; } else { checkBox3.Text = "密码错误"; } } private void checkBox3_Click(object sender, EventArgs e) { //屏蔽鼠标对它的操作 if (checkBox3.Checked) checkBox3.Checked = false; else checkBox3.Checked = true; } private void checkBox1_Click(object sender, EventArgs e) { if (checkBox1.Checked) checkBox1.Checked = false; else checkBox1.Checked = true; } private void checkBox2_Click(object sender, EventArgs e) { if (checkBox2.Checked) checkBox2.Checked = false; else checkBox2.Checked = true; } //密码确认按钮实现 private void textBox2_TextChanged(object sender, EventArgs e) { checkBox2.Checked = false; checkBox2.Text = ""; //检测确认密码和新密码是否相等 if (textBox1.Text != textBox2.Text) { //密码确认错了 checkBox2.Text = "确认错误~"; } else { //密码确认正确 checkBox2.Checked = true; } } private void button1_Click(object sender, EventArgs e) { //检测三个checkedBox状态确定是否可以修改密码 if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked) { //可以修改密码 DataClasses1DataContext MyDC = new DataClasses1DataContext(); var UserQuery = from Users in MyDC.UsersTable select Users; foreach (var user in UserQuery) { if (user.UerID == CurrentUser.GetUserID() && user.Identity == CurrentUser.GetIdentity()) { ", if (MessageBox.Show("您确认修改密码吗,", "提示 MessageBoxButtons.OKCancel) == DialogResult.OK) { user.Password = textBox1.Text; MyDC.SubmitChanges(); MessageBox.Show("密码修改成功~"); break; } } } } else { MessageBox.Show("信息不完整,请确认~~", "提示"); } } private void button2_Click(object sender, EventArgs e) { //取消按钮的实现 this.Close(); } } } 添加帐号: 代码: 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; namespace StuIFMS { public partial class AddUserForm : Form { public AddUserForm() { InitializeComponent(); //初始化checkBox状态 checkBox1.Text = ""; checkBox2.Text = ""; checkBox3.Text = ""; this.textBox1.Select(); } private void textBox1_TextChanged(object sender, EventArgs e) { bool isRegeisted = false; //文本变化时候更新checkBox1状态 checkBox1.Text = ""; checkBox1.Checked = false; //取出UsersTable里所有的用户数据信息 DataClasses1DataContext MyDataContext = new DataClasses1DataContext(); var UserQuery = from user in MyDataContext.UsersTable select user; //检测帐号合法性:帐号为11位以内的字符组成,不能含有空格 等特殊字符 if (textBox1.Text == "" || textBox1.Text.Contains(" ")) checkBox1.Text = "无效帐号"; else { if (textBox1.Text.Length < 6 || textBox1.Text.Length > 11) checkBox1.Text = "长度<6-11>"; else { //帐号格式正确,查询帐号是否被注册过了 foreach (var user in UserQuery) { if ((user.UerID == textBox1.Text && user.Identity == radioButton1.Text) || (user.UerID == textBox1.Text && user.Identity == radioButton2.Text)) //存在一个相同帐号,这个帐号不能注册 isRegeisted = true; } if (isRegeisted) checkBox1.Text = "已注册帐号~"; //帐号没有注册 else { checkBox1.Text = ""; checkBox1.Checked = true; textBox2.Enabled = true; } } } } private void textBox2_TextChanged(object sender, EventArgs e) { //检测新密码格式是否正确 if (textBox2.Text == "" || textBox2.Text.Contains(" ")) { checkBox2.Checked = false; checkBox2.Text = "含有空格!"; } else { if (textBox2.Text.Length > 16 || textBox2.Text.Length < 6) { checkBox2.Text = "长度<6-16>"; checkBox2.Checked = false; } else { //密码格式正确,检测新密码是否进行了改动 checkBox2.Checked = true; checkBox2.Text = ""; if (textBox3.Enabled == false) { //第一次密码格式正确,开放确认密码文本框、打勾 checkBox2 textBox3.Enabled = true; } // 确认密码已经可以填写,检测填写情况,并对确认密 码成功后改动新密码这一情况进行处理 else { //新密码已经是符合密码格式的密码了,所以用新密 码做为校对的标准,检测确认密码是否和新秘密相等 if (textBox2.Text != textBox3.Text) { //确认密码失败,更新checkBox2和、checkBox3的信息 checkBox3.Text = "确认失败~"; checkBox3.Checked = false; } else { //确认成功 checkBox3.Text = ""; checkBox3.Checked = true; } } } } } //确认密码文本改动时候更新消息 private void textBox3_TextChanged(object sender, EventArgs e) { //直接检测和新密码是否相等 if (textBox3.Text != textBox2.Text) { checkBox3.Text = "确认失败~"; checkBox3.Checked = false; } else { //确认成功 checkBox3.Text = ""; checkBox3.Checked = true; } } //取消按钮实现 private void button2_Click(object sender, EventArgs e) { //关闭当前对话框 this.Close(); } //添加按钮实现 private void button1_Click(object sender, EventArgs e) { //根据添加信息,向数据库用户表里插入一行就可以了 //检测是否可以添加用户 if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked) { //可以注册,获取用户表数据集 DataClasses1DataContext MyDataContext = new DataClasses1DataContext(); UsersTable tempTable = new UsersTable { UerID = textBox1.Text, Password = textBox2.Text }; if (radioButton1.Checked) tempTable.Identity = radioButton1.Text; else tempTable.Identity = radioButton2.Text; MyDataContext.UsersTable.InsertOnSubmit(tempTable); MyDataContext.SubmitChanges(); MessageBox.Show("添加成功~请牢记帐号和密码~", "提示"); this.Close(); } else { MessageBox.Show("信息不完整,无法添加", "警告"); } } private void checkBox1_Click(object sender, EventArgs e) { //屏蔽鼠标点击事件 if (checkBox1.Checked) checkBox1.Checked = false; else checkBox1.Checked = true; } private void checkBox2_Click(object sender, EventArgs e) { if (checkBox2.Checked) checkBox2.Checked = false; else checkBox2.Checked = true; } private void checkBox3_Click(object sender, EventArgs e) { if (checkBox3.Checked) checkBox3.Checked = false; else checkBox3.Checked = true; } } } 删除帐号: 代码: 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; namespace StuIFMS { public partial class DeleUserForm : Form { public DeleUserForm() { InitializeComponent(); } //更新信息方法 public void UpdateIF() { comboBox1.Text = ""; comboBox1.Items.Clear(); DataClasses1DataContext mydata = new DataClasses1DataContext(); dataGridView1.DataSource = mydata.UsersTable; dataGridView1.AutoGenerateColumns = false; dataGridView1.Columns[0].Visible = false; dataGridView1.Columns[2].Visible = false; "; //dataGridView1.Columns[0].HeaderText = "用户 //dataGridView1.Columns[2].HeaderText = "身份"; dataGridView1.Show(); //更新comboBox1内容 if (radioButton1.Checked) { //显示用户表里所有学生身份用户 var StuUser = from user in mydata.UsersTable where user.Identity=="学生" select user; foreach (var user in StuUser) { //加入用户名 comboBox1.Items.Add(user.UerID); } } else { //显示用户表里所有的非超级管理员的用户 var TeacherUser = from user in mydata.UsersTable where user.Identity == "教师" select user; //遍历一次,获取用户列表 foreach (var Tuser in TeacherUser) { if (Tuser.UerID != "SuperMan") comboBox1.Items.Add(Tuser.UerID); } } } private void button1_Click(object sender, EventArgs e) { DataClasses1DataContext mydata = new DataClasses1DataContext(); //不自动创建全部列 dataGridView1.DataSource = mydata.UsersTable; dataGridView1.AutoGenerateColumns = false; //获取表里的列 dataGridView1.Columns[0].Visible = false; //dataGridView1.Columns[0].DataPropertyName = "用户"; dataGridView1.Columns[2].Visible = false; //dataGridView1.Columns[2].DataPropertyName = "身份"; //dataGridView1.Show(); } private void DeleUserForm_Load(object sender, EventArgs e) { //窗体初始化,从数据库里用户表里读出内容到datagridview1里, 同时更新combox里内容 UpdateIF(); } private void button1_Click_1(object sender, EventArgs e) { //刷新按钮实现 UpdateIF(); } private void radioButton2_CheckedChanged(object sender, EventArgs e) { UpdateIF(); } private void radioButton1_CheckedChanged(object sender, EventArgs e) { UpdateIF(); } //取消按钮的实现 private void button3_Click(object sender, EventArgs e) { //关闭当前窗口 this.Close(); } //删除按钮的实现 private void button2_Click(object sender, EventArgs e) { //根据用户选择,删除用户表里的指定账户 //没有内容,用户表里没有内容 if (comboBox1.Items == null) MessageBox.Show("没有可删除帐号"); else { if (comboBox1.SelectedItem == null) MessageBox.Show("没有选择帐号~"); else { //选择了帐号,删除该帐号,并更新数据表里的内容,同时 更新界面的内容 DataClasses1DataContext myData = new DataClasses1DataContext(); //分情况考虑 if (radioButton1.Checked) { //删除学生帐号 var StuQuery = from user in myData.UsersTable select user; foreach (var stu in StuQuery) { if(stu.UerID==comboBox1.SelectedItem.ToString()&&stu.Identity==radioButton1.Text) myData.UsersTable.DeleteOnSubmit(stu); } } else { //删除教师学号 var TeaQuery = from users in myData.UsersTable select users; foreach (var tea in TeaQuery) { if(tea.UerID==comboBox1.SelectedItem.ToString()&&tea.Identity==radioButton2.Text ) myData.UsersTable.DeleteOnSubmit(tea); } } if (MessageBox.Show("删除数据将不可恢复~确定,","提 示",MessageBoxButtons.OKCancel) == DialogResult.OK) { //删除完了,保存结果,刷新界面 myData.SubmitChanges(); UpdateIF(); } } } } private void label2_Click(object sender, EventArgs e) { } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } } } 资源管理器截图: 数据库表截图: 以上就是学生学籍管理系统的详细代码和效果截图。
本文档为【学生学籍管理系统代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_852287
暂无简介~
格式:doc
大小:547KB
软件:Word
页数:123
分类:生活休闲
上传时间:2017-10-01
浏览量:35