Example #1
0
      public void Combobox(ComboBox ad)
      {
          const string sql = @"SELECT id_adress, name_adress FROM dbo.adress";
          var sqlDa = new SqlDataAdapter(sql, _sqlclass.SqlCon);
          var dtMain = new DataTable();

          try
          {
              sqlDa.Fill(dtMain);
          }
          catch (Exception exp)
          {
              MessageBox.Show(exp.Message);
          }
          var lmf = 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()
              };
              lmf.Add(temp);
          }
          ad.ItemsSource = lmf;
          ad.SelectedIndex = 0;
      }
Example #2
0
        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;
        }