Esempio n. 1
0
        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            SdelkaModel sdelkaModel = (SdelkaModel)sdelkaList.SelectedItem;

            using (ModelDB db = new ModelDB())
            {
                Sdelka sdelka = db.Sdelka.Where(p => p.sdelka1 == sdelkaModel.id).FirstOrDefault();
                if (sdelka != null)
                {
                    db.Entry(sdelka).State = EntityState.Deleted;
                    db.SaveChanges();
                }
            }
            sdelkaList.SelectedItem = null;
            UpdateSdelka();
        }
Esempio n. 2
0
 private void sdelkaList_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (sdelkaList.SelectedItem != null)
     {
         SdelkaModel sdelkaModel = (SdelkaModel)sdelkaList.SelectedItem;
         using (ModelDB db = new ModelDB())
         {
             Sdelka sdelka = db.Sdelka.Where(p => p.sdelka1 == sdelkaModel.id).FirstOrDefault();
             id_client.Text    = db.Client.Where(p => p.Id_client == sdelka.id_client).FirstOrDefault().Fio;
             id_tovar.Text     = db.Tovar.Where(p => p.id_tovar == sdelka.id_tovar).FirstOrDefault().name;
             count.Text        = sdelka.count.ToString();
             sum.Text          = sdelka.sum.ToString();
             Date.SelectedDate = sdelka.data;
             sdelkaModel       = null;
         }
     }
 }
Esempio n. 3
0
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            SdelkaModel sdelkaModel = (SdelkaModel)sdelkaList.SelectedItem;

            using (ModelDB db = new ModelDB())
            {
                Sdelka sdelka = db.Sdelka.Where(p => p.sdelka1 == sdelkaModel.id).FirstOrDefault();
                sdelka.sum     = decimal.Parse(sum.Text);
                sdelka.sdelka1 = sdelkaModel.id;
                sdelka.count   = int.Parse(count.Text);
                sdelka.data    = Date.SelectedDate.Value;
                string name = id_tovar.SelectedValue.ToString();
                string fio  = id_client.SelectedValue.ToString();
                sdelka.id_tovar        = db.Tovar.Where(p => p.name.Equals(name)).FirstOrDefault().id_tovar;
                sdelka.id_client       = db.Client.Where(p => p.Fio.Equals(fio)).FirstOrDefault().Id_client;
                db.Entry(sdelka).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            UpdateSdelka();
            sdelkaList.SelectedItem = null;
        }
Esempio n. 4
0
        private void Button_Click_5(object sender, RoutedEventArgs e)
        {
            Filter filter = new Filter();

            if (filter.ShowDialog() == true)
            {
                List <SdelkaModel> sdelkaModels = new List <SdelkaModel>();
                string             query        = filter.Querry;
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    SqlDataAdapter adapter = new SqlDataAdapter(query, connection);
                    DataSet        ds      = new DataSet();
                    adapter.Fill(ds);
                    foreach (DataTable dt in ds.Tables)
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            var         cells  = row.ItemArray;
                            SdelkaModel sdelka = new SdelkaModel();
                            sdelka.id    = int.Parse(cells[0].ToString());
                            sdelka.data  = DateTime.Parse(cells[1].ToString());
                            sdelka.count = int.Parse(cells[2].ToString());
                            sdelka.sum   = decimal.Parse(cells[3].ToString());
                            using (ModelDB db = new ModelDB())
                            {
                                int id_t = int.Parse(cells[4].ToString());
                                sdelka.name = db.Tovar.Where(p => p.id_tovar == id_t).FirstOrDefault().name;
                                int id_c = int.Parse(cells[5].ToString());
                                sdelka.fio = db.Client.Where(p => p.Id_client == id_c).FirstOrDefault().Fio;
                            }
                            sdelkaModels.Add(sdelka);
                        }
                    }
                    sdelkaList.ItemsSource = null;
                    sdelkaList.ItemsSource = sdelkaModels;
                }
            }
        }