private void getUserInfo() { UserLoginBUS ulBus = new UserLoginBUS(); DepartmentBUS dBus = new DepartmentBUS(); RoleDetailBUS rdBus = new RoleDetailBUS(); int userId = int.Parse(Request.QueryString["uid"].ToString()); DataTable tblUserDetail = Common.GetUserLoginDetail(userId); DataTable tblSendRegisterDetailByUser = Common.GetSendRegisterByUserId(userId); DataTable tblCustomerCreated = Common.GetCustomerCreatedByUserId(userId); if (tblUserDetail.Rows.Count > 0) { int departId = int.Parse(tblUserDetail.Rows[0]["DepartmentId"].ToString()); DataTable tblRoleDetail = rdBus.GetByDepartmentId(departId); lblUsername.Text = tblUserDetail.Rows[0]["Username"].ToString(); lblDepartment.Text = tblUserDetail.Rows[0]["Name"].ToString(); if(tblRoleDetail.Rows.Count>0){ lblHasSend.Text = tblSendRegisterDetailByUser.Rows.Count + " / " + tblRoleDetail.Rows[0]["limitSendMail"].ToString(); lblHasCustomerCreate.Text = tblCustomerCreated.Rows.Count + " / " + tblRoleDetail.Rows[0]["limitCreateCustomer"].ToString(); lblToDate.Text = tblRoleDetail.Rows[0]["toDate"].ToString(); } } }
protected void loadBasicRole() { String departmentId = Request.QueryString["departmentId"]; dmBus = new DepartmentBUS(); rlBus = new RoleListBUS(); rdBus = new RoleDetailBUS(); DataTable tblDepartment = dmBus.GetByID(int.Parse(departmentId)); if (tblDepartment.Rows.Count > 0) { string info = tblDepartment.Rows[0]["Name"].ToString(); lblDepartmentName.Text = info; } //load role list DataTable dtRoleList = null; if (getUserLogin().DepartmentId == 1) { dtRoleList = rlBus.GetAll(); } else { // load role list by role admin level 2. dtRoleList = rlBus.GetRoleByDepartmentId(getUserLogin().DepartmentId); } // Lấy danh sách quyền của phòng ban được chọn. DataTable dtRoleDetail = rdBus.GetByDepartmentId(int.Parse(departmentId)); // Không hiển thị với phân quyền tạo phòng ban & tạo user với admin cấp 2 DataTable dtNewRoleList = dtRoleList.Clone(); foreach (DataRow row in dtRoleList.Rows) { // Không hiển thị chức năng cấp quyền tạo phòng ban & tạo user // Với user thuộc phòng ban tấp 2 if (getUserLogin().DepartmentId != 1 && (int.Parse(row["roleId"].ToString()) == 9 || int.Parse(row["roleId"].ToString()) == 22)) { continue; } else { dtNewRoleList.ImportRow(row); } } dlRoleList.DataSource = dtNewRoleList; dlRoleList.DataBind(); for (int i = 0; i < dtNewRoleList.Rows.Count; i++) { DataRow row = dtNewRoleList.Rows[i]; string roleId = row["roleId"].ToString(); HiddenField hdfRoleId = (HiddenField)dlRoleList.Items[i].FindControl("hdfRoleId"); hdfRoleId.Value = roleId; //selected role with department CheckBox chkCheck = (CheckBox)dlRoleList.Items[i].FindControl("chkCheck"); for (int j = 0; j < dtRoleDetail.Rows.Count; j++) { int rId = int.Parse(dtRoleDetail.Rows[j]["roleId"].ToString()); if (rId == int.Parse(roleId)) { chkCheck.Checked = true; break; } } Label lblRoleName = (Label)dlRoleList.Items[i].FindControl("lblRoleName"); lblRoleName.Text = row["roleName"] != null ? row["roleName"].ToString() : ""; if (int.Parse(roleId) >= 100) // Là những tùy chọn chức năng chính. { lblRoleName.ForeColor = Color.Red; } } hdfDepartmentId.Value = departmentId; }
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; } }