public frmAddAccount() { employee = new Entities.Employees1(); if (!frmEmployee.pStatusAddEmployee) { employee = frmEmployee.employee; } InitializeComponent(); SettingControl(); }
private void frmAddAccount_FormClosed(object sender, FormClosedEventArgs e) { this.employee = null; }
private void btnSave_Click(object sender, EventArgs e) { string ppEmployeeId = ""; try { Entities.Employees1 emp = new Entities.Employees1(); emp = SetEmployee(); if (string.IsNullOrEmpty(emp.EmployeeCode)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM94"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } if (!Common.Validation.ValidateNumber(emp.EmployeeCode)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM519"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } if (string.IsNullOrEmpty(emp.EmployeeName)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM312"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } //if (!Common.Validation.ValidateBirthDate(emp.BirthDate)) //{ // CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM310"), // Common.clsLanguages.GetResource("CRM11"), // Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, // Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); // return; //} if (!string.IsNullOrEmpty(emp.Email)) { if (!Common.Validation.ValidateEmail(emp.Email)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM311"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } } if (!string.IsNullOrEmpty(emp.PhoneNumber)) { if (!Common.Validation.ValidatePhoneNumber(emp.PhoneNumber)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM47"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } } if (cbBCountry.SelectedIndex == 0) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM373"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } if (cbBEmployeeType.SelectedIndex == 0) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM514"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } if (pStatusAdd) { //Linh 29-12-2014 if (txtUserName.Text != "" && txtPassword.Text != "") { if (txtConfirm.Text == String.Empty) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM646"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } else { if (string.Compare(txtPassword.Text, txtConfirm.Text) != 0) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM647"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } } } if (employeeBLL.CheckEmployeeIsExist(emp.EmployeeCode, null)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM513"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } ppEmployeeId = employeeBLL.AddReturnId(emp); } else { if (employeeBLL.CheckEmployeeIsExist(emp.EmployeeCode, emp.EmployeeId)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM513"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } //Check mã đã tồn tại chưa DialogResult r = CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM227"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.YESNO); if (r == DialogResult.Yes) { employeeBLL.Edit(emp); this.Close(); } } if (!string.IsNullOrEmpty(employeeBLL.ErrorString)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM219"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } if (!string.IsNullOrEmpty(imagePath)) { employeeBLL.SaveImage(emp, imagePath); } if (!string.IsNullOrEmpty(employeeBLL.ErrorString)) { MessageBox.Show(employeeBLL.ErrorString, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!string.IsNullOrEmpty(imagePath)) { emp.Image = Image.FromFile(imagePath); } else { emp.Image = employee.Image; } #region Phân quyền DataTable roleTable = new DataTable(); roleTable.Columns.Add("EmployeeId", typeof(String)); roleTable.Columns.Add("RoleId", typeof(String)); if (pStatusAdd) { if (rdManager.Checked == true)//if (chkBManager.Checked == true) { DataRow row = roleTable.NewRow(); row["EmployeeId"] = ppEmployeeId; //for insert and update row["RoleId"] = "admin"; roleTable.Rows.Add(row); } if (rdEmployee.Checked == true)// if (chkBReception.Checked == true) { DataRow row = roleTable.NewRow(); row["EmployeeId"] = ppEmployeeId; //for insert and update row["RoleId"] = "letan"; roleTable.Rows.Add(row); } //if (chkBTablet.Checked == true) //{ // DataRow row = roleTable.NewRow(); // row["EmployeeId"] = ppEmployeeId; //for insert and update // row["RoleId"] = "tablet"; // roleTable.Rows.Add(row); //} roleBLL.UpdateRoleByUserId(ppEmployeeId, roleTable); } else { if (rdManager.Checked == true) //if (chkBManager.Checked == true) { DataRow row = roleTable.NewRow(); row["EmployeeId"] = emp.EmployeeId; row["RoleId"] = "admin"; roleTable.Rows.Add(row); } if (rdEmployee.Checked == true) //if (chkBReception.Checked == true) { DataRow row = roleTable.NewRow(); row["EmployeeId"] = emp.EmployeeId; row["RoleId"] = "letan"; roleTable.Rows.Add(row); } //if (chkBTablet.Checked == true) //{ // DataRow row = roleTable.NewRow(); // row["EmployeeId"] = emp.EmployeeId; // row["RoleId"] = "tablet"; // roleTable.Rows.Add(row); //} roleBLL.UpdateRoleByUserId(emp.EmployeeId, roleTable); } #endregion if (pStatusAdd) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM308"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); this.Close(); //btnAdd_Click(sender, e); } else { employee = emp; IsBeginLoad(false); Display(this.employee); } } catch (Exception) { string code = System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString(); if (code == "-532462766") { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM292"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); } return; } }
private void Display(Entities.Employees1 pEmployee) { if (pEmployee != null && !string.IsNullOrEmpty(pEmployee.EmployeeId)) { lblEmployeeId.Text = pEmployee.EmployeeId; txtEmployeeCode.Text = pEmployee.EmployeeCode; txtEmployeeName.Text = pEmployee.EmployeeName; if (pEmployee.Gender == 0) { //chkBGender.Checked = true; rdBFemal.Checked = true; } else { //chkBGender.Checked = false; rdBMale.Checked = true; } dteTBirthday.Value = pEmployee.BirthDate; txtEmail.Text = pEmployee.Email; txtPhoneNumber.Text = pEmployee.PhoneNumber; cbBCountry.SelectedValue = pEmployee.Country.CountryId; txtAddress.Text = pEmployee.Address; cbBEmployeeType.SelectedValue = pEmployee.EmployeeType.EmployeeTypeId; txtHourlyWages.Text = pEmployee.HourlyWages.ToString(); txtNote.Text = System.Text.RegularExpressions.Regex.Replace(pEmployee.Notes, "\n", "\r\n"); txtUserName.Text = pEmployee.UserName; txtPassword.Text = ""; //txtPassword.Text = pEmployee.Password; picBoxImage.Image = pEmployee.Image; //chkBManager.Checked = false; chkBReception.Checked = false; chkBTablet.Checked = false; txtPassword.Enabled = false; txtConfirm.Enabled = false; //txtConfirm.Enabled = false; chkBManager.Enabled = false; //rdManager.Enabled = false; chkBReception.Enabled = false; //rdEmployee.Enabled = false; DataTable employeeRoleTable = roleBLL.GetByUserId(pEmployee.EmployeeId); foreach (DataRow dataRow in employeeRoleTable.Rows) { if (dataRow["RoleId"].ToString().Trim() == "admin") { chkBManager.Checked = true; rdManager.Checked = true; } if (dataRow["RoleId"].ToString().Trim() == "letan") { chkBReception.Checked = true; rdEmployee.Checked = true; } if (dataRow["RoleId"].ToString().Trim() == "tablet") { chkBTablet.Checked = true; } } } else { lblEmployeeId.Text = ""; txtEmployeeCode.Text = ""; txtEmployeeName.Text = ""; // chkBGender.Checked = true; dteTBirthday.Value = DateTime.Now; txtEmail.Text = ""; txtPhoneNumber.Text = ""; cbBCountry.SelectedIndex = 0; txtAddress.Text = ""; cbBEmployeeType.SelectedIndex = 0; txtHourlyWages.Text = ""; txtNote.Text = ""; txtUserName.Text = ""; txtPassword.Text = ""; picBoxImage.Image = null; chkBManager.Checked = false; rdManager.Checked = false; //rdEmployee.Checked = true; //chkBReception.Checked = false; chkBTablet.Checked = false; } }