Beispiel #1
0
        public ExtenderControlBase getAjaxExtender(string className, DataTable attributtes)
        {
            ExtenderControlBase ec;

            switch (className)
            {
            case "FilteredTextBoxExtender":
                AjaxControlToolkit.FilteredTextBoxExtender fte = new FilteredTextBoxExtender();
                for (int x = 0; x < attributtes.Rows.Count; x++)
                {
                    switch (attributtes.Rows[x]["AttributeName"].ToString())
                    {
                    case "ID":
                        fte.ID = attributtes.Rows[x]["AttributeValue"].ToString();
                        break;

                    case "FilterType":
                        fte.FilterType = getFilterType(attributtes.Rows[x]["AttributeValue"].ToString());
                        break;

                    case "TargetControlID":
                        fte.TargetControlID = attributtes.Rows[x]["AttributeValue"].ToString();
                        break;
                    }
                }
                ec = fte;
                break;

            default:
                ec = null;
                break;
            }

            return(ec);
        }
Beispiel #2
0
        /// <summary>
        /// Inject the filtered textbox extenders
        /// </summary>
        private void AddFilteredTextBoxExtenders()
        {
            // Add a filtered TextBox extender for the country code
            this.countryCodeFilteredTextBoxExtender                 = new FilteredTextBoxExtender();
            this.countryCodeFilteredTextBoxExtender.FilterType      = FilterTypes.Custom | FilterTypes.Numbers;
            this.countryCodeFilteredTextBoxExtender.ValidChars      = "+";
            this.countryCodeFilteredTextBoxExtender.TargetControlID = this.countryCodeTextBox.ID;
            this.countryCodeFilteredTextBoxExtender.ID              = "countryCodeFilteredTextBoxExtender";

            // Add a filtered TextBox extender for the area code
            this.areaCodeFilteredTextBoxExtender                 = new FilteredTextBoxExtender();
            this.areaCodeFilteredTextBoxExtender.FilterType      = FilterTypes.Numbers;
            this.areaCodeFilteredTextBoxExtender.TargetControlID = this.areaCodeTextBox.ID;
            this.areaCodeFilteredTextBoxExtender.ID              = "areaCodeFilteredTextBoxExtender";

            // Add a filtered TextBox extender for the local number
            this.localNumberFilteredTextBoxExtender                 = new FilteredTextBoxExtender();
            this.localNumberFilteredTextBoxExtender.FilterType      = FilterTypes.Numbers;
            this.localNumberFilteredTextBoxExtender.TargetControlID = this.localNumberTextBox.ID;
            this.localNumberFilteredTextBoxExtender.ID              = "localNumberFilteredTextBoxExtender";

            this.Controls.Add(this.countryCodeFilteredTextBoxExtender);
            this.Controls.Add(this.areaCodeFilteredTextBoxExtender);
            this.Controls.Add(this.localNumberFilteredTextBoxExtender);
        }
Beispiel #3
0
 /// <summary>
 /// Adds a character filter to all Text Boxes on the page.
 /// Prevents users from entering the <, >, &, or # characters in Text Boxes.
 /// These characters trigger the HttpRequestValidationException that prevents script injection.
 /// Note: the JS behind the filter could be turned off, in which case, the exception will still occur.
 /// </summary>
 private void addCharFilterToAllTextBoxes()
 {
     Control[] allControls = getAllPageControls(Page);
     foreach (Control c in allControls)
     {
         TextBox tbx = c as TextBox;
         if (tbx != null)
         {
             FilteredTextBoxExtender fte = new FilteredTextBoxExtender();
             fte.FilterMode      = FilterModes.InvalidChars;
             fte.InvalidChars    = "<>&#";
             fte.TargetControlID = c.ID;
             tbx.Parent.Controls.Add(fte);
         }
     }
 }
        /// <summary>
        /// Handles the ItemDataBound event of the rptrCart control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.Web.UI.WebControls.RepeaterItemEventArgs"/> instance containing the event data.</param>
        void rptrCart_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            OrderItem               orderItem               = e.Item.DataItem as OrderItem;
            Product                 product                 = new Product(orderItem.ProductId);
            TextBox                 quantityTextBox         = e.Item.FindControl("txtQuantity") as TextBox;
            DropDownList            quantityDropDownList    = e.Item.FindControl("ddlQuantity") as DropDownList;
            FilteredTextBoxExtender filteredTextBoxExtender = e.Item.FindControl("ftbeQuantity") as FilteredTextBoxExtender;

            if (quantityTextBox != null)
            {
                if (this.IsEditable)
                {
                    if (product.AllowNegativeInventories)
                    {
                        quantityDropDownList.Visible = false;
                        quantityTextBox.Text         = orderItem.Quantity.ToString();
                    }
                    else
                    {
                        quantityTextBox.Visible         = false;
                        filteredTextBoxExtender.Enabled = false;
                        Sku sku = new Sku("Sku", orderItem.Sku);
                        for (int i = 1; i <= sku.Inventory; i++)
                        {
                            quantityDropDownList.Items.Add(new ListItem(i.ToString(), i.ToString()));
                        }
                        //Inventory may have changed, so try to set it, but we may have to reset it
                        if (quantityDropDownList.Items.FindByValue(orderItem.Quantity.ToString()) != null)
                        {
                            quantityDropDownList.SelectedValue = orderItem.Quantity.ToString();
                        }
                        else
                        {
                            quantityDropDownList.SelectedIndex = 0;
                        }
                    }
                }
                else
                {
                    quantityDropDownList.Visible = false;
                    quantityTextBox.Text         = orderItem.Quantity.ToString();
                    quantityTextBox.CssClass     = "readOnly";
                    quantityTextBox.ReadOnly     = true;
                }
            }
        }
Beispiel #5
0
        private void FunSetearCampos(int codigocampo)
        {
            try
            {
                txtValor.Text            = "";
                _dts                     = new EstrategiaDAO().FunGetDatosCampos(codigocampo);
                ViewState["CodigoTabla"] = _dts.Tables[0].Rows[0]["CodigoTabla"].ToString();
                ViewState["Tipo"]        = _dts.Tables[0].Rows[0]["Tipo"].ToString();
                txtValor.Attributes.Clear();

                switch (ViewState["Tipo"].ToString())
                {
                case "date":
                case "datetime":
                    CalendarExtender calExtender = new CalendarExtender();
                    calExtender.Format          = "MM/dd/yyyy";
                    calExtender.TargetControlID = txtValor.ID;
                    PlaceTxt.Controls.Add(calExtender);
                    break;

                case "int":
                case "smallint":
                case "tinyint":
                    FilteredTextBoxExtender filter = new FilteredTextBoxExtender();
                    filter.FilterType      = FilterTypes.Numbers;
                    filter.TargetControlID = txtValor.ID;
                    PlaceTxt.Controls.Add(filter);
                    break;

                case "decimal":
                case "numeric":
                case "float":
                case "money":
                case "real":
                    txtValor.Attributes.Add("onkeypress", "return NumeroDecimal(this.form.txtValor, event)");
                    txtValor.Attributes.Add("onchange", "ValidarDecimales();");
                    break;
                }
            }
            catch (Exception ex)
            {
                Lblerror.Text = ex.ToString();
            }
        }
        protected void repeaterResult_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView             rowView        = (DataRowView)e.Item.DataItem;
                string                  strDataType    = rowView["DataType"].ToString().ToUpper();
                string                  strResultValue = rowView["ResultValue"].ToString();
                string                  strResultText  = rowView["ResultText"].ToString();
                string                  strLimit       = rowView["DetectionLimit"].ToString();
                string                  strParameterId = rowView["ParameterId"].ToString();
                bool                    hasResult      = (strResultText != "" || strResultValue != "");
                FilteredTextBoxExtender fteLimit       = e.Item.FindControl("fteLimit") as FilteredTextBoxExtender;
                FilteredTextBoxExtender fteValue       = e.Item.FindControl("fteValue") as FilteredTextBoxExtender;
                RadComboBox             ddlResultUnit  = e.Item.FindControl("ddlResultUnit") as RadComboBox;
                DropDownList            ddlResultList  = e.Item.FindControl("ddlResultList") as DropDownList;
                TextBox                 txtResultText  = e.Item.FindControl("textResultText") as TextBox;
                //Label labelResultText = e.Item.FindControl("labelResultText") as Label;
                CheckBox cBox           = e.Item.FindControl("checkUndetectable") as CheckBox;
                TextBox  txtLimit       = e.Item.FindControl("textDetectionLimit") as TextBox;
                TextBox  txtResultValue = e.Item.FindControl("textResultValue") as TextBox;

                fteLimit.Enabled = fteValue.Enabled =
                    cBox.Enabled = ddlResultUnit.Enabled =
                        txtResultValue.Enabled = strDataType == "NUMERIC";
                if (strDataType == "NUMERIC")
                {
                    txtLimit.Attributes.Add("disabled", "disabled");

                    if (null != cBox)
                    {
                        this.InjectScript(ref cBox, ref txtLimit);
                    }

                    this.PopulateUnits(ref ddlResultUnit, ref txtLimit, int.Parse(strParameterId));
                }

                else if (strDataType == "SELECTLIST")
                {
                    this.PopulateSelectList(ref ddlResultList, int.Parse(strParameterId));
                }
            }
        }
        protected void repeaterResult_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                LabTestParameterResult rowView = (LabTestParameterResult)e.Item.DataItem;
                string  strDataType            = rowView.ResultDataType;
                decimal?strResultValue         = rowView.ResultValue;
                string  strResultText          = rowView.ResultText;
                decimal?strLimit       = rowView.DetectionLimit;
                int     strParameterId = rowView.ParameterId;

                bool hasResult = rowView.HasResult;
                FilteredTextBoxExtender fteLimit      = e.Item.FindControl("fteLimit") as FilteredTextBoxExtender;
                FilteredTextBoxExtender fteValue      = e.Item.FindControl("fteValue") as FilteredTextBoxExtender;
                DropDownList            ddlResultUnit = e.Item.FindControl("ddlResultUnit") as DropDownList;
                DropDownList            ddlResultList = e.Item.FindControl("ddlResultList") as DropDownList;
                TextBox txtResultText = e.Item.FindControl("textResultText") as TextBox;
                //Label labelResultText = e.Item.FindControl("labelResultText") as Label;
                CheckBox cBox           = e.Item.FindControl("checkUndetectable") as CheckBox;
                TextBox  txtLimit       = e.Item.FindControl("textDetectionLimit") as TextBox;
                TextBox  txtResultValue = e.Item.FindControl("textResultValue") as TextBox;

                fteLimit.Enabled = fteValue.Enabled =
                    cBox.Enabled = ddlResultUnit.Enabled =
                        txtResultValue.Enabled = strDataType == "NUMERIC";
                if (strDataType == "NUMERIC")
                {
                    txtLimit.Attributes.Add("disabled", "disabled");

                    if (null != cBox)
                    {
                        this.InjectScript(ref cBox, ref txtLimit, ref txtResultValue);
                    }

                    this.PopulateUnits(ref ddlResultUnit, ref txtLimit, strParameterId);
                }
                else if (strDataType == "SELECTLIST")
                {
                    this.PopulateSelectList(ref ddlResultList, strParameterId);
                }
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        SuperForm1                          = new SuperForm();
        SuperForm1.ID                       = "SuperForm1";
        SuperForm1.DataSourceID             = "SqlDataSource1";
        SuperForm1.AutoGenerateRows         = false;
        SuperForm1.AutoGenerateInsertButton = true;
        SuperForm1.AutoGenerateEditButton   = true;
        SuperForm1.AutoGenerateDeleteButton = true;
        SuperForm1.DataKeyNames             = new string[] { "ProductID" };
        SuperForm1.AllowPaging              = true;
        SuperForm1.DefaultMode              = DetailsViewMode.Edit;

        SuperForm1.ItemInserted += SuperForm1_ItemInserted;
        SuperForm1.ItemCommand  += SuperForm1_ItemCommand;

        Obout.SuperForm.BoundField field1 = new Obout.SuperForm.BoundField();
        field1.DataField     = "ProductID";
        field1.HeaderText    = "Product ID";
        field1.ReadOnly      = true;
        field1.InsertVisible = false;

        Obout.SuperForm.BoundField field2 = new Obout.SuperForm.BoundField();
        field2.DataField  = "ProductName";
        field2.HeaderText = "Product Name";
        field2.Required   = true;

        FilteredTextBoxExtender FilteredTextBoxExtender1 = new FilteredTextBoxExtender();

        FilteredTextBoxExtender1.ID         = "FilteredTextBoxExtender1";
        FilteredTextBoxExtender1.FilterType = FilterTypes.LowercaseLetters | FilterTypes.UppercaseLetters | FilterTypes.Custom;
        FilteredTextBoxExtender1.ValidChars = " ";
        field2.Filters.Add(FilteredTextBoxExtender1);

        Obout.SuperForm.BoundField field3 = new Obout.SuperForm.BoundField();
        field3.DataField  = "UnitsInStock";
        field3.HeaderText = "Units In Stock";

        FilteredTextBoxExtender FilteredTextBoxExtender2 = new FilteredTextBoxExtender();

        FilteredTextBoxExtender2.ID         = "FilteredTextBoxExtender2";
        FilteredTextBoxExtender2.FilterType = FilterTypes.Numbers;
        FilteredTextBoxExtender2.ValidChars = " ";
        field3.Filters.Add(FilteredTextBoxExtender2);

        Obout.SuperForm.BoundField field4 = new Obout.SuperForm.BoundField();
        field4.DataField  = "UnitsOnOrder";
        field4.HeaderText = "Units On Order";

        FilteredTextBoxExtender FilteredTextBoxExtender3 = new FilteredTextBoxExtender();

        FilteredTextBoxExtender3.ID         = "FilteredTextBoxExtender3";
        FilteredTextBoxExtender3.FilterType = FilterTypes.Numbers;
        field4.Filters.Add(FilteredTextBoxExtender3);


        SuperForm1.Fields.Add(field1);
        SuperForm1.Fields.Add(field2);
        SuperForm1.Fields.Add(field3);
        SuperForm1.Fields.Add(field4);

        SuperForm1Container.Controls.Add(SuperForm1);
    }
Beispiel #9
0
        private void DetermineConfigEditControl()
        {
            // clear out the controls collection for would be-new type of controls
            plhConfigValueEditor.Controls.Clear();

            GlobalConfig config   = this.Datasource;
            string       editorId = string.Format("ctrlConfigEditor{0}", config.ID);

            if (config.ValueType.EqualsIgnoreCase("integer"))
            {
                TextBox txt = new TextBox();
                txt.ID         = editorId;
                txt.Text       = config.ConfigValue;
                GetConfigValue = () => { return(txt.Text); };

                FilteredTextBoxExtender extFilterInt = new FilteredTextBoxExtender();
                extFilterInt.ID = "extFilterInt";
                extFilterInt.TargetControlID = editorId;
                extFilterInt.FilterType      = FilterTypes.Numbers;

                plhConfigValueEditor.Controls.Add(txt);
                plhConfigValueEditor.Controls.Add(extFilterInt);
            }
            else if (config.ValueType.EqualsIgnoreCase("decimal") || config.ValueType.EqualsIgnoreCase("double"))
            {
                TextBox txt = new TextBox();
                txt.ID         = editorId;
                txt.Text       = config.ConfigValue;
                GetConfigValue = () => { return(txt.Text); };

                FilteredTextBoxExtender extFilterNumeric = new FilteredTextBoxExtender();
                extFilterNumeric.ID = "extFilterNumeric";
                extFilterNumeric.TargetControlID = editorId;
                extFilterNumeric.FilterType      = FilterTypes.Numbers | FilterTypes.Custom;
                extFilterNumeric.ValidChars      = ".";

                plhConfigValueEditor.Controls.Add(txt);
                plhConfigValueEditor.Controls.Add(extFilterNumeric);
            }
            else if (config.ValueType.EqualsIgnoreCase("boolean"))
            {
                bool isYes = Localization.ParseBoolean(config.ConfigValue);

                RadioButtonList rbYesNo = new RadioButtonList();
                rbYesNo.ID = editorId;
                rbYesNo.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;

                ListItem optionYes = new ListItem("Yes");
                ListItem optionNo  = new ListItem("No");

                optionYes.Selected = isYes;
                optionNo.Selected  = !isYes;

                rbYesNo.Items.Add(optionYes);
                rbYesNo.Items.Add(optionNo);

                GetConfigValue = () => { return(optionYes.Selected.ToString().ToLowerInvariant()); };

                plhConfigValueEditor.Controls.Add(rbYesNo);
            }
            else if (config.ValueType.EqualsIgnoreCase("enum"))
            {
                DropDownList cboValues = new DropDownList();
                cboValues.ID = editorId;
                foreach (string value in config.AllowableValues)
                {
                    cboValues.Items.Add(value);
                }
                cboValues.SelectedValue = config.ConfigValue;

                GetConfigValue = () => { return(cboValues.SelectedValue); };

                plhConfigValueEditor.Controls.Add(cboValues);
            }
            else if (config.ValueType.EqualsIgnoreCase("invoke"))
            {
                DropDownList cboValues = new DropDownList();
                cboValues.ID = editorId;

                bool   invocationSuccessful = false;
                string errorMessage         = string.Empty;

                try
                {
                    if (config.AllowableValues.Count == 3)
                    {
                        // format should be
                        // {FullyQualifiedName},MethodName
                        // Fully qualified name format is Namespace.TypeName,AssemblyName
                        string typeName     = config.AllowableValues[0];
                        string assemblyName = config.AllowableValues[1];
                        string methodName   = config.AllowableValues[2];

                        string     fqName = typeName + "," + assemblyName;
                        Type       t      = Type.GetType(fqName);
                        object     o      = Activator.CreateInstance(t);
                        MethodInfo method = o.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.Static);
                        object     result = method.Invoke(o, new object[] { });

                        if (result is IEnumerable)
                        {
                            cboValues.DataSource = result;
                            cboValues.DataBind();

                            invocationSuccessful = true;

                            // now try to find which one is matching, case-insensitive
                            foreach (ListItem item in cboValues.Items)
                            {
                                item.Selected = item.Text.EqualsIgnoreCase(config.ConfigValue);
                            }
                        }
                        else
                        {
                            errorMessage         = "Invocation method must return IEnumerable";
                            invocationSuccessful = false;
                        }
                    }
                    else
                    {
                        errorMessage         = "Invalid invocation value";
                        invocationSuccessful = false;
                    }
                }
                catch (Exception ex)
                {
                    errorMessage         = ex.Message;
                    invocationSuccessful = false;
                }

                if (invocationSuccessful == false)
                {
                    cboValues.Items.Add(errorMessage);
                }

                GetConfigValue = () => { return(cboValues.SelectedValue); };

                plhConfigValueEditor.Controls.Add(cboValues);
            }
            else if (config.ValueType.EqualsIgnoreCase("multiselect"))
            {
                CheckBoxList chkValues = new CheckBoxList();
                chkValues.ID = editorId;

                Func <string, bool> isIncluded = (optionValue) =>
                {
                    return(config.ConfigValue.Split(',').Any(val => val.Trim().EqualsIgnoreCase(optionValue)));
                };

                foreach (string optionValue in config.AllowableValues)
                {
                    ListItem option = new ListItem(optionValue, optionValue);
                    option.Selected = isIncluded(optionValue);
                    chkValues.Items.Add(option);
                }

                GetConfigValue = () =>
                {
                    var selectedValues = new List <string>();
                    foreach (ListItem option in chkValues.Items)
                    {
                        if (option.Selected)
                        {
                            selectedValues.Add(option.Value);
                        }
                    }

                    // format the selected values into a comma delimited string
                    return(selectedValues.ToCommaDelimitedString());
                };

                plhConfigValueEditor.Controls.Add(chkValues);
            }
            else
            {
                // determine length for proper control to use
                string configValue = config.ConfigValue;

                TextBox txt = new TextBox();
                txt.ID   = editorId;
                txt.Text = configValue;

                if (configValue.Length >= MAX_COLUMN_LENGTH)
                {
                    // use textArea
                    txt.TextMode = TextBoxMode.MultiLine;
                    txt.Rows     = 4; // make it 4 rows by default
                }

                txt.Columns = DetermineProperTextColumnLength(configValue);

                GetConfigValue = () => { return(txt.Text); };

                plhConfigValueEditor.Controls.Add(txt);
            }
        }
Beispiel #10
0
        private void initConfigValue()
        {
            if (DataSource.AppConfigId < 1)
            {
                return;
            }

            if (DataSource.StoreId == 0 && TargetStoreId > 0)
            {
                litStoreName.Text         = Store.GetStoreName(TargetStoreId);
                pnlInheritWarning.Visible = true;
            }
            else
            {
                pnlInheritWarning.Visible = false;
            }

            AppConfigId.Value = DataSource.AppConfigId.ToString();

            AppConfigType type;

            if (!Enum.TryParse(DataSource.ValueType, true, out type))
            {
                type = AppConfigType.@string;
            }

            phValidators.Controls.Clear();
            tbxValue.Visible = ddValue.Visible = cblValue.Visible = rblValue.Visible = false;
            switch (type)
            {
            case AppConfigType.@string:
                tbxValue.Visible = true;
                tbxValue.Text    = DataSource.ConfigValue;
                //tbxValue.CssClass = DataSource.Name.Replace(".", string.Empty);
                break;

            case AppConfigType.boolean:
                rblValue.Visible       = true;
                rblValue.SelectedValue = DataSource.ConfigValue.ToBool().ToString().ToLower();
                //rblValue.CssClass = DataSource.Name.Replace(".", string.Empty);
                pnlInheritWarning.Visible = false;
                break;

            case AppConfigType.integer:
                tbxValue.Visible = true;
                tbxValue.Text    = DataSource.ConfigValue;
                //tbxValue.CssClass = DataSource.Name.Replace(".", string.Empty);
                RegularExpressionValidator regExInt = new RegularExpressionValidator();
                regExInt.ValidationExpression = @"^-{0,1}\d+$";
                regExInt.ErrorMessage         = String.Format(AppLogic.GetString("admin.atom.integerError", AspDotNetStorefrontCore.Localization.GetDefaultLocale()), DataSource.Name);
                regExInt.ControlToValidate    = tbxValue.ID;
                phValidators.Controls.Add(regExInt);
                break;

            case AppConfigType.@decimal:
            case AppConfigType.@double:
                tbxValue.Visible = true;
                tbxValue.Text    = DataSource.ConfigValue;
                //tbxValue.CssClass = DataSource.Name.Replace(".", string.Empty);
                FilteredTextBoxExtender extFilterNumeric = new FilteredTextBoxExtender();
                extFilterNumeric.TargetControlID = tbxValue.ID;
                extFilterNumeric.FilterType      = FilterTypes.Numbers | FilterTypes.Custom;
                extFilterNumeric.ValidChars      = ".";
                phValidators.Controls.Add(extFilterNumeric);
                break;

            case AppConfigType.@enum:
                ddValue.Visible = true;
                ddValue.Items.Clear();
                ddValue.CssClass = DataSource.Name.Replace(".", string.Empty);
                foreach (string value in DataSource.AllowableValues)
                {
                    ddValue.Items.Add(value);
                }
                if (ddValue.Items.FindByValue(DataSource.ConfigValue) != null)
                {
                    ddValue.SelectedValue = DataSource.ConfigValue;
                }
                break;

            case AppConfigType.multiselect:
                cblValue.Visible = true;
                cblValue.Items.Clear();
                //cblValue.CssClass = DataSource.Name.Replace(".", string.Empty);
                Func <string, bool> isIncluded = (optionValue) =>
                {
                    return(DataSource.ConfigValue.Split(',').Any(val => val.Trim().EqualsIgnoreCase(optionValue)));
                };

                foreach (string optionValue in DataSource.AllowableValues)
                {
                    ListItem option = new ListItem(optionValue, optionValue);
                    option.Selected = isIncluded(optionValue);
                    cblValue.Items.Add(option);
                }

                List <string> selectedValues = new List <string>();
                foreach (ListItem option in cblValue.Items)
                {
                    if (option.Selected)
                    {
                        selectedValues.Add(option.Value);
                    }
                }
                break;

            case AppConfigType.invoke:
                ddValue.Visible = true;
                ddValue.Items.Clear();
                //ddValue.CssClass = DataSource.Name.Replace(".", string.Empty);
                bool   invocationSuccessful = false;
                string errorMessage         = string.Empty;

                try
                {
                    if (DataSource.AllowableValues.Count() == 3)
                    {
                        // format should be
                        // {FullyQualifiedName},MethodName
                        // Fully qualified name format is Namespace.TypeName,AssemblyName
                        string typeName     = DataSource.AllowableValues.ElementAt(0);
                        string assemblyName = DataSource.AllowableValues.ElementAt(1);
                        string methodName   = DataSource.AllowableValues.ElementAt(2);

                        string     fqName = typeName + "," + assemblyName;
                        Type       t      = Type.GetType(fqName);
                        object     o      = Activator.CreateInstance(t);
                        MethodInfo method = o.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.Static);
                        object     result = method.Invoke(o, new object[] { });

                        if (result is IEnumerable)
                        {
                            ddValue.DataSource = result;
                            ddValue.DataBind();

                            invocationSuccessful = true;

                            if (ddValue.Items.FindByValue(DataSource.ConfigValue) != null)
                            {
                                ddValue.SelectedValue = DataSource.ConfigValue;
                            }
                        }
                        else
                        {
                            errorMessage         = "Invocation method must return IEnumerable";
                            invocationSuccessful = false;
                        }
                    }
                    else
                    {
                        errorMessage         = "Invalid invocation value";
                        invocationSuccessful = false;
                    }
                }
                catch (Exception ex)
                {
                    errorMessage         = ex.Message;
                    invocationSuccessful = false;
                }

                if (invocationSuccessful == false)
                {
                    ddValue.Items.Add(errorMessage);
                }

                break;

            default:
                break;
            }
        }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        #region "Watermark extender"

        // Watermark extender
        // Disable watermark extender for nonempty fields (issue with value which is same as the watermark text)
        string resolvedWatermarkText = ContextResolver.ResolveMacros(WatermarkText);
        if (!String.IsNullOrEmpty(WatermarkText) && !String.IsNullOrEmpty(resolvedWatermarkText) && !CMSString.Equals(textbox.Text, WatermarkText))
        {
            // Create extender
            TextBoxWatermarkExtender exWatermark = new TextBoxWatermarkExtender();
            exWatermark.ID = "exWatermark";
            exWatermark.TargetControlID = textbox.ID;
            exWatermark.EnableViewState = false;
            Controls.Add(exWatermark);

            // Initialize extender
            exWatermark.WatermarkText     = resolvedWatermarkText;
            exWatermark.WatermarkCssClass = textbox.CssClass + " " + ValidationHelper.GetString(GetValue("WatermarkCssClass"), WatermarkCssClass);
        }

        #endregion


        #region "Filter extender"

        if (FilterEnabled)
        {
            // Create extender
            FilteredTextBoxExtender exFilter = new FilteredTextBoxExtender();
            exFilter.ID = "exFilter";
            exFilter.TargetControlID = textbox.ID;
            exFilter.EnableViewState = false;
            Controls.Add(exFilter);

            // Filter extender
            exFilter.FilterInterval = FilterInterval;

            // Set the filter type
            if (FilterTypeValue == null)
            {
                exFilter.FilterType = FilterType;
            }
            else
            {
                if (!string.IsNullOrEmpty(FilterTypeValue))
                {
                    FilterTypes filterType = 0;
                    string[]    types      = FilterTypeValue.Split(new char[] { ';', '|' }, StringSplitOptions.RemoveEmptyEntries);
                    if (types.Length > 0)
                    {
                        foreach (string typeStr in types)
                        {
                            int type = ValidationHelper.GetInteger(typeStr, 0);
                            switch (type)
                            {
                            case FILTER_NUMBERS:
                                filterType |= FilterTypes.Numbers;
                                break;

                            case FILTER_LOWERCASE:
                                filterType |= FilterTypes.LowercaseLetters;
                                break;

                            case FILTER_UPPERCASE:
                                filterType |= FilterTypes.UppercaseLetters;
                                break;

                            case FILTER_CUSTOM:
                                filterType |= FilterTypes.Custom;
                                break;
                            }
                        }
                        exFilter.FilterType = filterType;
                    }
                }
            }

            FilterModes filterMode = FilterMode;

            // Set valid and invalid characters
            if (exFilter.FilterType == FilterTypes.Custom)
            {
                // When filter type is Custom only, filter mode can be anything
                exFilter.FilterMode = filterMode;

                if (filterMode == FilterModes.InvalidChars)
                {
                    exFilter.InvalidChars = InvalidChars;
                }
                else
                {
                    exFilter.ValidChars = ValidChars;
                }
            }
            else
            {
                // Otherwise filter type must be valid chars
                exFilter.FilterMode = FilterModes.ValidChars;

                // Set valid chars only if original filter mode was valid chars and filter type contains Custom
                if ((filterMode == FilterModes.ValidChars) && ((exFilter.FilterType & FilterTypes.Custom) != 0))
                {
                    exFilter.ValidChars = ValidChars;
                }
            }
        }

        #endregion


        #region "Autocomplete extender"

        // Autocomplete extender
        if (!string.IsNullOrEmpty(AutoCompleteServiceMethod) && !string.IsNullOrEmpty(AutoCompleteServicePath))
        {
            // Create extender
            AutoCompleteExtender exAuto = new AutoCompleteExtender();
            exAuto.ID = "exAuto";
            exAuto.TargetControlID = textbox.ID;
            exAuto.EnableViewState = false;
            Controls.Add(exAuto);

            exAuto.ServiceMethod                           = AutoCompleteServiceMethod;
            exAuto.ServicePath                             = URLHelper.ResolveUrl(AutoCompleteServicePath);
            exAuto.MinimumPrefixLength                     = AutoCompleteMinimumPrefixLength;
            exAuto.ContextKey                              = ContextResolver.ResolveMacros(AutoCompleteContextKey);
            exAuto.CompletionInterval                      = AutoCompleteCompletionInterval;
            exAuto.EnableCaching                           = AutoCompleteEnableCaching;
            exAuto.CompletionSetCount                      = AutoCompleteCompletionSetCount;
            exAuto.CompletionListCssClass                  = AutoCompleteCompletionListCssClass;
            exAuto.CompletionListItemCssClass              = AutoCompleteCompletionListItemCssClass;
            exAuto.CompletionListHighlightedItemCssClass   = AutoCompleteCompletionListHighlightedItemCssClass;
            exAuto.DelimiterCharacters                     = AutoCompleteDelimiterCharacters;
            exAuto.FirstRowSelected                        = AutoCompleteFirstRowSelected;
            exAuto.ShowOnlyCurrentWordInCompletionListItem = AutoCompleteShowOnlyCurrentWordInCompletionListItem;
        }

        #endregion
    }
Beispiel #12
0
        private PlaceHolder DetermineConfigEditControl(string StoreName, int StoreId, AppConfig config)
        {
            PlaceHolder plhConfigValueEditor = new PlaceHolder();
            String      editorId;
            Boolean     isnew = (config == null);

            if (isnew)
            {
                //return AddParameterControl(StoreName, StoreId, config);
                config   = AppLogic.GetAppConfigRouted(this.Datasource.Name, StoreId);
                editorId = string.Format("ctrlNewConfig{0}_{1}", StoreId, this.Datasource.AppConfigID);
                plhConfigValueEditor.Controls.Add(new LiteralControl("<small style=\"color:gray;\">(Unassigned for <em>{0}</em>. Currently using default.)</small><br />".FormatWith(Store.GetStoreName(StoreId))));
            }
            else
            {
                editorId = string.Format("ctrlConfigEditor{0}", config.AppConfigID);
            }


            if (config.ValueType.EqualsIgnoreCase("integer"))
            {
                TextBox txt = new TextBox();
                txt.ID        = editorId;
                txt.Text      = config.ConfigValue;
                m_configvalue = txt.Text;

                CompareValidator compInt = new CompareValidator();
                compInt.Type              = ValidationDataType.Integer;
                compInt.Operator          = ValidationCompareOperator.DataTypeCheck;
                compInt.ControlToValidate = txt.ID;
                compInt.ErrorMessage      = AppLogic.GetString("admin.editquantitydiscounttable.EnterInteger", ThisCustomer.LocaleSetting);

                plhConfigValueEditor.Controls.Add(txt);
                plhConfigValueEditor.Controls.Add(compInt);
            }
            else if (config.ValueType.EqualsIgnoreCase("decimal") || config.ValueType.EqualsIgnoreCase("double"))
            {
                TextBox txt = new TextBox();
                txt.ID        = editorId;
                txt.Text      = config.ConfigValue;
                m_configvalue = txt.Text;

                FilteredTextBoxExtender extFilterNumeric = new FilteredTextBoxExtender();
                extFilterNumeric.ID = DB.GetNewGUID();
                extFilterNumeric.TargetControlID = editorId;
                extFilterNumeric.FilterType      = FilterTypes.Numbers | FilterTypes.Custom;
                extFilterNumeric.ValidChars      = ".";

                plhConfigValueEditor.Controls.Add(txt);
                plhConfigValueEditor.Controls.Add(extFilterNumeric);
            }
            else if (config.ValueType.EqualsIgnoreCase("boolean"))
            {
                bool isYes = Localization.ParseBoolean(config.ConfigValue);

                RadioButtonList rbYesNo = new RadioButtonList();
                rbYesNo.ID = editorId;
                rbYesNo.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;

                ListItem optionYes = new ListItem("Yes");
                ListItem optionNo  = new ListItem("No");

                if (StoreId == 0)
                {
                    optionYes.Attributes.Add("onclick", "$(this).parents('.modal_popup_Content').find('span.defaultTrue input').each(function (index, value) {$(value).click();});");
                    optionNo.Attributes.Add("onclick", "$(this).parents('.modal_popup_Content').find('span.defaultFalse input').each(function (index, value) {$(value).click();});");
                }
                else if (isnew)
                {
                    optionYes.Attributes.Add("class", "defaultTrue");
                    optionNo.Attributes.Add("class", "defaultFalse");
                }

                optionYes.Selected = isYes;
                optionNo.Selected  = !isYes;

                rbYesNo.Items.Add(optionYes);
                rbYesNo.Items.Add(optionNo);

                m_configvalue = optionYes.Selected.ToString().ToLowerInvariant();

                plhConfigValueEditor.Controls.Add(rbYesNo);
            }
            else if (config.ValueType.EqualsIgnoreCase("enum"))
            {
                DropDownList cboValues = new DropDownList();
                cboValues.ID = editorId;
                foreach (string value in config.AllowableValues)
                {
                    cboValues.Items.Add(value);
                }
                cboValues.SelectedValue = config.ConfigValue;

                m_configvalue = cboValues.SelectedValue;

                plhConfigValueEditor.Controls.Add(cboValues);
            }
            else if (config.ValueType.EqualsIgnoreCase("invoke"))
            {
                DropDownList cboValues = new DropDownList();
                cboValues.ID = editorId;

                bool   invocationSuccessful = false;
                string errorMessage         = string.Empty;

                try
                {
                    if (config.AllowableValues.Count == 3)
                    {
                        // format should be
                        // {FullyQualifiedName},MethodName
                        // Fully qualified name format is Namespace.TypeName,AssemblyName
                        string typeName     = config.AllowableValues[0];
                        string assemblyName = config.AllowableValues[1];
                        string methodName   = config.AllowableValues[2];

                        string     fqName = typeName + "," + assemblyName;
                        Type       t      = Type.GetType(fqName);
                        object     o      = Activator.CreateInstance(t);
                        MethodInfo method = o.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.Static);
                        object     result = method.Invoke(o, new object[] { });

                        if (result is IEnumerable)
                        {
                            cboValues.DataSource = result;
                            cboValues.DataBind();

                            invocationSuccessful = true;

                            // now try to find which one is matching, case-insensitive
                            foreach (ListItem item in cboValues.Items)
                            {
                                item.Selected = item.Text.EqualsIgnoreCase(config.ConfigValue);
                            }
                        }
                        else
                        {
                            errorMessage         = "Invocation method must return IEnumerable";
                            invocationSuccessful = false;
                        }
                    }
                    else
                    {
                        errorMessage         = "Invalid invocation value";
                        invocationSuccessful = false;
                    }
                }
                catch (Exception ex)
                {
                    errorMessage         = ex.Message;
                    invocationSuccessful = false;
                }

                if (invocationSuccessful == false)
                {
                    cboValues.Items.Add(errorMessage);
                }

                m_configvalue = cboValues.SelectedValue;

                plhConfigValueEditor.Controls.Add(cboValues);
            }
            else if (config.ValueType.EqualsIgnoreCase("multiselect"))
            {
                CheckBoxList chkValues = new CheckBoxList();
                chkValues.ID = editorId;

                Func <string, bool> isIncluded = (optionValue) =>
                {
                    return(config.ConfigValue.Split(',').Any(val => val.Trim().EqualsIgnoreCase(optionValue)));
                };

                foreach (string optionValue in config.AllowableValues)
                {
                    ListItem option = new ListItem(optionValue, optionValue);
                    option.Selected = isIncluded(optionValue);
                    chkValues.Items.Add(option);
                }

                List <string> selectedValues = new List <string>();
                foreach (ListItem option in chkValues.Items)
                {
                    if (option.Selected)
                    {
                        selectedValues.Add(option.Value);
                    }
                }

                // format the selected values into a comma delimited string
                m_configvalue = selectedValues.ToCommaDelimitedString();

                plhConfigValueEditor.Controls.Add(chkValues);
            }
            else
            {
                // determine length for proper control to use
                string configValue = config.ConfigValue;

                TextBox txt = new TextBox();
                txt.ID   = editorId;
                txt.Text = configValue;

                if (configValue.Length >= MAX_COLUMN_LENGTH)
                {
                    // use textArea
                    txt.TextMode = TextBoxMode.MultiLine;
                    txt.Rows     = 4; // make it 4 rows by default
                }

                txt.Columns = DetermineProperTextColumnLength(configValue);

                m_configvalue = txt.Text;

                plhConfigValueEditor.Controls.Add(txt);
            }

            return(plhConfigValueEditor);
        }
        public Tuple <TableRow, Button, TextBox, TextBox> AddTitle(string Id)
        {
            TextBox tb1  = new TextBox();
            TextBox tb2  = new TextBox();
            Label   lbl1 = new Label();
            Label   lbl2 = new Label();
            Label   lbl3 = new Label();
            Label   lbl4 = new Label();
            Button  btn  = new Button();
            Button  btn2 = new Button();

            TableRow                tbr  = new TableRow();
            TableCell               tbc1 = new TableCell();
            TableCell               tbc2 = new TableCell();
            TableCell               tbc3 = new TableCell();
            TableCell               tbc4 = new TableCell();
            TableCell               tbc5 = new TableCell();
            AutoCompleteExtender    autoCompleteExtender = new AjaxControlToolkit.AutoCompleteExtender();
            FilteredTextBoxExtender fteExpectedResouces  = new FilteredTextBoxExtender();

            //RequiredFieldValidator rfvInputTitle = new RequiredFieldValidator();
            //RequiredFieldValidator rfvInputExpected = new RequiredFieldValidator();

            tb1.ID           = "txt_Title" + Id;
            tb1.AutoPostBack = true;
            tb2.ID           = "txt_ExpectedResouces" + Id;
            tb2.AutoPostBack = true;
            lbl1.ID          = "lbl_TrainResources" + Id;
            lbl1.Text        = "0";
            lbl2.ID          = "lbl_ActualResources" + Id;
            lbl2.Font.Bold   = true;
            lbl2.Text        = "0";
            lbl3.ID          = "lbl_TitleExist" + Id;
            lbl3.Text        = "It does not exist";
            lbl3.Visible     = false;
            lbl4.Text        = " ";
            btn.ID           = "btn_RemoveTitle" + Id;
            btn2.ID          = "btn_AutoAllocation" + Id;
            tbr.ID           = "tbr_ContentTitle" + Id;
            btn.Text         = " - ";
            btn2.Text        = "A";

            autoCompleteExtender.ID = "at_TitleExtender" + Id;
            autoCompleteExtender.TargetControlID     = tb1.ID;
            autoCompleteExtender.ServiceMethod       = "GetCompletionList3LD";
            autoCompleteExtender.ServicePath         = "~/AutoComplete.asmx";
            autoCompleteExtender.CompletionInterval  = 200;
            autoCompleteExtender.CompletionSetCount  = 5;
            autoCompleteExtender.MinimumPrefixLength = 1;

            fteExpectedResouces.ID = "fte_ExpectedResouces" + Id;
            fteExpectedResouces.TargetControlID = "txt_ExpectedResouces" + Id;
            fteExpectedResouces.FilterType      = FilterTypes.Numbers | FilterTypes.Custom;
            fteExpectedResouces.ValidChars      = ".";

            //rfvInputTitle.InitialValue = "";
            //rfvInputTitle.ID = "rfvInputTitle" + Id;
            //rfvInputTitle.Display = ValidatorDisplay.Dynamic;
            //rfvInputTitle.ValidationGroup = "RAValidation";
            //rfvInputTitle.ControlToValidate = "txt_Title" + Id;
            //rfvInputTitle.ErrorMessage = "Input a title";
            //rfvInputTitle.CssClass = "label label-danger";

            //rfvInputExpected.InitialValue = "";
            //rfvInputExpected.ID = "rfvInputExpected" + Id;
            //rfvInputExpected.Display = ValidatorDisplay.Dynamic;
            //rfvInputExpected.ValidationGroup = "RAValidation";
            //rfvInputExpected.ControlToValidate = "txt_ExpectedResouces" + Id;
            //rfvInputExpected.ErrorMessage = "Input a number";
            //rfvInputExpected.CssClass = "label label-danger";

            autoCompleteExtender.CompletionListCssClass = "form-control";
            tb1.ControlStyle.CssClass  = "form-control";
            tb2.ControlStyle.CssClass  = "form-control";
            lbl3.ControlStyle.CssClass = "label label-danger";
            btn.ControlStyle.CssClass  = "btn btn-success btn-sm";
            btn2.ControlStyle.CssClass = "btn btn-info btn-sm";

            tbc1.Controls.Add(autoCompleteExtender);
            tbc1.Controls.Add(tb1);
            //tbc1.Controls.Add(rfvInputTitle);
            tbc1.Controls.Add(lbl3);
            tbc2.Controls.Add(tb2);
            //tbc2.Controls.Add(rfvInputExpected);
            tbc2.Controls.Add(fteExpectedResouces);
            tbc3.Controls.Add(lbl2);
            tbc4.Controls.Add(lbl1);
            //tbc5.Controls.Add(btn2);
            tbc5.Controls.Add(lbl4);
            tbc5.Controls.Add(btn);
            tbr.Cells.Add(tbc1);
            tbr.Cells.Add(tbc2);
            tbr.Cells.Add(tbc3);
            tbr.Cells.Add(tbc4);
            tbr.Cells.Add(tbc5);

            return(new Tuple <TableRow, Button, TextBox, TextBox>(tbr, btn, tb1, tb2));
        }