private void btSave_Click(object sender, RoutedEventArgs e) { tbGroupAccountValidation.Text = ""; if (tbName.Text == "") { // Name of Employee Type is empty tbGroupAccountValidation.Text = "Tên nhóm tài khoản không dược để trống."; return; } DTO_EmployeeType newEmpType = new DTO_EmployeeType("id", tbName.Text); BUS_EmployeeType busEmpType = new BUS_EmployeeType(); string newID = busEmpType.CreateEmployeeTypes(newEmpType); if (newID == "") { tbGroupAccountValidation.Text = "Tên nhóm tài khoản này đã được tạo trước đây."; } else { BUS_AccessPermissionGroup busAccPerGr = new BUS_AccessPermissionGroup(); foreach (AccessPermissionName item in dgSelectedList) { foreach (DataRow row in AccPersData.Rows) { if (item.name == row[1].ToString()) { busAccPerGr.CreateAccessPermissionGroup(new DTO_AccessPermissionGroup(row[0].ToString(), newID)); break; } } } MessageBox.Show($"Nhóm tài khoản {newEmpType.EmployeeTypeName} đã được tạo."); Window.GetWindow(this).Close(); } }
private void btSave_Click(object sender, RoutedEventArgs e) { tbGroupAccountValidation.Text = ""; if (tbName.Text == "") { // Name of Employee Type is empty tbGroupAccountValidation.Text = "Tên nhóm tài khoản không dược để trống."; return; } BUS_EmployeeType busEmpType = new BUS_EmployeeType(); string editID = busEmpType.GetIDByName(editGrAccInfo.name); bool result = busEmpType.EditEmployeeType(new DTO_EmployeeType(editID, tbName.Text)); if (!result) { tbGroupAccountValidation.Text = "Tên nhóm tài khoản bị trùng với một nhóm tài khoản khác."; return; } BUS_AccessPermissionGroup busAccPerGr = new BUS_AccessPermissionGroup(); #region Get List Permission List <AccessPermissionName> oldPerList = new List <AccessPermissionName>(); if (editGrAccInfo.cashier) { oldPerList.Add(new AccessPermissionName(Constants.CASHIER)); } if (editGrAccInfo.account) { oldPerList.Add(new AccessPermissionName(Constants.ACCOUNT)); } if (editGrAccInfo.accountType) { oldPerList.Add(new AccessPermissionName(Constants.ACCOUNTTYPE)); } if (editGrAccInfo.inventory) { oldPerList.Add(new AccessPermissionName(Constants.INVENTORY)); } if (editGrAccInfo.cost) { oldPerList.Add(new AccessPermissionName(Constants.COST)); } if (editGrAccInfo.menu) { oldPerList.Add(new AccessPermissionName(Constants.MENU)); } if (editGrAccInfo.discount) { oldPerList.Add(new AccessPermissionName(Constants.DISCOUNT)); } if (editGrAccInfo.report) { oldPerList.Add(new AccessPermissionName(Constants.REPORT)); } if (editGrAccInfo.rule) { oldPerList.Add(new AccessPermissionName(Constants.REPORT)); } #endregion // per deleted foreach (AccessPermissionName name in oldPerList) { if (!dgSelectedList.Contains(name)) { foreach (DataRow row in AccPersData.Rows) { if (name.name == row[1].ToString()) { result = busAccPerGr.DeleteAccessPermissionGroup(new DTO_AccessPermissionGroup(row[0].ToString(), editID)); if (!result) { MessageBox.Show($"Đã xảy ra lỗi do quyền bị xóa đi trong quá trình sửa nhóm tài khoản {editGrAccInfo.name}."); } break; } } } } // per added foreach (AccessPermissionName item in dgSelectedList) { if (!oldPerList.Contains(item)) { foreach (DataRow row in AccPersData.Rows) { if (item.name == row[1].ToString()) { result = busAccPerGr.CreateAccessPermissionGroup(new DTO_AccessPermissionGroup(row[0].ToString(), editID)); if (!result) { MessageBox.Show($"Đã xảy ra lỗi do quyền được thêm vào trong quá trình sửa nhóm tài khoản {editGrAccInfo.name}."); } break; } } } } MessageBox.Show($"Đã sửa thành công nhóm tài khoản {editGrAccInfo.name}."); Window.GetWindow(this).Close(); }