Пример #1
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            bool createAuditAccess = SessionManager.CheckUserPrivilege(SysPriv.config, SysScope.audit);

            var sourceId = Page.Request[Page.postEventSourceID];

            if (IsPostBack)
            {
                if (!uclAssessmentForm.IsEditContext)
                {
                    RadPersistenceManager1.StorageProviderKey = SessionManager.UserContext.Person.PERSON_ID.ToString();
                    RadPersistenceManager1.SaveState();
                }

                if (SessionManager.ReturnStatus == true)
                {
                    if (SessionManager.ReturnObject is string)
                    {
                        string type        = SessionManager.ReturnObject as string;
                        string auditStatus = "";
                        switch (type)
                        {
                        case "DisplayAudits":
                            rbNew.Visible = createAuditAccess;
                            UpdateDisplayState(DisplayState.AuditList);
                            break;

                        case "Notification":
                            //UpdateDisplayState(DisplayState.AuditNotificationEdit);
                            //UpdateDisplayState(DisplayState.AuditReportEdit);
                            uclAssessmentForm.EditAuditId = SessionManager.ReturnRecordID;
                            // need to determine if the Audit is past due and force it into display mode (probelm when coming from Calendar)
                            auditStatus   = EHSAuditMgr.SelectAuditStatus(SessionManager.ReturnRecordID);
                            rbNew.Visible = false;
                            if (auditStatus == "C")
                            {
                                UpdateDisplayState(DisplayState.AuditNotificationDisplay);
                            }
                            else
                            {
                                UpdateDisplayState(DisplayState.AuditNotificationEdit);
                            }
                            if (isDirected)
                            {
                                uclAssessmentForm.EnableReturnButton(false);
                            }
                            break;

                        case "ReAudit":
                            decimal reauditId = CreateReAudit(SessionManager.ReturnRecordID);
                            if (reauditId > 0)
                            {
                                SessionManager.ReturnRecordID = reauditId;
                                uclAssessmentForm.EditAuditId = reauditId;
                                rbNew.Visible = false;
                                UpdateDisplayState(DisplayState.AuditNotificationEdit);

                                if (isDirected)
                                {
                                    uclAssessmentForm.EnableReturnButton(false);
                                }
                            }
                            else
                            {
                                // probably need to show some sort of error message...
                                rbNew.Visible = createAuditAccess;
                                UpdateDisplayState(DisplayState.AuditList);
                            }
                            break;

                        case "Closed":
                            uclAssessmentForm.EditAuditId = SessionManager.ReturnRecordID;
                            UpdateDisplayState(DisplayState.AuditNotificationClosed);
                            rbNew.Visible = false;
                            if (isDirected)
                            {
                                uclAssessmentForm.EnableReturnButton(false);
                            }
                            break;

                        case "DisplayOnly":
                            uclAssessmentForm.EditAuditId = SessionManager.ReturnRecordID;
                            UpdateDisplayState(DisplayState.AuditNotificationDisplay);
                            rbNew.Visible = false;
                            if (isDirected)
                            {
                                uclAssessmentForm.EnableReturnButton(false);
                            }
                            break;

                        case "AddAttachment":
                        case "AddTask":
                            //UpdateDisplayState(DisplayState.AuditNotificationEdit);
                            //UpdateDisplayState(DisplayState.AuditReportEdit);
                            uclAssessmentForm.EditAuditId = SessionManager.ReturnRecordID;
                            // need to determine if the Audit is past due and force it into display mode (probelm when coming from Calendar)
                            auditStatus   = EHSAuditMgr.SelectAuditStatus(SessionManager.ReturnRecordID);
                            rbNew.Visible = false;
                            if (auditStatus == "C")
                            {
                                UpdateDisplayState(DisplayState.AuditNotificationDisplay);
                            }
                            else
                            {
                                UpdateDisplayState(DisplayState.AuditNotificationEdit);
                            }
                            if (isDirected)
                            {
                                uclAssessmentForm.EnableReturnButton(false);
                            }
                            break;
                        }
                    }
                    SessionManager.ClearReturns();
                }
            }
            else
            {
                uclAssessmentForm.EditReturnState = "NeedsRefresh";
                if (SessionManager.ReturnStatus == true && SessionManager.ReturnObject is string)
                {
                    try
                    {
                        // from inbox
                        DisplayNonPostback();
                        SessionManager.ReturnRecordID = Convert.ToDecimal(SessionManager.ReturnObject.ToString());
                        SessionManager.ReturnObject   = "Notification";
                        SessionManager.ReturnStatus   = true;
                        isDirected = true;

                        StringBuilder       sbScript = new StringBuilder();
                        ClientScriptManager cs       = Page.ClientScript;

                        sbScript.Append("<script language='JavaScript' type='text/javascript'>\n");
                        sbScript.Append("<!--\n");
                        sbScript.Append(cs.GetPostBackEventReference(this, "PBArg") + ";\n");
                        sbScript.Append("// -->\n");
                        sbScript.Append("</script>\n");

                        cs.RegisterStartupScript(this.GetType(), "AutoPostBackScript", sbScript.ToString());
                    }
                    catch
                    {
                        // not a number, parse as type
                        DisplayNonPostback();
                    }
                }
                else
                {
                    DisplayNonPostback();
                }
            }
            // for now, we will only let 'admin' create audits
            //if (!SessionManager.UserContext.Person.SSO_ID.ToLower().Equals("admin"))
            //	rbNew.Visible = false;
            rbNew.Visible = createAuditAccess;
        }