您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > C#制作学生管理系统
C#学生管理系统刚用C#做完一个学生管理系统,在这里写下部分思路与代码希望对在这方面有困扰的朋友一些帮助。用到的工具有:VisualStudio2005和SQL2005首先来说下功能:1.登陆界面具有“学生”和“管理员”两种登陆形式2.“学生”身份登陆后可以进行“个人资料查询”、“成绩查询”、“修改密码”等操作3.“管理员”身份登陆后,也可进行“查询”、“添加”、“修改”、“删除”等操作登陆界面注册界面如果还没有用户名,可以在登陆界面的“注册”处注册账号具有身份证、手机号码、邮政编码和密码等的位数限制功能还具有同一身份证不能重复注册,密码不能和数据库中有的重复等功能,注册后弹出用户名学生用户登陆后的个人资料查询界面学生用户登陆后的成绩查询界面修改密码界面管理员登陆后的“查询全部”界面管理员模式下的“个人查询”界面管理员模式下的“成绩录入”界面管理员模式下的学生资料删除界面登陆界面思路:1.选择用户身份“学生”和“Admin”登陆成功时,分别进入“学生操作界面”和“管理员操作界面”,用户身份为其他时提示不存在。2.点选“关闭”按钮时,主界面不弹出且关闭3.用户名或密码与数据库中不符合时,弹框提示4.用户名和密码验证正确后关闭登陆界面,弹出主界面5.点选“注册”按钮时弹出注册界面注册界面思路:1.除了“爱好”,其余各选项或输入处不能为空2.身份证为18位、手机号码为11位、邮政编码为6位且这些地方只能输入数字。3.输入身份证必须唯一,与数据库中重复时提示“此身份证已注册”4.密码与确认密码必须一致且都为6位数字5.密码必须唯一,与数据库中重复时提示“此密码已使用”6.注册成功后,弹框提供给用户一个用户名。并且关闭注册界面后,登陆界面会自动输入新注册的用户名在这里只介绍“登陆界面”和“注册界面”并附上思路和代码登陆界面代码:主界面load事件:privatevoidForm1_Load(objectsender,EventArgse){loadmm=newload();mm.ShowDialog();if(ww.t==1){selectToolStripMenuItem.Visible=false;MessageBox.Show(登陆成功...);}elseif(ww.t==2){manageToolStripMenuItem.Visible=false;MessageBox.Show(登陆成功...);}else{this.Close();//此为关闭主窗口}ww.t为定义的全局变量,用来判断用户身份.t=1时为“Admin”身份登陆弹出管理员主界面;t=2时为“学生”身份登陆弹出学生主界面;t为其他时关闭主界面。登陆代码:privatevoidzhuce_Click(objectsender,EventArgse){registeraa=newregister();aa.ShowDialog();}privatevoidload1_Click(objectsender,EventArgse){if(comboBox1.Text==Admin){if(username.Text.Trim()==Administrator&&userpsd.Text.Trim()==126127){this.Close();ww.t=1;}elseMessageBox.Show(账户名或密码错误!,提示);}elseif(comboBox1.Text==学生){con1nn=newcon1();SqlConnectionconnection=nn.cnn();SqlCommandcommand=connection.CreateCommand();command.CommandText=select*fromclasswhere1=1;command.ExecuteNonQuery();SqlDataReaderreader=command.ExecuteReader();booli=true;while(reader.Read()){if(username.Text.Trim()==reader[0].ToString()&&userpsd.Text.Trim()==reader[11].ToString()){i=true;ww.t=2;break;}elsei=false;}if(i){ww.x=username.Text.Trim();this.Close();}elseMessageBox.Show(用户名或密码错误!,提示);connection.Close();}elselabel2.Show();}privatevoidcomboBox1_MouseDown(objectsender,MouseEventArgse){label2.Hide();}privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){if(comboBox1.Text==Admin){username.Text=Administrator;userpsd.Text=;}if(comboBox1.Text==学生){username.Text=;userpsd.Text=;}}privatevoidload_Activated(objectsender,EventArgse){username.Text=ww.y;}注册界面代码:boolnumber=false;privatevoidbutton1_Click(objectsender,EventArgse){if(name1.Text==||idcard1.Text==||telephone1.Text==||post1.Text==||address1.Text==||email1.Text==||pad1.Text==||pad2.Text==){stringstr=;if(name1.Text==)str+=姓名不能为空+\r\n;if(idcard1.Text==)str+=身份证不能为空+\r\n;if(telephone1.Text==)str+=手机号码不能为空+\r\n;if(post1.Text==)str+=邮政编码不能为空+\r\n;if(address1.Text==)str+=家庭住址不能为空+\r\n;if(email1.Text==)str+=Email不能为空+\r\n;if(pad1.Text==)str+=登录密码不能为空+\r\n;if(pad2.Text==)str+=确认密码不能为空+\r\n;MessageBox.Show(str,提示,MessageBoxButtons.OK,MessageBoxIcon.Information);}else{if(idcard1.Text.Length==18){if(telephone1.Text.Length==11){if(post1.Text.Length==6){if(pad1.Text.Length==6&&pad2.Text.Length==6){if(pad1.Text==pad2.Text){boolj=true;con1dad=newcon1();SqlConnectionconnection1=dad.cnn();SqlCommandcommand2=connection1.CreateCommand();command2.CommandText=select*fromclasswhere1=1;command2.ExecuteNonQuery();SqlDataReaderreader1=command2.ExecuteReader();while(reader1.Read()){if(idcard1.Text.Trim()==reader1[6].ToString()){label15.Show();j=false;}if(pad1.Text.Trim()==reader1[11].ToString()){label16.Show();j=false;}}connection1.Close();if(j){con1data=newcon1();SqlConnectionconnention=data.cnn();SqlCommandcommand=connention.CreateCommand();command.CommandText=insertintoclass(name,sex,age,hobby,professional,idcard,telephone,post,address,email,password)+values(@a1,@a2,@a3,@a4,@a5,@a6,@a7,@a8,@a9,@a10,@a11);command.Parameters.Add(newSqlParameter(@a1,name1.Text));if(sexnan.Checked)command.Parameters.Add(newSqlParameter(@a2,男));if(sexnv.Checked)command.Parameters.Add(newSqlParameter(@a2,女));command.Parameters.Add(newSqlParameter(@a3,age1.Value.ToString()));stringcc=;if(youyong.Checked)cc+=游泳+;if(biancheng.Checked)cc+=电脑编程+\r\n+;if(sports.Checked)cc+=运动+;if(dance.Checked)cc+=舞蹈+\r\n+;if(dongman.Checked)cc+=动漫设计+;if(sing.Checked)cc+=唱歌;command.Parameters.Add(newSqlParameter(@a4,cc));command.Parameters.Add(newSqlParameter(@a5,zhuanye.Text));command.Parameters.Add(newSqlParameter(@a6,idcard1.Text));command.Parameters.Add(newSqlParameter(@a7,telephone1.Text));command.Parameters.Add(newSqlParameter(@a8,post1.Text));command.Parameters.Add(newSqlParameter(@a9,address1.Text));command.Parameters.Add(newSqlParameter(@a10,email1.Text));command.Parameters.Add(newSqlParameter(@a11,pad1.Text));command.ExecuteNonQuery();connention.Close();con1da=newcon1();SqlConnectionconnection=da.cnn();SqlCommandcommand1=connection.CreateCommand();command1.CommandText=selectuseridfromclasswhereidcard='+idcard1.Text+';command1.ExecuteNonQuery();SqlDataReaderreader=command1.ExecuteReader();stringstr1=注册成功!+\r\n;while(reader.Read()){str1+=用户名:+reader[0].ToString()+\r\n+*以后请用此用户名登陆*+\r\n;ww.y=reader[0].ToString();}MessageBox.Show(str1,
本文标题:C#制作学生管理系统
链接地址:https://www.777doc.com/doc-5892720 .html