protected void Button3_Click(object sender, EventArgs e)
        {
            string   tempcell = cusCellTxt.Text;
            DateTime tdt;
            int      tempAmount = 0;
            int      tempCredit = 0;
            int      tempDebit  = 0;

            try
            {
                using (AdvInvSystemEntities dbobj = new AdvInvSystemEntities())
                {
                    var cu = (from c in dbobj.Customers where c.CellNumber == tempcell select c).ToList();
                    GridView1.DataSource = cu;
                    GridView1.DataBind();
                    if (GridView1.Rows.Count != 0)
                    {
                        fundTxt.Enabled = true;

                        int tempCustId = Convert.ToInt32(GridView1.Rows[0].Cells[0].Text);
                        var si         = (from s in dbobj.SaleInvoices where s.CustomerId == tempCustId && s.Status != "Cleared" select s).ToList();

                        GridView2.DataSource = si;
                        GridView2.DataBind();

                        if (datepicker.Text != "")
                        {
                            if (datepicker1.Text != "")
                            {
                                tdt = DateTime.Parse(datepicker1.Text);
                            }
                            else
                            {
                                tdt = System.DateTime.Now;
                            }
                            DateTime fdt = DateTime.Parse(datepicker.Text);

                            var cusRep = dbobj.sp_Customer_Report(tempCustId, fdt, tdt).ToList();
                            ctlGridView.DataSource = cusRep;
                            ctlGridView.DataBind();

                            for (int i = 0; i < ctlGridView.Rows.Count; i++)
                            {
                                if (ctlGridView.Rows[i].Cells[0].Text != "Fund Deposit")
                                {
                                    tempAmount += Convert.ToInt32(ctlGridView.Rows[i].Cells[2].Text);
                                }
                                tempCredit += Convert.ToInt32(ctlGridView.Rows[i].Cells[3].Text);
                                tempDebit  += Convert.ToInt32(ctlGridView.Rows[i].Cells[4].Text);
                            }
                            tSaleTxt.Text = tempAmount.ToString();
                            tCredTxt.Text = tempCredit.ToString();
                            tRecTxt.Text  = tempDebit.ToString();

                            List <int> tempInvId = new List <int>();
                            var        tempInv   = (from i in dbobj.SaleInvoices where i.CustomerId == tempCustId & i.Date >= fdt & i.Date < tdt select i).ToList();
                            for (int i = 0; i < tempInv.Count; i++)
                            {
                                tempInvId.Add(tempInv[i].SaleInvoicId);
                            }

                            List <saleProduct> sp = new List <saleProduct>();


                            for (int i = 0; i < tempInvId.Count; i++)
                            {
                                int myinvId         = tempInvId[i];
                                var saleProductList = dbobj.sp_sale_detail(myinvId).ToList();

                                for (int j = 0; j < saleProductList.Count; j++)
                                {
                                    if (sp.Count >= 1)
                                    {
                                        for (int k = 0; k < sp.Count; k++)
                                        {
                                            if (sp[k].ProductNm == saleProductList[j].ProductName)
                                            {
                                                sp[k].ProductQnty = (Convert.ToInt32(sp[k].ProductQnty) + Convert.ToInt32(saleProductList[j].Quatity));
                                                sp[k].ProductCost = sp[k].ProductQnty * Convert.ToInt32(saleProductList[j].Rate);
                                                flag = 1;
                                                break;
                                            }
                                        }
                                        if (flag == 0)
                                        {
                                            sp.Add(new saleProduct {
                                                ProductNm = saleProductList[j].ProductName, ProductQnty = saleProductList[j].Quatity, ProductCost = saleProductList[j].Rate * saleProductList[j].Quatity
                                            });
                                        }
                                        flag = 0;
                                    }
                                    else
                                    {
                                        sp.Add(new saleProduct {
                                            ProductNm = saleProductList[j].ProductName, ProductQnty = saleProductList[j].Quatity, ProductCost = saleProductList[j].Rate * saleProductList[j].Quatity
                                        });
                                    }
                                }
                            }
                            gw4.DataSource = sp;
                            gw4.DataBind();
                        }
                    }
                }
            }

            catch (Exception)
            {
            }
        }