Esempio n. 1
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);
        }