protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.UrlReferrer == null)
            {
                base.AutoRedirect();
            }
            txtRcptNo.Attributes.Add("onkeypress", "return allowAlphabetAndNumer(event);");
            txtInvcDatefrom.Attributes.Add("onkeypress", "return notAllowAnything(event);");
            txtInvcDateto.Attributes.Add("onkeypress", "return notAllowAnything(event);");
            if (!Page.IsPostBack)
            {
                if (base.CheckUserRights(intFormId) == false)
                {
                    Response.Redirect("PermissionDenied.aspx");
                }
                if (base.Print == false)
                {
                    imgBtnExcel.Visible = false;
                }
                this.BindDateRange();
                ddldateRange.SelectedIndex = 0;
                ddldateRange_SelectedIndexChanged(null, null);

                RcvdAmntAgnstHireInvcDAL obj = new RcvdAmntAgnstHireInvcDAL();
                var lstGridData = obj.search(Convert.ToInt32(ddldateRange.SelectedValue), txtRcptNo.Text, Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtInvcDatefrom.Text)), Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtInvcDateto.Text)));
                if (lstGridData != null && lstGridData.Count > 0)
                {
                    lblTotalRecord.Text = "T. Record (s): " + lstGridData.Count;
                }
                ddldateRange.Focus();
            }
        }
        protected void grdMain_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string strMsg = string.Empty;

            if (e.CommandName == "cmdedit")
            {
                Response.Redirect("AmntAgainstInvoiceOTH.aspx?q=" + e.CommandArgument, true);
            }
            if (e.CommandName == "cmddelete")
            {
                Int64 UserIdno = 0;
                UserIdno = Convert.ToInt64(Session["UserIdno"]);
                RcvdAmntAgnstHireInvcDAL obj = new RcvdAmntAgnstHireInvcDAL();
                Int32 intValue = obj.Delete(Convert.ToInt32(e.CommandArgument), UserIdno, ApplicationFunction.ConnectionString());
                obj = null;
                if (intValue > 0)
                {
                    this.BindGrid();
                    strMsg = "Record deleted successfully.";
                    txtRcptNo.Focus();
                }
                else
                {
                    if (intValue == -1)
                    {
                        strMsg = "Record can not be deleted. It is in use!";
                    }
                    else
                    {
                        strMsg = "Record not deleted!";
                    }
                }
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alertstrMsg", "PassMessage('" + strMsg + "')", true);
            }
        }
        private void BindGrid()
        {
            RcvdAmntAgnstHireInvcDAL obj = new RcvdAmntAgnstHireInvcDAL();
            DateTime?dtfrom    = null;
            DateTime?dtto      = null;
            String   InvoiceNo = txtRcptNo.Text;

            if (string.IsNullOrEmpty(Convert.ToString(txtInvcDatefrom.Text)) == false)
            {
                dtfrom = Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtInvcDatefrom.Text));
            }
            if (string.IsNullOrEmpty(Convert.ToString(txtInvcDatefrom.Text)) == false)
            {
                dtto = Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtInvcDateto.Text));
            }

            var lstGridData = obj.search(Convert.ToInt32(ddldateRange.SelectedValue), InvoiceNo, dtfrom, dtto);

            obj = null;
            if (lstGridData != null && lstGridData.Count > 0)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("SrNo", typeof(string));
                dt.Columns.Add("InvoiceNo", typeof(string));
                dt.Columns.Add("Date", typeof(string));
                //dt.Columns.Add("FromCity", typeof(string));
                dt.Columns.Add("Sender", typeof(string));
                dt.Columns.Add("NetAmount", typeof(string));

                double TNet = 0; double TAmnt = 0;
                for (int i = 0; i < lstGridData.Count; i++)
                {
                    DataRow dr = dt.NewRow();
                    dr["SrNo"]      = Convert.ToString(i + 1);
                    dr["InvoiceNo"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "Inv_No"));
                    dr["Date"]      = Convert.ToDateTime(DataBinder.Eval(lstGridData[i], "Inv_Date")).ToString("dd-MM-yyyy");
                    //dr["FromCity"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "FromCity"));
                    dr["Sender"]    = Convert.ToString(DataBinder.Eval(lstGridData[i], "SenderName"));
                    dr["NetAmount"] = Convert.ToDouble(DataBinder.Eval(lstGridData[i], "Net_Amnt")).ToString("N2");
                    dt.Rows.Add(dr);

                    TNet += Convert.ToDouble(DataBinder.Eval(lstGridData[i], "Net_Amnt"));
                    if (i == lstGridData.Count - 1)
                    {
                        DataRow drr = dt.NewRow();
                        drr["Sender"]    = "Total";
                        drr["NetAmount"] = (TNet).ToString("N2");
                        dt.Rows.Add(drr);
                    }
                }
                if (dt != null && dt.Rows.Count > 0)
                {
                    ViewState["Dt"] = dt;
                }


                //
                Double TotalNetAmount = 0;

                for (int i = 0; i < lstGridData.Count; i++)
                {
                    TotalNetAmount += Convert.ToDouble(DataBinder.Eval(lstGridData[i], "Net_Amnt"));
                }
                lblNetTotalAmount.Text = TotalNetAmount.ToString("N2");

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


                int startRowOnPage = (grdMain.PageIndex * grdMain.PageSize) + 1;
                int lastRowOnPage  = startRowOnPage + grdMain.Rows.Count - 1;
                lblcontant.Text     = "Showing " + startRowOnPage.ToString() + " - " + lastRowOnPage.ToString() + " of " + lstGridData.Count.ToString();
                lblcontant.Visible  = true;
                imgBtnExcel.Visible = true;
                divpaging.Visible   = true;
            }
            else
            {
                grdMain.DataSource = null;
                grdMain.DataBind();
                lblTotalRecord.Text = "T. Record (s): 0 ";


                imgBtnExcel.Visible = false;
                lblcontant.Visible  = false;
                divpaging.Visible   = false;
            }
        }