Exemplo n.º 1
0
        private void AddToList(ref Collection <KeyValuePair <string, object> > list, string columnName,
                               string parentTableColumn, string dataType)
        {
            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)));
                        }
                    }
                }
            }
            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));
                }
            }
        }
Exemplo n.º 2
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);
        }