protected void insertdata()
        {
            BsolutionWebApp.Collecting object1 = new BsolutionWebApp.Collecting();

            object1.Collecting_No   = Int32.Parse(TextCollectingNo.Text);
            object1.Collecting_Name = TextCollectingName.Text;
            object1.Collecting_Note = TextBoxNote.Text;
            object1.Collecting_Date = Convert.ToDateTime(datepicker.Text);
            object1.IsDisable       = false;
            //object1.BankCashtype_Id = Int32.Parse(DropDownListbankcashtype.SelectedValue);

            object1.BankorCash        = int.Parse(ddChequeOrCash.SelectedValue);
            object1.Invoice_Id        = Int32.Parse(ddInvoice.SelectedValue);
            object1.Contact_Id        = Int32.Parse(ddContact.SelectedValue);
            object1.Operation_Type_Id = Int32.Parse(ddOperationType.SelectedValue);
            object1.Rectime           = DateTime.Now;
            object1.User_Id           = 0;


            DB.Collectings.InsertOnSubmit(object1);
            DB.SubmitChanges();

            bsclass bs = new bsclass();

            if (ddChequeOrCash.SelectedValue == "0")
            {
                bs.AddBank(object1.Collecting_Id, false, object1.Collecting_Amount, object1.Collecting_Date, Convert.ToInt32(DropDownListbankcashtype.SelectedValue), object1.Collecting_Note, "+", "", 0, 0, false);
            }
            else if (ddChequeOrCash.SelectedValue == "1")
            {
                bs.Addcash(object1.Collecting_Id, false, object1.Collecting_Amount, object1.Collecting_Date, Convert.ToInt32(DropDownListbankcashtype.SelectedValue), object1.Collecting_Note, "+", "", 0, 0, false);
            }
            Labelid.Text = object1.Collecting_Id.ToString();
        }
        protected void insertdata()
        {
            Labelstatus.Text = "";
            bsclass bs = new bsclass();

            decimal balance = 0;

            if (DropDownListbankcash.SelectedValue == "0")
            {
                balance = bs.checkblance(true, Convert.ToInt32(DropDownListbankcashtype.SelectedValue));
            }
            else if (DropDownListbankcash.SelectedValue == "1")
            {
                balance = bs.checkblance(false, Convert.ToInt32(DropDownListbankcashtype.SelectedValue));
            }

            if (balance >= Convert.ToDecimal(Convert.ToDouble(TextBoxunitcost.Text) * Convert.ToDouble(TextBoxquantity.Text)))
            {
                Expense newobject = new Expense();
                newobject.Expenses_No             = Convert.ToInt32(TextBoxExpensesNo.Text);
                newobject.Expenses_Cost           = Convert.ToDouble(TextBoxunitcost.Text);
                newobject.Expenses_Date           = Convert.ToDateTime(TextBoxdate.Text);
                newobject.Expenses_PersonInCharge = Convert.ToString(TextBoxfrom.Text);
                newobject.Expenses_Quantity       = Convert.ToDouble(TextBoxquantity.Text);
                newobject.Expenses_Total          = Convert.ToDouble(TextBoxunitcost.Text) * Convert.ToDouble(TextBoxquantity.Text);
                newobject.Expenses_Type_Id        = Convert.ToInt32(DropDownListExpenseType.SelectedValue);
                newobject.Rectime          = DateTime.Now;
                newobject.Expenses_Rectime = DateTime.Now;
                newobject.UserId           = Convert.ToInt32(Session["userid"]);
                newobject.IsDisable        = false;
                newobject.Expenses_From    = DateTime.Now;
                newobject.Note             = TextBoxNote.Text;

                DB.Expenses.InsertOnSubmit(newobject);
                DB.SubmitChanges();



                if (DropDownListbankcash.SelectedValue == "0")
                {
                    bs.AddBank(newobject.Expenses_Id, false, newobject.Expenses_Total, newobject.Expenses_Date, Convert.ToInt32(DropDownListbankcashtype.SelectedValue), newobject.Expenses_PersonInCharge, "-", "", 0, 0, false);
                }
                else if (DropDownListbankcash.SelectedValue == "1")
                {
                    bs.Addcash(newobject.Expenses_Id, false, newobject.Expenses_Total, newobject.Expenses_Date, Convert.ToInt32(DropDownListbankcashtype.SelectedValue), newobject.Expenses_PersonInCharge, "-", "", 0, 0, false);
                }
            }
            else

            {
                Labelstatus.Text = "The Currenct Balance Doesn't allow this transaction Current Balance is :" + balance;
            }
        }
        protected void Successbtnadd_Click(object sender, EventArgs e)
        {
            Labelstatus.Text = "";
            if (DropDownListcontac.SelectedValue != "0")
            {
                Invoice object1 = new Invoice();

                object1.Invoice_AfterDiscountprice      = 0;
                object1.Invoice_AfterDiscountprice_ATax = 0;
                object1.Invoice_Date = Convert.ToDateTime(datepicker.Text);
                //object1.Invoice_IsDone = Convert.ToByte(CheckBoxDone.Checked);
                object1.Invoice_No = Convert.ToInt32(Convert.ToString(Convert.ToInt32(DB.Invoice_Serial_Collects.Where(a => a.Invoice_Serial_Collect_Collecting.Equals(DropDownListinvoicetype.SelectedValue)).SingleOrDefault().Invoice) + 1));

                object1.Invoice_Price     = Convert.ToDouble(0);
                object1.Invoice_Rectime   = DateTime.Now;
                object1.Invoice_TotalCost = Convert.ToDouble(0);
                object1.Invoice_Type_Id   = Convert.ToInt32(DropDownListinvoicetype.SelectedValue);
                object1.Contact_Id        = Convert.ToInt32(DropDownListcontac.SelectedValue);
                object1.IsDisable         = false;

                DB.Invoices.InsertOnSubmit(object1);
                DB.SubmitChanges();



                bsclass bs = new bsclass();
                //if (object1.Invoice_Type_Id == 1)
                //    bs.Addtransaction(2, "Invoice+", object1.Invoice_Id, object1.Invoice_Date, object1.Invoice_TotalCost, object1.Invoice_Price, object1.Invoice_Price - object1.Invoice_TotalCost, "");
                //else if (object1.Invoice_Type_Id == 2)
                //    bs.Addtransaction(4, "Invoice-", object1.Invoice_Id, object1.Invoice_Date, object1.Invoice_TotalCost, object1.Invoice_Price, object1.Invoice_Price - object1.Invoice_TotalCost, "");

                bs.invoicetransaction(Convert.ToString(object1.Invoice_Id));



                var serical = DB.Invoice_Serial_Collects.Where(a => a.Invoice_Serial_Collect_Collecting.Equals(DropDownListinvoicetype.SelectedValue)).SingleOrDefault();
                serical.Invoice++;
                DB.Invoice_Serial_Collects.DefaultIfEmpty(serical);
                DB.SubmitChanges();

                Response.Redirect("AddInvoice.aspx?ID=" + object1.Invoice_Id);
            }
            else
            {
                Labelstatus.Text = "Please Choose A Contact ";
            }
        }
        /// <summary>
        ///  items
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Successbtnitem_Click(object sender, EventArgs e)
        {
            bsclass cls     = new bsclass();
            var     invoice = DB.Invoices.Where(a => a.Invoice_Id.Equals(Labelid.Text)).SingleOrDefault();

            if (invoice.Invoice_Type_Id == 1)
            {
                var item = DB.Items.Where(a => a.Items_Id.Equals(DropDownListItem.SelectedValue)).SingleOrDefault();

                if (item.HasStock == 1)
                {
                    var newstock = DB.Stocks.Where(a => a.Item_Id.Equals(DropDownListItem.SelectedValue)).SingleOrDefault();
                    if (newstock.Stock_Quantity >= Convert.ToInt32(TextBoxquentity.Text))
                    {
                        add();
                        cls.invoicesale(Convert.ToInt32(DropDownListItem.SelectedValue), Convert.ToInt32(TextBoxquentity.Text), false, Convert.ToDouble(textboxunticost.Text));
                    }
                    else
                    {
                        Response.Write("<script language=javascript>alert('Over Stock Quanitity');</script>");
                    }
                }
                else
                {
                    add();
                }
            }
            else
            {
                add();
                var item = DB.Items.Where(a => a.Items_Id.Equals(DropDownListItem.SelectedValue)).SingleOrDefault();

                if (item.HasStock == 1)
                {
                    cls.invoicesale(Convert.ToInt32(DropDownListItem.SelectedValue), Convert.ToInt32(TextBoxquentity.Text), true, Convert.ToDouble(textboxunticost.Text));
                }
            }

            onrefresh();
        }
Пример #5
0
        protected void insertdata()
        {
            BsolutionWebApp.Collecting object1 = new BsolutionWebApp.Collecting();

            object1.Collecting_No     = Int32.Parse(TextCollectingNo.Text);
            object1.Collecting_Name   = TextCollectingName.Text;
            object1.Collecting_Note   = TextBoxNote.Text;
            object1.Collecting_Date   = Convert.ToDateTime(datepicker.Text);
            object1.IsDisable         = false;
            object1.Cheque_Id         = Int32.Parse(ddCheque.SelectedValue);
            object1.Invoice_Id        = Int32.Parse(ddInvoice.SelectedValue);
            object1.Contact_Id        = Int32.Parse(ddContact.SelectedValue);
            object1.Operation_Type_Id = Int32.Parse(ddOperationType.SelectedValue);
            object1.Rectime           = DateTime.Now;
            object1.User_Id           = 0;


            DB.Collectings.InsertOnSubmit(object1);
            DB.SubmitChanges();

            bsclass bs = new bsclass();

            if (object1.Invoice_Type_Id == 1)
            {
                bs.Addtransaction(2, "Invoice+", object1.Invoice_Id, object1.Invoice_Date, object1.Invoice_TotalCost, object1.Invoice_Price, object1.Invoice_Price - object1.Invoice_TotalCost, "");
            }
            else if (object1.Invoice_Type_Id == 2)
            {
                bs.Addtransaction(4, "Invoice-", object1.Invoice_Id, object1.Invoice_Date, object1.Invoice_TotalCost, object1.Invoice_Price, object1.Invoice_Price - object1.Invoice_TotalCost, "");
            }

            var serical = DB.Invoice_Serial_Collects.Where(a => a.Invoice_Serial_Collect_Collecting.Equals(DropDownListinvoicetype.SelectedValue)).SingleOrDefault();

            serical.Invoice++;
            DB.Invoice_Serial_Collects.DefaultIfEmpty(serical);
            DB.SubmitChanges();

            Labelstatus.Text = "Invoice No=" + object1.Invoice_No + " -Date of Invoice" + object1.Invoice_Date;
        }
Пример #6
0
        private void editinvoicemoney(string id)
        {
            decimal amount        = 0;
            decimal percentage    = 0;
            decimal taxamount     = 0;
            decimal taxpercentage = 0;
            var     invoice       = DB.Invoices.Where(a => a.Invoice_Id.Equals(Labelid.Text)).SingleOrDefault();

            var discount = DB.DiscountInvoice2s.Where(a => a.Invoice_Id.Equals(invoice.Invoice_Id) && a.IsDisable.Equals(false));

            foreach (var item in discount)
            {
                amount     = amount + Convert.ToDecimal(item.DiscountInvoice_Amount);
                percentage = percentage + (Convert.ToDecimal(item.DiscountInvoice_Percentage) * Convert.ToDecimal(invoice.Invoice_Price)) / 100;
            }

            invoice.Invoice_AfterDiscountprice = Convert.ToDouble(Convert.ToDecimal(invoice.Invoice_Price) - Convert.ToDecimal(amount + percentage));

            var taxvalue = DB.InvoiceTaxes.Where(a => a.Invoice_ID.Equals(invoice.Invoice_Id) && a.IsDisable.Equals(false));

            foreach (var item in taxvalue)
            {
                taxamount     = taxamount + Convert.ToDecimal(item.InvoiceTax_Amount);
                taxpercentage = taxpercentage + (Convert.ToDecimal(item.InvoiceTax_Percentage) * Convert.ToDecimal(invoice.Invoice_AfterDiscountprice)) / 100;
            }

            invoice.Invoice_AfterDiscountprice_ATax = Convert.ToDouble(Convert.ToDecimal(invoice.Invoice_AfterDiscountprice) + Convert.ToDecimal(taxamount + taxpercentage));



            DB.Invoices.DefaultIfEmpty(invoice);
            DB.SubmitChanges();

            bsclass bs = new bsclass();

            bs.invoicetransaction(Labelid.Text);
        }
        protected void insertdata()
        {
            if (Labelid.Text == "0")
            {
                Invoice object1 = new Invoice();

                object1.Invoice_AfterDiscountprice      = 0;
                object1.Invoice_AfterDiscountprice_ATax = 0;
                object1.Invoice_Date = Convert.ToDateTime(datepicker.Text);
                //object1.Invoice_IsDone = Convert.ToByte(CheckBoxDone.Checked);
                object1.Invoice_No        = Convert.ToInt32(TextBoxInvoiceno.Text);
                object1.Invoice_Note      = TextBoxNote.Text;
                object1.Invoice_Price     = Convert.ToDouble(0);
                object1.Invoice_Rectime   = DateTime.Now;
                object1.Invoice_TotalCost = Convert.ToDouble(0);
                object1.Invoice_Type_Id   = Convert.ToInt32(DropDownListinvoicetype.SelectedValue);
                object1.Contact_Id        = Convert.ToInt32(DropDownListcontac.SelectedValue);
                object1.IsDisable         = false;

                DB.Invoices.InsertOnSubmit(object1);
                DB.SubmitChanges();


                Labelid.Text = Convert.ToString(object1.Invoice_Id);

                bsclass bs = new bsclass();
                if (object1.Invoice_Type_Id == 1)
                {
                    bs.Addtransaction(2, "Invoice+", object1.Invoice_Id, object1.Invoice_Date, object1.Invoice_TotalCost, object1.Invoice_Price, object1.Invoice_Price - object1.Invoice_TotalCost, "");
                }
                else if (object1.Invoice_Type_Id == 2)
                {
                    bs.Addtransaction(4, "Invoice-", object1.Invoice_Id, object1.Invoice_Date, object1.Invoice_TotalCost, object1.Invoice_Price, object1.Invoice_Price - object1.Invoice_TotalCost, "");
                }

                var serical = DB.Invoice_Serial_Collects.Where(a => a.Invoice_Serial_Collect_Collecting.Equals(DropDownListinvoicetype.SelectedValue)).SingleOrDefault();
                serical.Invoice++;
                DB.Invoice_Serial_Collects.DefaultIfEmpty(serical);
                DB.SubmitChanges();

                Labelstatus.Text = "Invoice No=" + object1.Invoice_No + " -Date of Invoice" + object1.Invoice_Date;
                // Response.Write("<script language=javascript>alert('Done');</script>");
            }
            else
            {
                Invoice object1 = DB.Invoices.Where(a => a.Invoice_Id.Equals(Labelid.Text)).SingleOrDefault();

                //object1.Invoice_AfterDiscountprice = Convert.ToDouble(TextBoxAfterDiscount.Text);
                //object1.Invoice_AfterDiscountprice_ATax = Convert.ToDouble(TextBoxTax.Text);
                object1.Invoice_Date = Convert.ToDateTime(datepicker.Text);
                // object1.Invoice_IsDone = Convert.ToByte(CheckBoxDone.Checked);
                //object1.Invoice_No = Convert.ToInt32(TextBoxInvoiceno.Text);
                object1.Invoice_Note = TextBoxNote.Text;
                //object1.Invoice_Price = Convert.ToDouble(TextBoxtotalprice.Text);
                object1.Invoice_Rectime = DateTime.Now;
                //object1.Invoice_TotalCost = Convert.ToDouble(TextBoxcost.Text);
                object1.Invoice_Type_Id = Convert.ToInt32(DropDownListinvoicetype.SelectedValue);
                object1.Contact_Id      = Convert.ToInt32(DropDownListcontac.SelectedValue);

                DB.Invoices.DefaultIfEmpty(object1);
                DB.SubmitChanges();

                Labelid.Text = "0";

                //bsclass bs = new bsclass();
                //bs.invoicetransaction(Labelid.Text);

                //Response.Redirect("AddInvoice.aspx");
            }
        }
Пример #8
0
        protected void inser()
        {
            BsolutionWebApp.Collecting object1 = null;
            if (Labelcollectingid.Text == "0")
            {
                Labelstatus.Text = "";
                if (DropDownListInvoicetype.SelectedValue == "2")
                {
                    bsclass bs = new bsclass();

                    decimal balance = 0;

                    if (DropDownList1.SelectedValue == "0")
                    {
                        balance = bs.checkblance(true, Convert.ToInt32(DropDownListbankcashtype.SelectedValue));
                    }
                    else if (DropDownList1.SelectedValue == "1")
                    {
                        balance = bs.checkblance(false, Convert.ToInt32(DropDownListbankcashtype.SelectedValue));
                    }


                    if (balance < Convert.ToDecimal((TextBoxamount.Text)))
                    {
                        Labelstatus.Text = "The Currenct Balance Doesn't allow this transaction Current Balance is :" + balance;
                        return;
                    }
                }


                object1 = new BsolutionWebApp.Collecting();

                object1.Collecting_No   = Int32.Parse(TextBoxCollectingNo.Text);
                object1.Collecting_Name = TextBoxcollectingname.Text;
                object1.Collecting_Note = TextBoxNote.Text;
                object1.Collecting_Date = Convert.ToDateTime(TextBoxdate.Text);
                object1.IsDisable       = false;
                object1.Collecting_Note = Convert.ToString(DropDownListbankcashtype.SelectedValue);
                if (RadioButtonBankOrCash.Checked == true)
                {
                    object1.BankorCash = int.Parse(DropDownList1.SelectedValue);
                }
                object1.Invoice_Id           = Int32.Parse(DropDownListInvoice.SelectedValue);
                object1.Collecting_Amount    = Convert.ToDouble(TextBoxamount.Text);
                object1.Collecting_WhatsLeft = Convert.ToDouble(TextBoxleft.Text) - Convert.ToDouble(TextBoxamount.Text);

                object1.Operation_Type_Id  = Int32.Parse(DropDownListInvoicetype.SelectedValue);
                object1.Rectime            = DateTime.Now;
                object1.User_Id            = 0;
                object1.Collecting_Rectime = DateTime.Now;
                object1.Log_Date           = DateTime.Now;


                DB.Collectings.InsertOnSubmit(object1);
                DB.SubmitChanges();

                var serial = DB.Invoice_Serial_Collects.Where(a => a.Invoice_Serial_Collect_Collecting.Equals(DropDownListInvoicetype.SelectedValue)).SingleOrDefault();
                serial.Collecting = object1.Collecting_No;

                DB.Invoice_Serial_Collects.DefaultIfEmpty(serial);
                DB.SubmitChanges();
            }
            else
            {
                object1 = DB.Collectings.Where(a => a.Collecting_Id.Equals(Labelcollectingid.Text)).SingleOrDefault();


                Labelstatus.Text = "";
                if (DropDownListInvoicetype.SelectedValue == "2")
                {
                    bsclass bs = new bsclass();

                    decimal balance = 0;

                    if (DropDownList1.SelectedValue == "0")
                    {
                        balance = bs.checkblance(true, Convert.ToInt32(DropDownListbankcashtype));
                    }
                    else if (DropDownList1.SelectedValue == "1")
                    {
                        balance = bs.checkblance(false, Convert.ToInt32(DropDownListbankcashtype));
                    }


                    if ((balance + Convert.ToDecimal(object1.Collecting_Amount)) < Convert.ToDecimal((TextBoxamount.Text)))
                    {
                        Labelstatus.Text = "The Currenct Balance Doesn't allow this transaction Current Balance is :" + balance;
                        return;
                    }
                }



                object1.Collecting_Name = TextBoxcollectingname.Text;
                object1.Collecting_Note = TextBoxNote.Text;
                object1.Collecting_Date = Convert.ToDateTime(TextBoxdate.Text);
                object1.IsDisable       = false;
                object1.Collecting_Note = Convert.ToString(DropDownListbankcashtype.SelectedValue);

                if (RadioButtonBankOrCash.Checked == true)
                {
                    object1.BankorCash = int.Parse(DropDownList1.SelectedValue);
                }

                object1.Collecting_Amount    = Convert.ToDouble(TextBoxamount.Text);
                object1.Collecting_WhatsLeft = Convert.ToDouble(TextBoxleft.Text) - Convert.ToDouble(TextBoxamount.Text);

                object1.Operation_Type_Id = Int32.Parse(DropDownListInvoicetype.SelectedValue);

                object1.User_Id            = 0;
                object1.Collecting_Rectime = DateTime.Now;
                object1.Log_Date           = DateTime.Now;

                DB.Collectings.DefaultIfEmpty(object1);
                DB.SubmitChanges();
            }
            if (RadioButtonBankOrCash.Checked == true)
            {
                bsclass bs = new bsclass();

                if (DropDownList1.SelectedValue == "0")
                {
                    if (DB.Banks.Where(a => a.Collecting_Id.Equals(object1.Collecting_Id)).Count() == 0)
                    {
                        if (DropDownListInvoicetype.SelectedValue == "1")
                        {
                            bs.AddBank(object1.Collecting_Id, true, object1.Collecting_Amount, object1.Collecting_Date, Convert.ToInt32(DropDownListbankcashtype.SelectedValue), "", "+", TextBoxNote.Text, object1.Collecting_Amount, 0, false);
                        }
                        else if (DropDownListInvoicetype.SelectedValue == "2")
                        {
                            bs.AddBank(object1.Collecting_Id, true, object1.Collecting_Amount, object1.Collecting_Date, Convert.ToInt32(DropDownListbankcashtype.SelectedValue), "", "-", TextBoxNote.Text, object1.Collecting_Amount, 0, false);
                        }
                    }
                    else
                    {
                        if (DropDownListInvoicetype.SelectedValue == "1")
                        {
                            bs.editBank(object1.Collecting_Id, true, object1.Collecting_Amount, object1.Collecting_Date, Convert.ToInt32(DropDownListbankcashtype.SelectedValue), "", "+", TextBoxNote.Text, object1.Collecting_Amount, 0, false);
                        }
                        else if (DropDownListInvoicetype.SelectedValue == "2")
                        {
                            bs.editBank(object1.Collecting_Id, true, object1.Collecting_Amount, object1.Collecting_Date, Convert.ToInt32(DropDownListbankcashtype.SelectedValue), "", "-", TextBoxNote.Text, object1.Collecting_Amount, 0, false);
                        }
                    }
                }
                else if (DropDownList1.SelectedValue == "1")
                {
                    if (DB.Cashes.Where(a => a.Collecting_Id.Equals(object1.Collecting_Id)).Count() == 0)
                    {
                        if (DropDownListInvoicetype.SelectedValue == "1")
                        {
                            bs.Addcash(object1.Collecting_Id, true, object1.Collecting_Amount, object1.Collecting_Date, Convert.ToInt32(DropDownListbankcashtype.SelectedValue), "", "+", TextBoxNote.Text, object1.Collecting_Amount, 0, false);
                        }
                        else if (DropDownListInvoicetype.SelectedValue == "2")
                        {
                            bs.Addcash(object1.Collecting_Id, true, object1.Collecting_Amount, object1.Collecting_Date, Convert.ToInt32(DropDownListbankcashtype.SelectedValue), "", "-", TextBoxNote.Text, object1.Collecting_Amount, 0, false);
                        }
                    }
                    else
                    {
                        if (DropDownListInvoicetype.SelectedValue == "1")
                        {
                            bs.editcash(object1.Collecting_Id, true, object1.Collecting_Amount, object1.Collecting_Date, Convert.ToInt32(DropDownListbankcashtype.SelectedValue), "", "+", TextBoxNote.Text, object1.Collecting_Amount, 0, false);
                        }
                        else if (DropDownListInvoicetype.SelectedValue == "2")
                        {
                            bs.editcash(object1.Collecting_Id, true, object1.Collecting_Amount, object1.Collecting_Date, Convert.ToInt32(DropDownListbankcashtype.SelectedValue), "", "-", TextBoxNote.Text, object1.Collecting_Amount, 0, false);
                        }
                    }
                }
            }
            else if (RadioButtonCheque.Checked == true)
            {
                var cheque = DB.Cheques.Where(a => a.Collecting_Id.Equals(object1.Collecting_Id));
                if (cheque.Count() == 0)
                {
                    BsolutionWebApp.Cheque object2 = new BsolutionWebApp.Cheque();
                    object2.Cheque_No        = Convert.ToString(TextBoxchequeno.Text);
                    object2.Cheque_Bank_Name = TextBoxchequebankname.Text;
                    object2.Cheque_Date      = Convert.ToDateTime(TextBoxdate.Text);
                    object2.IsDisable        = false;
                    object2.Cheque_Notes     = TextBoxNote.Text;
                    object2.Collecting_Id    = object1.Collecting_Id;
                    object2.RecTime          = DateTime.Now;
                    object2.PersonInCharge   = "";
                    object2.Cheque_Notes     = "";



                    DB.Cheques.InsertOnSubmit(object2);
                    DB.SubmitChanges();
                }

                else
                {
                    var cheque2 = DB.Cheques.Where(a => a.Collecting_Id.Equals(object1.Collecting_Id)).SingleOrDefault();
                    cheque2.Cheque_No        = Convert.ToString(TextBoxchequeno.Text);
                    cheque2.Cheque_Bank_Name = TextBoxchequebankname.Text;
                    cheque2.Cheque_Date      = Convert.ToDateTime(TextBoxdate.Text);
                    DB.Cheques.DefaultIfEmpty(cheque2);
                    DB.SubmitChanges();
                }
            }
            Labelcollectingid.Text = "0";
            Response.Redirect("CollectingPageAdd?ID=" + Labelinvoiceid.Text);
        }
        public void gridbind()
        {
            if (DropDownListbankcash.SelectedValue == "0")
            {
                bsclass bs = new bsclass();
                Labelstatus.Text = "Current Balance =" + bs.checkblance(true, Convert.ToInt32(DropDownListbankcashtype.SelectedValue));
                var banks = DB.Banks.Where(a => a.BankName_ID.Equals(DropDownListbankcashtype.SelectedValue));

                DataTable dt = new DataTable();

                dt.Columns.Add("Type");
                dt.Columns.Add("No.");
                dt.Columns.Add("+/-");
                dt.Columns.Add("DateTime");
                dt.Columns.Add("InvoiceNo.");
                dt.Columns.Add("DateInvoice");
                dt.Columns.Add("Amount");
                dt.Columns.Add("Contact");

                foreach (var bank in banks)
                {
                    if (bank.Collecting_Id != 0)
                    {
                        var collect = DB.Collectings.Where(a => a.Collecting_Id.Equals(bank.Collecting_Id)).SingleOrDefault();
                        if (collect.Invoice_Id != 0)
                        {
                            var invoice = DB.Invoices.Where(a => a.Invoice_Id.Equals(collect.Invoice_Id)).SingleOrDefault();
                            if (invoice.Invoice_Type_Id == 1)
                            {
                                DataRow _ravi = dt.NewRow();
                                _ravi["Type"]        = "تحصيل فاتورة بيع";
                                _ravi["No."]         = collect.Collecting_No;
                                _ravi["+/-"]         = "+";
                                _ravi["DateTime"]    = collect.Collecting_Date;
                                _ravi["InvoiceNo."]  = invoice.Invoice_No;
                                _ravi["DateInvoice"] = invoice.Invoice_Date;
                                _ravi["Amount"]      = collect.Collecting_Amount;
                                _ravi["Contact"]     = DB.Contact2s.Where(a => a.Contact_Id.Equals(invoice.Contact_Id)).SingleOrDefault().Contact_Name;
                                dt.Rows.Add(_ravi);
                            }
                            else if (invoice.Invoice_Type_Id == 2)
                            {
                                DataRow _ravi = dt.NewRow();
                                _ravi["Type"]        = "دفع فاتورة شراء";
                                _ravi["No."]         = collect.Collecting_No;
                                _ravi["+/-"]         = "-";
                                _ravi["DateTime"]    = collect.Collecting_Date;
                                _ravi["InvoiceNo."]  = invoice.Invoice_No;
                                _ravi["DateInvoice"] = invoice.Invoice_Date;
                                _ravi["Amount"]      = collect.Collecting_Amount;
                                _ravi["Contact"]     = DB.Contact2s.Where(a => a.Contact_Id.Equals(invoice.Contact_Id)).SingleOrDefault().Contact_Name;
                                dt.Rows.Add(_ravi);
                            }
                        }
                        else if (collect.Contact_Id != 0)
                        {
                            var contact = DB.Contact2s.Where(a => a.Contact_Id.Equals(collect.Contact_Id)).SingleOrDefault();

                            DataRow _ravi = dt.NewRow();
                            _ravi["Type"] = "حساب الشركاء";
                            _ravi["No."]  = collect.Collecting_No;

                            if (collect.Operation_Type_Id == 1)
                            {
                                _ravi["+/-"] = "+";
                            }
                            else if (collect.Operation_Type_Id == 2)
                            {
                                _ravi["+/-"] = "-";
                            }

                            _ravi["DateTime"]    = collect.Collecting_Date;
                            _ravi["InvoiceNo."]  = "";
                            _ravi["DateInvoice"] = "";
                            _ravi["Amount"]      = collect.Collecting_Amount;
                            _ravi["Contact"]     = contact.Contact_Name;
                            dt.Rows.Add(_ravi);
                        }
                    }
                    else if (bank.Expenses_Id != 0)
                    {
                        var expense = DB.Expenses.Where(a => a.Expenses_Id.Equals(bank.Expenses_Id)).SingleOrDefault();

                        DataRow _ravi = dt.NewRow();
                        _ravi["Type"]        = "مصروف";
                        _ravi["No."]         = expense.Expenses_No;
                        _ravi["+/-"]         = "-";
                        _ravi["DateTime"]    = expense.Expenses_Date;
                        _ravi["InvoiceNo."]  = "";
                        _ravi["DateInvoice"] = "";
                        _ravi["Amount"]      = expense.Expenses_Total;
                        _ravi["Contact"]     = expense.Expenses_From;
                        dt.Rows.Add(_ravi);
                    }
                }


                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
            else
            {
                bsclass bs = new bsclass();
                Labelstatus.Text = "Current Balance =" + bs.checkblance(false, Convert.ToInt32(DropDownListbankcashtype.SelectedValue));
                var banks = DB.Cashes.Where(a => a.CashID.Equals(DropDownListbankcashtype.SelectedValue));

                DataTable dt = new DataTable();

                dt.Columns.Add("Type");
                dt.Columns.Add("No.");
                dt.Columns.Add("+/-");
                dt.Columns.Add("DateTime");
                dt.Columns.Add("InvoiceNo.");
                dt.Columns.Add("DateInvoice");
                dt.Columns.Add("Amount");
                dt.Columns.Add("Contact");

                foreach (var bank in banks)
                {
                    if (bank.Collecting_Id != 0)
                    {
                        var collect = DB.Collectings.Where(a => a.Collecting_Id.Equals(bank.Collecting_Id)).SingleOrDefault();
                        if (collect.Invoice_Id != 0)
                        {
                            var invoice = DB.Invoices.Where(a => a.Invoice_Id.Equals(collect.Invoice_Id)).SingleOrDefault();
                            if (invoice.Invoice_Type_Id == 1)
                            {
                                DataRow _ravi = dt.NewRow();
                                _ravi["Type"]        = "تحصيل فاتورة بيع";
                                _ravi["No."]         = collect.Collecting_No;
                                _ravi["+/-"]         = "+";
                                _ravi["DateTime"]    = collect.Collecting_Date;
                                _ravi["InvoiceNo."]  = invoice.Invoice_No;
                                _ravi["DateInvoice"] = invoice.Invoice_Date;
                                _ravi["Amount"]      = collect.Collecting_Amount;
                                _ravi["Contact"]     = DB.Contact2s.Where(a => a.Contact_Id.Equals(invoice.Contact_Id)).SingleOrDefault().Contact_Name;
                                dt.Rows.Add(_ravi);
                            }
                            else if (invoice.Invoice_Type_Id == 2)
                            {
                                DataRow _ravi = dt.NewRow();
                                _ravi["Type"]        = "دفع فاتورة شراء";
                                _ravi["No."]         = collect.Collecting_No;
                                _ravi["+/-"]         = "-";
                                _ravi["DateTime"]    = collect.Collecting_Date;
                                _ravi["InvoiceNo."]  = invoice.Invoice_No;
                                _ravi["DateInvoice"] = invoice.Invoice_Date;
                                _ravi["Amount"]      = collect.Collecting_Amount;
                                _ravi["Contact"]     = DB.Contact2s.Where(a => a.Contact_Id.Equals(invoice.Contact_Id)).SingleOrDefault().Contact_Name;
                                dt.Rows.Add(_ravi);
                            }
                        }
                        else if (collect.Contact_Id != 0)
                        {
                            var contact = DB.Contact2s.Where(a => a.Contact_Id.Equals(collect.Contact_Id)).SingleOrDefault();

                            DataRow _ravi = dt.NewRow();
                            _ravi["Type"] = "حساب الشركاء";
                            _ravi["No."]  = collect.Collecting_No;

                            if (collect.Operation_Type_Id == 1)
                            {
                                _ravi["+/-"] = "+";
                            }
                            else if (collect.Operation_Type_Id == 2)
                            {
                                _ravi["+/-"] = "-";
                            }

                            _ravi["DateTime"]    = collect.Collecting_Date;
                            _ravi["InvoiceNo."]  = "";
                            _ravi["DateInvoice"] = "";
                            _ravi["Amount"]      = collect.Collecting_Amount;
                            _ravi["Contact"]     = contact.Contact_Name;
                            dt.Rows.Add(_ravi);
                        }
                    }
                    else if (bank.Expenses_Id != 0)
                    {
                        var expense = DB.Expenses.Where(a => a.Expenses_Id.Equals(bank.Expenses_Id)).SingleOrDefault();

                        DataRow _ravi = dt.NewRow();
                        _ravi["Type"]        = "مصروف";
                        _ravi["No."]         = expense.Expenses_No;
                        _ravi["+/-"]         = "-";
                        _ravi["DateTime"]    = expense.Expenses_Date;
                        _ravi["InvoiceNo."]  = "";
                        _ravi["DateInvoice"] = "";
                        _ravi["Amount"]      = expense.Expenses_Total;
                        _ravi["Contact"]     = expense.Expenses_From;
                        dt.Rows.Add(_ravi);
                    }
                }


                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }