学生管理系统实训报告超详细.docx

上传人:b****1 文档编号:23011178 上传时间:2023-04-30 格式:DOCX 页数:25 大小:2.49MB
下载 相关 举报
学生管理系统实训报告超详细.docx_第1页
第1页 / 共25页
学生管理系统实训报告超详细.docx_第2页
第2页 / 共25页
学生管理系统实训报告超详细.docx_第3页
第3页 / 共25页
学生管理系统实训报告超详细.docx_第4页
第4页 / 共25页
学生管理系统实训报告超详细.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

学生管理系统实训报告超详细.docx

《学生管理系统实训报告超详细.docx》由会员分享,可在线阅读,更多相关《学生管理系统实训报告超详细.docx(25页珍藏版)》请在冰豆网上搜索。

学生管理系统实训报告超详细.docx

学生管理系统实训报告超详细

C#实训项目学生管理系统

一,使用SQL.2005建立数据库系统:

1.打开数据库

2,新建数据库名称为asStu,并新建两个表为loginTable,StuInfo

3,修改表并打开表loginTable进行设置:

4,修改打开表StuInfo,进行设置:

二,使用VS2008建立窗体程序:

1,建立Form1.cs,并添加两个TexBox,两个button

双击对登陆按钮进行代码编写:

privatevoidbtnLogin_Click(objectsender,EventArgse)

{

stringusername,userpwd;

username=txtLoginName.Text;

userpwd=txtLoginPwd.Text;

stringstrsql="SELECTcount(*)FROM[asStu].[dbo].[loginTable]whereusername='"+username+"'andPwdword='"+userpwd+"'";

SqlConnectionconn=newSqlConnection("server=.;database=asstu;uid=sa;pwd=123");

conn.Open();

SqlCommandcmd=newSqlCommand(strsql,conn);

intres=(int)cmd.ExecuteScalar();

if(res>0)

{

MessageBox.Show("登录成功");

frmMainmf=newfrmMain();

mf.Show();

}

else

MessageBox.Show("用户名、密码非法,再想想!

");

}

对注册按钮代码进行编写:

privatevoidbtnReg_Click(objectsender,EventArgse)

{

stringusername=this.txtLoginName.Text;

stringuserpwd=this.txtLoginPwd.Text;

stringstrcon="server=.;database=asstu;uid=sa;pwd=123";

SqlConnectionsqlcon=newSqlConnection(strcon);

sqlcon.Open();

stringstrsql="insertintologintablevalues('"+username+"','"+userpwd+"')";

SqlCommandcmd=newSqlCommand(strsql,sqlcon);

intresult=cmd.ExecuteNonQuery();

if(result>0)

{

MessageBox.Show("注册成功,亲!

");

}

else

{

MessageBox.Show("注册失败,亲!

");

}

txtLoginName.Text=txtLoginPwd.Text="";

}

}

}

2,建立frmMain.cs窗体:

添加MenuStrip,ToolStrip控件

对“添加用户信息”进行代码编写实现窗体跳转;

privatevoid添加信息ToolStripMenuItem_Click(objectsender,EventArgse)

{

mainFormfrm=newmainForm();

frm.MdiParent=this;

frm.Show();

}

同时绑定“用户信息添加”的click事件

对“用户信息修改进行代码编写实现窗体跳转:

privatevoid用户信息修改ToolStripMenuItem_Click(objectsender,EventArgse)

{

frmSlectfrm=newfrmSlect();

frm.MdiParent=this;

frm.Show();

}

同时绑定“学生信息管理”的click事件:

3,建立mainForm.cs窗体,添加如截图所示的GroupBox容器,Label标签,Button按钮,TextBox控件,RadioButton,DateTimePicker控件,并设置好文字:

对“添加”按钮进行代码编写:

privatevoidbutton1_Click(objectsender,EventArgse)

{

stringpstusex="";

if(rbtM.Checked)

pstusex=rbtM.Text;

else

pstusex=radioButton2.Text;

stringstrcon="server=.;database=asstu;uid=sa;pwd=123";

SqlConnectionsqlcon=newSqlConnection(strcon);

sqlcon.Open();

stringstrsql=@"INSERTINTO[asStu].[dbo].[StuInfo]

([StudentID]

[StudentName]

[StudentSex]

[StudyDate]

[DepartName]

[classname]

[StudentIDCard]

[Address]

[StudentTel]

[ExtendField]

VALUES

('"+txtStuID.Text+"','"+txtStuName.Text+"','"+pstusex+"','"+dateTimePicker1.Text+"','"+cboDepartName.Text+"','"+cboClassName.Text+"','"+txtStuIDCard.Text+"','"+txtAddress.Text+"','"+txtStuTel.Text+"','"+txtExField.Text+"')";

SqlCommandcmd=newSqlCommand(strsql,sqlcon);

intresult=cmd.ExecuteNonQuery();

if(result>0)

{

MessageBox.Show("添加成功,亲!

");

sqlcon.Close();

}

}

4,建立frmSlect.cs窗体,添加GroupBox容器,DataGridView控件,三个Button按钮:

 

对“查询”按钮进行代码编辑:

privatevoidbutton1_Click(objectsender,EventArgse)

{

stringstrcon="server=.;database=asstu;uid=sa;pwd=123";

SqlConnectionsqlcon=newSqlConnection(strcon);

sqlcon.Open();

stringstrsql="select*fromstuinfo";

SqlCommandcmd=newSqlCommand(strsql,sqlcon);

SqlDataAdapteradp=newSqlDataAdapter(cmd);

DataSetds=newDataSet();

adp.Fill(ds);

dgvStudent.DataSource=ds.Tables[0];

}

对“修改”按钮进行代码编辑:

privatevoidbutton2_Click(objectsender,EventArgse)

{

frmUpdatefrm=newfrmUpdate();

frm.Show();

if(dgvStudent.SelectedRows.Count<=0)

{

MessageBox.Show("请先选定修改行!

");

return;

}

frm.txtStuID.Text=dgvStudent.SelectedRows[0].Cells[1].Value.ToString();

frm.txtStuName.Text=dgvStudent.SelectedRows[0].Cells[2].Value.ToString();

if(this.dgvStudent.SelectedRows[0].Cells[3].Value.ToString().Trim()=="男")

{

frm.rbtM.Checked=true;

}

else

{

frm.rbtW.Checked=true;

}

frm.dbtStudyDate.Text=dgvStudent.SelectedRows[0].Cells[4].Value.ToString();

frm.cboDepartName.Text=dgvStudent.SelectedRows[0].Cells[5].Value.ToString();

frm.cboClassName.Text=dgvStudent.SelectedRows[0].Cells[6].Value.ToString();

frm.txtStuIDCard.Text=dgvStudent.SelectedRows[0].Cells[7].Value.ToString();

frm.txtStuTel.Text=dgvStudent.SelectedRows[0].Cells[8].Value.ToString();

frm.txtStuID.Enabled=false;

}

对“删除”按钮进行代码编辑:

privatevoidbutton3_Click(objectsender,EventArgse)

{

if(dgvStudent.SelectedRows.Count!

=1)

{

MessageBox.Show("请选择删除行");

return;

}

stringstuid=dgvStudent.SelectedRows[0].Cells[1].Value.ToString();

stringstrsql="DELETEFROM[asStu].[dbo].[StuInfo]WHEREstudentID='"+stuid+"'";

stringstrcon="server=.;database=asstu;uid=sa;pwd=123";

SqlConnectionsqlcon=newSqlConnection(strcon);

sqlcon.Open();

SqlCommandcmd=newSqlCommand(strsql,sqlcon);

intresult=cmd.ExecuteNonQuery();

if(result>0)

MessageBox.Show("删除成功!

");

else

MessageBox.Show("删除失败!

");

}

}

}

4,建立frmUpdate.cs窗体,添加如截图所示的GroupBox容器,Label标签,Button按钮,TextBox控件,RadioButton,DateTimePicker控件,并设置好文字:

privatevoidbutton1_Click(objectsender,EventArgse)

{

stringpstusex="";

if(rbtM.Checked)

pstusex=rbtM.Text;

else

pstusex=rbtW.Text;

stringstrcon="server=.;database=asstu;uid=sa;pwd=123";

SqlConnectionsqlcon=newSqlConnection(strcon);

sqlcon.Open();

stringstrsql=@"UPDATE[asstu].[dbo].[stuinfo]

SET[studentid]='"+txtStuID.Text+"',[studentname]='"+txtStuName.Text+"',[studentsex]='"+pstusex+"',[studydate]='"+dbtStudyDate.Text+"',[departname]='"+cboDepartName.Text+"',[classname]='"+cboClassName.Text+"',[studentidcard]='"+txtStuIDCard.Text+"',[address]='"+txtAddress.Text+"',[studentTel]='"+txtStuTel.Text+"',[extendfield]='"+txtExField.Text+"'WHEREstudentID='"+txtStuID.Text+"'";

SqlCommandcmd=newSqlCommand(strsql,sqlcon);

intresult=cmd.ExecuteNonQuery();

if(result>0)

MessageBox.Show("修改成功!

");

else

MessageBox.Show("修改失败!

");

}

}

}

6,运行测试

1,注册用户

2,登录用户

3,自动跳转到

4,添加用户信息

 

5.添加用户成功

 

 

6,点击“用户信息添加”跳转到下一窗体,点击“查询”,显示添加信息

7,点击“修改”,自动跳转到下一窗体

8,点击“删除”,成功

三,学生管理系统完成。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1