Example #1
0
        private void btn_save_supllier_Click(object sender, EventArgs e)
        {
            try
            {
                Supplyer newSuppyer = new Supplyer();

                foreach (var item in supproductlocalList)
                {
                    newSuppyer.Name  = item.Name;
                    newSuppyer.Phone = item.Phone;

                    newSuppyer.Address = item.Address;
                    storeContext.Supplyers.Add(newSuppyer);
                    storeContext.SaveChanges();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("هناك عميل موجود بالفعل ");
            }
        }
Example #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            Supplyer     sup         = context.Supplyers.FirstOrDefault(s => s.Name == SupplyerCombo.Text);
            SupplyerBill suppleyBill = new SupplyerBill()
            {
                supplyer_ID = sup.ID,
                PaidPrice   = 0,
                DeptPrice   = 0
            };

            context.SupplyerBills.Add(suppleyBill);
            context.SaveChanges();
            SupplyerBill       supBill = context.SupplyerBills.OrderByDescending(s => s.ID).FirstOrDefault();
            SupplyerBillDetail supplyerBDetails;

            foreach (var item in supperList)
            {
                supplyerBDetails                    = new SupplyerBillDetail();
                supplyerBDetails.Amount             = item.Amount;
                supplyerBDetails.Date               = item.Date;
                supplyerBDetails.Paid               = 0;
                supplyerBDetails.Debt               = 0;
                supplyerBDetails.AmountPrice        = item.AmountPrice;
                supplyerBDetails.productOpj_ID      = item.productOpj_ID;
                supplyerBDetails.AdeyMortagaType    = item.AdeyMortagaType;
                supplyerBDetails.SupplyerBillobj_ID = supBill.supplyer_ID;
                context.SupplyerBillDetails.Add(supplyerBDetails);

                Product UpdateProduct = context.Products.FirstOrDefault(p => p.ID == supplyerBDetails.productOpj_ID);
                if (supplyerBDetails.AdeyMortagaType == "عادى")
                {
                    UpdateProduct.AmountInStock = UpdateProduct.AmountInStock + supplyerBDetails.Amount;
                }
                if (supplyerBDetails.AdeyMortagaType == "مرتجع")
                {
                    UpdateProduct.AmountInStock = UpdateProduct.AmountInStock - supplyerBDetails.Amount;
                }
                context.SaveChanges();
            }
        }