private void dgv_Bills_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            fillComboBoxes();
            int billID = int.Parse(dgv_Bills.SelectedRows[0].Cells[0].Value.ToString());

            GeneralBill = context.GeneralBills.FirstOrDefault(b => b.ID == billID);


            cmb_CustomerN.SelectedValue = GeneralBill.customers_Id;
            Cmb_Employee.SelectedValue  = GeneralBill.employee_Id;
            dtp_GBillDate.Value         = GeneralBill.BillDate;
            numTotalCost.Value          = Convert.ToDecimal(GeneralBill.totalCost);

            ///sales order payment

            GeneralBillPayment     = context.GeneralBillPayments.FirstOrDefault(b => b.generalBill_Id == billID);
            numericPaiedCost.Value = Convert.ToDecimal(GeneralBillPayment.Paied);
            numResCost.Value       = Convert.ToDecimal(GeneralBillPayment.Rest);

            var GeneralBillDetail = context.GeneralBillDetails.Where(b => b.generalBill_Id == billID).ToList();

            dgv_SalesBill.Rows.Clear();
            for (var item = 0; item < GeneralBillDetail.Count; item++)
            {
                int    pID      = GeneralBillDetail[item].Product_Id;
                var    product  = context.products.FirstOrDefault(p => p.ID == pID);
                string pName    = product.ProductName;
                double quantity = GeneralBillDetail[item].Quantity;
                double price    = product.Price_individual;
                double discount = product.Discount; // error we have to add discount column to generalBillDetail table
                dgv_SalesBill.Rows.Add(discount, price, quantity, pName, pID);
            }
        }
        private void btn_Save_Click(object sender, EventArgs e)
        {
            numTotalCost.Value = decimal.Parse(numTotalCost.Value.ToString());
            numResCost.Value   = numTotalCost.Value - numericPaiedCost.Value;
            GeneralBill generalBill = new GeneralBill();

            generalBill.customers_Id = int.Parse(cmb_CustomerN.SelectedValue.ToString());
            generalBill.employee_Id  = int.Parse(Cmb_Employee.SelectedValue.ToString());
            generalBill.BillDate     = dtp_GBillDate.Value;
            generalBill.totalCost    = double.Parse(numTotalCost.Value.ToString());
            generalBill.status       = false;
            context.GeneralBills.Add(generalBill);
            context.SaveChanges();
            context = new store();
            ///sales order payment
            GeneralBillPayment billPayment = new GeneralBillPayment();

            billPayment.Paied          = double.Parse(numericPaiedCost.Value.ToString());
            billPayment.Rest           = double.Parse(numResCost.Value.ToString());
            billPayment.generalBill_Id = generalBill.ID;
            context.GeneralBillPayments.Add(billPayment);
            context.SaveChanges();
            context = new store();
            for (var item = 0; item <= dgv_SalesBill.Rows.Count - 1; item++)
            {
                GeneralBillDetails billDetail = new GeneralBillDetails();
                billDetail.Product_Id     = int.Parse(dgv_SalesBill.Rows[item].Cells[4].Value.ToString());
                billDetail.Quantity       = int.Parse(dgv_SalesBill.Rows[item].Cells[2].Value.ToString());
                billDetail.generalBill_Id = generalBill.ID;
                context.GeneralBillDetails.Add(billDetail);
                var product = context.products.FirstOrDefault(p => p.ID == billDetail.Product_Id);
                product.quantityPerProducts -= billDetail.Quantity;
            }

            context.SaveChanges();

            context = new store();
            for (var item = 0; item < dgv_SalesBill.Rows.Count - 1; item++)
            {
                int      pidd    = Int32.Parse(dgv_SalesBill.Rows[item].Cells[4].Value.ToString());
                Products product = context.products.FirstOrDefault(d => d.ID == pidd);
                product.quantityPerGroup -= int.Parse(dgv_SalesBill.Rows[item].Cells[2].Value.ToString());
            }
            context.SaveChanges();

            MessageBox.Show("تم العمليه بنجاح");
            numericPaiedCost.Value = 0;
            numericDiscount.Value  = 0;
            numericQuantity.Value  = 0;
            numResCost.Value       = 0;
            numTotalCost.Value     = 0;
            dgv_SalesBill.Rows.Clear();
        }