学生管理代码.docx
- 文档编号:26905270
- 上传时间:2023-06-23
- 格式:DOCX
- 页数:33
- 大小:156.90KB
学生管理代码.docx
《学生管理代码.docx》由会员分享,可在线阅读,更多相关《学生管理代码.docx(33页珍藏版)》请在冰豆网上搜索。
学生管理代码
usingSystem.Data;
usingSystem.Data.SqlClient;//指定数据库驱动程序
namespacePlayingCards
{
publicpartialclassFormlogin:
Form
{
publicFormlogin()
{
InitializeComponent();
}
Privatevoidbutton1_Click(objectsender,EventArgse)
{
//2.连接数据库
//a连接本地数据库的三种方法
//SqlConnectionconn=newSqlConnection("server=121.195.254.98;database=shujukuyuanliyuyingyong;IntegratedSecurity=sspi");
//integratedsecurity=true的意思是集成验证,也就是说使用Windows验证的方式去连接到数据库服务器。
//这样方式的好处是不需要在连接字符串中编写用户名和密码,从一定程度上说提高了安全性
//SqlConnectionconn=newSqlConnection("server=(local);database=shujukuyuanliyuyingyong;IntegratedSecurity=sspi");
//SqlConnectionconn=newSqlConnection("server=localhost;database=shujukuyuanliyuyingyong;IntegratedSecurity=sspi");
//b连接其他数据库
//SqlConnectionconn=newSqlConnection("server=IP地址;database=所连数据库的名称;userid=用户名;pwd=密码");
SqlConnectionconn=newSqlConnection("server=172.17.81.246;database=jxgl;uid=swf;pwd=swf");
try
{
conn.Open();
//MessageBox.Show("连接数据库成功");
//3.执行sql语句
stringsql="selectcount(*)fromSwheresno='{0}'andpwd='{1}'";
sql=string.Format(sql,textBox1.Text,textBox2.Text);
SqlCommandcomm=newSqlCommand(sql,conn);
objectobj=comm.ExecuteScalar();//取select返回表的第一行第一列
//4.处理执行结果
intret=Convert.ToInt32(obj.ToString());
if(ret==1)
{
MessageBox.Show("登陆成功");
}
else
{
MessageBox.Show("你的用户名或密码错误");
}
}
catch(Exceptionex)
{
MessageBox.Show("连接数据库失败");
}
//5.关闭数据库连接
conn.Close();
}
}
}
usingSystem.Data;
usingSystem.Data.SqlClient;
namespacePlayingCards
{
publicpartialclassFormS:
Form
{
publicFormS()
{
InitializeComponent();
}
///学生信息界面
privatevoidForm4_Load(objectsender,EventArgse)
{
stringsql="selectdno,dnamefromdept";
DataSetds=SqlHelper.ExecutDataSet(sql);
for(inti=0;i { strings=ds.Tables[0].Rows[i]["dno"].ToString()+"|"+ds.Tables[0].Rows[i]["dname"].ToString(); comboBox1.Items.Add(s); listBox1.Items.Add(s); } } privatevoidbutton1_Click(objectsender,EventArgse) { stringsql="insertintoS(sno,sname,sex,birth,homadd,endate,pwd)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')"; stringdepno=comboBox1.SelectedText; //字符串类型分割 string[]a=depno.Split(newchar[]{'|',',',''}); if(rbMan.Checked) sql=string.Format(sql,textno.Text,textname.Text,rbMan.Text,dTPbirth.Value,textaddres.Text,dTPendata.Value,textpwd.Text,a[0]); if(rbWoman.Checked) sql=string.Format(sql,textno.Text,textname.Text,rbWoman.Text,dTPbirth.Value,textaddres.Text,dTPendata.Value,textpwd.Text,a[0]); //insertdeleteupdate intret=SqlHelper.ExecutNonQuery(sql); if(ret==1) { MessageBox.Show("添加成功"); } else { MessageBox.Show("添加失败"); } } privatevoidtextname_TextChanged(objectsender,EventArgse) { this.Text=textname.Text; } privatevoidbtdrop_Click(objectsender,EventArgse) { if(listBox1.SelectedItems.Count! =0) { SqlConnectionconn=newSqlConnection("server=172.17.81.246;database=jxgl;uid=swf;pwd=swf"); conn.Open(); //从数据库删除 for(inti=listBox1.SelectedItems.Count-1;i>=0;i--) { stringsql="deletefromdeptwheredno='{0}'"; //字符串类型分割 strings=listBox1.SelectedItems[i].ToString(); string[]b=s.Split(newchar[]{'|'}); sql=string.Format(sql,b[0]); SqlCommandcomm=newSqlCommand(sql,conn); intret=comm.ExecuteNonQuery(); } conn.Close(); //从listbox框中删除 for(inti=listBox1.SelectedItems.Count-1;i>=0;i--) listBox1.Items.RemoveAt(listBox1.SelectedIndex); } else { MessageBox.Show("请先选择,然后删除"); } } privatevoidbutton1_Click_1(objectsender,EventArgse) { strings=""; if(checkBox1.Checked) { s+=checkBox1.Text+","; } if(checkBox2.Checked) { s+=checkBox1.Text+","; } if(checkBox3.Checked) { s+=checkBox1.Text+","; } if(s! ="") { s=s.Substring(0,s.Length-1); } MessageBox.Show("你喜欢: "+s); } privatevoid删除ToolStripMenuItem_Click(objectsender,EventArgse) { stringsql="deletefromdeptwheredno='{0}'"; //字符串类型分割 strings=listBox1.SelectedItem.ToString(); string[]b=s.Split(newchar[]{'|'}); sql=string.Format(sql,b[0]); intret=SqlHelper.ExecutNonQuery(sql); //从listbox框中删除 listBox1.Items.RemoveAt(listBox1.SelectedIndex); } privatevoid编辑ToolStripMenuItem_Click(objectsender,EventArgse) { strings=listBox1.SelectedItem.ToString(); string[]b=s.Split(newchar[]{'|'}); FBJf=newFBJ(); f.DepCode=b[0]; f.ShowDialog(); } privatevoidbutton2_Click(objectsender,EventArgse) { listBox1.Items.Clear(); stringsql="selectdno,dnamefromdept"; DataSetds=SqlHelper.ExecutDataSet(sql); for(inti=0;i { strings=ds.Tables[0].Rows[i]["dno"].ToString()+"|"+ds.Tables[0].Rows[i]["dname"].ToString(); comboBox1.Items.Add(s); listBox1.Items.Add(s); } } privatevoidtextno_KeyPress(objectsender,KeyPressEventArgse) { if(e.KeyChar>='0'&&e.KeyChar<='9') { MessageBox.Show("xxxx"); } elsee.Handled=true; } } } usingSystem.Data; usingSystem.Data.SqlClient; namespacePlayingCards { publicpartialclassFormC: Form { publicFormC() { InitializeComponent(); } ///课程添加窗体 privatevoidbutton1_Click(objectsender,EventArgse) { stringsql="insertintoC(cno,cname,credit,cpno,tperiod,bno)values('{0}','{1}','{2}','{3}','{4}','{5}')"; stringdepno=comboBox1.SelectedText; //字符串类型分割 string[]a=depno.Split(newchar[]{'|',',',''}); sql=string.Format(sql,tBcno.Text,tBcname.Text,tBcredit.Text,tBcpno.Text,tBtperiod.Text,a[0]); intret=SqlHelper.ExecutNonQuery(sql); if(ret==1) { MessageBox.Show("添加成功"); } else { MessageBox.Show("添加失败"); } } privatevoidFormC_Load(objectsender,EventArgse) { stringsql="selectbno,bnamefrombook"; DataSetds=SqlHelper.ExecutDataSet(sql); for(inti=0;i { strings=ds.Tables[0].Rows[i]["bno"].ToString()+"|"+ds.Tables[0].Rows[i]["bname"].ToString(); comboBox1.Items.Add(s); listBox1.Items.Add(s); } } privatevoid删除ToolStripMenuItem_Click(objectsender,EventArgse) { //从数据库删除 stringsql="deletefrombookwherebno='{0}'"; //字符串类型分割 strings=listBox1.SelectedItem.ToString(); string[]b=s.Split(newchar[]{'|'}); sql=string.Format(sql,b[0]); //SqlCommandcomm=newSqlCommand(sql,conn); //intret=comm.ExecuteNonQuery(); intret=SqlHelper.ExecutNonQuery(sql); //从listbox框中删除 listBox1.Items.RemoveAt(listBox1.SelectedIndex); } privatevoid编辑ToolStripMenuItem_Click(objectsender,EventArgse) { strings=listBox1.SelectedItem.ToString(); string[]b=s.Split(newchar[]{'|'}); FBKGLf=newFBKGL(); f.BookCode=b[0]; f.ShowDialog(); } privatevoidbutton2_Click(objectsender,EventArgse) { listBox1.Items.Clear(); stringsql="selectbno,bnamefrombook"; DataSetds=SqlHelper.ExecutDataSet(sql); for(inti=0;i { strings=ds.Tables[0].Rows[i]["bno"].ToString()+"|"+ds.Tables[0].Rows[i]["bname"].ToString(); comboBox1.Items.Add(s); listBox1.Items.Add(s); } } } } usingSystem.Data; usingSystem.Data.SqlClient; namespacePlayingCards { publicpartialclassFormdept: Form { publicFormdept() { InitializeComponent(); } ///系别添加窗体 privatevoidbutton1_Click(objectsender,EventArgse) { stringsql="insertintoDEPT(dno,dname,dheader,snum)values('{0}','{1}','{2}','{3}')"; sql=string.Format(sql,textBox1.Text,tBdname.Text,tBdheader.Text,tBsnum.Text); intret=SqlHelper.ExecutNonQuery(sql); if(ret==1) { MessageBox.Show("添加成功"); } else { MessageBox.Show("添加失败"); } } privatevoid添加ToolStripMenuItem_Click(objectsender,EventArgse) { FdMf=newFdM(); f.MdiParent=this; f.Show(); } } } namespacePlayingCards { publicpartialclassFormSearch: Form { publicFormSearch() { InitializeComponent(); } privatevoidbutton1_Click(objectsender,EventArgse) { listBox1.Items.Clear(); SqlConnectionconn=newSqlConnection("server=172.17.81.246;database=jxgl;uid=swf;pwd=swf"); conn.Open(); stringsql="selectdno,dnamefromdeptwherednamelike'%{0}%'ordheaderlike'%{0}%'"; sql=string.Format(sql,textBox1.Text); DataSetds=newDataSet();//内存数据库,用来保存从数据库服务器上 SqlDataAdapterda=newSqlDataAdapter(sql,conn); da.Fill(ds,"xxx"); for(inti=0;i { strings=ds.Tables[0].Rows[i]["dno"].ToString()+"|"+ds.Tables[0].Rows[i]["dname"].ToString(); listBox1.Items.Add(s); } conn.Close(); } } } 课本管理 namespacePlayingCards { publicpartialclassFBM: Form { publicFBM() { InitializeComponent(); } privatevoidFBM_Load(objectsender,EventArgse) { stringsql="selectdno,dnamefromdept"; DataSetds=SqlHelper.ExecutDataSet(sql); for(inti=0;i { strings=ds.Tables[0].Rows[i]["dno"].ToString()+"|"+ds.Tables[0].Rows[i]["dname"].ToString(); listBox1.Items.Add(s); } } privatevoid删除ToolStripMenuItem_Click(objectsender,EventArgse) { //从数据库删除 stringsql="deletefromdeptwheredno='{0}'"; //字符串类型分割 strings=listBox1.SelectedItem.ToString(); string[]b=s.Split(newchar[]{'|'}); sql=string.Format(sql,b[0]); intret=SqlHelper.ExecutNonQuery(sql); //从listbox框中删除 listBox1.Items.RemoveAt(listBox1.SelectedIndex); } privatevoid编辑ToolStripMenuItem_Click(objectsender,EventArgse) { strings=listBo
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 学生 管理 代码