/// <summary> /// Get access group base on group id from DB /// </summary> /// <returns>one group access object</returns> public static GroupAccess GetAccessGroupById(string groupId) { GroupAccess groupAccesses = null; DataTable dt = null; try { ServiceReference1.WSACUSoapClient client = new ServiceReference1.WSACUSoapClient(); DataSet ds = client.GroupAccessQuery("Q", groupId, ""); dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { string Id = dr["groupId"].ToString(); string Name = dr["groupName"].ToString(); string description = dr["groupDescription"].ToString(); //Get user in group List <Users> users = Users.LoadUsersByACGroup(Id); //Get Guser in group List <GroupUser> groupUsers = GroupUser.LoadUserGroupByACGroup(Id); //Get Access Lv in group List <AccessLevel> accessLevels = AccessLevel.LoadAccessLevelByACGroup(Id); groupAccesses = new GroupAccess(Id, Name, description, accessLevels, users, groupUsers); } return(groupAccesses); } catch (Exception ex) { return(null); } }
/// <summary> /// Get user group from DB /// </summary> /// <param name="groupId">ID of user group need get</param> /// <returns>One group user object</returns> public static GroupUser LoadGroupUserById(string groupId) { DataTable dt = null; GroupUser groupUser = null; try { ServiceReference1.WSACUSoapClient client = new ServiceReference1.WSACUSoapClient(); DataSet ds = client.GroupUserQuery("Q", groupId, ""); dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { string Id = dr["groupId"].ToString(); string groupName = dr["groupName"].ToString(); List <Users> listUsers = Users.LoadUsersByGroup(groupId); groupUser = new GroupUser(groupId, groupName, listUsers); } return(groupUser); } catch (Exception ex) { return(null); } }
private void frmGUserDetail_Load(object sender, EventArgs e) { try { if (mode == "A") //Add new group { this.Text = "Add new user group"; txtID.ReadOnly = false; btnApply.Enabled = false; txtID.Text = GroupUser.GenGroupId(); } else if (mode == "E") //Edit group { this.Text = title; txtID.ReadOnly = true; btnApply.Enabled = true; txtName.Focus(); GetGroupUser(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Check exist group id /// </summary> private void txtID_Leave(object sender, EventArgs e) { try { if (mode == "A") { GroupUser g = GroupUser.LoadGroupUserById(txtID.Text); if (g != null) { lblTestID.Text = "Duplicate"; lblTestID.ForeColor = Color.Red; btnApply.Enabled = false; txtID.Focus(); } else { lblTestID.Text = "OK"; lblTestID.ForeColor = Color.Green; btnApply.Enabled = true; } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Generate Treelist structure /// </summary> private void GenTreeUserData() { List <GroupUser> groupUsers = GroupUser.LoadAllUserGroup(); CreateColumns(treeMenu); CreateTree(treeMenu, groupUsers); }
/// <summary> /// Update user info in DB /// </summary> /// <param name="groupUser">group user id include user</param> /// <param name="groupAccess">group access id include user</param> /// <param name="creator">user login id</param> /// <returns>OK or error from DB</returns> public string Update(string groupUser, string groupAccess, string creator) { string result = "OK"; DataTable dt = null; try { //Update user master ServiceReference1.WSACUSoapClient client = new ServiceReference1.WSACUSoapClient(); DataSet ds = client.UserSave("U", id, optLevel, userName, passWord, name, avatar, email, phoneNo, status, startDate, experiedDate, creator, DateTime.Now); dt = ds.Tables[0]; result = dt.Rows[0][0].ToString(); if (result == "OK") { //Delete user in old group user GroupUser group = new GroupUser("", ""); result = group.DeleteUser(id, creator); if (result == "OK") { //Add user to user group GroupUser group1 = new GroupUser(groupUser, ""); result = group1.AddUser(id, creator); if (result == "OK") { //Delete user in old access group GroupAccess accessGroup = new GroupAccess("", ""); result = accessGroup.DeleteUser(id, creator); if (result == "OK") { //Add user to access group GroupAccess accessGroup1 = new GroupAccess(groupAccess, ""); result = accessGroup1.AddUser(id, creator); if (result == "OK") { //Add card foreach (Card c in listCard) { result = c.Add(creator); result = c.AddUser(id, creator); } } } } } } return(result); } catch (Exception ex) { return(string.Format("User class - Update: {0}", ex.ToString())); } }
/// <summary> /// Save data to DB /// </summary> private void btnApply_Click(object sender, EventArgs e) { try { if (txtID.Text.Count() <= 0) { MessageBox.Show("Group ID can't be empty"); txtID.Focus(); return; } if (mode == "A") { //Add new group user GroupUser g = new GroupUser(txtID.Text, txtName.Text); string result = g.Add(userId); if (result == "OK") { DialogResult dr = MessageBox.Show("Add group " + txtName.Text + " success!", "Sucess", MessageBoxButtons.OK, MessageBoxIcon.Information); if (dr == DialogResult.OK) { txtID.Text = GroupUser.GenGroupId(); txtName.Focus(); txtName.Text = ""; btnApply.Enabled = true; } } else { MessageBox.Show("Error: " + result); } } else if (mode == "E") { //Update group user GroupUser g = new GroupUser(txtID.Text, txtName.Text); string result = g.Update(userId); if (result == "OK") { DialogResult dr = MessageBox.Show("Update group " + txtName.Text + " success!", "Sucess", MessageBoxButtons.OK, MessageBoxIcon.Information); if (dr == DialogResult.OK) { this.Hide(); } } else { MessageBox.Show("Error: " + result); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Show user info in controls when user choose edit user /// </summary> /// <param name="Id">ID of user</param> private void ShowUserInfo(string Id) { try { Users u = Users.LoadUsersById(Id); if (u != null) { txtUserId.Text = u.Id; txtName.Text = u.Name; dateStart.EditValue = u.StartDate; dateEnd.EditValue = u.ExperiedDate; txtUserName.Text = u.UserName; txtPassword.Text = u.PassWord; txtEmail.Text = u.Email; txtPhoneNo.Text = u.PhoneNo; switchStatus.Value = u.Status; GroupUser g = GroupUser.LoadGroupUserByUserId(u.Id); if (g != null) { cboGroup.EditValue = g.groupId; cboGroup.Text = g.groupName; } OperatorLevel o = OperatorLevel.GetOptLevelByUser(u.Id); if (o != null) { cboOptLevel.EditValue = o.OptId; cboOptLevel.Text = o.OptName; } GroupAccess access = GroupAccess.GetAccessGroupByUser(u.Id); if (access != null) { cboAccess.EditValue = access.groupId; cboAccess.Text = access.groupName; } picAvatar.Image = Common.byteArrayToImage(u.Avatar); foreach (Card c in u.ListCard) { listCard.Items.Add(c.CardNo); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Show group user info in controls /// </summary> private void GetGroupUser() { try { GroupUser g = GroupUser.LoadGroupUserById(groupId); if (g != null) { txtID.Text = g.groupId; txtName.Text = g.groupName; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Load all user group from DB and fill into checked combo box /// </summary> private void LoadAllUserGroup() { try { groupUsers = GroupUser.LoadAllUserGroup(); foreach (GroupUser u in groupUsers) { CheckedListBoxItem listBoxItem = new CheckedListBoxItem(); listBoxItem.Value = u.groupId; listBoxItem.Description = u.groupName; chkcbUserGroup.Properties.Items.Add(listBoxItem); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Get user group what state = checked in checked combo box /// </summary> /// <returns>list of user group</returns> private List <GroupUser> GetGroupUsersSave() { List <GroupUser> GuserSend = new List <GroupUser>(); try { foreach (CheckedListBoxItem item in chkcbUserGroup.Properties.Items) { if (item.CheckState == CheckState.Checked) { int pos = chkcbUserGroup.Properties.Items.IndexOf(item); GroupUser g = groupUsers[pos]; GuserSend.Add(g); } } return(GuserSend); } catch (Exception ex) { return(null); } }
/// <summary> /// Get user group by user inside this group /// </summary> /// <param name="userId">ID of user inside</param> /// <returns>One group user object</returns> public static GroupUser LoadGroupUserByUserId(string userId) { DataTable dt = null; GroupUser groupUser = null; try { ServiceReference1.WSACUSoapClient client = new ServiceReference1.WSACUSoapClient(); DataSet ds = client.GroupUserDetailQuery("Q", "", userId); dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { string groupId = dr["groupId"].ToString(); groupUser = LoadGroupUserById(groupId); } return(groupUser); } catch (Exception ex) { return(null); } }
/// <summary> /// Get group access, operator level, Group user from DB and add in combobox /// </summary> private void GetComboBoxData() { try { List <GroupAccess> groupAccesses = GroupAccess.GetAllAccessGroup(); cboAccess.Properties.DataSource = groupAccesses; cboAccess.Properties.DisplayMember = "groupName"; cboAccess.Properties.ValueMember = "groupId"; List <OperatorLevel> operatorLevels = OperatorLevel.GetAllOptLevel(); cboOptLevel.Properties.DataSource = operatorLevels; cboOptLevel.Properties.DisplayMember = "OptName"; cboOptLevel.Properties.ValueMember = "OptId"; List <GroupUser> groupUsers = GroupUser.LoadAllUserGroup(); cboGroup.Properties.DataSource = groupUsers; cboGroup.Properties.DisplayMember = "groupName"; cboGroup.Properties.ValueMember = "groupId"; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Get user group inside access group /// </summary> /// <param name="groupId">Id of access group include user groups</param> /// <returns>List of user group</returns> public static List <GroupUser> LoadUserGroupByACGroup(string groupId) { List <GroupUser> groupUsers = new List <GroupUser>(); DataTable dt = null; try { ServiceReference1.WSACUSoapClient client = new ServiceReference1.WSACUSoapClient(); DataSet ds = client.GroupAccessUGQuery("Q", groupId, ""); dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { string Id = dr["groupUserId"].ToString(); GroupUser groupUser = LoadGroupUserById(Id); groupUsers.Add(groupUser); } return(groupUsers); } catch (Exception ex) { return(null); } }
/// <summary> /// Delete user group when user choose delete in popup /// </summary> private void DeleteUGroup(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { if (groupUserId.Count() <= 0) { MessageBox.Show("Please choose user group!"); } else { DialogResult drQ = MessageBox.Show("Confirm delete group: " + groupUserName + "?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (drQ == DialogResult.Yes) { //Delete group user GroupUser g = new GroupUser(groupUserId, groupUserName); string result = g.Delete(userId); if (result == "OK") { DialogResult dr = MessageBox.Show("Delete group " + groupUserName + " success!", "Sucess", MessageBoxButtons.OK, MessageBoxIcon.Information); if (dr == DialogResult.OK) { GenTreeUserData(); } } else { MessageBox.Show("Error: " + result); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Show user info in gridcontrol when user choose in treelist control /// </summary> private void treeMenu_RowCellClick(object sender, DevExpress.XtraTreeList.RowCellClickEventArgs e) { try { TreeList treeList = (TreeList)sender; TreeListMultiSelection selectedNodes = treeList.Selection; //Get mode from treelist //G: Group //R: All user //I: One user string mode = selectedNodes[0].GetValue(treeList.Columns[2]).ToString(); //Edit user group info MouseEventArgs me = (MouseEventArgs)e; if (me.Button == MouseButtons.Right) { if (mode == "G") { groupUserId = selectedNodes[0].GetValue(treeList.Columns[0]).ToString(); groupUserName = selectedNodes[0].GetValue(treeList.Columns[1]).ToString(); popupUser.ShowPopup(Control.MousePosition); } return; } //Load user information to grid string title = ""; //Get all user List <GroupUser> groupUsers = GroupUser.LoadAllUserGroup(); //Init DataTable InitTableStructure(dtSource); if (mode == "R") { dtSource.Clear(); DataTable dt = new DataTable(); InitTableStructure(dt); //Load all user to grid foreach (GroupUser g in groupUsers) { dt = g.ToDataTable(); foreach (DataRow dr1 in dt.Rows) { dtSource.ImportRow(dr1); } } title = "All user"; } else if (mode == "G") { dtSource.Clear(); string groupUserId = selectedNodes[0].GetValue(treeList.Columns[0]).ToString(); //Load user by group to grid foreach (GroupUser g in groupUsers) { if (g.groupId == groupUserId) { dtSource = g.ToDataTable(); title = g.groupName; } } } else if (mode == "I") { dtSource.Clear(); string userId = selectedNodes[0].GetValue(treeList.Columns[0]).ToString(); //Load one user to grid foreach (GroupUser g in groupUsers) { foreach (Users u in g.ListUsers) { if (u.Id == userId) { DataRow dr2 = dtSource.NewRow(); dr2["userId"] = u.Id; dr2["personName"] = u.Name; dr2["email"] = u.Email; if (u.ListCard == null) { dr2["card"] = 0; } else { dr2["card"] = u.ListCard.Count; } dtSource.Rows.Add(dr2); if (Convert.ToBoolean(u.Status)) { dr2["status"] = "Active"; } else { dr2["status"] = "Deactive"; } title = u.Name; } } } } gridUser.DataSource = dtSource; lblTitle.Text = title; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }