private bool EmptyValueInField() { foreach (Control c in CreatedControls) { if (c is ComboBox) { if ((c as ComboBox).SelectedIndex == -1) { FieldForm ff = (c as ComboBox).Tag as FieldForm; MessageBox.Show("В поле '" + ff.FieldCaption + "' отсутствует значение!", "Ошибка", MessageBoxButtons.OK); return(true); } } else if (c is TextBox) { if ((c as TextBox).Text == "") { FieldForm ff = (c as TextBox).Tag as FieldForm; MessageBox.Show("В поле '" + ff.FieldCaption + "' отсутствует значение!", "Ошибка", MessageBoxButtons.OK); return(true); } } } return(false); }
private void UpdateComboBox(ComboBox cb, FieldForm fieldf) //Заполняем ComboBox данными { cb.Items.Clear(); List <string> valcombobox = GetValuesForComboBox(fieldf); for (int q = 0; q < valcombobox.Count; q++) { cb.Items.Add(valcombobox[q]); } }
private int GetValueFieldComboBox(ComboBox cb, FieldForm fieldf) //Получаем значение ID из другой таблицы { return(fieldf.IDs[cb.SelectedIndex]); /* * for (int i = 0; i < fieldf.IDs.Count; i++) * if (cb.SelectedIndex == i) * return fieldf.IDs[i]; * return -1; */ }
private void FillValues() { DataTable dt = _database.SelectQuery(string.Format("SELECT * FROM {0}", EditFormTable.NameTable)); dt = _database.SelectQuery(string.Format("SELECT * FROM {0} WHERE {1} = {2}", EditFormTable.NameTable, dt.Columns[0].ColumnName, ID)); for (int i = 1; i < dt.Columns.Count; i++) { if (dt.Columns[i] == null) { continue; } if (CreatedControls[i - 1] is ComboBox) { FieldForm ff = (CreatedControls[i - 1] as ComboBox).Tag as FieldForm; (CreatedControls[i - 1] as ComboBox).SelectedIndex = ff.IDs.IndexOf((int)dt.Rows[0][dt.Columns[i]]); } else if (CreatedControls[i - 1] is TextBox) { (CreatedControls[i - 1] as TextBox).Text = dt.Rows[0][dt.Columns[i]].ToString(); } else if (CreatedControls[i - 1] is DateTimePicker) { string date = dt.Rows[0][dt.Columns[i]].ToString(); string[] dateval; date = date.Split(' ')[0]; dateval = date.Split('/'); DateTime dtime = new DateTime(int.Parse(dateval[2]), int.Parse(dateval[0]), int.Parse(dateval[1])); (CreatedControls[i - 1] as DateTimePicker).Value = dtime; //= dtime; //(CreatedControls[i - 1] as DateTimePicker).Value = new DateTime(int.Parse(dateval[2]), int.Parse(dateval[1]), int.Parse(dateval[0]));//.Year = (int)dateval[2]; //(CreatedControls[i - 1] as DateTimePicker).SelectedIndex = ff.IDs.IndexOf((int)dt.Rows[0][dt.Columns[i]]); } else { bool valcheck = (bool)dt.Rows[0][dt.Columns[i]]; (CreatedControls[i - 1] as CheckBox).Checked = valcheck; //(CreatedControls[i - 1] as CheckBox).Checked = valcheck == 1 ? true : false; } } }
private List <string> GetValuesForComboBox(FieldForm fieldf) { fieldf.IDs.Clear(); List <string> stringsvalues = new List <string>(); DataTable dt; string query = "SELECT"; for (int i = 0; i < fieldf.FieldFullNames.Count; i++) { query += (i == 0? " ": ", ") + fieldf.FieldFullNames[i]; } query += " FROM " + fieldf.FieldFullNames[0].Split('.')[0]; dt = _database.SelectQuery(query); bool firstid; string str = string.Empty; foreach (DataRow row in dt.Rows) { str = ""; firstid = true; foreach (DataColumn column in dt.Columns) { if (firstid) { fieldf.IDs.Add(int.Parse(row[column].ToString())); } else { str += row[column] + " "; } firstid = false; } stringsvalues.Add(str); } return(stringsvalues); }