/// <summary> /// 数据准备 /// </summary> private void BindData() { Controller.EmpManageAction emp = new Controller.EmpManageAction(); string mag = string.Empty; string[] paras = new string[] { txtQuery.Text }; DataTable dt = emp.GetDepartment(out mag, paras); if (dt == null) { this.Response.Write($@"<script> alert('{mag}') </script>"); } GridView1.DataSource = null; GridView1.DataSource = dt; GridView1.DataBind(); }
/// <summary> /// 校验【保存】时数据输入是否有效 /// </summary> private bool ValidateSaveInput(bool isNew, out string mag) { mag = string.Empty; bool success = true; //*修改密码或者新增状态:新密码不能为空* if (chkPassword.Checked || isNew) { if (string.IsNullOrEmpty(txtNewPwd.Text)) { success = false; txtNewPwd.BorderColor = System.Drawing.Color.OrangeRed; mag += @"修改密码或新增用户时,新密码不能为空。\n"; } } //*选择代评分者* if (ddlStatus.SelectedValue == "3") { if (string.IsNullOrEmpty(txtDaiGradeCode.Text)) { success = false; txtDaiGradeCode.BorderColor = txtDaiGradeName.BorderColor = System.Drawing.Color.OrangeRed; mag += @"选择代评分者信息输入有误,请检查。\n"; } } //*员工编号、名称* if (string.IsNullOrEmpty(txtEmCode.Text) || string.IsNullOrEmpty(txtEmName.Text)) { success = false; txtEmCode.BorderColor = txtEmName.BorderColor = System.Drawing.Color.OrangeRed; mag += @"员工编号、名称是必填项,请确认。\n"; } //*必填项验证* if (string.IsNullOrEmpty(txtReGradeID.Text) || string.IsNullOrEmpty(txtDepartment.Text) || string.IsNullOrEmpty(txtPosition.Text)) { success = false; mag += @"带标记的必填项不能为空。\n"; } //**新增状态验证** if (isNew) { Controller.EmpManageAction action = new Controller.EmpManageAction(); //*验证员工编号是否已经存在* object x = action.ExistsTheSameEmployeeCode(out string existsEmcode, txtEmCode.Text); if (x == null && !string.IsNullOrEmpty(existsEmcode)) { success = false; mag += (existsEmcode + "\n"); } if (x != null) { mag += $@"存在相同的员工编号【{x.ToString()}】"; success = false; } } //*是否代评分者与代评分用户冲突* if (ddlStatus.SelectedValue == "3" && rbtDaiGradeYes.Checked) { success = false; mag += @"【被代评分者】不能兼容【代评分用户】。 \n"; } return(success); }
/// <summary> /// 保存 /// </summary> protected void btnSave_Click(object sender, EventArgs e) { string mag = string.Empty; employee_nom = null; bool success = true; //**获取当前数据状态:新增/修改** bool isNew = Convert.ToBoolean(Session["Employee_New"]); //**校验【保存】时数据输入是否有效** if (success) { if (!this.ValidateSaveInput(isNew, out mag)) { success = false; } } //**加载页面数据** if (success) { employee_nom = this.UpdatePageToModel(out mag); if (employee_nom == null) { success = false; } } //**数据处理** if (success) { Controller.EmpManageAction action = new Controller.EmpManageAction(); //**新增员工信息** if (isNew) { if (!action.InsertEmployeeDetail(out mag, employee_nom)) { success = false; } } //**更新员工信息表** else { if (!action.UpdateEmployeeDetail(employee_nom, out mag)) { success = false; } } if (success) { //*检验是否代评分用户--返回FCancellation状态* bool result = action.ValidateNewDaiGrade(out mag, out int status, new string[] { txtEmCode.Text }); //*异常* if (!result && status == -1) { success = false; } if (success) { //**状态 = 代评分** if (employee_nom.FStatus == "3") { //*新增代评分表记录* if (!result && status == 0) { if (!action.InsertDaiGradeRecord(out mag, new string[] { txtReGradeID.Text, txtEmCode.Text, txtDaiGradeCode.Text })) { success = false; } } //*修改代评分记录* if (result) { if (!action.UpdateDaiGradeRecord(out mag, new string[] { txtReGradeID.Text, txtDaiGradeCode.Text, txtEmCode.Text })) { success = false; } } } //**状态 != 代评分 -- 数据状态改为失效** else { if (result && status != 1) { if (!action.UpdateDaiGradeRecordStatus(out mag, new string[] { txtEmCode.Text })) { success = false; } } } } } } //**执行结果** if (!success) { Response.Write($@"<script>alert('{mag}');</script>"); return; } else { mag += @"数据更新成功。"; //*清空待修改的数据 Session* Session["Empmanager_employee"] = null; Session["EmployeInfomation_Status"] = null; if (isNew) { //*单据标识改为 修改* Response.Write($@"<script>alert('{mag}'),location='EmployeeManager.aspx';</script>"); } else { Response.Write($@"<script>alert('{mag}');</script>"); } } }