private void btnDelete_Click(object sender, EventArgs e)
        {
            PackageRepo db = new PackageRepo();

            if (lstOrder.SelectedIndex == -1)
            {
                return;
            }
            var seciliPaketSil = lstOrder.SelectedItem as Package;

            foreach (var item in db.GetAll())
            {
                if (item.OrderId == seciliPaketSil.OrderId)
                {
                    db.Delete(seciliPaketSil);
                    break;
                }
            }

            lstOrder.Items.Clear();
            lstOrder.Items.AddRange(db.GetAll(x => x.OrderId == (cmbOrderName.SelectedItem as Order).OrderId).ToArray());

            FormHelper.FormuTemizle(this);
            cmbPackageProduct.SelectedIndex = -1;
            SiparisFiyatHesapla();
        }
Example #2
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          = "";
        }