public void Table(DataGrid dg) { const string sqlDb = @"SELECT * FROM dbo.master, dbo.adress WHERE master.id_adress = adress.id_adress"; var sqlDa = new SqlDataAdapter(sqlDb, _sqlclass.SqlCon); var dtMain = new DataTable(); try { sqlDa.Fill(dtMain); } catch (Exception exp) { MessageBox.Show(exp.Message); } var lmf = new List<BdClass.Master>(); for (var i = 0; i < dtMain.Rows.Count; i++) { var temp = new BdClass.Master { Id = (int) dtMain.Rows[i]["id_master"], Name = dtMain.Rows[i]["name"].ToString(), Dol = dtMain.Rows[i]["dol"].ToString(), Adress = new BdClass.Adress { Id = (int) dtMain.Rows[i]["id_adress"], Name = dtMain.Rows[i]["name_adress"].ToString() } }; lmf.Add(temp); } dg.ItemsSource = lmf; }
public void Combobox(ComboBox tj, ComboBox ad, ComboBox mast, ComboBox ml, ComboBox sp, ComboBox ds, TextBox tl, TextBox cas, BdClass.Main ch) { var idF = ((BdClass.Adress)ad.SelectedItem).Id; { const string sql1 = @"SELECT id_malfunction, name_malfunction FROM dbo.malfunction"; var sqlDa = new SqlDataAdapter(sql1, _sqlclass.SqlCon); var dtMain = new DataTable(); try { sqlDa.Fill(dtMain); } catch (Exception exp) { MessageBox.Show(exp.Message); } var lmf1 = new List<BdClass.Malfunction> {new BdClass.Malfunction {Name = "Не выбрано"}}; for (int i = 0; i < dtMain.Rows.Count; i++) { var temp = new BdClass.Malfunction { Id = (int) dtMain.Rows[i]["id_malfunction"], Name = dtMain.Rows[i]["name_malfunction"].ToString() }; lmf1.Add(temp); } ml.ItemsSource = lmf1; ml.SelectedIndex = 0; if (ch != null) { for (int i = 0; i < ml.Items.Count; i++) { var kkk = (BdClass.Malfunction)ml.Items[i]; if (kkk.Id == ch.Malfunction.Id) { ml.SelectedIndex = i; break; } } } const string sql2 = @"SELECT * FROM dbo.spare_parts"; sqlDa = new SqlDataAdapter(sql2, _sqlclass.SqlCon); dtMain = new DataTable(); try { sqlDa.Fill(dtMain); } catch (Exception exp) { MessageBox.Show(exp.Message); } var lmf2 = new List<BdClass.SpareParts> {new BdClass.SpareParts {Name = "Не выбрано"}}; for (var i = 0; i < dtMain.Rows.Count; i++) { var temp = new BdClass.SpareParts { Id = (int) dtMain.Rows[i]["id_spare_parts"], Name = dtMain.Rows[i]["name_spare_parts"].ToString() }; lmf2.Add(temp); } sp.ItemsSource = lmf2; sp.SelectedIndex = 0; if (ch != null) { for (int i = 0; i < sp.Items.Count; i++) { var kkk = (BdClass.SpareParts)sp.Items[i]; if (kkk.Id != ch.SpareParts.Id) continue; sp.SelectedIndex = i; break; } } const string sql3 = @"SELECT id_discounts, name_discount FROM dbo.discounts"; sqlDa = new SqlDataAdapter(sql3, _sqlclass.SqlCon); dtMain = new DataTable(); try { sqlDa.Fill(dtMain); } catch (Exception exp) { MessageBox.Show(exp.Message); } var lmf3 = new List<BdClass.Discounts> {new BdClass.Discounts {Name = "Не выбрано"}}; for (int i = 0; i < dtMain.Rows.Count; i++) { var temp = new BdClass.Discounts { Id = (int) dtMain.Rows[i]["id_discounts"], Name = dtMain.Rows[i]["name_discount"].ToString() }; lmf3.Add(temp); } ds.ItemsSource = lmf3; ds.SelectedIndex = 0; if (ch != null) { for (int i = 0; i < ds.Items.Count; i++) { var kkk = (BdClass.Discounts)ds.Items[i]; if (kkk.Id != ch.Discounts.Id) continue; ds.SelectedIndex = i; break; } } string sql4 = @"SELECT * FROM dbo.master,dbo.adress WHERE master.id_adress = adress.id_adress and master.id_adress=" + idF; sqlDa = new SqlDataAdapter(sql4, _sqlclass.SqlCon); dtMain = new DataTable(); try { sqlDa.Fill(dtMain); } catch (Exception exp) { MessageBox.Show(exp.Message); } var lmf4 = new List<BdClass.Master> {new BdClass.Master {Name = "Не выбрано"}}; for (var i = 0; i < dtMain.Rows.Count; i++) { var temp = new BdClass.Master { Id = (int) dtMain.Rows[i]["id_master"], Name = dtMain.Rows[i]["name"].ToString() }; lmf4.Add(temp); } mast.ItemsSource = lmf4; mast.SelectedIndex = 0; if (ch != null) { for (var i = 0; i < mast.Items.Count; i++) { var kkk = (BdClass.Master)mast.Items[i]; if (kkk.Id != ch.Master.Id) continue; mast.SelectedIndex = i; break; } } const string sql5 = @"SELECT * FROM dbo.type_job"; sqlDa = new SqlDataAdapter(sql5, _sqlclass.SqlCon); dtMain = new DataTable(); try { sqlDa.Fill(dtMain); } catch (Exception exp) { MessageBox.Show(exp.Message); } var lmf5 = new List<BdClass.TypeJob> {new BdClass.TypeJob {Name = "Не выбрано"}}; for (var i = 0; i < dtMain.Rows.Count; i++) { var temp = new BdClass.TypeJob { Id = (int) dtMain.Rows[i]["id_type_job"], Name = dtMain.Rows[i]["name_type_job"].ToString() }; lmf5.Add(temp); } tj.ItemsSource = lmf5; tj.SelectedIndex = 0; if (ch == null) return; for (var i = 0; i < tj.Items.Count; i++) { var kkk = (BdClass.TypeJob)tj.Items[i]; if (kkk.Id != ch.Typejob.Id) continue; tj.SelectedIndex = i; break; } } }
public void Combobox(ComboBox tj, ComboBox ad, ComboBox mast) { const string sql = "SELECT * FROM dbo.type_job"; const string sql1 = "SELECT * FROM dbo.master"; const string sql2 = "SELECT * FROM dbo.adress"; var sqlDa = new SqlDataAdapter(sql, SqlCon); var dtMain = new DataTable(); try { sqlDa.Fill(dtMain); } catch (Exception exp) { MessageBox.Show(exp.Message); } var lmf = new List<BdClass.TypeJob> {new BdClass.TypeJob {Name = "Не выбранно"}}; for (int i = 0; i < dtMain.Rows.Count; i++) { var temp = new BdClass.TypeJob { Id = (int) dtMain.Rows[i]["id_type_job"], Name = dtMain.Rows[i]["name_type_job"].ToString() }; lmf.Add(temp); } tj.ItemsSource = lmf; tj.SelectedIndex = 0; sqlDa = new SqlDataAdapter(sql2, SqlCon); dtMain = new DataTable(); try { sqlDa.Fill(dtMain); } catch (Exception exp) { MessageBox.Show(exp.Message); } var lmf2 = new List<BdClass.Adress> {new BdClass.Adress {Name = "Не выбранно"}}; for (int i = 0; i < dtMain.Rows.Count; i++) { var temp = new BdClass.Adress { Id = (int) dtMain.Rows[i]["id_adress"], Name = dtMain.Rows[i]["name_adress"].ToString() }; lmf2.Add(temp); } ad.ItemsSource = lmf2; ad.SelectedIndex = 0; sqlDa = new SqlDataAdapter(sql1, SqlCon); dtMain = new DataTable(); try { sqlDa.Fill(dtMain); } catch (Exception exp) { MessageBox.Show(exp.Message); } var lmf3 = new List<BdClass.Master> {new BdClass.Master {Name = "Не выбранно"}}; for (int i = 0; i < dtMain.Rows.Count; i++) { var temp = new BdClass.Master { Id = (int) dtMain.Rows[i]["id_master"], Name = dtMain.Rows[i]["name"].ToString() }; lmf3.Add(temp); } mast.ItemsSource = lmf3; mast.SelectedIndex = 0; }