C#.NET程序设计课程设计说明书教师信息管理系统.doc
、C#.NET程序设计课程设计说明书设计题目: 教师信息管理系统 学院、系: 软件学院 专业班级: 软升本10-4 学生姓名: 某某 指导教师: 成 绩: 2011 年 7 月 12 日一、课程设计目的1)要求学生达到熟练掌握C#.NET基本结构以及C#语言的基本知识和技能;2)掌握面向对象程序开发的基本思路和方法;3)掌握ADO.NET数据库开发基本知识;4)能够利用所学的基本知识和技能,进行简单数据库应用程序设计。二、课程设计任务与要求1. 基本要求:1)要求利用C#的编程思想以及组件开发原理来完成系统的设计; 2)突出C#语言与其它语言不同点(即体现C#的高级功能,如属性概念、接口、事件、委托等);3)体现可视化编程基本思想,如系统带有菜单、工具栏、状态栏以及一些常用的高级控件。2. 创新要求:在基本要求达到后,可进行创新设计。三、需求分析本系统的设计主要具备以下功能:教师授课信息管理,即课程管理;教师个人信息管理;教师所属院系信息管理;教师月收入信息管理。开始的界面也很美观,同时也方便用户的使用,快捷,实用。这个设计中的每个模块都提供了以下四个功能:添加、修改,查询浏览以及删除,更清晰细致的展现了整个系统设计。四、概要设计1、模块功能:(1) 教师个人信息管理:添加:增加教师个人信息记录。浏览:对已有教师个人信息进行浏览。修改:对现有信息记录进行修改。删除:删除选中信息记录。(2) 课程信息管理:添加:增加课程信息记录。浏览:对已存在信息记录浏览。修改:修改已存在信息记录。删除:删除信息记录。(3) 院系类别信息管理:添加:增加院系类别信息记录。浏览:对已存在信息记录浏览。修改:修改已存在信息记录。删除:删除信息记录。(4) 教师工资管理:添加:增加教师月工资信息记录。浏览:对已存在信息记录浏览。修改:修改已存在信息记录。删除:删除信息记录。2、模块结构:3、数据库设计:授课信息Tb_course字段类型描述KIDKNameKbeizhuint(自动编号)Varchar(50)Varchar(50)课程编号课程名称课程备注 教师信息表Tb_teacher 字段类型描述TIDTNameBIDKNameTsexTplaceTlevelTspecialTbusiTbeizhuVarchar(50)Varchar(50)intVarchar(50)Varchar(50)Varchar(50)Varchar(50)Varchar(50)Varchar(50)Varchar(50)教师编号教师姓名部门编号课程名称性别教师籍贯学历所学专业职称备注部门信息表Tb_bumen 字段类型描述BidBNameBbeizhuint(自动编号) Varchar(50)Varchar(50)部门编号部门名称部门备注月收入Tb_shouru 字段类型描述SIDSMOnthTIDSncomeSbeizhuint(自动编号)Varchar(50)Varchar(50)Varchar(50)Varchar(50)收入编号月份教师编号月收入备注4、文件夹设计: 五、详细设计注意:此部分应包括具体设计过程,如设计目的、设计思路,界面设计,代码实现(关键代码)等,但不需要粘贴所有程序代码。(此部分必须包含主界面及至少两个模块设计)。 此部分红颜色文字在报告中应删去1、系统运行主页面:主要代码:public partial class FromMain : Form public FromMain() InitializeComponent(); private void FromMain_Load(object sender, EventArgs e) Addkecheng frmAddkecheng; private void menuAddkecheng_Click(object sender, EventArgs e) if (frmAddkecheng = null | frmAddkecheng.IsDisposed) frmAddkecheng = new Addkecheng(); for (int x = 0; x < this.MdiChildren.Length; x+) Form tempChild = (Form)this.MdiChildrenx; tempChild.Close(); frmAddkecheng.MdiParent = this; frmAddkecheng.Show(); Addyuanxi frmAddyuanxi; private void menuAddyuanxi_Click(object sender, EventArgs e) if (frmAddyuanxi = null | frmAddyuanxi.IsDisposed) frmAddyuanxi = new Addyuanxi(); for (int x = 0; x < this.MdiChildren.Length; x+) Form tempChild = (Form)this.MdiChildrenx; tempChild.Close(); frmAddyuanxi.MdiParent = this; frmAddyuanxi.Show(); 2、部门信息管理模块: 该模块主要实现用户对部门信息的添加、浏览、修改和删除操作。 运行结果如下图: 部分代码: Addkecheng.cs页面:private void button1_Click(object sender, EventArgs e) if (txtkechengName.Text.Trim() = "" | txtkeshi.Text.Trim() = "") MessageBox.Show("请输入课程名称和课时!", "提示", 0); else using (SqlConnection con = new SqlConnection(strConn) if (con.State = ConnectionState.Closed) con.Open();try SqlCommand cmd = new SqlCommand("select * from tb_kecheng where CName='" + txtkechengName.Text.Trim() + "'", con); if (cmd.ExecuteScalar() != null) MessageBox.Show("课程名重复,请重新输入!", "提示", 0); else string sql = "insert into tb_kecheng(CName,CTime) values('" + txtkechengName.Text.Trim() + "','" + txtkeshi.Text.Trim() + "')" cmd.CommandText = sql; cmd.ExecuteNonQuery(); MessageBox.Show("添加课程信息成功!", "提示", 0); txtkechengName.Clear(); txtkeshi.Clear(); catch (Exception ex) MessageBox.Show("错误:" + ex.Message, "错误提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Error); finally if (con.State = ConnectionState.Open) con.Close(); con.Dispose(); Browsekecheng.cs页面:private void Browsekecheng_Load(object sender, EventArgs e) showinf(); private void showinf() using (SqlConnection con = new SqlConnection(strConn) if (con.State = ConnectionState.Closed) con.Open(); try string sql = "select CId as 编号,CName as 课程名称,CTime as 总课时 from tb_kecheng order by CId" SqlDataAdapter adp = new SqlDataAdapter(sql, con); DataSet ds = new DataSet(); ds.Clear(); adp.Fill(ds, "kecheng"); this.dataGridView1.DataSource = ds.Tables0.DefaultView; catch(Exception ex) MessageBox.Show("错误:" + ex.Message , "错误提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); finally if (con.State = ConnectionState.Open) con.Close(); con.Dispose(); updatekecheng frmupdatekecheng; private void btnUpdate_Click(object sender, EventArgs e) if (this.dataGridView1.CurrentCell != null) frmupdatekecheng = new updatekecheng(); frmupdatekecheng.Tag = this.dataGridView10,this.dataGridView1.CurrentCell.RowIndex.Value.ToString().Trim(); frmupdatekecheng.StartPosition = FormStartPosition.CenterParent; frmupdatekecheng.ShowDialog(); if (frmupdatekecheng.DialogResult = DialogResult.OK) showinf(); private void btnExit_Click(object sender, EventArgs e) this.Close(); private void btnDelete_Click(object sender, EventArgs e) using (SqlConnection con = new SqlConnection(strConn) if (con.State = ConnectionState.Closed) con.Open(); try if (this.dataGridView1.CurrentCell != null) string sql = "select CName from tb_kecheng where CId=" + this.dataGridView10, this.dataGridView1.CurrentCell.RowIndex.Value.ToString().Trim() + " and CId not in (select distinct tb_kecheng.CId from tb_teacher inner join tb_kecheng on tb_teacher.CName=tb_kecheng.CName)" SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader dr; dr = cmd.ExecuteReader(); if (!dr.Read() MessageBox.Show("删除工种'" + this.dataGridView10, this.dataGridView1.CurrentCell.RowIndex.Value.ToString().Trim() + "'失败,请先删除与此工种相关的员工!", "提示"); dr.Close(); else dr.Close(); sql = "delete from tb_kecheng where CId=" + this.dataGridView10, this.dataGridView1.CurrentCell.RowIndex.Value.ToString().Trim() + " and CName not in (select distinct CName from tb_teacher)"cmd.CommandText = sql; cmd.ExecuteNonQuery(); MessageBox.Show("删除工种'" + this.dataGridView10, this.dataGridView1.CurrentCell.RowIndex.Value.ToString().Trim() + "'成功", "提示"); catch (Exception ex) MessageBox.Show("错误:" + ex.Message, "错误提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); finally if (con.State = ConnectionState.Open) con.Close(); con.Dispose(); showinf(); updatekecheng.cs页面:public partial class updatekecheng : Form public updatekecheng() InitializeComponent();private void updatekecheng_Load(object sender, EventArgs e) this.StartPosition = FormStartPosition.CenterParent; this.lblID .Text = this.Tag.ToString().Trim();private void btnExit_Click(object sender, EventArgs e) this.Close(); public static string strConn = "Data Source=(local);Initial Catalog=teacher;Integrated Security=true"private void tnOk_Click(object sender, EventArgs e) if (this.txtkechengName .Text.Trim() = "" | this.txtzhuanyeName .Text.Trim() = "") MessageBox.Show("请输入完整信息!", "提示", 0); else using (SqlConnection con = new SqlConnection(strConn) if (con.State = ConnectionState.Closed) con.Open(); try SqlCommand cmd = new SqlCommand("select * from tb_kecheng where CName='" + txtkechengName.Text.Trim() + "' and CId<>" + this.Tag.ToString().Trim(), con); if (cmd.ExecuteScalar() != null) MessageBox.Show("课程名称发生重复,请重新输入!", "提示", 0); else string sql = "update tb_kecheng set CName='" + txtkechengName.Text.Trim() + "',CTime='" + txtzhuanyeName.Text.Trim() + "' where CId=" + this.Tag.ToString().Trim(); cmd.CommandText = sql; cmd.ExecuteNonQuery(); MessageBox.Show("课程信息修改成功!", "提示", 0); catch (Exception ex) MessageBox.Show("错误:" + ex.Message, "错误提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); finally if (con.State = ConnectionState.Open) con.Close(); con.Dispose();3、教师个人信息管理模块: 该模块主要实现用户对教师个人信息进行操作,具体操作包括:添加、浏览、修改和删除操作。运行结果如下图: 部分代码: Addjiaoshi.cs页面:private void btnOk_Click(object sender, EventArgs e) if (this.txtTID .Text.Trim() = "" | this.txtTName .Text.Trim() = "" | this.cmbTSex .Text.Trim() = "" | this.txtPlevel.Text.Trim() = "" |this.cmbCName .Text.Trim() = "" | this.cmbYuanxiID .Text.Trim() = "" ) MessageBox.Show("请填写完整的教师信息!", "提示", 0); elseusing (SqlConnection con = new SqlConnection(strConn) if (con.State = ConnectionState.Closed) con.Open(); try SqlCommand cmd = new SqlCommand("select * from tb_teacher where TId='" + txtTID.Text.Trim() + "'", con); if (cmd.ExecuteScalar() != null) MessageBox.Show("教师编号重复,请重新输入!", "提示", 0); else string sql1, sql2, sql; sql1 = "insert into tb_teacher (TId,TName,TSex,TLevel,CName,YId" sql2 = "values ('" + txtTID.Text.ToString() + "','" + txtTName.Text.ToString() + "','" + cmbTSex.Text.Trim() + "','" + txtPlevel.Text.ToString() + "','" + cmbCName.Text.Trim() + "'," + cmbYuanxiID.SelectedValue.ToString(); sql = sql1 + ") " + sql2 + ")" cmd.CommandText = sql; cmd.ExecuteNonQuery(); MessageBox.Show("教师信息添加成功", "提示", 0); catch (Exception ex) MessageBox.Show("错误:" + ex.Message, "错误提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); finally if (con.State = ConnectionState.Open) con.Close(); con.Dispose(); Browsejiaoshi.cs页面:private void showinf() using (SqlConnection con = new SqlConnection(strConn) if (con.State = ConnectionState.Closed) con.Open(); try string sql = "select tb_teacher.TId as 教师编号,tb_teacher.TName as 教师姓名,tb_teacher.TSex as 性别,tb_teacher.Tlevel as 教师学历,tb_yuanxi.YName as 院系名称 from tb_teacher inner join tb_yuanxi on tb_teacher.YId = tb_yuanxi.YId where tb_yuanxi.YName='" + this.cmbYuanxiId.Text.ToString() + "' order by TId" SqlDataAdapter adp = new SqlDataAdapter(sql, con); DataSet ds = new DataSet(); ds.Clear(); adp.Fill(ds, "person"); if (ds.Tables0.Rows.Count != 0) this.dgvteacherInfo.DataSource = ds.Tables0.DefaultView; this.label2 .Text = "共有" + ds.Tables0.Rows.Count + "条查询结果" else this.label2 .Text = "没有您所查找的教师信息" this.dgvteacherInfo .DataSource = null; catch (Exception ex) MessageBox.Show("错误:" + ex.Message, "错误提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); finally if (con.State = ConnectionState.Open) con.Close(); con.Dispose(); private void button2_Click(object sender, EventArgs e) using (SqlConnection con = new SqlConnection(strConn) if (con.State = ConnectionState.Closed) con.Open(); try if (this.dgvteacherInfo.CurrentCell != null) string sql = "select * from tb_Income where TId='" + this.dgvteacherInfo0, this.dgvteacherInfo.CurrentCell.RowIndex.Value.ToString().Trim() + "'" SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader dr; dr = cmd.ExecuteReader(); if (dr.Read() MessageBox.Show("删除教师'" + this.dgvteacherInfo0, this.dgvteacherInfo.CurrentCell.RowIndex.Value.ToString().Trim() + "'失败,请先删除该教师的收入信息!", "提示"); dr.Close(); else dr.Close(); sql = "delete from tb_teacher where TId='" + this.dgvteacherInfo0, this.dgvteacherInfo.CurrentCell.RowIndex.Value.ToString().Trim() + "'"cmd.CommandText = sql; cmd.ExecuteNonQuery(); MessageBox.Show("删除员工'" + this.dgvteacherInfo0, this.dgvteacherInfo.CurrentCell.RowIndex.Value.ToString().Trim() + "'成功", "提示"); el