protected void BtnAddToBill_Click(object sender, EventArgs e)
        {
            bool allExists = true;

            foreach (Product p in (List <Product>)ViewState["ProductsList"])
            {
                int Current;
                if (!p.Check_amounts(out Current)) // amount not enough for the order
                {
                    lblConfirmMsg.Text += " لا توجد كل الكميه المطلوبه من المنتج" + " ( " + p.P_name + " ) " + " الكميه الموجوده = " + Current + "<br />";
                    allExists           = false;
                }
            }
            if (allExists)//add ps to bill list
            {
                Bill_Content content = new Bill_Content();
                bool         AllDone = true;
                string       m;
                System.Text.StringBuilder ConcatenatedNotes = new System.Text.StringBuilder("قام العميل باضافة منتجات جديدة للفاتورة : ");
                foreach (Product p in (List <Product>)ViewState["ProductsList"])
                {
                    if (!content.Add_Bill_Contents(out m, Convert.ToInt64(lblBill_ID.Text), p))
                    {
                        Response.Write("<script>alert('" + m + "')</script>");
                        AllDone = false;
                        break;
                    }
                    else
                    {
                        ConcatenatedNotes.AppendLine();
                        ConcatenatedNotes.Append(p.Amount.ToString() + " " + p.P_name + " " + (p.Mark != "Not found" ? ("ماركة  " + p.Mark + " " +
                                                                                                                        p.Inch.ToString() + " بوصه " + (p.Style != "Not found" ? "طراز " + p.Style + " " : "")) : "")
                                                 + " سعر الواحده يساوى" + p.Regulare_Price.ToString());
                    }
                }
                if (AllDone)
                {
                    lblConfirmMsg.ForeColor = System.Drawing.Color.Green;
                    Bill_Payments payment = new Bill_Payments();
                    payment.Pay_Date = new DateTime(Convert.ToInt32(txtYear.Text), Convert.ToInt32(txtMonth.Text), Convert.ToInt32(txtDay.Text),
                                                    DateTime.Now.Hour, DateTime.Now.Minute + 1, DateTime.Now.Second);
                    payment.Paid_amount = 0;
                    payment.Notes       = ConcatenatedNotes.ToString();
                    payment.Add_Bill_Payment(Convert.ToInt64(lblBill_ID.Text));
                    lblConfirmMsg.Text = "تم بنجاح";
                }
            }
        }
        protected void BtnFinish_Click(object sender, EventArgs e)
        {
            Bill_Content content = new Bill_Content();

            content.P_name = txtP_Name.Text;
            content.amount = Convert.ToDecimal(txtReturnedAmount.Text);
            string name, mark, inch, style, m;

            GetName(txtP_Name.Text, out name, out mark, out inch, out style);
            DateTime Return_Date = new DateTime(Convert.ToInt32(txtYear.Text), Convert.ToInt32(txtMonth.Text), Convert.ToInt32(txtDay.Text),
                                                DateTime.Now.Hour, DateTime.Now.Minute + 1, DateTime.Now.Second);
            long   Bill_ID = Convert.ToInt64(lblBill_ID.Text);
            double Rest_Of_Money;

            if (!content.Return_Products(out m, Bill_ID, style, inch, mark, name, Return_Date, out Rest_Of_Money))
            {
                lblFinishMsg.Text      = m;
                lblFinishMsg.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                // check for rest
                if (Rest_Of_Money < 0) // Paid_amount greater than bill cost
                {
                    ViewState["Paid_amount"] = Rest_Of_Money;
                    PanelRest.Visible        = true;
                    BtnFinish.BackColor      = System.Drawing.Color.Red;
                    BtnFinish.Enabled        = false;
                    lblRestOfMoney.Text      = (-Rest_Of_Money).ToString() + " جنيها";
                }
                else
                {
                    lblFinishMsg.Text      = "تم بنجاح";
                    lblFinishMsg.ForeColor = System.Drawing.Color.Green;
                }
            }
        }
 private void BindBill(long Bill_ID)
 {
     GridViewBillList.DataSource = Bill_Content.Get_Bill_Items(Bill_ID);
     GridViewBillList.DataBind();
 }
        protected void BtnBill_Click(object sender, EventArgs e)
        {
            Bill bill = new Bill();

            bill.Discount            = txtDiscount.Text == "" ? 0 : Convert.ToDouble(txtDiscount.Text);
            bill.Bill_Date           = new DateTime(Convert.ToInt32(txtYear.Text), Convert.ToInt32(txtMonth.Text), Convert.ToInt32(txtDay.Text), DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            bill.AdditionalCost      = txtAdditionalCost.Text == "" ? 0 : Convert.ToDouble(txtAdditionalCost.Text);
            bill.AdditionalCostNotes = txtAdditionalcostNotes.Text;
            Client client = new Client();

            client.C_name  = txtClient_Name.Text;
            client.Address = txtAddress.Text;

            long         Bill_ID = bill.Generate_Bill(client, Convert.ToDouble(lblTotalCost.Text) + bill.AdditionalCost, Convert.ToDouble(txtPaid_Amount.Text), TxtDesc.Text);
            Bill_Content content = new Bill_Content();
            string       m       = "";
            bool         AllDone = true;

            foreach (Product p in (List <Product>)ViewState["ProductsList"])
            {
                if (!content.Add_Bill_Contents(out m, Bill_ID, p))
                {
                    Response.Write("<script>alert('" + m + "')</script>");
                    AllDone = false;
                    break;
                }
            }
            if (AllDone)
            {
                lblBillDate.Text   = bill.Bill_Date.ToShortDateString();
                lblBill_ID.Text    = Bill_ID.ToString();
                lblClientName.Text = txtClient_Name.Text;
                lblAddress.Text    = txtAddress.Text;
                lblBillCost.Text   = lblTotalCost.Text;
                lblPaid_Value.Text = txtPaid_Amount.Text;
                if (!string.IsNullOrEmpty(txtDiscount.Text))
                {
                    lblDiscountValue.Text = txtDiscount.Text;
                }
                else
                {
                    lblDiscount.Visible      = false;
                    lblDiscountValue.Visible = false;
                }
                if (txtAdditionalCost.Text == "")
                {
                    lblAddtionalCost.Visible       = false;
                    lblAdditionalCostValue.Visible = false;
                    lblAdditionalcostNotes.Visible = false;
                }
                else
                {
                    lblAdditionalCostValue.Text = txtAdditionalCost.Text;
                    lblAdditionalcostNotes.Text = txtAdditionalcostNotes.Text;
                }
                lblRest.Text                = ((Convert.ToDouble(lblBillCost.Text) + bill.AdditionalCost) - Convert.ToDouble(lblDiscountValue.Text) - Convert.ToDouble(lblPaid_Value.Text)).ToString();
                PanelClientInfo.Visible     = false;
                PanelBill.Visible           = true;
                GridViewBillList.DataSource = (List <Product>)ViewState["ProductsList"];
                GridViewBillList.DataBind();
            }
        }