Ejemplo n.º 1
0
 /// <summary>
 /// 封装的选项类
 /// </summary>
 /// <param name="controlInstance">控件实例</param>
 /// <param name="fieldInfoInstance">选项数据类实例</param>
 public FieldControl(Control controlInstance, FieldInfo fieldInfoInstance)
 {
     this.controlInstance = controlInstance;
     this.fieldInfoInstance = fieldInfoInstance;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载选项信息
        /// </summary>
        private void LoadFieldInfo()
        {
            fieldPanel.Controls.Clear();

            Label currentLabel = stepLabelList[stepIndex];
            string tabID = currentLabel.Tag as string;
            string sqlString = string.Format("SELECT * FROM {0} WHERE TabID = {1} ORDER BY OrderIndex",
                                             fieldTableName, tabID);
            DataTable fieldTable = Helper.GetDataTable(sqlString, conn);

            bool inited = false;
            List<FieldInfo> fieldInfoList = guideData[stepIndex];

            if (fieldInfoList.Count > 0)
            {
                inited = true;
            }

            for (int i = 0; i < fieldTable.Rows.Count; i++)
            {
                DataRow dataRow = fieldTable.Rows[i];
                string fieldID = dataRow["ID"].ToString();
                string fieldName = dataRow["Name"].ToString();
                string fieldType = dataRow["Type"].ToString();
                string typeData = dataRow["TypeData"].ToString();
                string defaultValue = dataRow["DefaultValue"].ToString();
                bool allowNullValue = true;

                if (!Helper.IsNullOrDBNull(dataRow["AllowNullValue"]))
                {
                    allowNullValue = (bool)dataRow["AllowNullValue"];
                }

                Label fieldLabel = new Label();
                fieldLabel.Name = string.Format("{0}Label", fieldName);
                fieldLabel.Text = fieldName;
                fieldLabel.TextAlign = ContentAlignment.MiddleLeft;
                fieldLabel.Size = labelSize;
                fieldPanel.Controls.Add(fieldLabel, labelIndex, i);                   
                Control newItem = null;

                switch (fieldType)
                {
                    case "text":
                        {
                            TextBox textBox = new TextBox();
                            newItem = textBox;                            

                            break;
                        }
                    case "number":
                        {
                            TextBox textBox = new TextBox();
                            newItem = textBox;                           

                            break;
                        }
                    case "boolean":
                        {
                            ComboBox comboBox = new ComboBox();
                            comboBox.Items.Add("是");
                            comboBox.Items.Add("否");
                            comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                            newItem = comboBox;

                            break;
                        }
                    case "list":
                        {
                            ComboBox comboBox = new ComboBox();
                            comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                            newItem = comboBox;

                            InitComboBox(comboBox, typeData);                         

                            break;
                        }
                    case "file":
                        {
                            TextBox textBox = new TextBox();
                            newItem = textBox;

                            ButtonX button = new ButtonX();
                            button.Name = string.Format("{0}Button", fieldName);
                            button.Text = "浏览";
                            button.Size = buttonSize;
                            button.Tag = textBox;
                            button.Click += BrowseFile;
                            fieldPanel.Controls.Add(button, 2, i);

                            break;
                        }
                    case "custom":
                        {
                            TextBox textBox = new TextBox();
                            newItem = textBox;

                            ButtonX button = new ButtonX();                             
                            button.Name = string.Format("{0}Button", fieldName);
                            button.Text = "编辑";
                            button.Size = buttonSize;
                            button.Tag = textBox;
                            button.Click += CustomEdit;
                            fieldPanel.Controls.Add(button, 2, i);

                            break;
                        }
                }

                if (inited)
                {
                    FieldInfo fieldInfo = fieldInfoList[i];
                    newItem.Text = fieldInfo.FieldValue;                    
                }
                else
                {
                    FieldInfo fieldInfo = new FieldInfo(fieldID, fieldName, fieldType, typeData, defaultValue, allowNullValue);
                    fieldInfoList.Add(fieldInfo);

                    fieldInfoDictionary[fieldID] = fieldInfo;

                    LoadDefaultValue(newItem, fieldType, defaultValue);
                }

                newItem.Name = fieldName;
                newItem.Tag = fieldID;
                newItem.Size = itemSize;
                fieldPanel.Controls.Add(newItem, boxIndex, i);
            }
        }