Exemplo n.º 1
0
        protected void generateExcel(string upload_id, int status_flag, string file_name)
        {
            string username;

            if (Session["username"] != null)
            {
                username = Session["username"].ToString();
            }
            else
            {
                Session.Abandon();
                Response.Redirect("~/Login.aspx");
                return;
            }
            Cls_Business_rptBulkUpload obj = new Cls_Business_rptBulkUpload();
            DataTable dt = null;

            dt = obj.GetExcelData(username, upload_id, status_flag);
            if (dt == null)
            {
                lblSearchMsg.Text = "Something went wrong while fetching details...";
                return;
            }
            if (dt.Rows.Count == 0)
            {
                lblSearchMsg.Text = "No data found for clicked count figure...";
                return;
            }

            DateTime dd       = DateTime.Now;
            string   datetime = dd.Day + "" + dd.Month + "" + dd.Year + "" + dd.Hour + "" + dd.Minute + "" + dd.Second;

            string xls_file_name = file_name;

            if (status_flag == 0)
            {
                xls_file_name += "_all_";
            }
            else if (status_flag == 1)
            {
                xls_file_name += "_success_";
            }
            else if (status_flag == 2)
            {
                xls_file_name += "_fail_";
            }

            StreamWriter sw = new StreamWriter(Server.MapPath("../MyExcelFile/") + xls_file_name + datetime + ".xls");

            try
            {
                int    j         = 0;
                String strheader = "Sr. No." + Convert.ToChar(9) +
                                   "Customer No" + Convert.ToChar(9) +
                                   "VC ID" + Convert.ToChar(9) +
                                   "LCO Code" + Convert.ToChar(9) +
                                   "Plan Name" + Convert.ToChar(9) +
                                   "Transaction Type" + Convert.ToChar(9) +
                                   "Upload Id" + Convert.ToChar(9) +
                                   "Date Time" + Convert.ToChar(9) +
                                   "Status" + Convert.ToChar(9) +
                                   "Status Message" + 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]["cust_no"].ToString() + Convert.ToChar(9) +
                                        "'" + dt.Rows[i]["vc_id"].ToString().Trim() + Convert.ToChar(9) +
                                        dt.Rows[i]["lco_code"].ToString() + Convert.ToChar(9) +
                                        dt.Rows[i]["plan_name"].ToString() + Convert.ToChar(9) +
                                        dt.Rows[i]["action"].ToString() + Convert.ToChar(9) +
                                        dt.Rows[i]["upload_id"].ToString() + Convert.ToChar(9) +
                                        "'" + dt.Rows[i]["upload_date"].ToString() + Convert.ToChar(9) +
                                        dt.Rows[i]["status"].ToString() + Convert.ToChar(9) +
                                        dt.Rows[i]["message"].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;
            }
            Response.Redirect("../MyExcelFile/" + xls_file_name + datetime + ".xls");

            /*StreamWriter sw = new StreamWriter(Server.MapPath("../MyExcelFile/") + xls_file_name + datetime + ".xls");
             * try
             * {
             *  int j = 0;
             *  String strheader = "Sr. No." + Convert.ToChar(9) +
             *                     "Customer No" + Convert.ToChar(9) +
             *                     "VC ID" + Convert.ToChar(9) +
             *                     "LCO Code" + Convert.ToChar(9) +
             *                     "Plan Name" + Convert.ToChar(9) +
             *                     "Transaction Type" + Convert.ToChar(9) +
             *                     "Upload Id" + Convert.ToChar(9) +
             *                     "Date Time" + Convert.ToChar(9) +
             *                     "Status" + Convert.ToChar(9) +
             *                     "Status Message" + 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]["cust_no"].ToString() + Convert.ToChar(9) +
             *              "'" + dt.Rows[i]["vc_id"].ToString() + Convert.ToChar(9) +
             *              dt.Rows[i]["lco_code"].ToString() + Convert.ToChar(9) +
             *              dt.Rows[i]["plan_name"].ToString() + Convert.ToChar(9) +
             *              dt.Rows[i]["action"].ToString() + Convert.ToChar(9) +
             *              dt.Rows[i]["upload_id"].ToString() + Convert.ToChar(9) +
             *              "'" + dt.Rows[i]["upload_date"].ToString() + Convert.ToChar(9) +
             *              dt.Rows[i]["status"].ToString() + Convert.ToChar(9) +
             *              dt.Rows[i]["message"].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;
             * }
             * Response.Redirect("../MyExcelFile/" + xls_file_name + datetime + ".xls");*/
        }
Exemplo n.º 2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            grdBulkUpload.Visible = false;
            string   from = txtFrom.Text;
            string   to   = txtTo.Text;
            DateTime fromDt;
            DateTime toDt;

            //date validation
            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";
                    return;
                }
            }
            else
            {
                lblSearchMsg.Text = "From and To date cannot be blank";
                return;
            }

            string username, catid, operator_id;

            if (Session["username"] != null || Session["operator_id"] != null)
            {
                username    = Session["username"].ToString();
                catid       = Convert.ToString(Session["category"]);
                operator_id = Convert.ToString(Session["operator_id"]);
            }
            else
            {
                Session.Abandon();
                Response.Redirect("~/Login.aspx");
                return;
            }
            string    lco = ddlLco.SelectedValue.ToString().Trim();
            DataTable dt  = new DataTable();
            Cls_Business_rptBulkUpload objTran = new Cls_Business_rptBulkUpload();

            dt = objTran.GetBulkDetails(from, to, username, catid, lco);
            if (dt == null)
            {
                Response.Redirect("~/ErrorPage.aspx");
                return;
            }

            lblSearchParams.Text = Server.HtmlDecode("<b style='color:#094791;'></b><b>Upload Details From : </b>" + from + "<b> To : </b>" + to);

            if (dt.Rows.Count == 0)
            {
                grdBulkUpload.Visible = false;
                lblSearchMsg.Text     = "No data found";
            }
            else
            {
                lblSearchMsg.Text        = "";
                grdBulkUpload.DataSource = dt;
                grdBulkUpload.DataBind();

                grdBulkUpload.Visible = true;
            }
        }