protected void btnAssign_Click(object sender, System.EventArgs e) { int PolicyID; try { PolicyID = int.Parse(Session["PolicyID"].ToString()); } catch { PolicyID = -1; } string[] selectedUnits; selectedUnits = this.trvUnitsSelector.GetSelectedValues(); BusinessServices.Policy objPolicy = new BusinessServices.Policy(); objPolicy.ResetPolicyUnitAccess(PolicyID); if (selectedUnits.Length > 0) { foreach (string strUnitID in selectedUnits) { objPolicy.SetPolicyUnitAccess(PolicyID, Int32.Parse(strUnitID)); objPolicy.SetPolicyUserAccessByUnit(PolicyID, Int32.Parse(strUnitID)); } } this.lblUnitAssignMessage.Visible = true; this.lblUnitAssignMessage.Text = ResourceManager.GetString("lblMessage.SaveUnits"); this.lblUnitAssignMessage.CssClass = "SuccessMessage"; }
private DataView GetData() { string strParentUnits = ""; if (!blnViewUsers) { strParentUnits = String.Join(",", this.trvUserUnitsSelector.GetSelectedValues()); } int OrganisationID = UserContext.UserData.OrgID; int PolicyID; try { PolicyID = int.Parse(Session["PolicyID"].ToString()); } catch { PolicyID = -1; } BusinessServices.Policy objPolicy = new BusinessServices.Policy(); DataTable dtSearchResults = objPolicy.PolicyUserSearch(OrganisationID, PolicyID, strParentUnits, this.txtFirstName.Text, this.txtLastName.Text, this.txtUserName.Text, this.txtEmail.Text, this.txtExternalId.Text, UserContext.UserID, DisplayType); return(dtSearchResults.DefaultView); }
/// <summary> /// Add Policies to the criteria list via a csv list of Policy id's /// </summary> /// <param name="strPolicyIDs">Csv list of Policies</param> public void AddPolicies(string strPolicyIDs, int orgID) { // Local variables string[] astrPolicyIDs = strPolicyIDs.Split(','); string strPolicyNames = ""; // Get Policy List BusinessServices.Policy objPolicy = new BusinessServices.Policy(); DataTable dtbPolicy = objPolicy.GetPolicyListAccessableToOrg(orgID); // Loop through all Policies foreach (DataRow drwPolicy in dtbPolicy.Rows) { // loop through all required Policies for (int intPolicy = 0; intPolicy <= astrPolicyIDs.GetUpperBound(0); intPolicy++) { // if they match if (astrPolicyIDs[intPolicy] == drwPolicy["PolicyID"].ToString()) { // Add it to the string. strPolicyNames += drwPolicy["PolicyName"].ToString(); strPolicyNames += ", "; } } } // Remove trailing command if it exists and replace with a full stop if (strPolicyNames.Length > 0) { strPolicyNames = strPolicyNames.Substring(0, strPolicyNames.Length - 2); strPolicyNames += "."; } // add to the criteria list this.Criteria.Add(ResourceManager.GetString("lblPolicies"), strPolicyNames); }
private void LoadPolicy() { int UserID = UserContext.UserID; BusinessServices.User objUser = new BusinessServices.User(); DataTable dtUserProfiles = objUser.GetProfilePeriodList(UserID); int PolicyID = int.Parse(Request.QueryString["PolicyID"].ToString()); BusinessServices.Policy objPolicy = new BusinessServices.Policy(); // if the policy as not accepted, enable to checkbox if (!objPolicy.CheckAccepted(PolicyID, UserID)) { string ConfirmationMessage = objPolicy.GetConfirmationMessage(PolicyID); this.chkAgree.Text = ConfirmationMessage; } else { this.chkAgree.Enabled = false; this.chkAgree.Checked = true; string lastAccepted = objPolicy.GetLastAccepted(UserID, UserContext.UserData.OrgID, PolicyID); this.chkAgree.Text = ResourceManager.GetString("lblLastAccepted") + " " + lastAccepted; } string PolicyName = objPolicy.GetPolicyFileName(PolicyID, UserContext.UserData.OrgID); string PolicyDir = @"\General\Policy\" + UserContext.UserData.OrgID.ToString(); this.pdfFrame.Attributes["src"] = PolicyDir + @"\" + PolicyName; this.pdfFrame.Visible = true; }
private int Upload(int PolicyID, bool checkFile) { string OrganisationID = UserContext.UserData.OrgID.ToString(); // Create Policy object BusinessServices.Policy objPolicy = new BusinessServices.Policy(); //Get name of existing file string CurrentFile = objPolicy.GetPolicyFileName(PolicyID, UserContext.UserData.OrgID); //Location of file to be saved on server string DelPath = Server.MapPath(@"\General") + @"\Policy\" + OrganisationID; //Upload the file UploadSuccess = UploadPolicyFile(checkFile); if (UploadSuccess) { //Delete the old policy off the server if (File.Exists(DelPath + @"\" + CurrentFile) && checkFile) { File.Delete(DelPath + @"\" + CurrentFile); } //Update the database (mark existing as deleted, new policy with existing Name, status etc.) //filename of new file to be uploaded string FileName = GetFileName(); long FileLength = GetFileSize(); PolicyID = objPolicy.NewFileUpload(PolicyID, FileName, FileLength, UserContext.UserData.OrgID); Session["PolicyID"] = PolicyID; } else { objPolicy.DeletePolicy(PolicyID, OrganisationID); } return(PolicyID); }
/// <summary> /// Paint Critera section of the page. /// </summary> private void PaintCriteraPageState() { // Get Units accessable to this user. BusinessServices.Unit objUnit = new BusinessServices.Unit(); DataSet dstUnits = objUnit.GetUnitsTreeByUserID(UserContext.UserData.OrgID, UserContext.UserID, 'A'); // Convert this to an xml string for rendering by the UnitTreeConverter. string strUnits = UnitTreeConvert.ConvertXml(dstUnits); if (strUnits == "") { // No units found. this.lblError.Visible = true; this.lblError.Text += "<BR>" + ResourceManager.GetString("lblError.NoUnit"); //No units exist within this organisation."; this.lblError.CssClass = "FeedbackMessage"; this.plhSearchCriteria.Visible = false; } else { // Change to the appropriate view and load the Units in this.trvUnitsSelector.LoadXml(strUnits); } // Get Policies accessable to this organisation BusinessServices.Policy objPolicy = new BusinessServices.Policy(); Organisation objOrg = new Organisation(); //DataTable dtbPolicies = objPolicy. // objCourse.GetCourseListAccessableToOrg(UserContext.UserData.OrgID); DataTable dtbPolicies = objOrg.GetOrganisationPolicies(UserContext.UserData.OrgID); if (dtbPolicies.Rows.Count > 0) { lstPolicy.DataSource = dtbPolicies; lstPolicy.DataTextField = "PolicyName"; lstPolicy.DataValueField = "PolicyID"; lstPolicy.DataBind(); } else { this.lblError.Visible = true; this.lblError.Text += "<BR>" + ResourceManager.GetString("lblError.NoPolicy"); //"No courses exist within this organisation."; this.lblError.CssClass = "WarningMessage"; this.plhSearchCriteria.Visible = false; } // If there is at least one course then select it. if (lstPolicy.Items.Count > 0) { lstPolicy.SelectedIndex = 0; } // Initialise the date list boxes. WebTool.SetupHistoricDateControl(this.lstEffectiveDay, this.lstEffectiveMonth, this.lstEffectiveYear); WebTool.SetupHistoricDateControl(this.lstEffectiveToDay, this.lstEffectiveToMonth, this.lstEffectiveToYear); radAcceptance.Items[0].Text = ResourceManager.GetString("radAcceptance.1"); radAcceptance.Items[1].Text = ResourceManager.GetString("radAcceptance.2"); radAcceptance.Items[2].Text = ResourceManager.GetString("radAcceptance.3"); }
private void GetTitle() { int PolicyID = int.Parse(Request.QueryString["PolicyID"].ToString()); BusinessServices.Policy objPolicy = new BusinessServices.Policy(); DataTable dtPolicy = objPolicy.GetPolicy(PolicyID, UserContext.UserData.OrgID); string PolicyName = dtPolicy.Rows[0]["PolicyName"].ToString(); lblTitle.Text = PolicyName; }
protected void lnkResetUsers_Click(object sender, System.EventArgs e) { // business logic to reset users int OrganisationID = UserContext.UserData.OrgID; int PolicyID = Int32.Parse(Session["PolicyID"].ToString()); BusinessServices.Policy objPolicy = new BusinessServices.Policy(); objPolicy.ResetUsers(OrganisationID, PolicyID); Response.Redirect(@"\Administration\Policy\policydetails.aspx"); }
protected void lnkAssignUsers_Click(object sender, System.EventArgs e) { //TODO: functionality here int PolicyID; try { PolicyID = int.Parse(Session["PolicyID"].ToString()); } catch { PolicyID = -1; } BusinessServices.Policy objPolicy = new BusinessServices.Policy(); DisplayType = "search"; BusinessServices.Unit objUnit = new BusinessServices.Unit(); DataSet dstUnits = objUnit.GetUnitsTreeByUserID(UserContext.UserData.OrgID, UserContext.UserID, 'A', false); if (dstUnits.Tables[0].Rows.Count == 0) { //No Units and therefore no users - display message and hide controls this.panUserUnitSelect.Visible = false; this.panUserDetails.Visible = false; this.panSearchReset.Visible = false; this.lblUserMessage.Visible = true; this.lblUserMessage.Text = ResourceManager.GetString("NoUnits"); this.lblUserMessage.CssClass = "FeedbackMessage"; } else { this.panUserUnitSelect.Visible = true; this.panUserDetails.Visible = true; this.panSearchReset.Visible = true; this.lblUserMessage.Visible = false; } this.panAssignUsers.Visible = true; this.panAssignUnits.Visible = false; this.panUnitSelect.Visible = false; this.panAssign.Visible = false; this.panUserSearchResults.Visible = false; this.panUserSaveAll.Visible = false; this.panUserSearchMessage.Visible = false; this.panViewUsers.Visible = false; this.panUserList.Visible = false; this.panUnitSaveAll.Visible = false; this.lblUserAssignMessage.Text = String.Empty; blnViewUsers = false; }
private void SetAssignedUnits() { int PolicyID; try { PolicyID = int.Parse(Session["PolicyID"].ToString()); } catch { PolicyID = -1; } BusinessServices.Policy objPolicy = new BusinessServices.Policy(); DataTable dtAssignedUnits = objPolicy.GetPolicyUnitAccess(PolicyID); BusinessServices.Unit objUnit = new BusinessServices.Unit(); DataSet dstUnits = objUnit.GetUnitsTreeByUserID(UserContext.UserData.OrgID, UserContext.UserID, 'A', false); if (dstUnits.Tables[0].Rows.Count > 0) { //Loop through and assign values to a string array string[] strAssignedUnits = new string[dtAssignedUnits.Rows.Count]; for (int row = 0; row < dtAssignedUnits.Rows.Count; ++row) { strAssignedUnits[row] = dtAssignedUnits.Rows[row]["UnitID"].ToString(); } this.trvUnitsSelector.SetSelectedValues(strAssignedUnits); this.lblSelectUnits.Visible = true; this.lblUnitMessage.Visible = false; this.btnAssign.Visible = true; } else { //No units exist - display message this.lblUnitMessage.Visible = true; this.lblSelectUnits.Visible = false; this.lblUnitMessage.Text = ResourceManager.GetString("NoUnits"); this.lblUnitMessage.CssClass = "FeedbackMessage"; this.btnAssign.Visible = false; } }
protected void btnUserSaveAll_Click(object sender, System.EventArgs e) { int PolicyID; try { PolicyID = int.Parse(Session["PolicyID"].ToString()); } catch { PolicyID = -1; } BusinessServices.Policy objPolicy = new BusinessServices.Policy(); // Update each user in the datagrid GetCheckBoxValues(); RePopulateCheckBoxes(); DataView dvwPagination; dvwPagination = GetData(); ArrayList CheckedItems = new ArrayList(); foreach (DataRow dr in dvwPagination.Table.Rows) { int AssignUserAccess = 0; int UserID = int.Parse(dr["UserID"].ToString()); CheckedItems = (ArrayList)Session["CheckedItems"]; if (CheckedItems.Contains(UserID.ToString())) { AssignUserAccess = 1; } int Granted = Convert.ToInt32(Convert.ToBoolean(dr["Granted"].ToString())); objPolicy.SetPolicyUserAccessByUser(PolicyID, UserID, AssignUserAccess); } this.lblUserAssignMessage.Visible = true; this.lblUserAssignMessage.Text = ResourceManager.GetString("lblMessage.SaveUsers"); this.lblUserAssignMessage.CssClass = "SuccessMessage"; ShowData(int.Parse(Session["PageIndex"].ToString())); }
private void LoadPolicy(int PolicyID) { int OrganisationID = UserContext.UserData.OrgID; BusinessServices.Policy objPolicy = new BusinessServices.Policy(); DataTable dtPolicy = objPolicy.GetPolicy(PolicyID, OrganisationID); if (dtPolicy.Rows.Count != 0) //Policy exists { this.lnkResetUsers.Visible = true; this.txtName.Text = dtPolicy.Rows[0]["PolicyName"].ToString(); bool blnActive = bool.Parse(dtPolicy.Rows[0]["Active"].ToString()); this.ddlStatus.ClearSelection(); this.ddlStatus.Items.FindByValue(Convert.ToInt32(blnActive).ToString()).Selected = true; string strPolicyFile = dtPolicy.Rows[0]["PolicyFileName"].ToString(); string strPolicyPath = @"\General\Policy\" + OrganisationID.ToString(); this.hypFile.NavigateUrl = strPolicyPath + @"\" + strPolicyFile; this.hypFile.Target = "_blank"; this.hypFile.Text = strPolicyFile; string ConfirmationMessage = dtPolicy.Rows[0]["ConfirmationMessage"].ToString(); if (ConfirmationMessage.Equals(String.Empty)) { this.txtConfirmationMsg.Text = ResourceManager.GetString("DefaultConfirmationMsg"); } else { this.txtConfirmationMsg.Text = ConfirmationMessage; } //populate user acceptance int UsersAcceptedPolicy = objPolicy.GetAcceptedUsers(OrganisationID, PolicyID); int UsersTotal = objPolicy.GetTotalUsersAssignedToPolicy(PolicyID); this.lblUsersAccepted.Text = UsersAcceptedPolicy.ToString() + @" / " + UsersTotal.ToString(); } else // Policy does not exist - Upload new file and Reset Users should not be displayed until policy created { this.lnkResetUsers.Visible = false; this.txtConfirmationMsg.Text = ResourceManager.GetString("DefaultConfirmationMsg"); } }
protected void btnFinish_Click(object sender, System.EventArgs e) { int PolicyID = int.Parse(Request.QueryString["PolicyID"].ToString()); //int ProfileID = int.Parse(Request.QueryString["ProfileID"].ToString()); int UserID = UserContext.UserID; BusinessServices.User objUser = new BusinessServices.User(); DataTable dtUserProfiles = objUser.GetProfilePeriodList(UserID); BusinessServices.Policy objPolicy = new BusinessServices.Policy(); // Only want to do anything if user has read and understood the policy if (this.chkAgree.Checked) { // Check if policy marked as accepted // If not then mark user as accepted the policy if (!objPolicy.CheckAccepted(PolicyID, UserID)) { objPolicy.Accept(PolicyID, UserID); } // Check if points have already been assigned for this policy and user // If not then assign points for the policy to the user foreach (DataRow dr in dtUserProfiles.Rows) { int ProfileID = Int32.Parse(dr["ProfileID"].ToString()); if (!objPolicy.CheckPointsAssigned(PolicyID, UserID, ProfileID)) { if (objPolicy.CheckProfileExists(PolicyID, UserID, ProfileID)) { objPolicy.AssignPoints(PolicyID, UserID, ProfileID); } } } } Response.Redirect("/MyTraining.aspx"); //Response.Write("<script language='javascript'> {opener.location.reload(); self.close(); }</script>"); }
protected void lnkViewUsers_Click(object sender, System.EventArgs e) { BusinessServices.Policy objPolicy = new BusinessServices.Policy(); DisplayType = "view"; this.panAssignUnits.Visible = false; this.panUnitSelect.Visible = false; this.panAssign.Visible = false; this.panAssignUsers.Visible = false; this.panUserUnitSelect.Visible = false; this.panUserDetails.Visible = false; this.panSearchReset.Visible = false; this.panUserSearchResults.Visible = false; this.panUserSaveAll.Visible = true; this.panUserSearchMessage.Visible = false; this.panViewUsers.Visible = true; this.panUserList.Visible = false; this.panUnitSaveAll.Visible = false; blnViewUsers = true; ShowData(0); }
protected void btnSavePolicy_Click(object sender, System.EventArgs e) { int OrganisationID = UserContext.UserData.OrgID; int PolicyID; try { PolicyID = Int32.Parse(Session["PolicyID"].ToString()); } catch { PolicyID = -1; } string PolicyName = this.txtName.Text; bool CanUpload = false; string OrigPolicyName = ""; long FileLength = GetFileSize(); //Initialise upload message text ClearMessages(); // Create Policy object BusinessServices.Policy objPolicy = new BusinessServices.Policy(); // Check if Organisation has space for saving policies long lngOrgSizeLimit = objPolicy.GetAllocatedDiskSpace(OrganisationID); if (lngOrgSizeLimit == 0) { // No value returned - Organisation has not had size allocated in organisation details - message to user lblUploadFile.Text = ResourceManager.GetString("OrgNoSpaceAllocated"); lblUploadFile.CssClass = "WarningMessage"; } //Check if the file is less than 2 mb else if (FileLength > 2097152) { lblUploadFile.Text = ResourceManager.GetString("FSZTOOBIG"); lblUploadFile.CssClass = "WarningMessage"; } else { // Get policies original name DataTable dtPolicy = objPolicy.GetPolicy(PolicyID, OrganisationID); if (dtPolicy.Rows.Count > 0) { OrigPolicyName = dtPolicy.Rows[0]["PolicyName"].ToString(); } // Check policy with same name does not already exist DataTable CheckPolicyName = new DataTable(); CheckPolicyName = objPolicy.CheckPolicyName(OrganisationID, PolicyName); if (CheckPolicyName.Rows.Count == 0) { CanUpload = true; } else { if (PolicyName == OrigPolicyName) { CanUpload = true; } else { // Policy Exists - display message for user to select another name lblPolicyName.Text = ResourceManager.GetString("PolicyExists"); lblPolicyName.CssClass = "WarningMessage"; } } if (CanUpload) { PolicyID = SavePolicy(); Session["PolicyID"] = PolicyID; LoadPolicy(PolicyID); if (PolicyID != -1) { if ((UploadSuccess && UploadFile.Value.Length > 0) || (!UploadSuccess && UploadFile.Value.Length == 0)) { Response.Redirect(@"\Administration\Policy\policydetails.aspx?Success=true"); } } } } }
private int SavePolicy() //change to int { int PolicyID; int NewPolicyID; try { PolicyID = Int32.Parse(Session["PolicyID"].ToString()); NewPolicyID = Int32.Parse(Session["PolicyID"].ToString()); } catch { PolicyID = -1; NewPolicyID = -1; } //Get values int OrganisationID = UserContext.UserData.OrgID; string PolicyName = this.txtName.Text; string ConfirmationMessage = this.txtConfirmationMsg.Text; bool Active = (this.ddlStatus.SelectedIndex == 0); bool Deleted = false; string FileName = this.UploadFile.PostedFile.FileName; // Create Policy object BusinessServices.Policy objPolicy = new BusinessServices.Policy(); if (PolicyID > 0) { //Existing Policy - updating objPolicy.UpdatePolicy(PolicyID, OrganisationID, PolicyName, Active, ConfirmationMessage); //Check to see if new file needs to be uploaded if (FileName.Length > 0) { NewPolicyID = Upload(PolicyID, true); } if (this.chkAssignAllUsers.Checked) { objPolicy.InitialisePolicyAccess(OrganisationID, NewPolicyID, this.chkAssignAllUsers.Checked); } Session["PolicyID"] = NewPolicyID; return(NewPolicyID); } else { if (FileName.Length > 0) { string PolicyFileName = Path.GetFileName(FileName); DataTable dt = objPolicy.CheckFileName(OrganisationID, PolicyFileName); int CheckRowCount = dt.Rows.Count; if (CheckRowCount == 0) { //Check if the file is less than 2 mb long PolicyFileSize = GetFileSize(); //New Policy - adding PolicyID = objPolicy.AddPolicy(OrganisationID, PolicyName, Active, Deleted, PolicyFileName, PolicyFileSize, ConfirmationMessage); NewPolicyID = Upload(PolicyID, false); objPolicy.InitialisePolicyAccess(OrganisationID, NewPolicyID, this.chkAssignAllUsers.Checked); Session["PolicyID"] = NewPolicyID; return(NewPolicyID); } else { lblUploadFile.Text = ResourceManager.GetString("FileExists"); lblUploadFile.CssClass = "WarningMessage"; return(-1); } } else { //File has not been specified for a new policy - prompt user to set file to upload lblUploadFile.Text = ResourceManager.GetString("NoUploadFile"); lblUploadFile.CssClass = "WarningMessage"; return(-1); } } }
private bool UploadPolicyFile(bool checkFile) { bool UploadStatus = false; // Create Policy object BusinessServices.Policy objPolicy = new BusinessServices.Policy(); //Check value in the upload file input if ((UploadFile.PostedFile != null) && (UploadFile.PostedFile.ContentLength > 0)) { //Get filename of file to be uploaded string FileName = GetFileName(); int CheckRowCount = 0; //code to check the database for a filename that has been previously used //If it exists then display message indicating that filenames need to be unique and do not allow upload of file int OrganisationID = UserContext.UserData.OrgID; if (checkFile) { DataTable dt = objPolicy.CheckFileName(OrganisationID, FileName); CheckRowCount = dt.Rows.Count; } if (CheckRowCount != 0 && checkFile) { // File with this name already exists for this organisation lblUploadFile.Text = ResourceManager.GetString("FileExists"); lblUploadFile.CssClass = "WarningMessage"; CheckCanUpload = false; } else { //Get fileinfo of file to be uploaded - length() returns file size in bytes long FileLength = GetFileSize(); //Obtain the size limit the organisation has long lngOrgSizeLimit = objPolicy.GetAllocatedDiskSpace(OrganisationID); if (lngOrgSizeLimit == 0) { // No value returned - Organisation has not had size allocated in organisation details - message to user lblUploadFile.Text = ResourceManager.GetString("OrgNoSpaceAllocated"); lblUploadFile.CssClass = "WarningMessage"; } else { //Determine the size of files already on server - note that at this stage this includes the file you are currently uploading long lngOrgUsedLimit = objPolicy.GetUsedPolicyDiskSpace(OrganisationID); //check that size of files already on server + new file size does not exceed the size limit for organisation. //If it does then do not upload the file and get them to contact SALT administrator CheckCanUpload = objPolicy.CheckCanUpload(lngOrgSizeLimit, lngOrgUsedLimit); if (CheckCanUpload) { //Location for file to be saved on server string SaveDir = Server.MapPath(@"\General") + @"\Policy\" + UserContext.UserData.OrgID.ToString(); //Check that the directory exists - if it doesn't then create it if (!Directory.Exists(SaveDir)) { Directory.CreateDirectory(SaveDir); } string SaveLocation = SaveDir + @"\" + FileName; try { UploadFile.PostedFile.SaveAs(SaveLocation); lblUploadFile.Text = ResourceManager.GetString("UploadSuccess"); lblUploadFile.CssClass = "SuccessMessage"; UploadStatus = true; } catch (Exception ex) { //log exception to event log ErrorHandler.ErrorLog el = new ErrorHandler.ErrorLog(ex, ErrorLevel.High, "PolicyDetails.aspx.cs", "UploadPolicyFile", ex.Message); //display friendly message to user lblUploadFile.Text = ResourceManager.GetString("UploadFail"); lblUploadFile.CssClass = "WarningMessage"; } } else { // Organisation allocated size will be exceeded - message to tell user this lblUploadFile.Text = ResourceManager.GetString("ExceedOrgSizeAllocation"); lblUploadFile.CssClass = "WarningMessage"; } } } } else { lblUploadFile.Text = ResourceManager.GetString("NoUploadFile"); lblUploadFile.CssClass = "WarningMessage"; } return(UploadStatus); }