Example #1
0
        protected void BtngenexportPDF_Click(object sender, EventArgs e)
        {
            string           username = Convert.ToString(Session["lco_username"]);
            string           strCon   = ConfigurationSettings.AppSettings["conString"].ToString().Trim();
            OracleConnection con      = new OracleConnection(strCon);


            try
            {
                double Amount  = 0;
                string User    = "";
                string lcoCode = "";
                string Remark  = "";
                try
                {
                    string str = "select * from aoup_lcopre_lco_online_pay_det where trim(num_lcopay_transid)=trim(" + ViewState["TransId"] + ")";

                    OracleCommand cmd = new OracleCommand(str, con);
                    con.Open();
                    OracleDataReader dr = cmd.ExecuteReader();

                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            User    = dr["var_lcopay_insby"].ToString();
                            lcoCode = dr["var_lcopay_lcocode"].ToString();
                            Amount  = Convert.ToDouble(dr["num_lcopay_amount"].ToString());
                            Remark  = dr["var_lcopay_remark"].ToString();
                        }
                    }
                    else
                    {
                        ListItem lst = new ListItem();
                        lst.Text  = "No Record Found ";
                        lst.Value = "0";
                        //return lst.Text;
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message.ToString());
                }

                Session["rcpt_pt_rcptno1"]     = ViewState["rcptno"].ToString();
                Session["rcpt_pt_rcptno2"]     = ViewState["BillDeskRef"].ToString();
                Session["rcpt_pt_date1"]       = DateTime.Now.ToString("dd/MM/yyyy");
                Session["rcpt_pt_cashiername"] = "N/A";
                Session["rcpt_pt_address"]     = "";
                Session["rcpt_pt_company"]     = "";
                Session["rcpt_pt_lcocd1"]      = username;
                Session["rcpt_pt_lconm1"]      = Session["name"].ToString();
                Session["rcpt_pt_amt1"]        = Amount;
                Session["rcpt_pt_paymode1"]    = "Online";
                Session["rcpt_pt_cheqno1"]     = "N/A";
                Session["rcpt_pt_bnknm1"]      = "N/A";
                Session["rcpt_pt_premark1"]    = Remark.ToString();
                Response.Write("<script language='javascript'> window.open('../Transaction/rcptPaymentReceiptInvoice.aspx', 'Print_Receipt','HEIGHT=600,WIDTH=820,top=50,left=50,toolbar=no,scrollbars=yes,resizable=yes,location=no,status=no');</script>");
                return;

                online_payment_pdf myreceiptreport = new online_payment_pdf();
                string             ReportPath      = Server.MapPath("online_payment_pdf.rpt");
                myreceiptreport.Load(ReportPath);

                myreceiptreport.SetParameterValue("par_rcptno", ViewState["BillDeskRef"].ToString());
                myreceiptreport.SetParameterValue("par_rcptdt", DateTime.Now.ToString("dd/MM/yyyy"));
                myreceiptreport.SetParameterValue("par_lcocd", username);
                myreceiptreport.SetParameterValue("par_lconm", Session["name"].ToString());
                myreceiptreport.SetParameterValue("par_cashier", "");
                myreceiptreport.SetParameterValue("par_amt", Amount);
                myreceiptreport.SetParameterValue("par_premark", Remark.ToString());
                myreceiptreport.SetParameterValue("par_company", "");
                myreceiptreport.SetParameterValue("par_address", "");
                myreceiptreport.SetParameterValue("par_transid", ViewState["rcptno"].ToString());


                String ExportPath = Server.MapPath("..\\MyExcelFile\\") + ViewState["BillDeskRef"].ToString() + " myrecpt " + DateTime.Now.ToString("dd-MM-yy hh mm ss") + ".pdf";
                myreceiptreport.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, ExportPath);

                FileStream fs = null;
                fs = File.Open(ExportPath, FileMode.Open);
                byte[] btFile = new byte[fs.Length];
                fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
                fs.Close();
                Response.AddHeader("Content-disposition", "attachment; filename=" + ViewState["BillDeskRef"].ToString() + " myrecpt " + DateTime.Now.ToString("dd-MM-yy hh mm ss") + ".pdf");
                Response.ContentType = "application/octet-stream";
                Response.BinaryWrite(btFile);
                Response.End();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message.ToString());
            }
        }