Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Int64 forPopulationTypeId = 0;


            if (MercuryApplication == null)
            {
                return;
            }

            if ((!MercuryApplication.HasEnvironmentPermission(Mercury.Server.EnvironmentPermissions.PopulationTypeReview))

                && (!MercuryApplication.HasEnvironmentPermission(Mercury.Server.EnvironmentPermissions.PopulationTypeManage)))
            {
                Response.Redirect("/PermissionDenied.aspx", true); return;
            }


            if (!Page.IsPostBack)
            {
                #region Initial Page Load

                if (Request.QueryString["PopulationTypeId"] != null)
                {
                    forPopulationTypeId = Int64.Parse(Request.QueryString["PopulationTypeId"]);
                }

                if (forPopulationTypeId != 0)
                {
                    populationType = MercuryApplication.PopulationTypeGet(forPopulationTypeId, false);

                    if (populationType == null)
                    {
                        populationType = new Mercury.Client.Core.Population.PopulationType(MercuryApplication);
                    }
                }

                else
                {
                    populationType = new Mercury.Client.Core.Population.PopulationType(MercuryApplication);
                }

                InitializeAll();

                Session[SessionCachePrefix + "PopulationType"] = populationType;

                Session[SessionCachePrefix + "PopulationTypeUnmodified"] = populationType.Copy();

                #endregion
            } // Initial Page Load

            else   // Postback

            {
                populationType = (Mercury.Client.Core.Population.PopulationType)Session[SessionCachePrefix + "PopulationType"];
            }

            ApplySecurity();

            if (!String.IsNullOrEmpty(populationType.Name))
            {
                Page.Title = "Population Type - " + populationType.Name;
            }
            else
            {
                Page.Title = "Population Type";
            }

            return;
        }
Beispiel #2
0
        protected Boolean ApplyChanges()
        {
            Boolean isModified = false;

            Boolean success = false;

            Boolean isValid = false;

            System.Collections.Generic.Dictionary <String, String> validationResponse;



            Mercury.Client.Core.Population.PopulationType populationTypeUnmodified = (Mercury.Client.Core.Population.PopulationType)Session[SessionCachePrefix + "PopulationTypeUnmodified"];

            if (populationTypeUnmodified.Id == 0)
            {
                isModified = true;
            }


            populationType.Name = PopulationTypeName.Text.Trim();

            populationType.Description = PopulationTypeDescription.Text.Trim();

            populationType.Enabled = PopulationTypeEnabled.Checked;

            populationType.Visible = PopulationTypeVisible.Checked;

            if (!isModified)
            {
                isModified = !populationType.IsEqual(populationTypeUnmodified);
            }


            validationResponse = populationType.Validate();

            isValid = (validationResponse.Count == 0);


            if ((isModified) && (isValid))
            {
                success = MercuryApplication.PopulationTypeSave(populationType);

                if (success)
                {
                    populationType = MercuryApplication.PopulationTypeGet(populationType.Id, false);

                    Session[SessionCachePrefix + "PopulationType"] = populationType;

                    Session[SessionCachePrefix + "PopulationTypeUnmodified"] = populationType.Copy();

                    SaveResponseLabel.Text = "Save Successful";

                    InitializeAll();
                }

                else
                {
                    SaveResponseLabel.Text = "Unable to Save.";

                    if (MercuryApplication.LastException != null)
                    {
                        SaveResponseLabel.Text = SaveResponseLabel.Text + " [" + MercuryApplication.LastException.Message + "]";
                    }

                    success = false;
                }
            }

            else if (!isModified)
            {
                SaveResponseLabel.Text = "No Changes Detected."; success = true;
            }

            else if (!isValid)
            {
                foreach (String validationKey in validationResponse.Keys)
                {
                    SaveResponseLabel.Text = "Invalid [" + validationKey + "]: " + validationResponse[validationKey];

                    break;
                }

                success = false;
            }

            return(success);
        }