Пример #1
0
        private void btnOrderSave_Click(object sender, EventArgs e)
        {
            bool varMi = false;

            PackageRepo db      = new PackageRepo();
            OrderRepo   dbOrder = new OrderRepo();

            try
            {
                Package package = new Package();


                package.PackageName            = txtPackageName.Text;
                package.ProductId              = (cmbPackageProduct.SelectedItem as Product).ProductId;
                package.OrderId                = (cmbOrderName.SelectedItem as Order).OrderId;
                package.PackagePurchasingPrice = Convert.ToDecimal(txtOrderPackagePrice.Text);
                package.PackageProductQuantity = Convert.ToInt32(nmOrderQuantity.Value);
                package.PackageBarcode         = txtPackageBarcode.Text;


                foreach (var item in lstOrder.Items)
                {
                    if (package.PackageBarcode == (item as Package).PackageBarcode || package.PackageName == (item as Package).PackageName)
                    {
                        varMi = true;
                        break;
                    }
                }

                if (varMi == false)
                {
                    db.Insert(package);
                    MessageBox.Show("Sipariş sepetine yeni ürün eklenmiştir.");
                }
                else
                {
                    MessageBox.Show("Seçili olan siparişte bu ürün zaten mevcuttur.");
                }

                dbOrder.Update();

                PaketleriGetir();

                SiparisFiyatHesapla();
            }
            catch (Exception)
            {
                throw;
            }

            dbOrder.Update();
            db.Update();
        }
Пример #2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (lstOrder.SelectedIndex == -1)
            {
                return;
            }

            PackageRepo packagedb = new PackageRepo();
            ProductRepo productdb = new ProductRepo();

            var seciliPaketGuncelle = lstOrder.SelectedItem as Package;

            foreach (var item in packagedb.GetAll())
            {
                if (item.ProductId == seciliPaketGuncelle.ProductId)
                {
                    foreach (var item2 in productdb.GetAll())
                    {
                        if (item2.ProductId == seciliPaketGuncelle.ProductId)
                        {
                            item2.ProductStock        = Convert.ToInt32(nmOrderQuantity.Value);
                            item2.ProductSellingPrice = (item2.ProductPurchasingPrice * (1 + 0.18m));
                        }
                    }

                    break;
                }
            }
            seciliPaketGuncelle.PackageName            = txtPackageName.Text;
            seciliPaketGuncelle.ProductId              = (cmbPackageProduct.SelectedItem as Product).ProductId;
            seciliPaketGuncelle.OrderId                = (cmbOrderName.SelectedItem as Order).OrderId;
            seciliPaketGuncelle.PackagePurchasingPrice = Convert.ToDecimal(txtOrderPackagePrice.Text);
            seciliPaketGuncelle.PackageProductQuantity = Convert.ToInt32(nmOrderQuantity.Value);
            seciliPaketGuncelle.PackageBarcode         = txtPackageBarcode.Text;


            SiparisFiyatHesapla();
            packagedb.Update();
            productdb.Update();

            PaketleriGetir();

            MessageBox.Show($"Güncelleme başarılı");
        }
Пример #3
0
        private void btnOrderSave_Click(object sender, EventArgs e)
        {
            if (cmbOrderProduct.SelectedIndex == -1)
            {
                return;
            }

            bool control = false;

            var     products    = new List <PackageViewModel>();
            Package package     = new Package();
            var     seciliPaket = ((cmbOrderProduct.SelectedItem as OrderViewModel).PackageId);

            try
            {
                products.AddRange(new PackageRepo().GetAll()
                                  .OrderBy(x => x.PackageName)
                                  .Where(x => x.PackageId == seciliPaket)
                                  .Select(x => new PackageViewModel()
                {
                    PackageName            = x.PackageName,
                    PackageBarcode         = x.PackageBarcode,
                    PackageProductQuantity = x.PackageProductQuantity
                }));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            foreach (var item in products)
            {
                lstGoodAcceptance.Items.Add(item);
            }


            var orders = new List <OrderViewModel>();

            try
            {
                orders.AddRange(new PackageRepo().GetAll()
                                .OrderBy(x => x.PackageName)
                                .Select(x => new OrderViewModel()
                {
                    PackageName    = x.PackageName,
                    PackageBarcode = x.PackageBarcode,
                    PackageId      = x.PackageId
                }));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            PackageRepo pr           = new PackageRepo();
            ProductRepo prodb        = new ProductRepo();
            var         seciliPaket1 = cmbOrderProduct.SelectedItem as OrderViewModel;

            foreach (var item in pr.GetAll())
            {
                foreach (var item1 in prodb.GetAll())
                {
                    if (item.ProductId == item1.ProductId)
                    {
                        if (seciliPaket1.ProductId == item1.ProductId)
                        {
                            item1.ProductStock       += seciliPaket1.PackageProductQuantity;
                            item1.ProductSellingPrice = (item1.ProductPurchasingPrice * (1 + 0.18m));
                        }
                    }
                }
            }

            pr.Update();
            prodb.Update();

            cmbOrderProduct.Items.Clear();
            cmbOrderProduct.Items.AddRange(new List <Package>().ToArray());

            PackageRepo db = new PackageRepo();



            var orders1 = db.GetAll(x => x.OrderId == (cmbGoodsAcceptanceOrders.SelectedItem as Order).OrderId);

            foreach (var item in orders)
            {
                foreach (var item1 in orders1)
                {
                    if (item.PackageId == seciliPaket && item.PackageId == item1.PackageId)
                    {
                        orders.Remove(item);
                        db.Delete(item1);
                        control = true;
                        break;
                    }
                }

                if (control == true)
                {
                    break;
                }
            }

            control = false;
            db.Update();
            cmbOrderProduct.Items.Clear();
            cmbOrderProduct.Items.AddRange(orders.ToArray());


            cmbOrderProduct.SelectedIndex = -1;
            cmbOrderProduct.Text          = "";
        }