Esempio n. 1
0
        internal static void AddDropDownList(string catalog, HtmlTable htmlTable, string resourceClassName, string itemSelectorPath, string columnName, bool isNullable, string tableSchema, string tableName, string tableColumn, string defaultValue, string displayFields, string displayViews, bool useDisplayViewsAsParent, string selectedValues, string errorCssClass, bool disabled)
        {
            string label = ScrudLocalizationHelper.GetResourceString(resourceClassName, columnName);

            using (DropDownList dropDownList = GetDropDownList(columnName + "_dropdownlist"))
            {
                if (disabled)
                {
                    dropDownList.Attributes.Add("disabled", "disabled");
                }

                using (DataTable table = GetTable(catalog, tableSchema, tableName, tableColumn, displayViews, useDisplayViewsAsParent))
                {
                    SetDisplayFields(catalog, dropDownList, table, tableSchema, tableName, tableColumn, displayFields);

                    using (HtmlAnchor itemSelectorAnchor = GetItemSelector(catalog, dropDownList.ClientID, itemSelectorPath, tableSchema, tableName, tableColumn, displayViews, resourceClassName, label))
                    {
                        if (disabled)
                        {
                            itemSelectorAnchor.Attributes.Add("style", "pointer-events:none;");
                        }

                        SetSelectedValue(catalog, dropDownList, tableSchema, tableName, tableColumn, defaultValue, selectedValues);

                        if (isNullable)
                        {
                            dropDownList.Items.Insert(0, new ListItem(String.Empty, String.Empty));
                            ScrudFactoryHelper.AddDropDownList(htmlTable, label, dropDownList, itemSelectorAnchor, null);
                        }
                        else
                        {
                            RequiredFieldValidator required = ScrudFactoryHelper.GetRequiredFieldValidator(dropDownList, errorCssClass);
                            ScrudFactoryHelper.AddDropDownList(htmlTable, label + Titles.RequiredFieldIndicator, dropDownList, itemSelectorAnchor, required);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        internal static void AddDateTextBox(HtmlTable htmlTable, string resourceClassName, string columnName, string defaultValue, bool isNullable, string validatorCssClass, Assembly assembly, bool disabled)
        {
            if (htmlTable == null)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(columnName))
            {
                return;
            }

            string id = columnName + "_textbox";

            using (TextBox textBox = ScrudTextBox.GetTextBox(id, 100))
            {
                Net.Common.jQueryHelper.jQueryUI.AddjQueryUIDatePicker(null, id, null, null);

                string label = ScrudLocalizationHelper.GetResourceString(assembly, resourceClassName, columnName);

                textBox.Text     = GetLocalizedDate(defaultValue);
                textBox.ReadOnly = disabled;

                using (CompareValidator dateValidator = GetDateValidator(textBox, validatorCssClass))
                {
                    if (!isNullable)
                    {
                        using (RequiredFieldValidator required = ScrudFactoryHelper.GetRequiredFieldValidator(textBox, validatorCssClass))
                        {
                            ScrudFactoryHelper.AddRow(htmlTable, label + Titles.RequiredFieldIndicator, textBox, dateValidator, required);
                            return;
                        }
                    }

                    ScrudFactoryHelper.AddRow(htmlTable, label, textBox, dateValidator);
                }
            }
        }
Esempio n. 3
0
        internal static void AddDecimalTextBox(HtmlTable htmlTable, string resourceClassName, string columnName, string defaultValue, bool isNullable, int maxLength, string domain, string errorCssClass, bool disabled)
        {
            using (TextBox textBox = ScrudTextBox.GetTextBox(columnName + "_textbox", maxLength))
            {
                string label = ScrudLocalizationHelper.GetResourceString(resourceClassName, columnName);

                using (CompareValidator validator = GetDecimalValidator(textBox, domain, errorCssClass))
                {
                    textBox.Text     = defaultValue;
                    textBox.ReadOnly = disabled;
                    textBox.CssClass = "decimal";

                    if (!isNullable)
                    {
                        RequiredFieldValidator required = ScrudFactoryHelper.GetRequiredFieldValidator(textBox, errorCssClass);
                        ScrudFactoryHelper.AddRow(htmlTable, label + Titles.RequiredFieldIndicator, textBox, validator, required);
                        return;
                    }

                    ScrudFactoryHelper.AddRow(htmlTable, label, textBox, validator);
                }
            }
        }
Esempio n. 4
0
        public static void AddRadioButtonList(HtmlTable htmlTable, string resourceClassName, string columnName, bool isNullable, string keys, string values, string selectedValue)
        {
            if (htmlTable == null)
            {
                return;
            }

            using (var radioButtonList = GetRadioButtonList(columnName + "_radiobuttonlist", keys, values, selectedValue))
            {
                var label = LocalizationHelper.GetResourceString(resourceClassName, columnName);

                if (!isNullable)
                {
                    using (var required = ScrudFactoryHelper.GetRequiredFieldValidator(radioButtonList))
                    {
                        ScrudFactoryHelper.AddRow(htmlTable, label + ScrudResource.RequiredFieldIndicator, radioButtonList, required);
                        return;
                    }
                }

                ScrudFactoryHelper.AddRow(htmlTable, label, radioButtonList);
            }
        }
Esempio n. 5
0
        private void LoadForm(Panel container, DataTable values)
        {
            using (var htmlTable = new HtmlTable())
            {
                htmlTable.Attributes["class"] = "valignmiddle";

                using (var table = TableHelper.GetTable(this.TableSchema, this.Table, this.Exclude))
                {
                    if (table.Rows.Count > 0)
                    {
                        foreach (DataRow row in table.Rows)
                        {
                            var columnName   = Conversion.TryCastString(row["column_name"]);
                            var defaultValue = Conversion.TryCastString(row["column_default"]); //nextval('%_seq'::regclass)
                            var isSerial     = defaultValue.StartsWith("nextval", StringComparison.OrdinalIgnoreCase);
                            var isNullable   = Conversion.TryCastBoolean(row["is_nullable"]);
                            var dataType     = Conversion.TryCastString(row["data_type"]);
                            var domain       = Conversion.TryCastString(row["domain_name"]);
                            var maxLength    = Conversion.TryCastInteger(row["character_maximum_length"]);

                            var parentTableSchema = Conversion.TryCastString(row["references_schema"]);
                            var parentTable       = Conversion.TryCastString(row["references_table"]);
                            var parentTableColumn = Conversion.TryCastString(row["references_field"]);

                            if (values.Rows.Count.Equals(1))
                            {
                                defaultValue = Conversion.TryCastString(values.Rows[0][columnName]);
                            }

                            ScrudFactoryHelper.AddField(htmlTable, this.GetResourceClassName(), this.GetItemSelectorPath(), columnName, defaultValue, isSerial, isNullable, dataType, domain, maxLength, parentTableSchema, parentTable, parentTableColumn, this.DisplayFields, this.DisplayViews, this.SelectedValues);
                        }
                    }
                }

                container.Controls.Add(htmlTable);
            }
        }
Esempio n. 6
0
        private void LoadForm(Panel container, DataTable values, bool editing = false)
        {
            using (HtmlTable htmlTable = new HtmlTable())
            {
                htmlTable.Attributes.Add("role", "scrud");

                using (DataTable table = TableHelper.GetTable(this.Catalog, this.TableSchema, this.Table, this.Exclude))
                {
                    if (table.Rows.Count > 0)
                    {
                        foreach (DataRow row in table.Rows)
                        {
                            string columnName   = Conversion.TryCastString(row["column_name"]);
                            string defaultValue = Conversion.TryCastString(row["column_default"]);
                            bool   isSerial     = defaultValue.StartsWith("nextval", StringComparison.OrdinalIgnoreCase);
                            bool   isNullable   = Conversion.TryCastBoolean(row["is_nullable"]);
                            string dataType     = Conversion.TryCastString(row["data_type"]);
                            string domain       = Conversion.TryCastString(row["domain_name"]);
                            int    maxLength    = Conversion.TryCastInteger(row["character_maximum_length"]);

                            string parentTableSchema = Conversion.TryCastString(row["references_schema"]);
                            string parentTable       = Conversion.TryCastString(row["references_table"]);
                            string parentTableColumn = Conversion.TryCastString(row["references_field"]);

                            if (values.Rows.Count.Equals(1))
                            {
                                defaultValue = Conversion.TryCastString(values.Rows[0][columnName]);
                            }

                            bool disabled = false;

                            if (editing)
                            {
                                if (!string.IsNullOrWhiteSpace(this.ExcludeEdit))
                                {
                                    if (
                                        this.ExcludeEdit.Split(',')
                                        .Any(
                                            column =>
                                            column.Trim()
                                            .ToUpperInvariant()
                                            .Equals(columnName.ToUpperInvariant())))
                                    {
                                        disabled = true;
                                    }
                                }
                            }


                            ScrudFactoryHelper.AddField(this.Catalog, htmlTable, this.GetResourceClassName(),
                                                        this.GetItemSelectorPath(), columnName, defaultValue, isSerial, isNullable, dataType,
                                                        domain, maxLength, parentTableSchema, parentTable, parentTableColumn, this.DisplayFields,
                                                        this.DisplayViews, this.UseDisplayViewsAsParents, this.SelectedValues,
                                                        this.GetErrorCssClass(), disabled);
                        }
                    }
                }

                container.Controls.Add(htmlTable);
            }
        }
Esempio n. 7
0
        internal static void AddDropDownList(string catalog, HtmlTable container, string resourcePrefix,
                                             string itemSelectorPath, string currentSchema, string currentTable, string columnName, string label, string description,
                                             bool isNullable, string targetSchema, string targetTable,
                                             string targetColumn, string defaultValue, string displayFields, string displayViews,
                                             bool useDisplayViewsAsParent, string selectedValues, string errorCssClass, bool disabled,
                                             bool useLocalColumnInDisplayViews)
        {
            if (string.IsNullOrWhiteSpace(label))
            {
                label = ScrudLocalizationHelper.GetResourceString(resourcePrefix, columnName);
            }

            using (DropDownList dropDownList = GetDropDownList(columnName + "_dropdownlist"))
            {
                if (!string.IsNullOrWhiteSpace(description))
                {
                    dropDownList.CssClass += " activating element";
                    dropDownList.Attributes.Add("data-content", description);
                }

                if (disabled)
                {
                    dropDownList.Attributes.Add("disabled", "disabled");
                }

                using (
                    DataTable table = GetTable(catalog, targetSchema, targetTable, targetColumn,
                                               currentSchema, currentTable, columnName, displayViews, useDisplayViewsAsParent,
                                               useLocalColumnInDisplayViews))
                {
                    SetDisplayFields(catalog, dropDownList, table, targetSchema, targetTable, targetColumn,
                                     currentSchema, currentTable, columnName, displayFields,
                                     useLocalColumnInDisplayViews);

                    using (
                        HtmlAnchor itemSelectorAnchor = GetItemSelector(catalog, dropDownList.ClientID, itemSelectorPath,
                                                                        targetSchema, targetTable, targetColumn, currentSchema,
                                                                        currentTable, columnName, displayViews, resourcePrefix, label,
                                                                        useLocalColumnInDisplayViews))
                    {
                        if (disabled)
                        {
                            itemSelectorAnchor.Attributes.Add("style", "pointer-events:none;");
                        }

                        SetSelectedValue(catalog, dropDownList, targetSchema, targetTable, targetColumn,
                                         currentSchema, currentTable, columnName, defaultValue, selectedValues,
                                         useLocalColumnInDisplayViews);

                        if (isNullable)
                        {
                            dropDownList.Items.Insert(0, new ListItem(String.Empty, String.Empty));
                            ScrudFactoryHelper.AddDropDownList(container, label, dropDownList, itemSelectorAnchor, null);
                        }
                        else
                        {
                            RequiredFieldValidator required = ScrudFactoryHelper.GetRequiredFieldValidator(
                                dropDownList, errorCssClass);
                            ScrudFactoryHelper.AddDropDownList(container, label + Labels.RequiredFieldIndicator,
                                                               dropDownList, itemSelectorAnchor, required);
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        internal static void AddNumberTextBox(HtmlTable htmlTable, string resourceClassName, string columnName, string label, string description,
                                              string defaultValue, bool isSerial, bool isNullable, int maxLength, string domain, string errorCssClass,
                                              bool disabled)
        {
            if (htmlTable == null)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(columnName))
            {
                return;
            }

            using (TextBox textBox = ScrudTextBox.GetTextBox(columnName + "_textbox", maxLength))
            {
                if (!string.IsNullOrWhiteSpace(description))
                {
                    textBox.CssClass += " activating element";
                    textBox.Attributes.Add("data-content", description);
                }

                using (CompareValidator numberValidator = GetNumberValidator(textBox, domain, errorCssClass))
                {
                    if (string.IsNullOrWhiteSpace(label))
                    {
                        label = ScrudLocalizationHelper.GetResourceString(resourceClassName, columnName);
                    }

                    if (!string.IsNullOrWhiteSpace(defaultValue))
                    {
                        if (!defaultValue.StartsWith("nextVal", StringComparison.OrdinalIgnoreCase))
                        {
                            textBox.Text = defaultValue;
                        }
                    }

                    textBox.ReadOnly = disabled;

                    if (isSerial)
                    {
                        textBox.ReadOnly = true;
                    }
                    else
                    {
                        if (!isNullable)
                        {
                            using (
                                RequiredFieldValidator required = ScrudFactoryHelper.GetRequiredFieldValidator(textBox,
                                                                                                               errorCssClass))
                            {
                                ScrudFactoryHelper.AddRow(htmlTable, label + Labels.RequiredFieldIndicator, textBox,
                                                          numberValidator, required);
                                return;
                            }
                        }
                    }

                    ScrudFactoryHelper.AddRow(htmlTable, label, textBox, numberValidator);
                }
            }
        }
Esempio n. 9
0
        internal static void AddTextBox(HtmlTable htmlTable, string resourceClassName, string columnName, string label, string description,
                                        string dataType, string defaultValue, bool isNullable, int maxLength, string errorCssClass, bool disabled)
        {
            if (htmlTable == null)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(columnName))
            {
                return;
            }

            bool isPasswordField = columnName.ToUpperInvariant().Contains("PASSWORD");

            if (isPasswordField && disabled)
            {
                defaultValue = "fake-password";
            }

            using (TextBox textBox = GetTextBox(columnName + "_textbox", maxLength))
            {
                if (string.IsNullOrWhiteSpace(label))
                {
                    label = ScrudLocalizationHelper.GetResourceString(resourceClassName, columnName);
                }


                if (dataType.ToUpperInvariant().Equals("COLOR"))
                {
                    textBox.CssClass = "color";
                }

                if (dataType.ToUpperInvariant().Equals("IMAGE"))
                {
                    textBox.CssClass = "image";
                }

                if (isPasswordField)
                {
                    textBox.Attributes.Add("type", "password");
                }

                if (disabled && !isPasswordField)
                {
                    textBox.ReadOnly = true;
                }

                if (!string.IsNullOrWhiteSpace(description))
                {
                    textBox.CssClass += " activating element";
                    textBox.Attributes.Add("data-content", description);
                }

                textBox.Text = defaultValue;


                if (!isNullable)
                {
                    using (
                        RequiredFieldValidator required = ScrudFactoryHelper.GetRequiredFieldValidator(textBox,
                                                                                                       errorCssClass))
                    {
                        ScrudFactoryHelper.AddRow(htmlTable, label + Labels.RequiredFieldIndicator, textBox, required);
                        return;
                    }
                }

                ScrudFactoryHelper.AddRow(htmlTable, label, textBox);
            }
        }