/// <summary> /// remove role from channel /// </summary> /// <param name="userID"></param> /// <param name="channelID"></param> /// <param name="roleID"></param> public void RemoveRole(string userID, string channelID, string roleID) { try { using (MainDB db = new MainDB()) { //lấy ra danh sách các Cat_ID //DataTable category = db.SelectQuery("select Cat_ID from " + Const.VIEW_Permission_withCategory + " where User_ID='" + userID + "' and Channel_ID=" + channelID); //DataTable category = db.StoreProcedure.vc_Execute_Sql("select Cat_ID from " + Const.VIEW_Permission_withCategory + " where User_ID='" + userID + "' and Channel_ID=" + channelID); //DataRow[] drCat_ID = category.Select(); //if (drCat_ID != null && drCat_ID.Length > 0) //{ // for (int i = 0; i < drCat_ID.Length; i++) // { // string Cat_ID = drCat_ID[i][0].ToString(); // RemoveCategory(userID, channelID, roleID, Cat_ID); // } //} Channel_UserRow channel_user = db.Channel_UserCollection.GetAsArray("User_ID='" + userID + "' and Channel_ID=" + channelID, "")[0]; //Channel_User_RoleRow channel_user_role = db.Channel_User_RoleCollection.GetAsArray("CU_ID=" + channel_user.CU_ID + " and Role_ID=" + roleID, "")[0]; db.Channel_User_RoleCollection.Delete("CU_ID=" + channel_user.CU_ID + " and Role_ID=" + roleID); } } catch (Exception ex) { throw ex; } }
} // BindForm #endregion #region Save and Cancel button event handlers private void OnSaveClick(object sender, EventArgs e) { try { Business.User user = new Business.User(); UserRow row = new UserRow(); // Neu ma truong hop Update thi Get cac thong tin cua user len if (txtUser_ID.Enabled == false) { using (MainDB db = new MainDB()) { row = db.UserCollection.GetAsArray(" User_Id = '" + txtUser_ID.Text + "'", "")[0]; } } if (this.txtUser_ID.Text.Length > 0) { row.User_ID = this.txtUser_ID.Text; } if (this.txtUser_Name.Text.Length > 0) { row.User_Name = this.txtUser_Name.Text; } if ((this.txtUser_Pwd.Text.Length > 0 && !cbxPassword.Visible) || this.txtUser_Pwd.Text.Length > 0 && cbxPassword.Checked) { string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtUser_Pwd.Text, "MD5"); row.User_Pwd = pass; } if (this.txtUser_Email.Text.Length > 0) { row.User_Email = this.txtUser_Email.Text; } if (this.txtUser_Address.Text.Length > 0) { row.User_Address = this.txtUser_Address.Text; } if (this.txtUser_PhoneNum.Text.Length > 0) { row.User_PhoneNum = this.txtUser_PhoneNum.Text; } if (this.txtUser_Im.Text.Length > 0) { row.User_Im = this.txtUser_Im.Text; } if (this.txtUser_Website.Text.Length > 0) { row.User_Website = this.txtUser_Website.Text; } row.User_isActive = this.chkUser_isActive.Checked; using (MainDB db = new MainDB()) { string originalId = (string)ViewState["originalId"]; if (originalId != null && originalId.Length > 0) { row.User_ID = originalId; row.User_ModifiedDate = DateTime.Now; db.UserCollection.Update(row); //kiểm tra xem người dùng đã được gán vào kênh này chưa. Channel_UserRow[] curCheck = db.Channel_UserCollection.GetAsArray("User_ID='" + (string)ViewState["originalId"] + "' and Channel_ID=" + ddlChannel.SelectedValue, ""); if (curCheck == null) { //gán người dùng vào kênh Channel_UserRow cur = new Channel_UserRow(); cur.User_ID = txtUser_ID.Text; cur.Channel_ID = Int32.Parse(ddlChannel.SelectedValue); db.Channel_UserCollection.Insert(cur); } } else { if (user.isUserExited(txtUser_ID.Text)) { SetErrorMessage("Đã tồn tại User này"); return; } row.User_CreatedDate = DateTime.Now; db.UserCollection.Insert(row); //gán người dùng vào kênh Channel_UserRow cur = new Channel_UserRow(); cur.User_ID = txtUser_ID.Text; cur.Channel_ID = Int32.Parse(ddlChannel.SelectedValue); db.Channel_UserCollection.Insert(cur); } } Session["Edit_UserID"] = ""; Response.Redirect(listPage); } // try catch (Exception ex) { SetErrorMessage(ex.Message); } // try/catch }
protected void btnAssignPermission_Click1(object sender, EventArgs e) { if (!Validated()) { return; } int channelID = 1; string userID = lblUserName.Text; int roleID = Int32.Parse(lbxRole.SelectedValue); Business.User user = new Business.User(); //gán dữ liệu cho bảng channel_user Channel_UserRow cur = new Channel_UserRow(); cur.Channel_ID = channelID; cur.User_ID = userID; //--------------------------------- //gán dữ liệu cho bảng channel_user_role Channel_User_RoleRow curr = new Channel_User_RoleRow(); curr.Role_ID = roleID; //---------------------------------- using (MainDB db = new MainDB()) { //Kiểm tra xem user đã tồn tại trong kênh này chưa Channel_UserRow[] chanU = db.Channel_UserCollection.GetAsArray("User_ID='" + userID + "' and Channel_ID=" + channelID, ""); //nếu đã tồn tại thì lấy ID của bảng channel_user gán vào bảng channel_user_role if (chanU != null && chanU.Length > 0) { curr.CU_ID = chanU[0].CU_ID; } else // nếu chưa tồn tại thì insert 1 bản ghi vào bảng channel_user sau đó lấy ID gán vào channel_user_role { //inssert dữ liệu vào bảng channel_user db.Channel_UserCollection.Insert(cur); //gán ID của channel_user_role bằng id vừa thêm vào curr.CU_ID = cur.CU_ID; } //Kiểm tra xem người dùng ở kênh này đã có role này chưa DataTable dtChannelUserRole = user.GetChannelUserRole(userID, channelID, roleID); int CUR_ID = -1; if (dtChannelUserRole != null && dtChannelUserRole.Rows.Count > 0) { CUR_ID = Convert.ToInt32(dtChannelUserRole.Rows[0][0]); } else { //gán channel_user vào role db.Channel_User_RoleCollection.Insert(curr); } //nếu gán cho các role không phải là quản trị kênh thì gán đầy đủ quyền và chuyên mục if (lbxRole.SelectedValue != RoleConst.QuanTriKenh.ToString()) { User_PermissionRow upr; User_CategoryRow ucr; //duyệt qua các item của chuyên mục foreach (ListItem li in clbCategory.Items) { //nếu chuyện mục nào được chọn thì gán cho chuyên mục đó if (li.Selected) { upr = new User_PermissionRow(); //nếu không tồn tại role này thì lấy giá trị gán theo role mới if (CUR_ID == -1) { upr.CUR_ID = curr.CUR_ID; } else // nếu đã tồn tại role này thì lấy giá trị role này luôn. { upr.CUR_ID = CUR_ID; } //duyệt qua các item của quyền foreach (ListItem liPermission in clbPermission.Items) { //nếu quyền nào được chọn thì gán cho quyền đó if (liPermission.Selected) { upr.Permission_ID = Int32.Parse(liPermission.Value); //gán vào bảng permission db.User_PermissionCollection.Insert(upr); ucr = new User_CategoryRow(); ucr.UP_ID = upr.UP_ID; ucr.Cat_ID = Int32.Parse(li.Value); //gán user permission vào categorry db.User_CategoryCollection.Insert(ucr); } } } } } //khi gán quyền sẽ đặt acive cho user = true UserRow ur = db.UserCollection.GetByPrimaryKey(userID); if (!ur.User_isActive) { ur.User_isActive = true; db.UserCollection.Update(ur); } } lblMessage.Text = "Gán thành công"; ResetCategory(); LoadLtsBox(); //Response.Redirect("/users/userassign.aspx"); DFISYS.BO.Editoral.Category.CategoryHelper.CleanCacheCategory(); DFISYS.BO.Editoral.Category.CategoryHelper.CleanCachePermission(); //GetPermission1_ }