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();
        }
Exemple #2
0
        private void btnSepeteEkle_Click(object sender, EventArgs e)
        {
            List <Package> packages = new PackageRepo().GetAll();

            try
            {
                #region package save
                var sonuc       = new ProductRepo().GetAll(x => x.Barcode == txtBarcodeProduct.Text).FirstOrDefault();
                var FindPackage = new PackageRepo().GetAll(x => x.Barcode == txtBarcodePackage.Text).FirstOrDefault();
                if (FindPackage == null)
                {
                    ////// package save part
                    Package package = new Package()
                    {
                        ProductId   = sonuc.Id,
                        Barcode     = txtBarcodePackage.Text,
                        PackageType = nuPackageQuantity.Value,
                        BuyPrice    = Convert.ToDecimal(txtBuyPrice.Text),
                    };

                    using (var packageRepo = new PackageRepo())
                    {
                        foreach (var item in packages)
                        {
                            if (package.Barcode == item.Barcode)
                            {
                                throw new Exception("Aynı barkoda sahip koliniz var");
                            }
                        }
                        packageRepo.Insert(package);
                    }
                    var pack    = new PackageRepo().GetAll(x => x.Barcode == txtBarcodePackage.Text).FirstOrDefault();
                    var product = new ProductRepo().GetAll(x => x.Barcode == pack.Product.Barcode).FirstOrDefault();
                    var order   = new OrderRepo().GetAll(x => x.CreatedDate == (cmbOrder.SelectedItem as Order).CreatedDate).FirstOrDefault();
                    ods.Add(new OrderDetail()
                    {
                        Id              = order.Id,
                        Id2             = pack.Id,
                        PackageQuantity = nuQuantity.Value,
                        PackageType     = pack.PackageType,
                        ProductName     = product.ProductName
                    });
                }
                else
                {
                    var product = new ProductRepo().GetAll(x => x.Barcode == FindPackage.Product.Barcode).FirstOrDefault();
                    var order   = new OrderRepo().GetAll(x => x.CreatedDate == (cmbOrder.SelectedItem as Order).CreatedDate).FirstOrDefault();
                    ods.Add(new OrderDetail()
                    {
                        Id              = order.Id,
                        Id2             = FindPackage.Id,
                        PackageQuantity = nuQuantity.Value,
                        PackageType     = FindPackage.PackageType,
                        ProductName     = product.ProductName
                    });
                    FindPackage.BuyPrice = Convert.ToDecimal(txtBuyPrice.Text);
                    var pr = new PackageRepo().Update();
                }

                addList();

                #endregion
            }
            catch (DbEntityValidationException ex)
            {
                new EntityHelper().FindError(ex);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }