【教务管理员操作流程】.docx
教务管理员操作流程1、 使用Admin账号登陆教务管理员系统代码区域:int count = 0; bool isValidUser = false; if (loginType = "教务管理员") string sql = string.Format("select count(*) from Admin where LoginId='0' AND LoginPwd='1'", loginId, loginPwd); try SqlCommand command = new SqlCommand(sql, DBHelper.connection); DBHelper.connection.Open(); count = (int)command.ExecuteScalar(); if (count = 1) isValidUser = true; else index+; if (index <=3) message = "用户名或密码不存在!" else if (index >= 3) Application.Exit(); isValidUser = false; catch (Exception ex) message = ex.Message; Console.WriteLine(ex.Message); finally DBHelper.connection.Close(); if (cboType.Text = "教务管理员") AdminForm adminForm = new AdminForm(); adminForm.Show(); return true; 成功进入后可以进行AdminForm.cs (教务管理员窗体)用户管理新增用户新增学生信息(代码如下:) AddStudentForm addstudnetForm = new AddStudentForm(); addstudnetForm.MdiParent = this; addstudnetForm.Show();弹出窗口(学生信息添加)Student表AdminStudentForm.cs保存按钮代码如下: if (TianJia() try SqlCommand command = new SqlCommand(sql, DBHelper.connection); DBHelper.connection.Open(); int result = command.ExecuteNonQuery(); if (result != 1) MessageBox.Show("添加失败", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show("添加成功", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); catch (Exception ex) MessageBox.Show(ex.Message); finally DBHelper.connection.Close(); private void AddStudentForm_Load(object sender, EventArgs e) string sql = "select gradeName from Grade" try SqlCommand command=new SqlCommand(sql,DBHelper.connection); DBHelper.connection.Open(); SqlDataReader reader=command.ExecuteReader(); while(reader.Read() string gradeName=(string)reader0; cboGrade.Items.Add(gradeName); reader.Close(); catch(Exception ex) MessageBox.Show(ex.Message); finally DBHelper.connection.Close(); private void cboGrade_SelectedIndexChanged(object sender, EventArgs e) if (cboGrade.Text.Trim() != "") int gradeId = -1; string sql = string.Format("select GradeId from Grade where GradeName='0'",cboGrade.Text); SqlCommand command = new SqlCommand(sql, DBHelper.connection); try DBHelper.connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.Read() gradeId = (int)reader0; reader.Close(); catch (Exception ex) MessageBox.Show("操作数据库出错"); Console.WriteLine(ex.Message); finally DBHelper.connection.Close(); sql = "SELECT ClassName FROM Class WHERE GradeId=" +gradeId; command.CommandText = sql; try DBHelper.connection.Open(); SqlDataReader reader = command.ExecuteReader(); string className = "" cboClass.Items.Clear(); while (reader.Read() className = (string)reader"ClassName" cboClass.Items.Add(className); reader.Close(); catch (Exception ex) MessageBox.Show("操作数据库出错"); Console.WriteLine(ex.Message); finally DBHelper.connection.Close(); private void txtStudentPassword_TextChanged(object sender, EventArgs e) AdminTeacherForm.cs (教师信息添加窗体) 新增教师信息弹出窗口(教师信息添加)Teacher表保存按钮代码如下:if (TianJia() try SqlCommand command = new SqlCommand(sql, DBHelper.connection); DBHelper.connection.Open(); int result = command.ExecuteNonQuery(); if (result != 1) MessageBox.Show("添加失败", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show("添加成功", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); catch (Exception ex) MessageBox.Show("操作数据库出错", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); Console.WriteLine(ex.Message); finally DBHelper.connection.Close(); 查询修改信息学生信息查询及删除信息(可以进行模糊查询)SearchStudentForm.cs (学生查询及删除信息窗体)查询按钮代码:if (txtName.Text = "") MessageBox.Show("请输入用户名", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtName.Focus(); else SearchStudent(); private void tsmiDelete_Click(object sender, EventArgs e) if (listView1.SelectedItems.Count = 0) MessageBox.Show("您没有选择任何用户", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); else DialogResult choice = MessageBox.Show("确定要删除该用户吗", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); if (choice = DialogResult.OK) int result = 0; try string sql = string.Format("delete Student where StudentId=0", (int)listView1.SelectedItems0.Tag); SqlCommand command = new SqlCommand(sql, DBHelper.connection); DBHelper.connection.Open(); result = command.ExecuteNonQuery(); catch (Exception ex) MessageBox.Show(ex.Message); finally DBHelper.connection.Close(); if (result < 1) MessageBox.Show("删除失败", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); else MessageBox.Show("删除成功", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); SearchStudent(); UpdateStudentForm.cs (学生更新信息窗体)保存信息按钮代码:DialogResult result = MessageBox.Show("确实要将修改保存到数据库吗?", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); if (result = DialogResult.OK) SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter); dataAdapter.Update(dataSet, "Student"); MessageBox.Show("保存成功", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show("保存失败", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); SearchTeacherForm.cs (教师查询及删除信息窗体)查询按钮代码:if (txtName.Text = "") MessageBox.Show("请输入用户名", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtName.Focus(); else SearchTeacher(); private void btnExit_Click(object sender, EventArgs e) this.Close(); private void tsmiDelete1_Click(object sender, EventArgs e) if (listView1.SelectedItems.Count = 0) MessageBox.Show("您没有选择任何用户", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); else DialogResult choice = MessageBox.Show("确定要删除该用户吗", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); if (choice = DialogResult.OK) int result = 0; try string sql = string.Format("delete Teacher where TeacherId=0", (int)listView1.SelectedItems0.Tag); SqlCommand command = new SqlCommand(sql, DBHelper.connection); DBHelper.connection.Open(); result = command.ExecuteNonQuery(); catch (Exception ex) MessageBox.Show(ex.Message); finally DBHelper.connection.Close(); if (result < 1) MessageBox.Show("删除失败", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); else MessageBox.Show("删除成功", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); SearchTeacher(); UpdateTeacherForm.cs (教师更新信息窗体)保存信息按钮代码:DialogResult result = MessageBox.Show("确实要将修改保存到数据库吗?", "输入提示",MessageBoxButtons.OK, MessageBoxIcon.Information); if (result = DialogResult.OK) SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter); dataAdapter.Update(dataSet, "Teacher"); MessageBox.Show("保存成功", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show("保存失败", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 娱乐通过引用完成操作退出系统 重新登录(代码如下:) LoginForm fm1 = new LoginForm(); this.Hide(); fm1.Show();帮助说明版权说明(HelpForm.cs 帮助窗体)帮助信息(MessageBox.Show("欢迎使用帮助系统n本系统新建用户初始密码:n【123】", "帮助信息");)运行屏保(引用外部文件)