public static void InitCombobox(MyComboBox combo, string tableName, string where, string colName) { if (tableName == "" || colName == "") { return; } string sql = "SELECT " + colName + " FROM " + tableName; if (where != "") { sql += " where " + where; } sql += " group by " + colName; //DataSet ds = DBAccess.Query(sql); using (MAction action = new MAction(sql, global.g5_sys.connStr)) { DataTable dt = action.Select().ToDataTable(); combo.DataSource = dt; combo.ListData = dt; combo.DisplayMember = colName; combo.ValueMember = colName; } }
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); } } } } }
public void InitCombobox(string fieldName, string tableName, string where, string colName) { Control[] c = this.Controls.Find(fieldName, true); if (c.Length > 0) { MyComboBox combobox = c[0] as MyComboBox; if (combobox != null && combobox.DataSource == null) { string value = combobox.Text; Common.InitCombobox(combobox, tableName, where, colName); combobox.Text = value; } } }
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); } } }