Пример #1
0
        private static void BuildField(MetadataColumn col, string TableName, string Alias, FormSection section, MetadataColumn IncludeFrom, bool ForceReadOnly = false)
        {
            if (col.IsRowGuid)
            {
                return;
            }
            FormField field = null;

            if (col.IsForeignKey)
            {
                field = new LookupFormField()
                {
                    LookupSource = LookupSources.SqlBuilder,
                    Builder      = col.ToSqlBuilder()
                };
            }
            else
            {
                field = new FormField();
            }


            field.DisplayName = (IncludeFrom != null ? IncludeFrom.DisplayName + " " : "") + col.DisplayName;
            field.ID          = col.Name;
            field.Name        = col.Name;
            field.Alias       = Alias;
            field.TableName   = TableName;
            field.NullText    = "Enter " + col.Name;
            field.IsReadOnly  = ForceReadOnly || col.IsReadOnly || col.IsPrimaryKey;
            field.IsRequired  = !col.Nullable;
            ResolveFieldType(col, field);
            section.Fields.Add(field);
        }
Пример #2
0
        private static void BuildField(MetadataColumn col, string TableName, string Alias, FormSection section, MetadataColumn IncludeFrom, bool ForceReadOnly = false)
        {
            if (col.IsRowGuid)
            {
                return;
            }
            FormField field = null;

            if (col.IsForeignKey)
            {
                field = new LookupFormField()
                {
                    LookupSource = LookupSources.SqlBuilder,
                    Builder = col.ToSqlBuilder()
                };
            }
            else
            {
                field = new FormField();
            }


            field.DisplayName = (IncludeFrom != null ? IncludeFrom.DisplayName + " " : "") + col.DisplayName;
            field.ID = col.Name;
            field.Name = col.Name;
            field.Alias = Alias;
            field.TableName = TableName;
            field.NullText = "Enter " + col.Name;
            field.IsReadOnly = ForceReadOnly || col.IsReadOnly || col.IsPrimaryKey;
            field.IsRequired = !col.Nullable;
            ResolveFieldType(col, field);
            section.Fields.Add(field);
        }
        public static MvcHtmlString TinySqlInput(this HtmlHelper helper, FieldModel model)
        {
            string ctrl     = "";
            string ReadOnly = model.Field.IsReadOnly ? "readonly" : "";

            if (model.Field.IsHidden)
            {
                ctrl = string.Format("<input type=\"hidden\" name=\"{0}\" value=\"{1}\" >",
                                     model.Field.ControlName,                               // 0
                                     model.Data == null ? "" : Convert.ToString(model.Data) // 1
                                     );
            }
            else if (model.Field.FieldType == FieldTypes.TextArea)
            {
                ctrl = string.Format("<textarea id=\"{0}\" name=\"{1}\" class=\"{2}\" placeholder=\"{3}\" rows=\"{4}\" {7} {5}>{6}</textarea>",
                                     model.Field.ID,
                                     model.Field.ControlName,
                                     model.Field.CssInputControlLayout,
                                     model.Field.NullText,
                                     model.Field.MultiLineInputRows,
                                     model.Field.IsReadOnly ? "disabled": "",
                                     model.Data != null ? Convert.ToString(model.Data) : "",
                                     model.Field.IsRequired && !model.Field.IsReadOnly ? "required" : ""
                                     );
            }
            else if (model.Field.FieldType == FieldTypes.Checkbox)
            {
                bool b;
                if (bool.TryParse(model.Data.ToString(), out b))
                {
                    ctrl = string.Format("<label><input type=\"checkbox\" value=\"true\" name=\"{1}\" id=\"input{0}\" {2} > {3}</label>",
                                         model.Field.ID,
                                         model.Field.ControlName,
                                         // model.Data == null ? "" : Convert.ToString(model.Data),
                                         b ? "checked" : "",
                                         model.Field.DisplayName,
                                         model.Field.CssCheckBoxLayout,
                                         model.Field.IsReadOnly ? "disabled" : ""
                                         );
                }
                else
                {
                    throw new ArgumentException("Non boolean value specified for the form field " + model.Field.Name, "model");
                }
            }
            else if (model.Field.FieldType == FieldTypes.Input)
            {
                ctrl = string.Format("<input type=\"{4}\" class=\"{2}\" name=\"{1}\" id=\"input{0}\" placeholder=\"Enter {7}\" value=\"{5}\" {6} >",
                                     model.Field.ID,                                         // 0
                                                                                             //model.Field.TableName + "_" + model.Field.Name,                                       // 1
                                     model.Field.Alias ?? model.Field.Name,                  // 1
                                     model.Field.CssInputControlLayout,                      // 2
                                     model.Field.NullText,                                   // 3
                                     model.Field.InputType.ToString().Replace("_", "-"),     // 4
                                     model.Data == null ? "" : Convert.ToString(model.Data), // 5
                                     ReadOnly,                                               // 6
                                     model.Field.DisplayName
                                     );
            }
            else if (model.Field.FieldType == FieldTypes.LookupInput || model.Field.FieldType == FieldTypes.SelectList)
            {
                LookupFormField lookup  = (model.Field as LookupFormField);
                ResultTable     results = null;
                if (lookup.FieldType == FieldTypes.SelectList)
                {
                    string ctrlItems = "";
                    string v         = model.Data != null?Convert.ToString(model.Data) : "";

                    if (lookup.LookupSource == LookupSources.NameValueCollection)
                    {
                        foreach (string name in lookup.Collection.AllKeys)
                        {
                            string value = lookup.Collection[name];
                            ctrlItems += string.Format("<option value=\"{0}\" {1}>{2}</option>",
                                                       value,
                                                       v.Equals(value) ? "selected" : "",
                                                       name);
                        }
                    }
                    else if (lookup.LookupSource == LookupSources.SqlBuilder)
                    {
                        results = lookup.Builder.Execute();
                        foreach (RowData row in results)
                        {
                            string name  = Convert.ToString(row.Column(row.Columns[0]));
                            string value = Convert.ToString(row.Column(row.Columns[1]));
                            ctrlItems += string.Format("<option value=\"{0}\" {1}>{2}</option>",
                                                       value,
                                                       v.Equals(value) ? "selected" : "",
                                                       name);
                        }
                    }
                    ctrl = string.Format("<select id=\"{0}\" name=\"{1}\" class=\"{2}\" {3} >{4}</select>",
                                         lookup.ID,                    // 0
                                         lookup.Alias ?? lookup.Name,  // 1
                                                                       //lookup.TableName + "_" + lookup.Name,                    // 1
                                         lookup.CssInputControlLayout, // 2
                                         ReadOnly,                     // 3
                                         ctrlItems                     // 4
                                         );
                }
                else if (lookup.FieldType == FieldTypes.LookupInput)
                {
                    throw new NotImplementedException();
                }
            }


            return(MvcHtmlString.Create(ctrl));
        }