Exemplo n.º 1
0
 public static void SetUIValue(MDataTable dt, Control panel1)
 {
     for (int i = 0; i < dt.Columns.Count; i++)
     {
         string    name     = dt.Rows[0][i].ColumnName;
         Control[] controls = panel1.Controls.Find(name, true);
         if (controls.Length > 0)
         {
             string controlType = controls[0].GetType().Name;
             if (controlType == "MyTextBox")
             {
                 MyTextBox myTextBox = controls[0] as MyTextBox;
                 if (myTextBox != null)
                 {
                     myTextBox.OldText = Common.GetString(dt.Rows[0][i].Value);
                     myTextBox.Text    = Common.GetString(dt.Rows[0][i].Value);
                 }
             }
             if (controlType == "MyComboBox")
             {
                 MyComboBox myComboBox = controls[0] as MyComboBox;
                 if (myComboBox != null)
                 {
                     myComboBox.OldText = Common.GetString(dt.Rows[0][i].Value);
                     myComboBox.Text    = Common.GetString(dt.Rows[0][i].Value);
                 }
             }
             if (controlType == "MyDateTime")
             {
                 MyDateTime myDateTime = controls[0] as MyDateTime;
                 if (myDateTime != null)
                 {
                     DateTime date = DateTime.MinValue;
                     DateTime.TryParse(Common.GetString(dt.Rows[0][i].Value), out date);
                     if (date != DateTime.MinValue)
                     {
                         myDateTime.OldText = date.ToString("yyyy-MM-dd HH:mm:ss");
                         myDateTime.Text    = date.ToString("yyyy-MM-dd HH:mm:ss");
                     }
                     else
                     {
                         myDateTime.OldText = "";
                         myDateTime.Text    = "";
                     }
                 }
             }
             if (controlType == "MyOptions")
             {
                 MyOptions myOptions = controls[0] as MyOptions;
                 if (myOptions != null)
                 {
                     myOptions.OldText = Common.GetString(dt.Rows[0][i].Value);
                     myOptions.Text    = Common.GetString(dt.Rows[0][i].Value);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        public static void InitDDLB(Control c, System.Data.DataTable dt)
        {
            MyComboBox mc = c as MyComboBox;

            if (mc != null)
            {
                mc.DataSource    = dt;
                mc.ListData      = dt;
                mc.DisplayMember = "Name";
                mc.ValueMember   = "Value";
            }
            else
            {
                MyOptions mo = c as MyOptions;
                if (mo != null)
                {
                    mo.BindData(dt);
                }
            }
        }