protected void teacherdelete_Click(object sender, EventArgs e) { int gh = Int32.Parse((sender as Button).CommandArgument.ToString()); string sql = "delete from tb_teacher where gh ='" + gh + "'"; try { if (DBControl.delete(sql) > 0) { TeacherListView.DataSource = null; TeacherListView.DataBind(); ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('删除成功')", true); } else { TeacherListView.DataSource = null; TeacherListView.DataBind(); ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('该教师不存在')", true); } } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('系统异常')", true); } }
protected void teachereditsub_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(teachereditage.Text.Trim())) { ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('工龄不能为空!')", true); } if (string.IsNullOrEmpty(teachereditsalary.Text.Trim())) { ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('基本工资不能为空!')", true); } if (Convert.ToInt32(teachereditdept.SelectedValue) == 0) { ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('请选择院系!')", true); } int gh = 0; string xb = null; string xm = null; string zc = null; DateTime csrq = System.DateTime.Now; int gl = 0; int jbgz = 0; int dno = 0; try { gh = Convert.ToInt32(teacheredituser.Text.Trim()); xm = teachereditname.Text.Trim(); xb = "男"; if (teachereditsex2.Checked) { xb = "女"; } zc = teacheredittitles.Text.Trim(); gl = Convert.ToInt32(teachereditage.Text.Trim()); csrq = Convert.ToDateTime(teachereditbirth.Text.Trim()); jbgz = Convert.ToInt32(teachereditsalary.Text.Trim()); dno = Convert.ToInt32(teachereditdept.SelectedValue); } catch (Exception) { ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('请在工龄、基本工资中输入数字')", true); } string sql = "update tb_teacher set xm='" + xm + "',xb='" + xb + "',zc='" + zc + "',gl='" + gl + "',csrq='" + csrq + "',jbgz='" + jbgz + "',dno='" + dno + "' where gh ='" + gh + "'"; try { DBControl.update(sql); ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('编辑成功')", true); TeacherListView.DataSource = null; TeacherListView.DataBind(); manageteacher_panel.Visible = true; editteacher_panel.Visible = false; } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('编辑失败')", true); } }
private void add_Click(object sender, EventArgs e) { var newTeacher = new Teacher { f = teacherF.Text, i = teacherI.Text, o = teacherO.Text, phone = teacherPhone.Text, birth_date = teacherBirthDate.Value }; tRepo.add(newTeacher); RefreshView((int)RefreshType.TeachersOnly); var teacherList = (List <Teacher>)TeacherListView.DataSource; var addedTeacher = teacherList.FirstOrDefault(t => t.f == newTeacher.f && t.i == newTeacher.i && t.o == newTeacher.o); var newIndex = -1; for (int i = 0; i < teacherList.Count; i++) { if (teacherList[i].f == newTeacher.f && teacherList[i].i == newTeacher.i && teacherList[i].o == newTeacher.o) { newIndex = i; } } if (newIndex != -1) { TeacherListView.ClearSelection(); TeacherListView.Rows[newIndex].Selected = true; TeacherListView.FirstDisplayedScrollingRowIndex = newIndex; } }