public static void AddField(HtmlTable t, string columnName, string defaultValue, bool isSerial, bool isNullable, string dataType, string domain, int maxLength, string parentTableSchema, string parentTable, string parentTableColumn, string displayFields, string displayViews, string selectedValues)
        {
            if (string.IsNullOrWhiteSpace(parentTableColumn))
            {
                switch (dataType)
                {
                case "national character varying":
                case "character varying":
                case "national character":
                case "character":
                case "char":
                case "varchar":
                case "nvarchar":
                case "text":
                    ScrudTextBox.AddTextBox(t, columnName, defaultValue, isNullable, maxLength);
                    break;

                case "smallint":
                case "integer":
                case "bigint":
                    ScrudNumberTextBox.AddNumberTextBox(t, columnName, defaultValue, isSerial, isNullable, maxLength, domain);
                    break;

                case "numeric":
                case "money":
                case "double":
                case "double precision":
                case "float":
                case "real":
                case "currency":
                    ScrudDecimalTextBox.AddDecimalTextBox(t, columnName, defaultValue, isNullable, maxLength, domain);
                    break;

                case "boolean":
                    ScrudRadioButtonList.AddRadioButtonList(t, columnName, isNullable, Resources.ScrudResource.YesNo, "true,false", defaultValue);
                    break;

                case "date":
                    ScrudDateTextBox.AddDateTextBox(t, columnName, defaultValue, isNullable, maxLength);
                    break;

                case "bytea":
                    ScrudFileUpload.AddFileUpload(t, columnName, isNullable);
                    break;

                case "timestamp with time zone":
                    //Do not show this field
                    break;
                }
            }
            else
            {
                ScrudDropDownList.AddDropDownList(t, columnName, isNullable, parentTableSchema, parentTable, parentTableColumn, defaultValue, displayFields, displayViews, selectedValues);
            }
        }
        internal static void AddField(HtmlTable htmlTable, string resourceClassName, string itemSelectorPath, string columnName, string defaultValue, bool isSerial, bool isNullable, string dataType, string domain, int maxLength, string parentTableSchema, string parentTable, string parentTableColumn, string displayFields, string displayViews, bool useDisplayFieldAsParent, string selectedValues, string errorCssClass, Assembly assembly, bool disabled)
        {
            if (isSerial)
            {
                disabled = true;
            }

            if (htmlTable == null)
            {
                return;
            }

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

            if (string.IsNullOrWhiteSpace(parentTableColumn))
            {
                if (ScrudTypes.Strings.Contains(dataType))
                {
                    ScrudTextBox.AddTextBox(htmlTable, resourceClassName, columnName, dataType, defaultValue, isNullable, maxLength, errorCssClass, assembly, disabled);
                }

                if (ScrudTypes.Shorts.Contains(dataType) || ScrudTypes.Integers.Contains(dataType) || ScrudTypes.Longs.Contains(dataType))
                {
                    ScrudNumberTextBox.AddNumberTextBox(htmlTable, resourceClassName, columnName, defaultValue, isSerial, isNullable, maxLength, domain, errorCssClass, assembly, disabled);
                }

                if (ScrudTypes.Decimals.Contains(dataType))
                {
                    ScrudDecimalTextBox.AddDecimalTextBox(htmlTable, resourceClassName, columnName, defaultValue, isNullable, maxLength, domain, errorCssClass, assembly, disabled);
                }

                if (ScrudTypes.Bools.Contains(dataType))
                {
                    ScrudRadioButtonList.AddRadioButtonList(htmlTable, resourceClassName, columnName, isNullable, Titles.YesNo, "true,false", defaultValue, errorCssClass, assembly, disabled);
                }

                if (ScrudTypes.Dates.Contains(dataType))
                {
                    ScrudDateTextBox.AddDateTextBox(htmlTable, resourceClassName, columnName, defaultValue, isNullable, errorCssClass, assembly, disabled);
                }

                if (ScrudTypes.Files.Contains(dataType))
                {
                    ScrudFileUpload.AddFileUpload(htmlTable, resourceClassName, columnName, isNullable, errorCssClass, assembly);
                }
            }
            else
            {
                ScrudDropDownList.AddDropDownList(htmlTable, resourceClassName, itemSelectorPath, columnName, isNullable, parentTableSchema, parentTable, parentTableColumn, defaultValue, displayFields, displayViews, useDisplayFieldAsParent, selectedValues, errorCssClass, assembly, disabled);
            }
        }
示例#3
0
        /// <summary>
        /// This function iterates through all the dynamically added controls,
        /// checks their values, and returns a list of column and values
        /// mapped as KeyValuePair of column_name (key) and value.
        /// </summary>
        /// <param name="skipSerial">
        /// Skip the PostgreSQL serial column.
        /// There is no need to explicitly set the value for the serial column.
        /// This value should be <strong>true</strong> if you are obtaining the form to insert the record.
        /// Set this paramter to <b>false</b> if you want to update the form, based on the serial's columns value.
        /// </param>
        /// <returns>Returns a list of column and values mapped as
        /// KeyValuePair of column_name (key) and value.</returns>
        private Collection <KeyValuePair <string, string> > GetFormCollection(bool skipSerial)
        {
            var list = new Collection <KeyValuePair <string, string> >();

            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"]);
                        var isSerial          = defaultValue.StartsWith("nextval", StringComparison.OrdinalIgnoreCase);
                        var parentTableColumn = Conversion.TryCastString(row["references_field"]);
                        var dataType          = Conversion.TryCastString(row["data_type"]);

                        if (skipSerial)
                        {
                            if (isSerial)
                            {
                                continue;
                            }
                        }

                        if (string.IsNullOrWhiteSpace(parentTableColumn))
                        {
                            switch (dataType)
                            {
                            case "national character varying":
                            case "character varying":
                            case "national character":
                            case "character":
                            case "char":
                            case "varchar":
                            case "nvarchar":
                            case "text":
                            case "date":
                            case "smallint":
                            case "integer":
                            case "bigint":
                            case "numeric":
                            case "money":
                            case "double":
                            case "double precision":
                            case "float":
                            case "real":
                            case "currency":
                                //TextBox
                                var t = (TextBox)this.formContainer.FindControl(columnName + "_textbox");
                                if (t != null)
                                {
                                    list.Add(new KeyValuePair <string, string>(columnName, t.Text));
                                }
                                break;

                            case "boolean":
                                var r = (RadioButtonList)this.formContainer.FindControl(columnName + "_radiobuttonlist");
                                list.Add(new KeyValuePair <string, string>(columnName, r.Text));
                                break;

                            case "bytea":
                                var f    = (FileUpload)this.formContainer.FindControl(columnName + "_fileupload");
                                var file = ScrudFileUpload.UploadFile(f);
                                list.Add(new KeyValuePair <string, string>(columnName, file));
                                this.imageColumn = columnName;
                                break;
                            }
                        }
                        else
                        {
                            //DropDownList
                            var d = (DropDownList)this.formContainer.FindControl(columnName + "_dropdownlist");
                            list.Add(new KeyValuePair <string, string>(columnName, d.Text));
                        }
                    }
                }
            }

            return(list);
        }
示例#4
0
        public static void AddField(HtmlTable htmlTable, string resourceClassName, string itemSelectorPath, string columnName, string defaultValue, bool isSerial, bool isNullable, string dataType, string domain, int maxLength, string parentTableSchema, string parentTable, string parentTableColumn, string displayFields, string displayViews, bool useDisplayFieldAsParent, string selectedValues)
        {
            if (htmlTable == null)
            {
                return;
            }

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

            if (string.IsNullOrWhiteSpace(parentTableColumn))
            {
                switch (dataType)
                {
                case "national character varying":
                case "character varying":
                case "national character":
                case "character":
                case "char":
                case "varchar":
                case "nvarchar":
                case "text":
                    ScrudTextBox.AddTextBox(htmlTable, resourceClassName, columnName, defaultValue, isNullable, maxLength);
                    break;

                case "smallint":
                case "integer":
                case "bigint":
                    ScrudNumberTextBox.AddNumberTextBox(htmlTable, resourceClassName, columnName, defaultValue, isSerial, isNullable, maxLength, domain);
                    break;

                case "numeric":
                case "money":
                case "double":
                case "double precision":
                case "float":
                case "real":
                case "currency":
                    ScrudDecimalTextBox.AddDecimalTextBox(htmlTable, resourceClassName, columnName, defaultValue, isNullable, maxLength, domain);
                    break;

                case "boolean":
                    ScrudRadioButtonList.AddRadioButtonList(htmlTable, resourceClassName, columnName, isNullable, ScrudResource.YesNo, "true,false", defaultValue);
                    break;

                case "date":
                    ScrudDateTextBox.AddDateTextBox(htmlTable, resourceClassName, columnName, defaultValue, isNullable);
                    break;

                case "bytea":
                    ScrudFileUpload.AddFileUpload(htmlTable, resourceClassName, columnName, isNullable);
                    break;

                case "timestamp with time zone":
                    //Do not show this field
                    break;
                }
            }
            else
            {
                //Todo: Add an implementation of overriding the behavior of the parent table data being populated into the list.
                ScrudDropDownList.AddDropDownList(htmlTable, resourceClassName, itemSelectorPath, columnName, isNullable, parentTableSchema, parentTable, parentTableColumn, defaultValue, displayFields, displayViews, useDisplayFieldAsParent, selectedValues);
            }
        }
示例#5
0
        /// <summary>
        ///     This function iterates through all the dynamically added controls,
        ///     checks their values, and returns a list of column and values
        ///     mapped as KeyValuePair of column_name (key) and value.
        /// </summary>
        /// <param name="skipSerial">
        ///     Skip the PostgreSQL serial column.
        ///     There is no need to explicitly set the value for the serial column.
        ///     This value should be <strong>true</strong> if you are obtaining the form to insert the record.
        ///     Set this parameter to <b>false</b> if you want to update the form, based on the serial's columns value.
        /// </param>
        /// <returns>
        ///     Returns a list of column and values mapped as
        ///     KeyValuePair of column_name (key) and value.
        /// </returns>
        private Collection <KeyValuePair <string, object> > GetFormCollection(bool skipSerial)
        {
            Collection <KeyValuePair <string, object> > list = new Collection <KeyValuePair <string, object> >();

            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);
                        string parentTableColumn = Conversion.TryCastString(row["references_field"]);
                        string dataType          = Conversion.TryCastString(row["data_type"]);

                        if (skipSerial)
                        {
                            if (isSerial)
                            {
                                continue;
                            }
                        }

                        if (string.IsNullOrWhiteSpace(parentTableColumn))
                        {
                            if (ScrudTypes.TextBoxTypes.Contains(dataType))
                            {
                                using (
                                    TextBox textBox = this.formContainer.FindControl(columnName + "_textbox") as TextBox
                                    )
                                {
                                    if (textBox != null)
                                    {
                                        list.Add(new KeyValuePair <string, object>(columnName,
                                                                                   ScrudParser.ParseValue(textBox.Text, dataType)));
                                    }
                                }
                            }

                            if (ScrudTypes.Bools.Contains(dataType))
                            {
                                using (
                                    RadioButtonList radioButtonList =
                                        this.formContainer.FindControl(columnName + "_radiobuttonlist") as
                                        RadioButtonList)
                                {
                                    if (radioButtonList != null)
                                    {
                                        list.Add(new KeyValuePair <string, object>(columnName,
                                                                                   ScrudParser.ParseValue(radioButtonList.Text, dataType)));
                                    }
                                }
                            }

                            if (dataType.Equals("bytea"))
                            {
                                using (
                                    FileUpload fileUpload =
                                        this.formContainer.FindControl(columnName + "_fileupload") as FileUpload)
                                {
                                    if (fileUpload != null)
                                    {
                                        var file = ScrudFileUpload.UploadFile(this.Catalog, fileUpload);
                                        list.Add(new KeyValuePair <string, object>(columnName, file));
                                        this.imageColumn = columnName;
                                    }
                                }
                            }
                        }
                        else
                        {
                            //DropDownList
                            using (
                                DropDownList dropDownList =
                                    this.formContainer.FindControl(columnName + "_dropdownlist") as DropDownList)
                            {
                                object value = null;

                                if (dropDownList != null && !string.IsNullOrWhiteSpace(dropDownList.Text))
                                {
                                    value = dropDownList.SelectedValue;
                                }

                                list.Add(new KeyValuePair <string, object>(columnName, value));
                            }
                        }
                    }
                }
            }

            return(list);
        }