protected void Page_Load(object sender, EventArgs e)
    {
        ErrorMessageLabel.Visible = false;

        // Get the query string values.
        NameValueCollection coll = Request.QueryString;

        int       id         = Convert.ToInt32(coll.Get("id"));
        int       eventId    = Convert.ToInt32(coll.Get("eId"));
        int       scheduleId = Convert.ToInt32(coll.Get("sId"));
        EventType eventType  = EventType.Future;

        if (coll.Get("et") != "" && coll.Get("et") != null)
        {
            eventType = (EventType)Convert.ToInt32(coll.Get("et"));
        }
        int    agentId   = Convert.ToInt32(coll.Get("aId"));
        string agentName = coll.Get("aName");
        string mode      = string.Empty;

        if (coll.Get("mode") != "" && coll.Get("mode") != null)
        {
            mode = coll.Get("mode");
        }
        int planType   = Convert.ToInt32(coll.Get("ptype"));
        int pageNumber = Convert.ToInt32(coll.Get("pg"));

        // Display the agent name if one exists.
        if (agentName != "")
        {
            AgentNameLabel.Text = "Agent Name: " + agentName + " ";
        }

        if (!IsPostBack)
        {
            // Set the required query string varables into hidden fields.
            IdHiddenField.Value         = id.ToString();
            EventIdHiddenField.Value    = eventId.ToString();
            ScheduleIdHiddenField.Value = scheduleId.ToString();
            EventTypeHiddenField.Value  = Convert.ToInt32(eventType).ToString();
            AgentIdHiddenField.Value    = agentId.ToString();
            AgentNameHiddenField.Value  = agentName;
            ModeHiddenField.Value       = mode;
            PlanTypeHiddenField.Value   = planType.ToString();
            PageNumberHiddenField.Value = pageNumber.ToString();

            try
            {
                // Get the schedule event entry details and display.
                ScheduleService.ScheduleService scheduleService =
                    serviceLoader.GetSchedule();
                ScheduleService.ScheduleInfo schedule =
                    scheduleService.GetEventEntry(eventId, id);

                EventNumberLabel.Text = schedule.Events[0].EventNumber.ToString();
                EventDateLabel.Text   = schedule.Events[0].EventDate.ToString("MM/dd/yyyy");
                FarmLabel.Text        = schedule.FarmName;
                MailingPlanLabel.Text = schedule.Plan.Title;
                StartDateLabel.Text   = schedule.StartDate.ToString("MM/dd/yyyy");
                EndDateLabel.Text     = schedule.EndDate.ToString("MM/dd/yyyy");
                PlotLabel.Text        = schedule.Events[0].Entries[0].PlotName;

                // Get the design details for the event entry.
                ScheduleService.DesignInfo design =
                    scheduleService.GetDesign(eventId);

                int    index         = design.LowResolutionFile.LastIndexOf(".");
                string pageImagePath = ConfigurationManager.AppSettings["ApprovedDesignRoot"] +
                                       "\\ExtractedPages\\" +
                                       design.LowResolutionFile.Substring(0, index) +
                                       "_Page.jpg";

                if (!File.Exists(pageImagePath))
                {
                    pageImagePath = ConfigurationManager.AppSettings["ApprovedDesignRoot"] +
                                    "\\ExtractedPages\\dummy_page.jpg";

                    ErrorMessageLabel.Text    = "The preview message is not available. Please try again after some time or contact your administrator.";
                    ErrorMessageLabel.Visible = true;
                }

                float      zoomFactor;
                RectangleF messageRectangleActual;
                Util.CalculateMessageActual(design.MessageRectangle, design.Size,
                                            pageImagePath, out zoomFactor, out messageRectangleActual);

                pageImagePath = pageImagePath.Substring(pageImagePath.IndexOf("\\Members\\ApprovedDesignPages"));
                pageImagePath = pageImagePath.Replace("\\", "/");

                DesignImage.ImageUrl = "~" + pageImagePath;

                DesignTextLayer.Style.Add("left", messageRectangleActual.X.ToString() + "px");
                DesignTextLayer.Style.Add("top", messageRectangleActual.Y.ToString() + "px");
                DesignTextLayer.Style.Add("width", messageRectangleActual.Width.ToString() + "px");
                DesignTextLayer.Style.Add("height", messageRectangleActual.Height.ToString() + "px");
                DesignTextLayer.Style.Add("clip", "rect(0px " + messageRectangleActual.Width.ToString() + "px " + messageRectangleActual.Height.ToString() + "px 0px)");

                DesignText.Style.Add("zoom", zoomFactor.ToString());
                if (Session["MessagePreviewType"].ToString() == "text")
                {
                    DesignText.InnerHtml = Session["MessagePreviewText"].ToString();
                }
                else
                {
                    MessageImage.ImageUrl = Session["MessagePreviewText"].ToString();
                    MessageImage.Visible  = true;
                }

                if (!ClientScript.IsStartupScriptRegistered(this.GetType(), "Startup"))
                {
                    String scriptString = "<script language=JavaScript>";
                    scriptString += "var ctrlPrefix = 'ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_';";
                    scriptString += "var left = document.getElementById(ctrlPrefix + 'DesignImageLayer').offsetLeft;";
                    scriptString += "var top = document.getElementById(ctrlPrefix + 'DesignImageLayer').offsetTop;";
                    scriptString += "var leftOffset = document.getElementById(ctrlPrefix + 'DesignTextLayer').offsetLeft;";
                    scriptString += "var topOffset = document.getElementById(ctrlPrefix + 'DesignTextLayer').offsetTop;";
                    scriptString += "document.getElementById(ctrlPrefix + 'DesignTextLayer').style.left = left + leftOffset;";
                    scriptString += "document.getElementById(ctrlPrefix + 'DesignTextLayer').style.top = top + topOffset;";
                    scriptString += "</script>";

                    ClientScript.RegisterStartupScript(this.GetType(), "Startup", scriptString);
                }
            }
            catch (Exception ex)
            {
                ErrorMessageLabel.Text    = "Unable to process the request. Please contact your administrator.";
                ErrorMessageLabel.Visible = true;

                log.Error("Unknown Error", ex);
            }
        }
    }
Beispiel #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ErrorMessageLabel.Visible = false;

        // Get the query string values.
        NameValueCollection coll = Request.QueryString;

        int       id         = Convert.ToInt32(coll.Get("id"));
        int       eventId    = Convert.ToInt32(coll.Get("eId"));
        int       scheduleId = Convert.ToInt32(coll.Get("sId"));
        EventType eventType  = EventType.Future;

        if (coll.Get("et") != "" && coll.Get("et") != null)
        {
            eventType = (EventType)Convert.ToInt32(coll.Get("et"));
        }
        int    agentId   = Convert.ToInt32(coll.Get("aId"));
        string agentName = coll.Get("aName");
        string mode      = string.Empty;

        if (coll.Get("mode") != "" && coll.Get("mode") != null)
        {
            mode = coll.Get("mode");
        }
        int planType   = Convert.ToInt32(coll.Get("ptype"));
        int pageNumber = Convert.ToInt32(coll.Get("pg"));

        // Display the agent name if one exists.
        if (agentName != "")
        {
            AgentNameLabel.Text = "Agent Name: " + agentName + "&nbsp;";
        }

        if (!IsPostBack)
        {
            // Set the required query string varables into hidden fields.
            IdHiddenField.Value         = id.ToString();
            EventIdHiddenField.Value    = eventId.ToString();
            ScheduleIdHiddenField.Value = scheduleId.ToString();
            EventTypeHiddenField.Value  = Convert.ToInt32(eventType).ToString();
            AgentIdHiddenField.Value    = agentId.ToString();
            AgentNameHiddenField.Value  = agentName;
            ModeHiddenField.Value       = mode;
            PlanTypeHiddenField.Value   = planType.ToString();
            PageNumberHiddenField.Value = pageNumber.ToString();

            // Get the schedule event entry details and display.
            try
            {
                ScheduleService.ScheduleService scheduleService =
                    serviceLoader.GetSchedule();
                ScheduleService.ScheduleInfo schedule =
                    scheduleService.GetEventEntry(eventId, id);

                EventNumberLabel.Text   = schedule.Events[0].EventNumber.ToString();
                EventDateLabel.Text     = schedule.Events[0].EventDate.ToString("MM/dd/yyyy");
                FarmIdHiddenField.Value = schedule.FarmId.ToString();
                FarmLabel.Text          = schedule.FarmName;
                MailingPlanLabel.Text   = schedule.Plan.Title;
                StartDateLabel.Text     = schedule.StartDate.ToString("MM/dd/yyyy");
                EndDateLabel.Text       = schedule.EndDate.ToString("MM/dd/yyyy");

                PlotLabel.Text = schedule.Events[0].Entries[0].PlotName;
                PrevMessageIdHiddenField.Value =
                    schedule.Events[0].Entries[0].Message.MessageId.ToString();

                if (coll.Get("fm") != "" && coll.Get("fm") != null && coll.Get("fm") == "pmp")
                {
                    if (Session["MessagePreviewTextId"].ToString().Length >= 6)
                    {
                        MessageTypeDropDownList.SelectedValue =
                            Session["MessagePreviewTypeId"].ToString();
                        MessageTypeDropDownList_Changed(MessageTypeDropDownList, new EventArgs());
                        MessageDropDownList.SelectedValue =
                            Session["MessagePreviewTextId"].ToString();
                        MessageDropDownList_Changed(MessageDropDownList, new EventArgs());
                    }
                    else
                    {
                        MessageTypeDropDownList_Changed(MessageTypeDropDownList, new EventArgs());
                    }
                }
                else
                {
                    if (schedule.Events[0].Entries[0].Message.MessageId != 0)
                    {
                        if (schedule.Events[0].Entries[0].Message.MessageType ==
                            ScheduleService.MessageType.Standard)
                        {
                            MessageTypeDropDownList.SelectedValue = "1";
                        }
                        else
                        {
                            MessageTypeDropDownList.SelectedValue = "2";
                        }
                        MessageTypeDropDownList_Changed(MessageTypeDropDownList, new EventArgs());
                        MessageDropDownList.SelectedValue =
                            schedule.Events[0].Entries[0].Message.MessageId.ToString();
                        MessageDropDownList_Changed(MessageDropDownList, new EventArgs());
                    }
                    else
                    {
                        MessageTypeDropDownList_Changed(MessageTypeDropDownList, new EventArgs());
                    }
                }

                if (mode == "view")
                {
                    MessageTypeDropDownList.Enabled = false;
                    MessageDropDownList.Enabled     = false;
                    SaveButton.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                ErrorMessageLabel.Text    = "Unable to process the request. Please contact your administrator.";
                ErrorMessageLabel.Visible = true;

                log.Error("Unknown Error", ex);
            }
        }
    }