protected void gvDepartments_RowUpdating(object sender, GridViewUpdateEventArgs e) { int deptID = Convert.ToInt32(e.Keys[0]); // 获取被编辑的行所对应Department的编号。需在GridView中预先设置DataKeyNames GridViewRow gvr = gvDepartments.Rows[e.RowIndex]; // 获取当前被编辑的行 TextBox txtDepartmentName = gvr.FindControl("txtDepartmentName") as TextBox; // 找到部门名称编辑框 string newName = txtDepartmentName.Text; Department department = new Department(); department.DepartmentID = deptID; department.DepartmentName = newName; StaffOpResult result = BLLStaff.UpdateDepartment(department); string script; if (result == StaffOpResult.Duplicate) { script = "<script type='text/javascript'>alert('部门:" + newName + " 已经存在!');</script>"; Page.ClientScript.RegisterStartupScript(this.GetType(), "duplicate", script); e.Cancel = true; // 不再执行后续操作,回到编辑状态 } else { script = "<script type='text/javascript'>alert('部门修改成功!');</script>"; Page.ClientScript.RegisterStartupScript(this.GetType(), "success", script); gvDepartments.EditIndex = -1; // 退出编辑状态 BindDepartments(); } }
protected void btnSubmit_Click(object sender, EventArgs e) { string oldPassword = txtOrigin.Text; string newPassword = txtNew.Text; StaffOpResult result = BLLStaff.ChangePassword(oldPassword, newPassword); string script = ""; if (result == StaffOpResult.PasswordIncorrect) { script = "<script type='text/javascript'>alert('原始密码错误!');</script>"; Page.ClientScript.RegisterStartupScript(this.GetType(), "error", script); } else { script = "<script type='text/javascript'>alert('密码修改成功!');</script>"; Page.ClientScript.RegisterStartupScript(this.GetType(), "success", script); } }
protected void gvDepartments_RowDeleting(object sender, GridViewDeleteEventArgs e) { int deptID = Convert.ToInt32(e.Keys[0]); StaffOpResult result = BLLStaff.DeleteDepartment(deptID); string script; if (result == StaffOpResult.DependanceExists) { script = "<script type='text/javascript'>alert('该部门下仍有员工,不能删除!');</script>"; Page.ClientScript.RegisterStartupScript(this.GetType(), "duplicate", script); e.Cancel = true; } else { script = "<script type='text/javascript'>alert('部门删除成功!');</script>"; Page.ClientScript.RegisterStartupScript(this.GetType(), "success", script); BindDepartments(); } }
protected void btnSubmit_Click(object sender, EventArgs e) { string departmentName = txtDepartmentName.Text; StaffOpResult result = BLLStaff.AddDepartment(departmentName); string script; if (result == StaffOpResult.Duplicate) { script = "<script type='text/javascript'>alert('部门:" + departmentName + " 已经存在!');</script>"; Page.ClientScript.RegisterStartupScript(this.GetType(), "duplicate", script); } else { BindDepartments(); // 重新绑定以显示新增部门数据 txtDepartmentName.Text = ""; script = "<script type='text/javascript'>alert('部门:" + departmentName + " 添加成功!');</script>"; Page.ClientScript.RegisterStartupScript(this.GetType(), "success", script); } }
protected void btnSubmit_Click(object sender, EventArgs e) { string employeeName = txtEmployeeName.Text; string userName = txtUserName.Text; string password = txtPassword.Text; string email = txtEmail.Text; string phone = txtPhone.Text; Employee employee = new Employee(); employee.EmployeeName = employeeName; employee.UserName = userName; employee.Password = password; employee.Phone = phone; employee.Email = email; Department department = new Department(); department.DepartmentID = Convert.ToInt32(ddlDepartments.SelectedValue); department.DepartmentName = ddlDepartments.SelectedItem.Text; employee.RelatedDepartment = department; employee.Status = EmployeeStatusType.Inactive; StaffOpResult result = BLLStaff.Register(employee); if (result == StaffOpResult.Duplicate) { lblResult.Text = "用户名或电子邮件已经存在,请修改!"; } else if (result == StaffOpResult.UserCreateError) { lblResult.Text = "创建用户账号失败,请联系管理员!"; } else { txtEmployeeName.Text = ""; txtUserName.Text = ""; txtPhone.Text = ""; txtEmail.Text = ""; ddlDepartments.SelectedIndex = 0; lblResult.Text = "注册成功!"; } }