protected void Page_Load(object sender, EventArgs e) { txtPrefixNum.Attributes.Add("onkeypress", "return allowAlphabetAndNumer(event);"); txtGRNo.Attributes.Add("onkeypress", "return allowOnlyNumber(event);"); if (Request.UrlReferrer == null) { base.AutoRedirect(); } if (!Page.IsPostBack) { if (base.CheckUserRights(intFormId) == false) { Response.Redirect("PermissionDenied.aspx"); } if (base.Print == false) { imgBtnExcel.Visible = false; } if (Convert.ToString(Session["Userclass"]) == "Admin") { this.BindCityFrom(); } else { this.BindCityFrom(Convert.ToInt64(Session["UserIdno"])); } // drpCityFrom.SelectedValue = Convert.ToString(base.UserFromCity); Datefrom.Attributes.Add("onkeypress", "return notAllowAnything(event);"); Dateto.Attributes.Add("onkeypress", "return notAllowAnything(event);"); this.BindDateRange(); ddlDateRange.SelectedValue = Convert.ToString(base.UserDateRng); ddlDateRange_SelectedIndexChanged(null, null); this.BindCity(); bindsender(); GRPrepRetailerDAL obj = new GRPrepRetailerDAL(); DateTime? dtfrom = null; DateTime? dtto = null; Int64 yearIDNO = Convert.ToInt32(ddlDateRange.SelectedValue); int GrNo = string.IsNullOrEmpty(Convert.ToString(txtGRNo.Text)) ? 0 : Convert.ToInt32(txtGRNo.Text); //if (string.IsNullOrEmpty(Convert.ToString(Datefrom.Text)) == false) //{ // dtfrom = Convert.ToDateTime(ApplicationFunction.mmddyyyy(Datefrom.Text)); //} //if (string.IsNullOrEmpty(Convert.ToString(Datefrom.Text)) == false) //{ // dtto = Convert.ToDateTime(ApplicationFunction.mmddyyyy(Dateto.Text)); //} string MnNo = string.IsNullOrEmpty(Convert.ToString(txtManNo.Text)) ? "0" : Convert.ToString(txtManNo.Text); string strPrefixNum = txtPrefixNum.Text.Trim(); int citto = Convert.ToInt32(drpCityTo.SelectedValue); int cityfrom = Convert.ToInt32(drpCityFrom.SelectedValue); int citydel = Convert.ToInt32(drpCityDelivery.SelectedValue); int senderr = Convert.ToInt32(ddlSender.SelectedValue == "" ? 0 : Convert.ToInt32(ddlSender.SelectedValue)); Int32 yearidno = Convert.ToInt32(ddlDateRange.SelectedValue == "" ? 0 : Convert.ToInt32(ddlDateRange.SelectedValue)); Int64 UserIdno = 0; if (Convert.ToString(Session["Userclass"]) != "Admin") { UserIdno = Convert.ToInt64(Session["UserIdno"]); } var lstGridData = obj.SelectGRRetailer(GrNo, dtfrom, dtto, cityfrom, citydel, citto, senderr, yearidno, UserIdno, strPrefixNum, MnNo); obj = null; if (lstGridData != null && lstGridData.Count > 0) { lblTotalRecord.Text = "T. Record (s): " + lstGridData.Count; } } }
private void BindGrid() { GRPrepRetailerDAL objRet = new GRPrepRetailerDAL(); DateTime? dtfrom = null; DateTime? dtto = null; Int64 yearIDNO = Convert.ToInt32(ddlDateRange.SelectedValue); int GrNo = string.IsNullOrEmpty(Convert.ToString(txtGRNo.Text)) ? 0 : Convert.ToInt32(txtGRNo.Text); string MnNo = string.IsNullOrEmpty(Convert.ToString(txtManNo.Text)) ? "" : Convert.ToString(txtManNo.Text); string strPrefixNum = txtPrefixNum.Text.Trim(); if (string.IsNullOrEmpty(Convert.ToString(Datefrom.Text)) == false) { dtfrom = Convert.ToDateTime(ApplicationFunction.mmddyyyy(Datefrom.Text)); } if (string.IsNullOrEmpty(Convert.ToString(Datefrom.Text)) == false) { dtto = Convert.ToDateTime(ApplicationFunction.mmddyyyy(Dateto.Text)); } int citto = Convert.ToInt32(drpCityTo.SelectedValue); int cityfrom = Convert.ToInt32(drpCityFrom.SelectedValue); int citydel = Convert.ToInt32(drpCityDelivery.SelectedValue); int sender = Convert.ToInt32(ddlSender.SelectedValue == "" ? 0 : Convert.ToInt32(ddlSender.SelectedValue)); Int32 yearidno = Convert.ToInt32(ddlDateRange.SelectedValue == "" ? 0 : Convert.ToInt32(ddlDateRange.SelectedValue)); Int64 UserIdno = 0; if (Convert.ToString(Session["Userclass"]) != "Admin") { UserIdno = Convert.ToInt64(Session["UserIdno"]); } var lstGridData = objRet.SelectGRRetailer(GrNo, dtfrom, dtto, cityfrom, citydel, citto, sender, yearidno, UserIdno, strPrefixNum, MnNo); objRet = null; if (lstGridData != null && lstGridData.Count > 0) { DataTable dt = new DataTable(); dt.Columns.Add("SrNo", typeof(string)); dt.Columns.Add("GrNo", typeof(string)); dt.Columns.Add("GrDate", typeof(string)); dt.Columns.Add("GRType", typeof(string)); dt.Columns.Add("Sender", typeof(string)); dt.Columns.Add("Receiver", typeof(string)); dt.Columns.Add("FromCity", typeof(string)); dt.Columns.Add("ToCity", typeof(string)); dt.Columns.Add("ViaCity", typeof(string)); dt.Columns.Add("LorryNo", typeof(string)); dt.Columns.Add("OwnerName", typeof(string)); dt.Columns.Add("Qty", typeof(string)); dt.Columns.Add("Amount", 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["GrNo"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "GRRet_Pref")) + "" + Convert.ToString(DataBinder.Eval(lstGridData[i], "GrRet_No")); dr["GrDate"] = Convert.ToDateTime(DataBinder.Eval(lstGridData[i], "GRRet_Date")).ToString("dd-MM-yyyy"); dr["GRType"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "GR_Typ")); dr["Sender"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "Sender")); dr["Receiver"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "Receiver")); dr["FromCity"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "CityFrom")); dr["ToCity"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "CityTo")); dr["ViaCity"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "CityVia")); dr["LorryNo"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "Lorry_No")); dr["OwnerName"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "Owner_Name")); dr["Qty"] = Convert.ToString(DataBinder.Eval(lstGridData[i], "Qty")); dr["Amount"] = Convert.ToDouble(DataBinder.Eval(lstGridData[i], "Gross_Amnt")).ToString("N2"); dr["NetAmount"] = Convert.ToDouble(DataBinder.Eval(lstGridData[i], "Net_Amount")).ToString("N2"); dt.Rows.Add(dr); TAmnt += Convert.ToDouble(DataBinder.Eval(lstGridData[i], "Gross_Amnt")); TNet += Convert.ToDouble(DataBinder.Eval(lstGridData[i], "Net_Amount")); if (i == lstGridData.Count - 1) { DataRow drr = dt.NewRow(); drr["ToCity"] = "Total"; drr["Amount"] = (TAmnt).ToString("N2"); drr["NetAmount"] = (TNet).ToString("N2"); dt.Rows.Add(drr); } } if (dt != null && dt.Rows.Count > 0) { ViewState["Dt"] = dt; } // Double TotalGrossNetAmount = 0; Double TotalNetAmount = 0; for (int i = 0; i < lstGridData.Count; i++) { TotalGrossNetAmount += Convert.ToDouble(DataBinder.Eval(lstGridData[i], "Gross_Amnt")); TotalNetAmount += Convert.ToDouble(DataBinder.Eval(lstGridData[i], "Net_Amount")); } lblNetGrossTotalAmount.Text = TotalGrossNetAmount.ToString("N2"); lblNetTotalAmount.Text = TotalNetAmount.ToString("N2"); grdMain.DataSource = lstGridData; grdMain.DataBind(); lblTotalRecord.Text = "T. Record (s): " + lstGridData.Count; //grdprint.DataSource = lstGridData; //grdprint.DataBind(); 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 "; //grdprint.DataSource = null; //grdprint.DataBind(); imgBtnExcel.Visible = false; lblcontant.Visible = false; divpaging.Visible = false; } }