protected void lbtChangeAdvance_Click(object sender, EventArgs e) { try { RoleDetailBUS rdBus = new RoleDetailBUS(); PanelAdvance.Visible = false; int departmentId = int.Parse(hdfDepartmentId.Value); int limitSendMail = int.Parse(txtLimitMailSend.Text); string toDate = txtToDate.Text; int limitCreateCustomer = int.Parse(txtLimitCreateCustomer.Text); if (chkAdvance.Checked) { // Cap nhat voi hang ngach gui mail, tao khach hang. RoleDetailDTO rdDto = new RoleDetailDTO(); rdDto.roleId = -1; rdDto.departmentId = departmentId; rdDto.limitSendMail = limitSendMail; rdDto.limitCreateCustomer = limitCreateCustomer; rdDto.toDate = convertStringToDate(toDate); ConnectionData.OpenMyConnection(); int rsUpdate = rdBus.tblRoleDetail_Update(rdDto); ConnectionData.CloseMyConnection(); if (rsUpdate <= 0) { // Them voi hang ngach gui mail, tao khach hang. ConnectionData.OpenMyConnection(); rdBus.tblRoleDetail_insert(rdDto); ConnectionData.CloseMyConnection(); } // Reset thong tin so luong da gui mail cua tat ca user trong group. UserLoginBUS ulBus = new UserLoginBUS(); ConnectionData.OpenMyConnection(); ulBus.tblUserLogin_UpdateByDepartmentId(departmentId, 0); ConnectionData.CloseMyConnection(); } else { // Xóa phân quyền nâng cao. ConnectionData.OpenMyConnection(); rdBus.tblRoleDetail_Delete(-1, departmentId); ConnectionData.CloseMyConnection(); } PanelAdvanceSuccess.Visible = true; lblAdvanceSuccess.Text = "Cập nhập thành công !"; } catch (Exception) { PanelAdvanceSuccess.Visible = false; PanelAdvance.Visible = true; lblAdvanceError.Text = "Kiểm tra lại dữ liệu nhập !"; } }
protected void lbtChangeRole_Click(object sender, EventArgs e) { try { // Get role list by departmentId int departId = int.Parse(hdfDepartmentId.Value.ToString()); rdBus = new RoleDetailBUS(); DataTable dtOldRole = rdBus.GetByDepartmentId(departId); DataTable insertRole = new DataTable(); insertRole.Columns.Add("roleId", typeof(int)); //iterator to check new_role with old_role for (int i = 0; i < dlRoleList.Items.Count; i++) { CheckBox chkCheck = (CheckBox)dlRoleList.Items[i].FindControl("chkCheck"); HiddenField hdfRoleId = (HiddenField)dlRoleList.Items[i].FindControl("hdfRoleId"); if (chkCheck.Checked) { checkNewOldRole(dtOldRole, insertRole, int.Parse(hdfRoleId.Value)); } } //delete old role if (dtOldRole.Rows.Count > 0) { for (int j = 0; j < dtOldRole.Rows.Count; j++) { int roleId = int.Parse(dtOldRole.Rows[j]["roleId"].ToString()); ConnectionData.OpenMyConnection(); rdBus.tblRoleDetail_Delete(roleId, departId); ConnectionData.CloseMyConnection(); } } //insert new role if (insertRole.Rows.Count > 0) { for (int k = 0; k < insertRole.Rows.Count; k++) { int roleId = int.Parse(insertRole.Rows[k]["roleId"].ToString()); RoleDetailDTO rdDto = new RoleDetailDTO(); rdDto.roleId = roleId; rdDto.departmentId = departId; rdDto.limitSendMail = 0; // Set default value. rdDto.limitCreateCustomer = 0; // Set default value rdDto.toDate = DateTime.Now; // Set default value ConnectionData.OpenMyConnection(); rdBus.tblRoleDetail_insert(rdDto); ConnectionData.CloseMyConnection(); } } pnSuccess.Visible = true; pnError.Visible = false; lblSuccess.Text = "Đã thay đổi quyền thành công !"; } catch (Exception) { throw; } }