/// <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 all access group from DB /// </summary> private void GetAllGroupAccess() { try { //Load all access group List <GroupAccess> group = GroupAccess.GetAllAccessGroup(); listAccessGroup.DataSource = group; listAccessGroup.DisplayMember = "groupName"; listAccessGroup.ValueMember = "groupId"; gcDescription.Caption = "Description"; dt.Clear(); //Create grid soure foreach (GroupAccess g in group) { DataRow row = dt.NewRow(); row["id"] = g.groupId; row["name"] = g.groupName; row["number"] = g.GroupDescription; dt.Rows.Add(row); } gridData.DataSource = dt; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Show access group info on gridcontrol /// </summary> private void listAccessGroup_SelectedIndexChanged(object sender, EventArgs e) { try { if (listAccessGroup.SelectedValue != null) { string groupId = listAccessGroup.SelectedValue.ToString(); GroupAccess g = GroupAccess.GetAccessGroupById(groupId); if (g != null) { dt.Clear(); DataRow row = dt.NewRow(); row["id"] = g.groupId; row["name"] = g.groupName; row["number"] = g.GroupDescription; dt.Rows.Add(row); gridData.DataSource = dt; } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Delete access group /// </summary> private void itemDelACSGroup_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { GroupAccess g = (GroupAccess)listAccessGroup.SelectedItem; if (g != null) { DialogResult drQ = MessageBox.Show("Confirm delete access group: " + g.groupName + "?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (drQ == DialogResult.Yes) { string result = g.Delete(userId); if (result == "OK") { DialogResult dr = MessageBox.Show("Delete access group " + g.groupName + " success!", "Sucess", MessageBoxButtons.OK, MessageBoxIcon.Information); if (dr == DialogResult.OK) { GetAllGroupAccess(); } } else { MessageBox.Show("Error: " + result); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void CreateUsageChart() { try { //Chart user int userCount = 0; List <Users> users = Users.LoadAllUsers(); if (users != null) { userCount = users.Count; } Point p = new Point(20, 3); CreateChart(string.Format("User({0})", userCount.ToString()), userCount, p); //Chart card int cardCount = 0; List <Card> cards = Card.LoadAllCard(); if (cards != null) { cardCount = cards.Count; } Point p1 = new Point(138, 3); CreateChart(string.Format("Card({0})", cardCount.ToString()), cardCount, p1); //Chart device int deviceCount = 0; List <Device> devices = Device.LoadAllDevices(); if (devices != null) { deviceCount = devices.Count; } Point p2 = new Point(256, 3); CreateChart(string.Format("Device({0})", deviceCount.ToString()), deviceCount, p2); //Chart door int doorCount = 0; List <Door> doors = Door.LoadAllDoors(); if (doors != null) { doorCount = doors.Count; } Point p3 = new Point(374, 3); CreateChart(string.Format("Door({0})", doorCount.ToString()), doorCount, p3); //Chart access group int accessCount = 0; List <GroupAccess> g = GroupAccess.GetAllAccessGroup(); if (g != null) { accessCount = g.Count; } Point p4 = new Point(492, 3); CreateChart(string.Format("Access group({0})", accessCount.ToString()), accessCount, p4); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <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> /// 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 access group detail /// </summary> private void ShowAGInfo() { try { GroupAccess group = GroupAccess.GetAccessGroupById(accessGroupId); if (group != null) { txtID.Text = group.groupId; txtName.Text = group.groupName; txtDescription.Text = group.GroupDescription; //Fill user in checked combo box foreach (Users u in group.ListUsers) { int index = users.FindIndex(f => f.Id == u.Id); if (index >= 0) { chkcbUser.Properties.Items[index].CheckState = CheckState.Checked; } } //Fill user group in checked combo box foreach (GroupUser groupU in group.ListGroupUsers) { int index = groupUsers.FindIndex(f => f.groupId == groupU.groupId); if (index >= 0) { chkcbUserGroup.Properties.Items[index].CheckState = CheckState.Checked; } } //Fill access level in checked combo box foreach (AccessLevel accessLv in group.AccessLv) { int index = accessLevels.FindIndex(f => f.groupId == accessLv.groupId); if (index >= 0) { chkcbAccessLevel.Properties.Items[index].CheckState = CheckState.Checked; } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Save data to DB /// </summary> private void btnApply_Click(object sender, EventArgs e) { try { //Mode = A: Add new //Mode = E: modify GroupAccess g = new GroupAccess(txtID.Text, txtName.Text, txtDescription.Text, GetAccessLvSave(), GetUsersSave(), GetGroupUsersSave()); if (mode == "A") { if (txtID.Text.Count() <= 0) { MessageBox.Show("Please input group ID"); txtID.Focus(); return; } //Add new access group string result = g.Add(userId); if (result == "OK") { MessageBox.Show("Add group access " + txtName.Text + " success!"); txtID.Text = GroupAccess.GenGroupId(); } else { MessageBox.Show("Error: " + result); } } else if (mode == "E") { //Update access group info string result = g.Update(userId); if (result == "OK") { MessageBox.Show("Update group access " + txtName.Text + " success!"); } else { MessageBox.Show("Error: " + result); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Get access group base on user inside it from DB /// </summary> /// <returns>one group access object</returns> public static GroupAccess GetAccessGroupByUser(string userId) { GroupAccess groupAccesses = null; DataTable dt = null; try { ServiceReference1.WSACUSoapClient client = new ServiceReference1.WSACUSoapClient(); DataSet ds = client.GroupAccessUQuery("Q", "", userId); dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { string Id = dr["groupAccessId"].ToString(); groupAccesses = GroupAccess.GetAccessGroupById(Id); } return(groupAccesses); } catch (Exception ex) { return(groupAccesses); } }
/// <summary> /// Get all access group from DB /// </summary> /// <returns>list of access group</returns> public static List <GroupAccess> GetAllAccessGroup() { List <GroupAccess> groupAccesses = new List <GroupAccess>(); DataTable dt = null; try { ServiceReference1.WSACUSoapClient client = new ServiceReference1.WSACUSoapClient(); DataSet ds = client.GroupAccessQuery("Q", "", ""); dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { string Id = dr["groupID"].ToString(); GroupAccess group = GroupAccess.GetAccessGroupById(Id); groupAccesses.Add(group); } return(groupAccesses); } catch (Exception ex) { return(null); } }
private void ucAccessGroupDetail_Load(object sender, EventArgs e) { //Set title lblTitle.Text = title; LoadAllAccessLevel(); LoadAllUserGroup(); LoadAllUser(); //Mode = A: Add new //Mode = E: modify if (mode == "A") { txtID.ReadOnly = false; txtID.Text = GroupAccess.GenGroupId(); } else if (mode == "E") { txtID.ReadOnly = true; ShowAGInfo(); } }
/// <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()); } }