protected void ExportExcel() { Hashtable htAddPlanParams = getLedgerParamsData(); string username, catid, operator_id; if (Session["username"] != null || Session["operator_id"] != null) { username = Session["username"].ToString(); catid = Convert.ToString(Session["category"]); operator_id = ddlLco.SelectedValue.Split('#')[1].ToString();// Convert.ToString(Session["operator_id"]); } else { Session.Abandon(); Response.Redirect("~/Login.aspx"); return; } DataTable dt = new DataTable(); Cls_Business_rptExpired objTran = new Cls_Business_rptExpired(); dt = objTran.GetDetails(htAddPlanParams, username, operator_id, catid); if (dt == null) { Response.Redirect("~/ErrorPage.aspx"); return; } if (dt.Rows.Count > 0) { DateTime dd = DateTime.Now; string datetime = dd.Day + "" + dd.Month + "" + dd.Year + "" + dd.Hour + "" + dd.Minute + "" + dd.Second; StreamWriter sw = new StreamWriter(Server.MapPath("../MyExcelFile/") + "PlanExpired_" + datetime + ".xls"); try { int j = 0; String strheader = "Sr. No." + Convert.ToChar(9) + "Account Number" + Convert.ToChar(9) + "VC Id" + Convert.ToChar(9) + "Customer Name" + Convert.ToChar(9) + "Address" + Convert.ToChar(9) + "LCO Name" + Convert.ToChar(9) + "Lco code" + Convert.ToChar(9) + "Mobile" + Convert.ToChar(9) + "Package" + Convert.ToChar(9) + "City" + Convert.ToChar(9) + "Plan Type" + Convert.ToChar(9) + "Disconnect Date" + Convert.ToChar(9); while (j < dt.Rows.Count) { sw.WriteLine(strheader); for (int i = 0; i < dt.Rows.Count; i++) { j = j + 1; string strrow = j.ToString() + Convert.ToChar(9) + dt.Rows[i]["account_no"].ToString() + Convert.ToChar(9) + dt.Rows[i]["vc"].ToString() + Convert.ToChar(9) + dt.Rows[i]["fullname"].ToString() + Convert.ToChar(9) + dt.Rows[i]["address"].ToString() + Convert.ToChar(9) + dt.Rows[i]["lco_name"].ToString() + Convert.ToChar(9) + dt.Rows[i]["lco_code"].ToString() + Convert.ToChar(9) + dt.Rows[i]["mobile"].ToString() + Convert.ToChar(9) + dt.Rows[i]["planname"].ToString() + Convert.ToChar(9) + dt.Rows[i]["cityname"].ToString() + Convert.ToChar(9) + dt.Rows[i]["plantype"].ToString() + Convert.ToChar(9) + "'" + dt.Rows[i]["enddate"].ToString() + Convert.ToChar(9); sw.WriteLine(strrow); } } sw.Flush(); sw.Close(); } catch (Exception ex) { sw.Flush(); sw.Close(); Response.Write("Error : " + ex.Message.Trim()); return; } dt.Dispose(); Response.Redirect("../MyExcelFile/" + "PlanExpired_" + datetime + ".xls"); if (catid == "0" || catid == "10") { Response.Redirect("../Reports/rptExpired.aspx"); } } if (dt.Rows.Count == 0) { grdExpiry.Visible = false; lblSearchMsg.Text = "No data found"; } }
protected void binddata() { string from = txtFrom.Text; string to = txtTo.Text; DateTime fromDt; DateTime toDt; if (!String.IsNullOrEmpty(from) && !String.IsNullOrEmpty(to)) { fromDt = new DateTime(); toDt = new DateTime(); fromDt = DateTime.ParseExact(from, "dd-MMM-yyyy", null); toDt = DateTime.ParseExact(to, "dd-MMM-yyyy", null); if (toDt.CompareTo(fromDt) < 0) { lblSearchMsg.Text = "To date must be later than From date"; grdExpiry.Visible = false; lblSearchMsg.ForeColor = System.Drawing.Color.Red; return; } else if (Convert.ToDateTime(txtFrom.Text.ToString()) >= DateTime.Now.Date) { lblSearchMsg.Text = "You can not select From date later or equal to current date!"; //"You can not select From date later than 15 days from current date!"; return; } else if (Convert.ToDateTime(txtTo.Text.ToString()) >= DateTime.Now.Date) { lblSearchMsg.Text = "You can not select To date later or equal to current date!"; // "You can not select To date later than 15 days from current date!"; return; } else { lblSearchMsg.Text = ""; grdExpiry.Visible = true; } } Hashtable htAddPlanParams = getLedgerParamsData(); string username, catid, operator_id; if (Session["username"] != null || Session["operator_id"] != null) { username = Session["username"].ToString(); catid = Convert.ToString(Session["category"]); operator_id = ddlLco.SelectedValue.Split('#')[1].ToString(); //Convert.ToString(Session["operator_id"]); } else { Session.Abandon(); Response.Redirect("~/Login.aspx"); return; } DataTable dt = new DataTable(); if (catid != "0" && catid != "10") { Cls_Business_rptExpired objTran = new Cls_Business_rptExpired(); dt = objTran.GetDetails(htAddPlanParams, username, operator_id, catid); if (dt == null) { Response.Redirect("~/ErrorPage.aspx"); return; } if (dt.Rows.Count == 0) { btnGenerateExcel.Visible = false; grdExpiry.Visible = false; lblSearchMsg.Text = "No data found"; } else { btnGenerateExcel.Visible = true; grdExpiry.Visible = true; lblSearchMsg.Text = ""; ViewState["searched_trans"] = dt; grdExpiry.DataSource = dt; grdExpiry.DataBind(); } } else if (catid == "0" || catid == "10") { ExportExcel(); } }