コード例 #1
0
        public void binddata()
        {
            Hashtable htAddPlanParams = getAddPlanParamsData();

            string username;

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

            Cls_Business_rptcustcandetails objTran = new Cls_Business_rptcustcandetails();
            Hashtable htResponse = objTran.GetTransationsDet(htAddPlanParams, username);

            DataTable dt = null; //check for exception

            if (htResponse["htResponse"] != null)
            {
                dt = (DataTable)htResponse["htResponse"];
            }

            if (dt == null)
            {
                Response.Redirect("~/ErrorPage.aspx");
                return;
            }

            if (dt.Rows.Count == 0)
            {
                grdTransDet.Visible  = false;
                lblSearchMsg.Text    = "No data found";
                btn_genExcel.Visible = false;
            }
            else
            {
                grdTransDet.Visible    = true;
                btn_genExcel.Visible   = true;
                lblSearchMsg.Text      = "";
                grdTransDet.DataSource = dt;
                grdTransDet.DataBind();
                htResponse["htResponse"] = null;
                dt.Dispose();
            }
        }
コード例 #2
0
        protected void btn_genExcel_Click(object sender, EventArgs e)
        {
            Hashtable htAddPlanParams = getAddPlanParamsData();

            string username;

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

            Cls_Business_rptcustcandetails objTran = new Cls_Business_rptcustcandetails();
            Hashtable htResponse = objTran.GetTransationsDet(htAddPlanParams, username);

            DataTable dt = null; //check for exception

            if (htResponse["htResponse"] != null)
            {
                dt = (DataTable)htResponse["htResponse"];

                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/") + "PackCancellation_" + datetime + ".xls");
                try
                {
                    int    j         = 0;
                    String strheader = "Sr. No." + Convert.ToChar(9)
                                       + "Customer ID" + Convert.ToChar(9)
                                       + "Customer Name" + Convert.ToChar(9)
                                       + "Customer Address" + Convert.ToChar(9)
                                       + "VC ID" + Convert.ToChar(9)
                                       + "Plan Name" + Convert.ToChar(9)
                                       + "Plan Type" + Convert.ToChar(9)
                                       + "Transaction Type" + Convert.ToChar(9)
                                       + "Reason" + Convert.ToChar(9)
                                       + "User ID" + Convert.ToChar(9)
                                       + "User Name" + Convert.ToChar(9)
                                       + "'" + "Transaction Date & Time" + Convert.ToChar(9)
                                       + "MRP" + Convert.ToChar(9)
                                       + "Amount deducted" + Convert.ToChar(9)
                                       + "'" + "Expiry date" + Convert.ToChar(9)
                                       + "Pay Term" + Convert.ToChar(9)
                                       + "Balance" + Convert.ToChar(9)
                                       + "LCO Code" + Convert.ToChar(9)
                                       + "LCO Name" + Convert.ToChar(9)
                                       + "JV Name" + Convert.ToChar(9)
                                       + "ERP LCO A/C" + Convert.ToChar(9)
                                       + "Distributor" + Convert.ToChar(9)
                                       + "Sub distributor" + Convert.ToChar(9)
                                       + "City" + Convert.ToChar(9)
                                       + "State" + Convert.ToChar(9)
                                       + "OBRM Status" + 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]["custid"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["custname"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["custaddr"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["vc"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["plnname"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["plntyp"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["flag"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["reason"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["uname"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["userowner"].ToString() + Convert.ToChar(9)
                                            + "'" + dt.Rows[i]["tdt"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["custprice"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["amtdd"].ToString() + Convert.ToChar(9)
                                            + "'" + dt.Rows[i]["expdt"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["payterm"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["bal"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["lcocode"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["lconame"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["jvname"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["erplco_ac"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["distname"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["subdist"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["city"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["state"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["OBRMSTATUS"].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;
                }
                htResponse["htResponse"] = null;
                dt.Dispose();
                Response.Redirect("../MyExcelFile/" + "PackCancellation_" + datetime + ".xls");
            }


            if (dt.Rows.Count == 0)
            {
                grdTransDet.Visible = false;
                lblSearchMsg.Text   = "No data found";
            }
            else
            {
                btn_genExcel.Visible = true;
                grdTransDet.Visible  = true;
            }
        }