private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (ApplicationDBContext context = new ApplicationDBContext())
                {
                    if (_bor == true)
                    {
                        Partiya partiya = new Partiya()
                        {
                            BazaPrice     = Convert.ToDecimal(txtbazaviyPrice.Text),
                            SalePrice     = Convert.ToDecimal(txtSotuvPrice.Text),
                            CountProduct  = Convert.ToDecimal(txtSoni.Text),
                            CountProduct2 = Convert.ToDecimal(txtSoni.Text),
                            TodayDate     = (DateTime)date1.SelectedDate,
                            ProductId     = _id,
                            ProviderId    = tProvider,
                        };
                        context.Partiyas.Add(partiya);
                        context.SaveChanges();
                    }
                    else
                    {
                        Product product = new Product()
                        {
                            Shtrix        = txtShtrix.Text,
                            NameOfProduct = txtNameOfProduct.Text,
                            MassaId       = tMassa,
                            TypesId       = tType,
                        };
                        context.Products.Add(product);
                        context.SaveChanges();

                        Partiya partiya = new Partiya()
                        {
                            BazaPrice     = Convert.ToDecimal(txtbazaviyPrice.Text),
                            SalePrice     = Convert.ToDecimal(txtSotuvPrice.Text),
                            CountProduct  = Convert.ToDecimal(txtSoni.Text),
                            CountProduct2 = Convert.ToDecimal(txtSoni.Text),
                            TodayDate     = (DateTime)date1.SelectedDate,
                            Product       = product,
                            ProviderId    = tProvider
                        };
                        context.Partiyas.Add(partiya);
                        context.SaveChanges();
                    }
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error33");
            }
        }
Пример #2
0
        private void btnYes_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (ApplicationDBContext context = new ApplicationDBContext())
                {
                    Sold v = (from a in context.Solds
                              where a.Id == _id
                              select a).FirstOrDefault();

                    if (v != null)
                    {
                        Partiya p = (from a in context.Partiyas
                                     .Include(x => x.Product)
                                     .Include(x => x.Product.Massa)
                                     .Include(x => x.Product.Types)
                                     where v.PartiyaId == a.Id
                                     select a).FirstOrDefault();
                        p.CountProduct += v.CountProduct;

                        Vazvrat t = new Vazvrat()
                        {
                            Tovar        = p.Product.NameOfProduct,
                            Shtrix       = p.Product.Shtrix,
                            MassaName    = p.Product.Massa.Name,
                            TypeName     = p.Product.Types.TypeName,
                            CountProduct = v.CountProduct
                        };
                        context.Vazvrats.Add(t);
                        context.Solds.Remove(v);
                        context.SaveChanges();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Этот товар не найден в базе");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error44");
            }
        }
Пример #3
0
        private void DG_AllProduct_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (DG_AllProduct.SelectedCells.Count > 0 && DG_AllProduct.SelectedCells[0].IsValid)
                {
                    InfoPartiya t = DG_AllProduct.SelectedItem as InfoPartiya;
                    using (ApplicationDBContext context = new ApplicationDBContext())
                    {
                        Partiya v = (from a in context.Partiyas
                                     .Include(p => p.Product)
                                     where a.Id == t.Id
                                     orderby a.TodayDate
                                     select a).FirstOrDefault();

                        if (v != null)
                        {
                            var t1 = (from a in context.Kassas
                                      where a.Partiya.Id == v.Id
                                      where a.WorkerID == Properties.Settings.Default.UserId
                                      select a).FirstOrDefault();

                            if (t1 != null)
                            {
                                if (v.CountProduct > t1.CountProduct)
                                {
                                    var y = (from a in context.Kassas
                                             where a.Partiya.Id == v.Id
                                             where a.WorkerID == Properties.Settings.Default.UserId
                                             select a).FirstOrDefault();
                                    y.CountProduct += 1;
                                    y.AllPrice      = v.SalePrice * y.CountProduct;
                                    context.SaveChanges();
                                }
                            }
                            else
                            {
                                Kassa k = new Kassa()
                                {
                                    CountProduct = 1,
                                    AllPrice     = v.SalePrice,
                                    Partiya      = v,
                                    WorkerID     = Properties.Settings.Default.UserId
                                };
                                context.Kassas.Add(k);
                                context.SaveChanges();
                            }
                            txtSearch.Text = "";
                            RefreshKassa();
                            RefreshProductAll();
                            Skidkaga();
                        }
                        else
                        {
                            txtSearch.Text = "";
                            MessageBox.Show("Этот товар не найден в базе");
                        }
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }

            txtSearch.Focus();
        }