Пример #1
0
        /// <summary>
        /// 复选框
        /// </summary>
        /// <param name="field"></param>
        /// <param name="control"></param>
        /// <param name="canSave"></param>
        protected virtual void SetFormItemCheckBox(FieldItem field, CheckBox control, Boolean canSave)
        {
            Type type = field.Type;

            ExtAspNet.CheckBox controlChk = control as ExtAspNet.CheckBox;
            if (type == typeof(Boolean))
            {
                controlChk.Checked = (Boolean)Entity[field.Name];
            }
            else if (type == typeof(Int32))
            {
                controlChk.Checked = (Int32)Entity[field.Name] != 0;
            }
            else
            {
                controlChk.Checked = Entity[field.Name] != null;
            }
        }
Пример #2
0
        /// <summary>
        /// 初始化窗体
        /// </summary>
        private void InitForm()
        {
            String PKName = null;

            // 处理扩展字段
            if (Entity <TEntity> .Meta.Table.Relations != null && Entity <TEntity> .Meta.Table.Relations.Length > 0)
            {
                InitExtFields(Entity <TEntity> .Meta.Table.Relations, RelationsDropDownList, RelationsTriggerBox);
            }

            #region 处理所字段
            FieldItemEx[] fieldEx = new FieldItemEx[Entity <TEntity> .Meta.Fields.Length];
            for (int i = 0; i < Entity <TEntity> .Meta.Fields.Length; i++)
            {
                fieldEx[i] = Entity <TEntity> .Meta.Fields[i];
            }

            foreach (FieldItemEx fieldItemEx in InitFields(fieldEx))
            {
                FieldItem Field = fieldItemEx.Field;
                String    pname = Field.Name;
                if (Field.PrimaryKey)
                {
                    PKName = pname; continue;
                }

                String   frmName = "frm" + pname;
                TypeCode code    = Type.GetTypeCode(Field.Type);

                #region 初始化界面控件
                switch (code)
                {
                case TypeCode.Boolean:
                    ExtAspNet.CheckBox CheckBoxTextBox = new ExtAspNet.CheckBox();
                    CheckBoxTextBox.ID          = frmName;
                    CheckBoxTextBox.Label       = Field.Description;
                    CheckBoxTextBox.ShowRedStar = !Field.IsNullable;
                    CheckBoxTextBox.Enabled     = fieldItemEx.Editabled;
                    (ExtSimpleForm as ExtAspNet.SimpleForm).Items.Add(CheckBoxTextBox);
                    break;

                case TypeCode.Byte:
                    break;

                case TypeCode.Char:
                    break;

                case TypeCode.DBNull:
                    break;

                case TypeCode.DateTime:
                    ExtAspNet.DatePicker DateTimeTextBox = new ExtAspNet.DatePicker();
                    DateTimeTextBox.ID          = frmName;
                    DateTimeTextBox.Label       = Field.Description;
                    DateTimeTextBox.Required    = !Field.IsNullable;
                    DateTimeTextBox.ShowRedStar = !Field.IsNullable;
                    DateTimeTextBox.Enabled     = fieldItemEx.Editabled;
                    (ExtSimpleForm as ExtAspNet.SimpleForm).Items.Add(DateTimeTextBox);
                    break;

                case TypeCode.Decimal:
                    ExtAspNet.NumberBox DecimaltBox = new ExtAspNet.NumberBox();
                    DecimaltBox.ID          = frmName;
                    DecimaltBox.Label       = Field.Description;
                    DecimaltBox.NoDecimal   = false;
                    DecimaltBox.Required    = !Field.IsNullable;
                    DecimaltBox.ShowRedStar = !Field.IsNullable;
                    DecimaltBox.Enabled     = fieldItemEx.Editabled;
                    (ExtSimpleForm as ExtAspNet.SimpleForm).Items.Add(DecimaltBox);
                    break;

                case TypeCode.Double:
                    ExtAspNet.NumberBox DoubleTextBox = new ExtAspNet.NumberBox();
                    DoubleTextBox.ID          = frmName;
                    DoubleTextBox.Label       = Field.Description;
                    DoubleTextBox.NoDecimal   = false;
                    DoubleTextBox.Required    = !Field.IsNullable;
                    DoubleTextBox.ShowRedStar = !Field.IsNullable;
                    DoubleTextBox.Enabled     = fieldItemEx.Editabled;
                    (ExtSimpleForm as ExtAspNet.SimpleForm).Items.Add(DoubleTextBox);
                    break;

                case TypeCode.Empty:
                    break;

                case TypeCode.Int16:
                    break;

                case TypeCode.Int32:
                    if (RelationsDropDownList.ContainsKey(Field.Name))
                    {
                        RelationsDropDownList[Field.Name].Label = Field.Description;
                        RelationsDropDownList[Field.Name].DataBind();
                        RelationsDropDownList[Field.Name].Enabled = fieldItemEx.Editabled;
                        (ExtSimpleForm as ExtAspNet.SimpleForm).Items.Add(RelationsDropDownList[Field.Name]);
                    }
                    else
                    {
                        ExtAspNet.NumberBox Int32TextBox = new ExtAspNet.NumberBox();
                        Int32TextBox.ID          = frmName;
                        Int32TextBox.Label       = Field.Description;
                        Int32TextBox.Required    = true;
                        Int32TextBox.ShowRedStar = true;
                        Int32TextBox.Required    = !Field.IsNullable;
                        Int32TextBox.ShowRedStar = !Field.IsNullable;
                        Int32TextBox.Enabled     = fieldItemEx.Editabled;
                        (ExtSimpleForm as ExtAspNet.SimpleForm).Items.Add(Int32TextBox);
                    }
                    break;

                case TypeCode.Int64:
                    break;

                case TypeCode.Object:
                    break;

                case TypeCode.SByte:
                    break;

                case TypeCode.Single:
                    break;

                case TypeCode.String:
                    #region String
                    if (pname.Equals("Password", StringComparison.OrdinalIgnoreCase) || pname.Equals("Pass", StringComparison.OrdinalIgnoreCase))
                    {
                        ExtAspNet.TextBox TextBoxP = new ExtAspNet.TextBox();
                        TextBoxP.ID          = frmName;
                        TextBoxP.Label       = Field.Description;
                        TextBoxP.TextMode    = TextMode.Password;
                        TextBoxP.Required    = !Field.IsNullable;
                        TextBoxP.ShowRedStar = TextBoxP.Required;
                        TextBoxP.Enabled     = fieldItemEx.Editabled;
                        (ExtSimpleForm as ExtAspNet.SimpleForm).Items.Add(TextBoxP);
                    }
                    else if (Field.Length > 300 || Field.Length < 0)
                    {
                        ExtAspNet.TextArea TextBoxP = new ExtAspNet.TextArea();
                        TextBoxP.ID          = frmName;
                        TextBoxP.Label       = Field.Description;
                        TextBoxP.Required    = !Field.IsNullable;
                        TextBoxP.ShowRedStar = TextBoxP.Required;
                        TextBoxP.Enabled     = fieldItemEx.Editabled;
                        (ExtSimpleForm as ExtAspNet.SimpleForm).Items.Add(TextBoxP);
                    }
                    else
                    {
                        ExtAspNet.TextBox TextBoxP = new ExtAspNet.TextBox();
                        TextBoxP.ID          = frmName;
                        TextBoxP.Label       = Field.Description;
                        TextBoxP.TextMode    = TextMode.Text;
                        TextBoxP.Required    = !Field.IsNullable;
                        TextBoxP.ShowRedStar = TextBoxP.Required;
                        TextBoxP.Enabled     = fieldItemEx.Editabled;
                        (ExtSimpleForm as ExtAspNet.SimpleForm).Items.Add(TextBoxP);
                    }
                    #endregion
                    break;

                case TypeCode.UInt16:
                    break;

                case TypeCode.UInt32:
                    break;

                case TypeCode.UInt64:
                    break;

                default:
                    break;
                }
                #endregion
            }
            #endregion
        }