// string con = ConfigurationManager.ConnectionStrings["TransportMandiConnectionString"].ConnectionString;
        #endregion

        #region Page Load...
        protected void Page_Load(object sender, EventArgs e)
        {
            txtReceiptNo.Attributes.Add("onkeypress", "return allowAlphabetAndNumer(event);");
            if (Request.UrlReferrer == null)
            {
                base.AutoRedirect();
            }
            if (!Page.IsPostBack)
            {
                if (base.CheckUserRights(intFormId) == false)
                {
                    Response.Redirect("PermissionDenied.aspx");
                }

                //this.BindState();
                if (Convert.ToString(Session["Userclass"]) == "Admin")
                {
                    this.BindCity();
                }
                else
                {
                    this.BindCity(Convert.ToInt64(Session["UserIdno"]));
                }
                drpCityFrom.SelectedValue = Convert.ToString(base.UserFromCity);
                this.BindDateRange();
                ddldateRange.SelectedValue = Convert.ToString(base.UserDateRng);
                ddldateRange_SelectedIndexChanged(null, null);
                this.BindTruckNo();
                BindLorryParty();
                txtReceiptDatefrom.Attributes.Add("onkeypress", "return notAllowAnything(event);");
                txtReceiptDateto.Attributes.Add("onkeypress", "return notAllowAnything(event);");

                lblTruckNo.Text = "Truck No.";
                ChlnBookingDAL obj       = new ChlnBookingDAL();
                DateTime?      dtfrom    = null;
                DateTime?      dtto      = null;
                String         challanNo = txtReceiptNo.Text;
                if (string.IsNullOrEmpty(Convert.ToString(txtReceiptDatefrom.Text)) == false)
                {
                    dtfrom = Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtReceiptDatefrom.Text));
                }
                if (string.IsNullOrEmpty(Convert.ToString(txtReceiptDatefrom.Text)) == false)
                {
                    dtto = Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtReceiptDateto.Text));
                }
                int cityfrom = Convert.ToInt32((drpCityFrom.SelectedIndex <= 0) ? "0" : drpCityFrom.SelectedValue);

                int TruckId = Convert.ToInt32((ddltruckNo.SelectedIndex <= 0) ? "0" : ddltruckNo.SelectedValue);

                Int64 UserIdno = 0;
                if (Convert.ToString(Session["Userclass"]) != "Admin")
                {
                    UserIdno = Convert.ToInt64(Session["UserIdno"]);
                }
                DataTable lstGridData = null;
                lstGridData = obj.SearchChallnBulkUpdate(ApplicationFunction.ConnectionString(), "SelectChallan", Convert.ToInt32(ddldateRange.SelectedValue), challanNo, dtfrom, dtto, cityfrom, TruckId, UserIdno, ddlGrtype.SelectedValue, Convert.ToInt64(ddlLorryParty.SelectedValue == "" ? "0" : ddlLorryParty.SelectedValue));
                obj         = null;
                if (lstGridData != null && lstGridData.Rows.Count > 0)
                {
                    lblTotalRecord.Text = "T. Record (s): " + lstGridData.Rows.Count;
                }
                Trantype();
                BindCity();
            }
        }
        private void BindGrid()
        {
            ChlnBookingDAL obj       = new ChlnBookingDAL();
            DateTime?      dtfrom    = null;
            DateTime?      dtto      = null;
            String         challanNo = txtReceiptNo.Text;

            if (string.IsNullOrEmpty(Convert.ToString(txtReceiptDatefrom.Text)) == false)
            {
                dtfrom = Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtReceiptDatefrom.Text));
            }
            if (string.IsNullOrEmpty(Convert.ToString(txtReceiptDatefrom.Text)) == false)
            {
                dtto = Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtReceiptDateto.Text));
            }
            int cityfrom = Convert.ToInt32((drpCityFrom.SelectedIndex <= 0) ? "0" : drpCityFrom.SelectedValue);

            int TruckId = Convert.ToInt32((ddltruckNo.SelectedIndex <= 0) ? "0" : ddltruckNo.SelectedValue);

            Int64 UserIdno = 0;

            if (Convert.ToString(Session["Userclass"]) != "Admin")
            {
                UserIdno = Convert.ToInt64(Session["UserIdno"]);
            }
            //var lstGridData=(IList)null;
            DataTable lstGridData = null;
            DataTable dtRcptDetl  = new DataTable();

            if (ddlGrtype.SelectedValue == "GR")
            {
                lstGridData = obj.SearchChallnBulkUpdate(ApplicationFunction.ConnectionString(), "AllChallan4BulkUpdate", Convert.ToInt32(ddldateRange.SelectedValue), challanNo, dtfrom, dtto, cityfrom, TruckId, UserIdno, ddlGrtype.SelectedValue, Convert.ToInt64(ddlLorryParty.SelectedValue == "" ? "0" : ddlLorryParty.SelectedValue));
            }
            else
            {
                //dtRcptDetl = obj.SelectGRRChlnDetail(ApplicationFunction.ConnectionString(), Convert.ToInt32(ddldateRange.SelectedValue), challanNo, dtfrom, dtto, cityfrom, TruckId, UserIdno, ddlGrtype.SelectedValue, Convert.ToString(ddlTranstype.SelectedValue));
            }
            #region Gr....
            obj = null;
            if ((lstGridData != null && lstGridData.Rows.Count > 0))
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("ChlnDate", typeof(string));
                dt.Columns.Add("ChlnNo", typeof(string));
                dt.Columns.Add("LorryNo", typeof(string));
                dt.Columns.Add("FromCity", typeof(string));
                dt.Columns.Add("NetAmnt", typeof(string));

                double TNet = 0;
                for (int i = 0; i < lstGridData.Rows.Count; i++)
                {
                    DataRow dr = dt.NewRow();
                    dr["ChlnDate"] = Convert.ToDateTime(lstGridData.Rows[i]["Chln_Date"]).ToString("dd-MM-yyyy");
                    dr["ChlnNo"]   = Convert.ToString(lstGridData.Rows[i]["Chln_No"]);
                    dr["LorryNo"]  = Convert.ToString(lstGridData.Rows[i]["Lorry_No"]);
                    dr["FromCity"] = Convert.ToString(lstGridData.Rows[i]["FromCity"]);
                    dr["NetAmnt"]  = Convert.ToDouble(lstGridData.Rows[i]["Net_Amnt"]).ToString("N2");
                    dt.Rows.Add(dr);
                    TNet += Convert.ToDouble(lstGridData.Rows[i]["Net_Amnt"]);
                    if (i == lstGridData.Rows.Count - 1)
                    {
                        DataRow drr = dt.NewRow();
                        drr["ChlnDate"] = "";
                        drr["ChlnNo"]   = "";
                        drr["LorryNo"]  = "";
                        drr["FromCity"] = "Total";
                        drr["NetAmnt"]  = (TNet).ToString("N2");
                        dt.Rows.Add(drr);
                    }
                }
                if (dt != null && dt.Rows.Count > 0)
                {
                    ViewState["Dt"] = dt;
                }


                grdMain.DataSource = lstGridData;
                grdMain.DataBind();
                lblTotalRecord.Text = "T. Record (s): " + lstGridData.Rows.Count;

                Double TotalNetAmount = 0;

                for (int i = 0; i < lstGridData.Rows.Count; i++)
                {
                    TotalNetAmount += Convert.ToDouble(lstGridData.Rows[i]["Net_Amnt"]);
                }
                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 " + lstGridData.Rows.Count.ToString();
                lblcontant.Visible = true;
                divpaging.Visible  = true;
            }
            else if ((dtRcptDetl != null && dtRcptDetl.Rows.Count > 0))
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("ChlnDate", typeof(string));
                dt.Columns.Add("ChlnNo", typeof(string));
                dt.Columns.Add("LorryNo", typeof(string));
                dt.Columns.Add("FromCity", typeof(string));
                dt.Columns.Add("NetAmnt", typeof(string));

                double TNet = 0;
                for (int i = 0; i < dtRcptDetl.Rows.Count; i++)
                {
                    DataRow dr = dt.NewRow();
                    dr["ChlnDate"] = Convert.ToDateTime(dtRcptDetl.Rows[i]["Chln_Date"]).ToString("dd-MM-yyyy");
                    dr["ChlnNo"]   = Convert.ToString((dtRcptDetl.Rows[i]["Chln_No"]));
                    dr["LorryNo"]  = Convert.ToString((dtRcptDetl.Rows[i]["Lorry_No"]));
                    dr["FromCity"] = Convert.ToString((dtRcptDetl.Rows[i]["FromCity"]));
                    dr["NetAmnt"]  = Convert.ToDouble((dtRcptDetl.Rows[i]["Net_Amnt"])).ToString("N2");
                    dt.Rows.Add(dr);
                    TNet += Convert.ToDouble((dtRcptDetl.Rows[i]["Net_Amnt"]));
                    if (i == dtRcptDetl.Rows.Count - 1)
                    {
                        DataRow drr = dt.NewRow();
                        drr["ChlnDate"] = "";
                        drr["ChlnNo"]   = "";
                        drr["LorryNo"]  = "";
                        drr["FromCity"] = "Total";
                        drr["NetAmnt"]  = (TNet).ToString("N2");
                        dt.Rows.Add(drr);
                    }
                }
                if (dt != null && dt.Rows.Count > 0)
                {
                    ViewState["Dt"] = dt;
                }


                grdMain.DataSource = dtRcptDetl;
                grdMain.DataBind();
                lblTotalRecord.Text = "T. Record (s): " + dtRcptDetl.Rows.Count;

                Double TotalNetAmount = 0;

                for (int i = 0; i < dtRcptDetl.Rows.Count; i++)
                {
                    TotalNetAmount += Convert.ToDouble((dtRcptDetl.Rows[i]["Net_Amnt"]));
                }
                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 " + dtRcptDetl.Rows.Count.ToString();
                lblcontant.Visible = true;
                divpaging.Visible  = true;
            }
            else
            {
                grdMain.DataSource = null;
                grdMain.DataBind();
                lblTotalRecord.Text = "T. Record (s): 0 ";
                lblcontant.Visible  = false;
                divpaging.Visible   = false;
            }
            #endregion
        }