예제 #1
0
파일: Forms.cs 프로젝트: pmarflee/TinySql
 internal FieldModel(FormField field, MetadataColumn model, object data, SectionLayouts sectionLayout)
 {
     this.Field = field;
     this.Model = model;
     this.Data = data;
     this.SectionLayout = sectionLayout;
 }
예제 #2
0
        private static void ResolveFieldType(MetadataColumn col, FormField field)
        {
            switch (col.SqlDataType)
            {
                case System.Data.SqlDbType.Text:
                case System.Data.SqlDbType.NText:
                case System.Data.SqlDbType.VarChar:
                case System.Data.SqlDbType.NVarChar:
                case System.Data.SqlDbType.Char:
                case System.Data.SqlDbType.NChar:
                    field.FieldType = FieldTypes.Input;
                    field.InputType = InputTypes.text;
                    if (col.Length <= 0)
                    {
                        field.FieldType = FieldTypes.TextArea;
                    }
                    field.MaxLength = col.Length;
                    break;

                case System.Data.SqlDbType.Date:
                    field.FieldType = FieldTypes.Input;
                    field.InputType = InputTypes.date;
                    break;

                case System.Data.SqlDbType.SmallDateTime:
                case System.Data.SqlDbType.DateTime:
                case System.Data.SqlDbType.DateTime2:
                    field.FieldType = FieldTypes.Input;
                    field.InputType = InputTypes.datetime_local;
                    break;

                case System.Data.SqlDbType.DateTimeOffset:
                    field.FieldType = FieldTypes.Input;
                    field.InputType = InputTypes.datetime;
                    break;

                case System.Data.SqlDbType.Time:
                    field.FieldType = FieldTypes.Input;
                    field.InputType = InputTypes.time;
                    break;

                case System.Data.SqlDbType.Bit:
                    field.FieldType = FieldTypes.Checkbox;
                    break;

                case System.Data.SqlDbType.Decimal:
                case System.Data.SqlDbType.Float:
                case System.Data.SqlDbType.Int:
                case System.Data.SqlDbType.Money:
                case System.Data.SqlDbType.BigInt:
                case System.Data.SqlDbType.Real:
                case System.Data.SqlDbType.SmallInt:
                case System.Data.SqlDbType.SmallMoney:
                case System.Data.SqlDbType.TinyInt:
                    field.FieldType = FieldTypes.Input;
                    field.InputType = InputTypes.number;
                    break;

                case System.Data.SqlDbType.VarBinary:
                case System.Data.SqlDbType.Timestamp:
                case System.Data.SqlDbType.Structured:
                case System.Data.SqlDbType.Binary:
                case System.Data.SqlDbType.Variant:
                case System.Data.SqlDbType.Xml:
                case System.Data.SqlDbType.Image:
                case System.Data.SqlDbType.Udt:
                case System.Data.SqlDbType.UniqueIdentifier:
                default:
                    field.FieldType = FieldTypes.Input;
                    field.IsHidden = true;
                    return;
            }

            // Special cases
            if (col.IsForeignKey)
            {
                field.FieldType = FieldTypes.SelectList;
            }

        }
예제 #3
0
파일: Forms.cs 프로젝트: pmarflee/TinySql
        public FieldModel GetFieldModel(FormField Field, MetadataTable Model, RowData Data)
        {
            MetadataColumn mc = null;
            MetadataTable mt = Model;
            if (Field.ID.StartsWith("__"))
            {
                return new FieldModel(Field, null, Data.Column(Field.Name), SectionLayout);
            }
            if (Field.TableName != Model.Fullname)
            {
                mt = SqlBuilder.DefaultMetadata.FindTable(Field.TableName);
            }
            if (!mt.Columns.TryGetValue(Field.Name, out mc))
            {
                throw new InvalidOperationException("Cannot get a model for " + Field.Name);
            }

            return new FieldModel(Field, mc, Data.Column(Field.Alias ?? Field.Name), SectionLayout);

        }
예제 #4
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);
        }