protected void BindGroupsList()
		{
			BPCompanyGroups groups = new BPCompanyGroups();

			DSCompanyGroups = groups.SelectAll();

			dgGroups.DataBind();
		}
		private void dgPermissions_UpdateCommand(object source, DataGridCommandEventArgs e)
		{
			//Cell Index is the index of permissionID
			int CompanyPermissionID = Convert.ToInt32( e.Item.Cells[0].Text);

			BPCompanyGroups bp = new BPCompanyGroups();
			DSCompanyGroups = bp.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);

			BECompanyGroups.tbl_CompanyGroupPermissionsRow groupPermission = DSCompanyGroups.tbl_CompanyGroupPermissions.FindByCompanyGroupIDCompanyPermissionID(CompanyGroupID, CompanyPermissionID);

			DropDownList lstPermValues = (DropDownList) e.Item.FindControl("lstPermValues");
			groupPermission.CompanyGroupPermissionValue = Convert.ToInt16(lstPermValues.SelectedValue);

			bp.UpdateCompanyGroupPermissions(DSCompanyGroups);

			DSCompanyGroups = bp.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);

			dgPermissions.EditItemIndex = -1;
			dgPermissions.SelectedIndex = -1;
			dgPermissions.DataBind();
		}
		private void btnDelete_Click(object sender, EventArgs e)
		{
			BPCompanyGroups bp = new BPCompanyGroups();
			BECompanyGroups.tbl_CompanyGroupsRow group;
			
			DSCompanyGroups = bp.SelectCompanyGroupsByID(CompanyGroupID);
			group = DSCompanyGroups.tbl_CompanyGroups.FindByCompanyGroupID(CompanyGroupID);

			group.Delete();
			bp.Update(DSCompanyGroups);

			Response.Redirect("BrowseCompanyPermissionGroups.aspx");
		}
		private void dgPermissions_ItemCommand(object source, DataGridCommandEventArgs e)
		{
			//if (this.OryxUser.RolePermission(Globals.PermissionLevels.ManageAdministratorGroups) > 1)
			//{
			BPCompanyGroups bp = new BPCompanyGroups();
			DSCompanyGroups = bp.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);
			
			if (e.Item.Cells[0].Text != string.Empty)
			{
				int permissionID = Convert.ToInt32( e.Item.Cells[0].Text);
				if (dgPermissions.EditItemIndex == e.Item.ItemIndex)
				{
					dgPermissions.EditItemIndex = -1;
				}
				else
				{
					dgPermissions.EditItemIndex = e.Item.ItemIndex;
					DSCompanyGroups.tbl_CompanyPermissionValues.DefaultView.RowFilter = string.Format("CompanyPermissionID = {0}", permissionID);
				}
			}

			dgPermissions.DataBind();
			//}
		}
		private void dgPermissions_CancelCommand(object source, DataGridCommandEventArgs e)
		{
			BPCompanyGroups bp = new BPCompanyGroups();
			DSCompanyGroups = bp.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);

			dgPermissions.EditItemIndex = -1;
			dgPermissions.SelectedIndex = -1;
			dgPermissions.DataBind();
		}
		private void btnSubmit_Click(object sender, EventArgs e)
		{
			BPCompanyGroups groups = new BPCompanyGroups();
			BECompanyGroups.tbl_CompanyGroupsRow group;
			
			DSCompanyGroups = groups.SelectCompanyGroupsByID(CompanyGroupID);
			group = DSCompanyGroups.tbl_CompanyGroups.FindByCompanyGroupID(CompanyGroupID);
			if (CompanyGroupID == 0)
			{
				group = DSCompanyGroups.tbl_CompanyGroups.Newtbl_CompanyGroupsRow();
				group.DateCreated = DateTime.Now;
				group.ModifiedByAdminID = 1;
			}
			group.CompanyGroupName = txtGroupName.Text;
			group.CompanyGroupDescription = txtGroupDescription.Text;
			group.CompanyGroupActive = chkActive.Checked;
			group.DateModified = DateTime.Now;

			if(CompanyGroupID == 0)
			{
				DSCompanyGroups.tbl_CompanyGroups.Addtbl_CompanyGroupsRow(group);
			}

			groups.Update(DSCompanyGroups);
			if (_HasChangedUsers )
			{
				groups.UpdateCompanyUsers(group.CompanyGroupID, UserGroupsList);
			}
			
			//Cache.Remove("dsAdmins");

			if (CompanyGroupID == 0)
			{
				Response.Redirect("EditCompanyPermissionGroups.aspx?CompanyGroupID=" + group.CompanyGroupID);
			}
			else
			{
				Response.Redirect("BrowseCompanyPermissionGroups.aspx");
			}
		}
		private void btnDone_Click(object sender, EventArgs e)
		{
			if (_HasChangedUsers )
			{
				BPCompanyGroups BPCompanyGroups = new BPCompanyGroups();
			
				if (_HasChangedUsers )
				{
					DSCompanyGroups = BPCompanyGroups.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);
					ArrayList perms = new ArrayList(PermList);
					perms.Sort();

					//Remove Duplicates
					if (perms.Count > 1)
					{
						int iLast,iCurrent;
						iLast = (int) perms[0];
						for (int i=1; i<perms.Count; i++)
						{
							iCurrent = (int) perms[i];

							if (iCurrent == iLast)
							{
								perms.RemoveAt(i);
							}
							iLast = iCurrent;
						}
					}

					int searchIndex;
					foreach (BECompanyGroups.tbl_CompanyGroupPermissionsRow groupPerm in DSCompanyGroups.tbl_CompanyGroupPermissions)
					{
						searchIndex = perms.BinarySearch(groupPerm.CompanyPermissionID);
						if (searchIndex < 0)
							//if (Array.BinarySearch(groupPerm.PermissionID))
						{
							//Not Found
							groupPerm.Delete();
						}
						else
						{
							perms.RemoveAt(searchIndex);
						}
					}

					foreach (int i in perms)
					{
						BECompanyGroups.tbl_CompanyGroupPermissionsRow groupPerm;
						groupPerm = DSCompanyGroups.tbl_CompanyGroupPermissions.FindByCompanyGroupIDCompanyPermissionID(CompanyGroupID, i);
						if(groupPerm == null)
						{
							groupPerm = DSCompanyGroups.tbl_CompanyGroupPermissions.Newtbl_CompanyGroupPermissionsRow();
							groupPerm.CompanyGroupID = CompanyGroupID;
							groupPerm.CompanyPermissionID = i;
							groupPerm.CompanyGroupPermissionValue = 2;
							DSCompanyGroups.tbl_CompanyGroupPermissions.Addtbl_CompanyGroupPermissionsRow(groupPerm);
						}

						//The first value for a permission should always be 1.
						groupPerm.CompanyGroupPermissionValue = 2;
					}
				}

				BPCompanyGroups.UpdateCompanyGroupPermissions(DSCompanyGroups);
				DSCompanyGroups = BPCompanyGroups.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);
				dgPermissions.DataBind();
			}
			pnlAssign.Visible = false;
			pnlPermissions.Visible = true;

			tab1.Attributes["class"] = "";
			tab2.Attributes["class"] = "current";
		}
		private void lnkPermissions_Click(object sender, EventArgs e)
		{
			pnlAssign.Visible = false;
			pnlPermissions.Visible = true;

			tab1.Attributes["class"] = "";
			tab2.Attributes["class"] = "current";

			BPCompanyGroups bp = new BPCompanyGroups();
			DSCompanyGroups = bp.SelectCompanyGroupsByID(CompanyGroupID);
			DSCompanyGroups = bp.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);

			dgPermissions.DataBind();
		}
		private void FillSelectedPerms()
		{
			lstSelectedPerms.Items.Clear();

			BPCompanyGroups bp = new BPCompanyGroups();
			BECompanyGroups ds = bp.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);

			MyListViewItem listItem;

			foreach (BECompanyGroups.tbl_CompanyGroupPermissionsRow groupPerm in ds.tbl_CompanyGroupPermissions)
			{
				listItem = lstSelectedPerms.Items.Add();
				listItem.CheckBox = true;
				listItem.ItemValue = groupPerm.CompanyPermissionID.ToString();
				listItem.Text = groupPerm.CompanyPermissionName;
			}
		}
		private void ShowGroupUsers()
		{
			pnlUsers.Visible = true;

			if (_HasChangedUsers)
			{
				BPCompanyGroups groups = new BPCompanyGroups();
				BECompanyGroups.tbl_CompanyGroupsRow group;
			
				DSCompanyGroups = groups.SelectCompanyGroupsByID(CompanyGroupID);
				group = DSCompanyGroups.tbl_CompanyGroups.FindByCompanyGroupID(CompanyGroupID);

				groups.Update(DSCompanyGroups);
				if (_HasChangedUsers)
				{
					groups.UpdateCompanyUsers(group.CompanyGroupID, UserGroupsList);
				}
			}

			BPCompanyUsers bp = new BPCompanyUsers();
			DSCompanyUsers = bp.SelectByCompanyGroupID(CompanyGroupID);
			dgUsers.DataBind();
		}
		private void Page_Load(object sender, EventArgs e)
		{
			this.AuthenticatePage(new string[] {Globals.PermissionLevels.EditCompanyPermissionGroups, Globals.PermissionLevels.AddCompanyPermissionGroups, Globals.PermissionLevels.ViewCompanyPermissionGroups});
			if (CompanyGroupID > 0)
			{
				if (this.OryxUser.RolePermission(Globals.PermissionLevels.EditCompanyPermissionGroups) != 2)
				{
					btnSubmit.Visible = false;
					btnDelete.Visible = false;
					lnkAssign.Enabled = false;
					lnkAddUsers.Enabled = false;
				}
			}
			else
			{
				if (this.OryxUser.RolePermission(Globals.PermissionLevels.AddCompanyPermissionGroups) != 2)
				{
					btnSubmit.Visible = false;
					btnDelete.Visible = false;
					lnkAssign.Enabled = false;
					lnkAddUsers.Enabled = false;
				}
			}

			if (IsNewSession)
			{
				AddToListIfAdmin();
				IsNewSession = false;
			}

			if (hdnCompanyUserPermissions.Value == "hidden")
			{
				pnlCompanyUserPermissions.CssClass = "panel-closed";
				cntCompanyUserPermissions.Style.Add("display", "none");
				hdnCompanyUserPermissions.Value = "hidden";
			}
			else 
			{
				pnlCompanyUserPermissions.CssClass = "panel-open";
				cntCompanyUserPermissions.Style.Add("display", "");
				hdnCompanyUserPermissions.Value = "visible";
			}

			if (hdnCompanyPermissionUsers.Value == "hidden")
			{
				pnlCompanyPermissionUsers.CssClass = "panel-closed";
				cntCompanyPermissionUsers.Style.Add("display", "none");
				hdnCompanyPermissionUsers.Value = "hidden";
			}
			else 
			{
				pnlCompanyPermissionUsers.CssClass = "panel-open";
				cntCompanyPermissionUsers.Style.Add("display", "");
				hdnCompanyPermissionUsers.Value = "visible";
			}
			
			if (!Page.IsPostBack)
			{
				BPCompanyGroups bp = new BPCompanyGroups();

				if (CompanyGroupID != 0)
				{
					BECompanyGroups.tbl_CompanyGroupsRow group;

					DSCompanyGroups = bp.SelectCompanyGroupsByID(CompanyGroupID);
					group = DSCompanyGroups.tbl_CompanyGroups.FindByCompanyGroupID(CompanyGroupID);
					
					txtGroupName.Text = group.CompanyGroupName;
					txtGroupDescription.Text = group.CompanyGroupDescription;
					chkActive.Checked = group.CompanyGroupActive;

					DSCompanyGroups = bp.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);

					dgPermissions.DataBind();

					ShowAssignPerms();

					ShowGroupUsers();

					BindGroupsList();
				}
				else
				{
					lblTitle.Text = "Add Company Permission Group";
					btnDelete.Visible = false;
					btnSubmit.Text = "Next >";

					//DSCompanyGroups = bp.SelectAllGroupTypes();

					pnlCompanyUserPermissions.Visible = false;
					pnlCompanyPermissionUsers.Visible = false;
					pnlAreaTabs.Visible = false;
					pnlUserTabs.Visible = false;
				}
				//BindGroupsList();
			}
		}
Ejemplo n.º 12
0
		public void UpdateCompanyUsers (int CompanyGroupID, int[] InstIDS)
		{
			ArrayList userList = new ArrayList(InstIDS);

			ArrayList currentUserList;

			BPCompanyGroups bp = new BPCompanyGroups();
			BECompanyGroups DSCompanyGroups = new BECompanyGroups();
		
			DSCompanyGroups = bp.SelectCompanyUsersByCompanyGroupID(CompanyGroupID);

			_CurrentCompanyUserCompanyGroupIDS = new int[DSCompanyGroups.Tables["tbl_CompanyUserGroups"].Rows.Count];			
			for (int i=0; i < DSCompanyGroups.Tables["tbl_CompanyUserGroups"].Rows.Count; i++)
			{
				_CurrentCompanyUserCompanyGroupIDS[i] = Convert.ToInt32(DSCompanyGroups.Tables["tbl_CompanyUserGroups"].Rows[i]["CompanyUserID"]);
			}
			currentUserList = new ArrayList(_CurrentCompanyUserCompanyGroupIDS);

			//DACompanyGroups da = new DACompanyGroups();
			DACompanyUserGroups daUserGroups = new DACompanyUserGroups();

			userList.Sort();
			currentUserList.Sort();

			//Insert the records that are new
			foreach (int userID in userList)
			{
				if (currentUserList.BinarySearch(userID) < 0)
				{
					//not found in the current users, add it.
					daUserGroups.InsertByID(userID, CompanyGroupID);
				}
			}

			//delete the old records
			foreach (int userID in currentUserList)
			{
				if (userList.BinarySearch(userID) < 0)
				{
					//not found in the current groups, add it.
					daUserGroups.DeleteByID(userID, CompanyGroupID);
				}
			}
		}