public static List <RowEntity> GenReflectElements <T>(T entity, List <string> ignoreFields)
        {
            List <RowEntity> list = new List <RowEntity>();

            if (entity == null)
            {
                entity = System.Activator.CreateInstance <T>();
            }
            int  index = 1;
            Type type  = typeof(T);

            foreach (PropertyInfo pi in type.GetProperties())
            {
                if (ignoreFields.Contains(pi.Name))
                {
                    continue;
                }
                RowEntity row = new RowEntity();
                list.Add(row);
                object[] objs     = pi.GetCustomAttributes(typeof(DescriptionAttribute), true);
                string   descName = objs.Length > 0 ? ((DescriptionAttribute)objs[0]).Description : pi.Name;
                row.Key   = pi.Name;
                row.Name  = descName;
                row.Value = pi.GetValue(entity, null) ?? string.Empty;
                row.Index = index++;
                row.Type  = ControlType.TEXT_BOX;
                if (pi.PropertyType == typeof(DateTime))
                {
                    row.Type = ControlType.DATE_TIME;
                }
                row.DataType = pi.PropertyType;
            }
            return(list);
        }
        public UCProjectRowComboBox(RowEntity row, List <object> list)
        {
            InitializeComponent();
            this.row                  = row;
            this.Dock                 = DockStyle.Fill;
            this.label1.Text          = row.Name + ":";
            this.comboBox1.DataSource = list;
            if (row.Value != null)
            {
                this.comboBox1.Text = row.Value.ToString();
            }
            else if (list.Count > 0)
            {
                this.comboBox1.SelectedIndex = 0;
            }
            this.comboBox1.DisplayMember = row.DisplayMember;

            if (list.Count == 1)
            {
                this.comboBox1.Dock = DockStyle.Top;
                this.label1.Dock    = DockStyle.Top;
            }
            else
            {
                this.comboBox1.Dock = DockStyle.Bottom;
            }
        }
 public UCProjectRowComboBox(RowEntity row)
 {
     InitializeComponent();
     this.row         = row;
     this.Dock        = DockStyle.Fill;
     this.label1.Text = row.Name + ":";
 }
示例#4
0
 public UCRowTextBox(RowEntity row)
 {
     InitializeComponent();
     this.Dock          = DockStyle.Fill;
     this.label1.Text   = row.Name + ":";
     this.textBox1.Text = row.Value.ToString();
     this.row           = row;
 }
示例#5
0
 public UCRowDateTime(RowEntity row)
 {
     InitializeComponent();
     this.Dock                 = DockStyle.Fill;
     this.label1.Text          = row.Name + ":";
     this.dateTimePicker1.Text = row.Value.ToString();
     this.row = row;
 }
示例#6
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);
        }