Пример #1
0
        public void Init(List <RowEntity> list, Dictionary <string, List <object> > comboList, Dictionary <string, Action <object, EventArgs> > actionList)
        {
            if (list == null)
            {
                list = new List <RowEntity>();
            }
            if (comboList == null)
            {
                comboList = new Dictionary <string, List <object> >();
            }
            if (actionList == null)
            {
                actionList = new Dictionary <string, Action <object, EventArgs> >();
            }
            float f = 100F / list.Count;

            this.tableLayoutPanel1.RowStyles[0].Height = f;
            this.tableLayoutPanel1.RowCount            = list.Count;
            int j = 0;

            for (int i = 1; i < list.Count; i++)
            {
                this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, f));
            }
            foreach (RowEntity inst in list)
            {
                if (inst.Type == ControlType.TEXT_BOX)
                {
                    UCRowTextBox row = new UCRowTextBox(inst);
                    this.tableLayoutPanel1.Controls.Add(row, 0, j++);
                }
                else if (inst.Type == ControlType.COMBO_BOX)
                {
                    if (comboList.ContainsKey(inst.Key))
                    {
                        UCRowComboBox row = new UCRowComboBox(inst, comboList[inst.Key]);
                        if (actionList.ContainsKey(inst.Key))
                        {
                            row.SelectChanged = actionList[inst.Key];
                        }
                        this.tableLayoutPanel1.Controls.Add(row, 0, j++);
                    }
                }
                else if (inst.Type == ControlType.DATE_TIME)
                {
                    UCRowDateTime row = new UCRowDateTime(inst);
                    this.tableLayoutPanel1.Controls.Add(row, 0, j++);
                }
            }
        }
Пример #2
0
        public bool ReadUI()
        {
            List <RowEntity> list = new List <RowEntity>();

            if (this.Entity == null)
            {
                this.Entity = System.Activator.CreateInstance <T>();
            }
            foreach (Control control in this.tableLayoutPanel1.Controls)
            {
                if (control is UCRowTextBox)
                {
                    UCRowTextBox uc     = control as UCRowTextBox;
                    RowEntity    entity = uc.GetRow();
                    if (entity == null)
                    {
                        return(false);
                    }
                    list.Add(entity);
                }
                else if (control is UCRowComboBox)
                {
                    UCRowComboBox uc     = control as UCRowComboBox;
                    RowEntity     entity = uc.GetRow();
                    if (entity == null)
                    {
                        return(false);
                    }
                    list.Add(entity);
                }
                else if (control is UCRowDateTime)
                {
                    UCRowDateTime uc     = control as UCRowDateTime;
                    RowEntity     entity = uc.GetRow();
                    if (entity == null)
                    {
                        return(false);
                    }
                    list.Add(entity);
                }
            }
            Type type = typeof(T);

            foreach (RowEntity inst in list)
            {
                foreach (PropertyInfo pi in type.GetProperties())
                {
                    if (this.ignoreFields.Contains(pi.Name))
                    {
                        continue;
                    }
                    if (inst.Key == pi.Name)
                    {
                        if (inst.DataType.IsEnum)
                        {
                            Type t = inst.DataType;
                            pi.SetValue(this.Entity, (int)(Enum.Parse(t, inst.Value.ToString())), null);
                        }
                        else
                        {
                            pi.SetValue(this.Entity, inst.Value, null);
                        }
                        break;
                    }
                }
            }
            return(true);
        }