protected void Page_Load(object sender, EventArgs e)
    {
        _MessageHelper = _ContentApi.EkMsgRef;
            _StyleHelper = new StyleHelper();

            imgCloseAddItemModal.ImageUrl = _ContentApi.ApplicationPath + "images/ui/icons/cancel.png";
            if (Request.QueryString["os"] == "true")
            {
                devicetype.Attributes.Add("onkeypress", "return CheckKeyValue(event, '34,13, 60, 62');");
                selectDevice.Text = "Select a Device OS";
                iframeAddItemsModal.Attributes.Add("src", _ContentApi.ApplicationPath + "devicemodelselection.aspx?os=true");
            }
            else
            {
                selectDevice.Text = _MessageHelper.GetMessage("lbl select a device model");
                iframeAddItemsModal.Attributes.Add("src", _ContentApi.ApplicationPath + "devicemodelselection.aspx?os=false");
            }

            selectTemplate.Text = _MessageHelper.GetMessage("lbl pagebuilder select template");
            tbAddDeviceName.Attributes.Add("onkeypress", "return CheckKeyValue(event, '34,13, 60, 62');");
            tbEditDeviceName.Attributes.Add("onkeypress", "return CheckKeyValue(event, '34,13, 60, 62');");

            FileInfo fInfo = new FileInfo(Server.MapPath("~/App_Data/wurfl.xml.gz"));
            ltrNotification.Text = _MessageHelper.GetMessage("lbl device list update") + fInfo.LastWriteTime + ". " + _MessageHelper.GetMessage("lbl updated file") + " <a style=\"font-style: italic; font-weight: bold; cursor:pointer;\" href=\"http://sourceforge.net/projects/wurfl/files/WURFL/\" target=\"_blank\">" + _MessageHelper.GetMessage("lbl here") + "</a> ";

            setLocalizedString();

            if (!string.IsNullOrEmpty(Request.QueryString["action"]))
            {
                _action = EkFunctions.HtmlEncode(Request.QueryString["action"].ToString());
            }

            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                _Id = Convert.ToInt64(Request.QueryString["id"]);
            }

            CmsDeviceConfiguration cDevice = new CmsDeviceConfiguration(_ContentApi.RequestInformationRef);
            CmsDeviceConfigurationData deviceData = new CmsDeviceConfigurationData();

            if (!Page.IsPostBack)
            {
                DeviceConfigurationToolBar();
                if (_action == "adddeviceconfiguration")
                {
                    deviceConfigurationView.SetActiveView(Add);
                    if (Request.QueryString["os"] == "true")
                    {
                        trDeviceType1.Visible = true;
                        both.Selected = true;
                    }
                    else
                    {
                        trDeviceType1.Visible = false;
                    }
                }
                else
                {
                    if (_Id > -1)
                    {
                        deviceData = cDevice.GetItem(_Id);
                    }

                    deviceConfigurationView.SetActiveView(Edit);
                    if (deviceData != null)
                    {
                        //trDeviceType.Visible = true;
                        tbEditDeviceName.Text = deviceData.Name;
                        //tbEditPreviewTemplate.Text = deviceData.PreviewTemplate;
                        tbEditPreviewWidth.Value   = deviceData.Width.ToString();
                        tbEditPreviewHeight.Value = deviceData.Height.ToString();

                        if (Request.QueryString["os"] == "true")
                        {
                            trDeviceType.Visible = true;

                            switch (deviceData.DeviceType)
                            {
                                case (0):
                                    eboth.Selected = true;
                                    break;
                                case (1):
                                    ehandheld.Selected = true;
                                    break;
                                case (2):
                                    etablet.Selected = true;
                                    break;
                                default:
                                    eboth.Selected = true;
                                    break;
                            }

                            if (deviceData.DeviceType != null)
                            {
                                deviceData.DeviceType = deviceData.DeviceType;
                            }
                        }

                        if (deviceData.Models != null && deviceData.Models.Count > 0)
                        {
                            sBuilder = new StringBuilder();
                            sBuilder.Append("arDeviceNodes = new Array(");
                            int order = 0;
                            foreach (string node in deviceData.Models)
                            {
                                if (order != 0)
                                    sBuilder.Append(",");
                                sBuilder.Append("new node('" + node + "','" + order + "')");
                                order += 1;
                            }
                            sBuilder.AppendLine(");");
                            sBuilder.AppendLine("renderDeviceModels();");
                        }
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "renderDeviceList", sBuilder.ToString(), true);
                    }
                }
            }
            else
            {
                long _deviceID = 0;
                string backpage = "settings.aspx?action=viewalldeviceconfigurations";
                if (_action == "adddeviceconfiguration")
                {
                    deviceData.Name = Request.Form[tbAddDeviceName.UniqueID];
                    deviceData.Id = 0; //Add

                    deviceData.Width = Convert.ToInt32(Request.Form[tbAddPreviewWidth.UniqueID]);
                    deviceData.Height = Convert.ToInt32(Request.Form[tbAddPreviewHeight.UniqueID]);
                    if (Request.QueryString["os"] == "true")
                    {
                        trDeviceType1.Visible = true;
                        deviceData.DisplayFor = 1;
                        devicetype.Attributes.Add("onkeypress", "return CheckKeyValue(event, '34,13, 60, 62');");
                        if (Request.Form[devicetype.UniqueID] != null)
                        {
                            deviceData.DeviceType = Convert.ToInt16(Request.Form[devicetype.UniqueID]);
                        }
                    }
                    else
                    {
                        trDeviceType1.Visible = false;
                        deviceData.DisplayFor = 0;
                    }
                    deviceData.Models = DeserializeDeviceModels();

                    _deviceID = cDevice.Add(deviceData);
                    if (_deviceID == 0)
                        Utilities.ShowError(_MessageHelper.GetMessage("lbl device configuration exists"));
                    else
                        Response.Redirect(backpage, false);
                }
                else
                {
                    deviceData = cDevice.GetItem(_Id);
                    deviceData.Name = Request.Form[tbEditDeviceName.UniqueID];

                    deviceData.Id = _Id;

                    deviceData.Width = Convert.ToInt32(Request.Form[tbEditPreviewWidth.UniqueID]);
                    deviceData.Height = Convert.ToInt32(Request.Form[tbEditPreviewHeight.UniqueID]);

                    if (Request.QueryString["os"] == "true")
                    {
                        trDeviceType.Visible = true;
                        trDeviceType1.Visible = true;
                        deviceData.DisplayFor = 1;

                        if (Request.Form[edevicetype.UniqueID] != null)
                        {
                            deviceData.DeviceType = Convert.ToInt16(Request.Form[edevicetype.UniqueID]);
                        }

                        else if (deviceData.DeviceType == null)
                        {
                            deviceData.DeviceType = deviceData.DeviceType;
                        }

                    }
                    else
                    {
                        trDeviceType.Visible = false;
                        trDeviceType1.Visible = false;
                        deviceData.DisplayFor = 0;
                    }
                    deviceData.Models = DeserializeDeviceModels();

                    _deviceID = cDevice.Update(deviceData);
                    if (_deviceID == 0)
                        Utilities.ShowError(_MessageHelper.GetMessage("lbl device configuration exists"));
                    else
                        Response.Redirect("settings.aspx?action=viewdeviceconfiguration&id=" + _Id, false);
                }

            }
    }
Ejemplo n.º 2
0
    private void BindData()
    {
        CmsDeviceConfiguration cDevice = new CmsDeviceConfiguration(_ContentApi.RequestInformationRef);
        CmsDeviceConfigurationData deviceData = new CmsDeviceConfigurationData();

        deviceData = cDevice.GetItem(_Id);

        if (Request.QueryString["os"] != null)
        {
            if (deviceData != null)
            {
                lblDeviceName.Text = EkFunctions.HtmlEncode(deviceData.Name);
                lblPreviewWidth.Text = deviceData.Width.ToString();
                lblPreviewHeight.Text = deviceData.Height.ToString();

                if (deviceData.Models.Count > 0)
                {
                    if (Request.QueryString["os"] == "true")
                    {
                        trDeviceType.Visible = true;
                        lblDeviceType.Attributes.Add("title", _MessageHelper.GetMessage("lbl Device Type"));
                        lblDeviceType.InnerHtml = _MessageHelper.GetMessage("lbl Device Type");

                        ltrModels.Text = "<td class='label'>" + _MessageHelper.GetMessage("lbl operating systems") + ":</td><td>";
                        switch (deviceData.DeviceType)
                        {
                            case (0): ltrDeviceType.Text = _MessageHelper.GetMessage("lbl devicetype both");
                                break;
                            case (1): ltrDeviceType.Text = _MessageHelper.GetMessage("lbl devicetype handheld");
                                break;
                            case (2): ltrDeviceType.Text = _MessageHelper.GetMessage("lbl devicetype tablet");
                                break;
                            default:
                                ltrDeviceType.Text = _MessageHelper.GetMessage("lbl devicetype both");
                                break;
                        }
                    }
                    else
                    {
                        ltrModels.Text = "<td class='label'>" + _MessageHelper.GetMessage("lbl Device Models") + "</td><td>";
                    }
                    foreach (string mItem in deviceData.Models)
                    {
                        ltrModels.Text += "" + mItem + " ,";
                    }
                    ltrModels.Text = ltrModels.Text.ToString().TrimEnd(new char[] { ',' });
                    ltrModels.Text += "</td>";

                }
                else
                {
                    dvModels.Visible = false;
                }
            }
        }
        else
        {
            if (deviceData.DisplayFor == 0)
            {
                Response.Redirect("settings.aspx?action=viewdeviceconfiguration&os=false&id=" + deviceData.Id);
            }
            else
            {
                Response.Redirect("settings.aspx?action=viewdeviceconfiguration&os=true&id=" + deviceData.Id);
            }
        }
    }