private void TotalRecords()
 {
     using (TransportMandiEntities db = new TransportMandiEntities(MultipleDBDAL.strDynamicConString()))
     {
         string UserClass = Convert.ToString(Session["Userclass"]);
         Int64  UserIdno  = 0;
         if (UserClass != "Admin")
         {
             UserIdno = Convert.ToInt64(Session["UserIdno"]);
         }
         InvoiceRepOTHDAL obj     = new InvoiceRepOTHDAL();
         Int64            iInvTyp = (Convert.ToString(ddlInvType.SelectedValue) == "" ? 0 : Convert.ToInt64(ddlInvType.SelectedValue));
         DataTable        list1   = obj.SelectRep("SelectInvwiseRep", Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtDateFrom.Text)), Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtDateTo.Text)), String.Empty, 0, 0, 0, UserIdno, iInvTyp, ApplicationFunction.ConnectionString());
         lblTotalRecord.Text = "T. Record (s): " + Convert.ToString(list1.Rows.Count);
     }
 }
        private void BindGrid()
        {
            try
            {
                InvoiceRepOTHDAL obj = new InvoiceRepOTHDAL();

                string userclass = Convert.ToString(Session["Userclass"]);
                Int64  UserIdno  = 0;
                if (userclass != "Admin")
                {
                    UserIdno = Convert.ToInt64(Session["UserIdno"]);
                }

                Int64  iFromCityIDNO = (Convert.ToString(drpBaseCity.SelectedValue) == "" ? 0 : Convert.ToInt64(drpBaseCity.SelectedValue));
                Int64  iSenderIDNO   = (Convert.ToString(drpSenderName.SelectedValue) == "" ? 0 : Convert.ToInt64(drpSenderName.SelectedValue));
                Int32  iInvoiceNo    = (Convert.ToString(txtInvoiceNo.Text) == "" ? 0 : Convert.ToInt32(txtInvoiceNo.Text));
                Int64  iInvTyp       = (Convert.ToString(ddlInvType.SelectedValue) == "" ? 0 : Convert.ToInt64(ddlInvType.SelectedValue));
                string strAction     = "";
                if (ddlRepType.SelectedIndex == 0)
                {
                    strAction = "SelectInvwiseRep";
                }
                else
                {
                    strAction = "SelectGrwiseRep";
                }
                DataTable DsGrdetail = obj.SelectRep(strAction, Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtDateFrom.Text)), Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtDateTo.Text)), txtLorryNo.Text, iFromCityIDNO, iSenderIDNO, iInvoiceNo, UserIdno, iInvTyp, ApplicationFunction.ConnectionString());
                if ((DsGrdetail != null) && (DsGrdetail.Rows.Count > 0))
                {
                    Int32 j = 0; Int32 GrIdno = 0; Int32 InvIdno = 0;
                    if (ddlRepType.SelectedIndex == 1)
                    {
                        for (int k = 0; k < DsGrdetail.Rows.Count; k++)
                        {
                            GrIdno  = Convert.ToInt32(DsGrdetail.Rows[k]["Gr_Idno"]);
                            InvIdno = Convert.ToInt32(DsGrdetail.Rows[k]["ID"]);
                            if (k == 0)
                            {
                                DsGrdetail.Rows[k]["Gross_Amnt"] = Convert.ToString(DsGrdetail.Rows[k]["Gross_Amnt"]);
                                DsGrdetail.Rows[k]["Net_Amnt"]   = Convert.ToString(DsGrdetail.Rows[k]["Net_Amnt"]);
                                j++;
                            }
                            else
                            {
                                if (GrIdno == Convert.ToInt32(DsGrdetail.Rows[k - 1]["Gr_Idno"]))
                                {
                                    DsGrdetail.Rows[k]["Gr_Amnt"] = "";
                                }

                                if (InvIdno == Convert.ToInt32(DsGrdetail.Rows[k - 1]["ID"]))
                                {
                                    DsGrdetail.Rows[k]["Gross_Amnt"] = "";
                                    DsGrdetail.Rows[k]["Net_Amnt"]   = "";
                                }
                                else
                                {
                                    j = 0;
                                    DsGrdetail.Rows[k]["Gross_Amnt"] = Convert.ToString(DsGrdetail.Rows[k]["Gross_Amnt"]);
                                    DsGrdetail.Rows[k]["Net_Amnt"]   = Convert.ToString(DsGrdetail.Rows[k]["Net_Amnt"]);
                                }
                            }
                        }
                    }
                    ViewState["dtCSV"] = DsGrdetail;
                    grdMain.DataSource = DsGrdetail;
                    grdMain.DataBind();

                    Double TotalNetAmount = 0, TotGrossAmnt = 0;


                    for (int i = 0; i < DsGrdetail.Rows.Count; i++)
                    {
                        TotGrossAmnt   += Convert.ToDouble(string.IsNullOrEmpty(Convert.ToString(DsGrdetail.Rows[i]["Gross_Amnt"])) ? "0" : DsGrdetail.Rows[i]["Gross_Amnt"].ToString());
                        TotalNetAmount += Convert.ToDouble(string.IsNullOrEmpty(Convert.ToString(DsGrdetail.Rows[i]["Net_Amnt"])) ? "0" : DsGrdetail.Rows[i]["Net_Amnt"].ToString());
                    }
                    lblGrossAmnt.Text      = TotGrossAmnt.ToString("N2");
                    lblNetTotalAmount.Text = TotalNetAmount.ToString("N2");

                    int startRowOnPage = (grdMain.PageIndex * grdMain.PageSize) + 1;
                    int lastRowOnPage  = startRowOnPage + grdMain.Rows.Count - 1;
                    lblcontant.Text     = "Showing " + startRowOnPage.ToString() + " - " + lastRowOnPage.ToString() + " of " + DsGrdetail.Rows.Count.ToString();
                    lblcontant.Visible  = true;
                    imgBtnExcel.Visible = true;
                    divpaging.Visible   = true;
                    lblTotalRecord.Text = "T. Record(s): " + DsGrdetail.Rows.Count;


                    //if (ddlRepType.SelectedIndex == 0)
                    //{
                    //    foreach (DataControlField col in grdMain.Columns)
                    //    {
                    //        //if ((col.HeaderText == "Gr No.") || (col.HeaderText == "Gr Date") || (col.HeaderText == "Qty") || (col.HeaderText == "Weight") || (col.HeaderText == "Gr Amnt") || (col.HeaderText == "Chln No") || (col.HeaderText == "Gr Shrtg Amnt") || (col.HeaderText == "Lorry No."))
                    //        //if ((col.HeaderText == "Gr No.") || (col.HeaderText == "Gr Date") || (col.HeaderText == "Gr Amnt") || (col.HeaderText == "Chln No") || (col.HeaderText == "Lorry No."))
                    //        //{
                    //        //    col.Visible = false;
                    //        //}
                    //    }
                    //}
                    //else
                    //{
                    //    foreach (DataControlField col in grdMain.Columns)
                    //    {
                    //        //if ((col.HeaderText == "Gr No.") || (col.HeaderText == "Gr Date") || (col.HeaderText == "Qty") || (col.HeaderText == "Weight") || (col.HeaderText == "Gr Amnt") || (col.HeaderText == "Chln No") || (col.HeaderText == "Gr Shrtg Amnt") || (col.HeaderText == "Lorry No."))
                    //        //if ((col.HeaderText == "Gr No.") || (col.HeaderText == "Gr Date") || (col.HeaderText == "Gr Amnt") || (col.HeaderText == "Chln No") || (col.HeaderText == "Lorry No."))
                    //        //{
                    //        //    col.Visible = true;
                    //        //}
                    //    }
                    //}
                }
                else
                {
                    ViewState["dtCSV"] = null;
                    grdMain.DataSource = null;
                    grdMain.DataBind();
                    //printRep.Visible = false;
                    imgBtnExcel.Visible = false;
                    lblTotalRecord.Text = "Total Record (s): 0 ";
                    lblcontant.Visible  = false;
                    divpaging.Visible   = false;
                }
            }
            catch (Exception Ex)
            {
                throw (Ex);
            }
        }