예제 #1
0
        protected void binddata()
        {
            DataTable dt   = new DataTable();
            string    from = txtFrom.Text;
            string    to   = txtTo.Text;
            Cls_Business_RptBulkTransProces objTran = new Cls_Business_RptBulkTransProces();

            dt = objTran.GetBulkEcafDetails(Session["username"].ToString(), from, to);
            if (dt.Rows.Count == 0)
            {
                grdBulkUpload.DataSource = null;
                grdBulkUpload.DataBind();
                grdBulkUpload.Visible = false;
                lblSearchMsg.Text     = "No data found";
            }
            else
            {
                //lblSearchParams.Text = "SELECT * from view_lcopre_bulk_ecaf_summary where trunc(insdate)>='" + from + "' and trunc(insdate)<='" + to + "' and insby='" + Session["username"].ToString() + "'";

                grdBulkUpload.DataSource = dt;
                ViewState["Data"]        = dt;
                grdBulkUpload.DataBind();
                grdBulkUpload.Visible = true;
            }
        }
예제 #2
0
        protected void btn_genExl_Click(object sender, EventArgs e)
        {
            string username;

            if (Session["username"] != null)
            {
                username = Session["username"].ToString();
            }
            else
            {
                Session.Abandon();
                Response.Redirect("~/Login.aspx");
                return;
            }
            Cls_Business_RptBulkTransProces objTran = new Cls_Business_RptBulkTransProces();
            DataTable dt   = null; //check for exception
            string    from = txtFrom.Text;
            string    to   = txtTo.Text;

            dt = objTran.GetBulkEcafDetails(Session["username"].ToString(), from, to);
            ViewState["Data"] = dt;
            if (ViewState["Data"] != null)
            {
                dt = (DataTable)ViewState["Data"];

                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/") + "BulkEcaf_" + datetime + ".csv");
                try
                {
                    int    j         = 0;
                    String strheader = "Sr. No." + ","
                                       + "Uniqu No" + ","
                                       + "STB NO" + ","
                                       + "VC ID" + ","
                                       + "VC ID" + ","
                                       + "First Name" + ","
                                       + "Meddil Name" + ","
                                       + "Last Name" + ","
                                       + "Mobile No" + ","
                                       + "Email Id" + ","
                                       + "User Name" + ","
                                       + "Status" + ","
                                       + "Status MSG" + ","
                                       + "Transaction by" + ","
                                       + "'Transaction Date";


                    while (j < dt.Rows.Count)
                    {
                        sw.WriteLine(strheader);
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            j = j + 1;
                            string strrow = j.ToString() + ","
                                            + dt.Rows[i]["uniquno"].ToString() + ","
                                            + dt.Rows[i]["stb"].ToString() + ","
                                            + dt.Rows[i]["vc"].ToString() + ","
                                            + dt.Rows[i]["firstnm"].ToString() + ","
                                            + dt.Rows[i]["meddilnm"].ToString() + ","
                                            + dt.Rows[i]["lastnm"].ToString() + ","
                                            + dt.Rows[i]["mobileno"].ToString() + ","
                                            + dt.Rows[i]["email"].ToString() + ","
                                            + dt.Rows[i]["Status"].ToString() + ","
                                            + dt.Rows[i]["errormsg"].ToString() + ","
                                            + dt.Rows[i]["insby"].ToString() + ","
                                            + "'" + dt.Rows[i]["insdate"].ToString();


                            sw.WriteLine(strrow);
                        }
                    }
                    sw.Flush();
                    sw.Close();
                }
                catch (Exception ex)
                {
                    sw.Flush();
                    sw.Close();
                    Response.Write("Error : " + ex.Message.Trim());
                    return;
                }
                dt.Dispose();
                Response.AddHeader("Content-disposition", "attachment; filename=BulkEcaf_" + datetime + ".csv");
                Response.ContentType = "text/csv";
                Response.Redirect("../MyExcelFile/" + "BulkEcaf_" + datetime + ".csv");
            }
        }