Beispiel #1
0
        /// <summary>
        /// This method populates the page controls from the passed ReportCatalog object
        /// </summary>
        /// <param name="reportCatalog">The ReportCatalog object with values to populate the page controls</param>
        private void PopulatePage(Models.ReportCatalog reportCatalog)
        {
            //Set the page controls to the values from the object
            tbCriteriaOptions.Text         = reportCatalog.CriteriaOptions;
            tbCriteriaDefaults.Text        = reportCatalog.CriteriaDefaults;
            tbKeywords.Text                = reportCatalog.Keywords;
            tbOptionalCriteriaOptions.Text = reportCatalog.OptionalCriteriaOptions;
            ddReportCategory.SelectedItem  = ddReportCategory.Items.FindByValue(reportCatalog.ReportCategory);
            txtReportClass.Value           = reportCatalog.ReportClass;
            txtReportDescription.Value     = reportCatalog.ReportDescription;
            txtReportName.Value            = reportCatalog.ReportName;
            tbRolesAuthorizedToRun.Value   = reportCatalog.RolesAuthorizedToRun;
            txtDocumentationFileName.Value = Path.GetFileName(reportCatalog.DocumentationLink);

            //Check to see if there is existing documentation
            if (!string.IsNullOrWhiteSpace(reportCatalog.DocumentationLink))
            {
                //There is existing documentation, set the link's URL and show it
                lnkExistingDocumentation.NavigateUrl = string.Format("/Pages/ViewFile.aspx?ReportCatalogPK={0}", reportCatalog.ReportCatalogPK.ToString());
                lnkExistingDocumentation.Visible     = true;
            }
            else
            {
                //There is no existing documentation, hide the link
                lnkExistingDocumentation.Visible = false;
            }
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Get the user's current program role
            currentProgramRole = Utilities.GetProgramRoleFromSession(Session);

            //Only allow super admins
            if (currentProgramRole.RoleFK.Value != (int)Utilities.ProgramRoleFKs.SUPER_ADMIN)
            {
                Response.Redirect("/Default.aspx");
            }

            //Get the CoachingLog PK from the query string
            if (!string.IsNullOrWhiteSpace(Request.QueryString["ReportCatalogPK"]))
            {
                int.TryParse(Request.QueryString["ReportCatalogPK"], out currentReportCatalogPK);
            }

            using (PyramidContext context = new PyramidContext())
            {
                //Get the Report Catalog item from the database
                currentReportCatalog = context.ReportCatalog.AsNoTracking().Where(rc => rc.ReportCatalogPK == currentReportCatalogPK).FirstOrDefault();

                //Check to see if the Report Catalog item from the database exists
                if (currentReportCatalog == null)
                {
                    //The Report Catalog item from the database doesn't exist, set the current Report Catalog item to a default value
                    currentReportCatalog = new Models.ReportCatalog();
                }
            }

            if (!IsPostBack)
            {
                //Hide the master page title
                ((LoggedIn)this.Master).HideTitle();

                //Bind the databound controls
                BindDataBoundControls();

                //Check to see if this is an edit or view
                if (currentReportCatalogPK > 0)
                {
                    //This is an edit or view
                    //Populate the page
                    PopulatePage(currentReportCatalog);
                }

                //Get the action from the query string
                string action;
                if (Request.QueryString["action"] != null)
                {
                    action = Request.QueryString["action"];
                }
                else
                {
                    action = "View";
                }

                //Allow adding/editing depending on the user's role and the action
                if (currentReportCatalog.ReportCatalogPK == 0 && currentProgramRole.AllowedToEdit.Value)
                {
                    //Show the submit button
                    submitReportCatalogItem.ShowSubmitButton = true;

                    //Show certain controls
                    hfViewOnly.Value = "False";

                    //Enable page controls
                    EnableControls(true);

                    //Set the page title
                    lblPageTitle.Text = "Add New Report Catalog Item";
                }
                else if (currentReportCatalog.ReportCatalogPK > 0 && action.ToLower() == "edit" && currentProgramRole.AllowedToEdit.Value)
                {
                    //Show the submit button
                    submitReportCatalogItem.ShowSubmitButton = true;

                    //Show certain controls
                    hfViewOnly.Value = "False";

                    //Enable page controls
                    EnableControls(true);

                    //Set the page title
                    lblPageTitle.Text = "Edit Report Catalog Item";
                }
                else
                {
                    //Hide the submit button
                    submitReportCatalogItem.ShowSubmitButton = false;

                    //Hide certain controls
                    hfViewOnly.Value = "True";

                    //Disable page controls
                    EnableControls(false);

                    //Set the page title
                    lblPageTitle.Text = "View Report Catalog Item";
                }

                //Set the focus to the report name field
                txtReportName.Focus();
            }
        }
Beispiel #3
0
        /// <summary>
        /// This method executes when the user clicks the save button for the report catalog item
        /// and it saves the information to the database
        /// </summary>
        /// <param name="sender">The submitReportCatalogItem submit user control</param>
        /// <param name="e">The Click event</param>
        protected void submitReportCatalogItem_Click(object sender, EventArgs e)
        {
            //To hold the success message type, file path, and file name
            string successMessageType = null;

            //Ensure user is allowed to edit
            if (currentProgramRole.AllowedToEdit.Value)
            {
                //Get the relative file path
                string relativePath = "~/Reports/Documentation/" + txtDocumentationFileName.Value.ToString();

                //Set the field values
                currentReportCatalog.CriteriaOptions         = tbCriteriaOptions.Text + ",";
                currentReportCatalog.CriteriaDefaults        = tbCriteriaDefaults.Text + ",";
                currentReportCatalog.DocumentationLink       = relativePath;
                currentReportCatalog.Keywords                = tbKeywords.Text + ",";
                currentReportCatalog.OptionalCriteriaOptions = tbOptionalCriteriaOptions.Text + ",";
                currentReportCatalog.ReportCategory          = (ddReportCategory.Value.ToString().ToLower().Contains("other") ? txtReportCategorySpecify.Value.ToString() : ddReportCategory.Value.ToString());
                currentReportCatalog.ReportClass             = txtReportClass.Value.ToString();
                currentReportCatalog.ReportDescription       = txtReportDescription.Value.ToString();
                currentReportCatalog.ReportName              = txtReportName.Value.ToString();
                currentReportCatalog.RolesAuthorizedToRun    = tbRolesAuthorizedToRun.Value.ToString() + ",";

                //Check to see if this is an edit or add
                if (currentReportCatalog.ReportCatalogPK > 0)
                {
                    //This is an edit
                    using (PyramidContext context = new PyramidContext())
                    {
                        //Set the success message
                        successMessageType = "ReportCatalogItemEdited";

                        //Get the existing ReportCatalog record
                        Models.ReportCatalog existingReportCatalog = context.ReportCatalog.Find(currentReportCatalog.ReportCatalogPK);

                        //Overwrite the existing ReportCatalog record with the values from the form
                        context.Entry(existingReportCatalog).CurrentValues.SetValues(currentReportCatalog);
                        context.SaveChanges();
                    }

                    //Redirect the user to the report catalog maintenance page
                    Response.Redirect(string.Format("/Admin/ReportCatalogMaintenance.aspx?messageType={0}", successMessageType));
                }
                else
                {
                    //This is an add
                    using (PyramidContext context = new PyramidContext())
                    {
                        //Set the success message
                        successMessageType = "ReportCatalogItemAdded";

                        //Set the edit-only fields
                        currentReportCatalog.Creator    = User.Identity.Name;
                        currentReportCatalog.CreateDate = DateTime.Now;

                        //Add the ReportCatalog record to the database
                        context.ReportCatalog.Add(currentReportCatalog);
                        context.SaveChanges();
                    }

                    //Redirect the user to the report catalog maintenance page
                    Response.Redirect(string.Format("/Admin/ReportCatalogMaintenance.aspx?messageType={0}", successMessageType));
                }
            }
            else
            {
                msgSys.ShowMessageToUser("danger", "Error", "You are not authorized to make changes!", 120000);
            }
        }