Exemplo n.º 1
0
        public static CReport GetReportFromWinService(CReportList rpl, string exportType)
        {
            CReport rpt = new CReport(rpl.Name, rpl.ReportHeaderTitle, rpl.ReportFileName, exportType);

            try
            {
                //SINGLE_REPORT|UserID|Session|LanguageID|ExportType|ReportFileName
                //string reportListBase64 = CBinaryUtils.BinaryToBase64(CBinaryUtils.SerializeObject(rpl));

                string comand = string.Format("SINGLE_REPORT|{0}|{1}|{2}|{3}|{4}", rpl.UserID, rpl.Session.ToString(), rpl.LanguageID, exportType, rpl.ReportFileName);

                string serverIP   = CReportConfig.WinServiceServer.Split(':')[0];
                int    serverPort = 20000;
                if (CReportConfig.WinServiceServer.Split(':').Length > 1)
                {
                    int.TryParse(CReportConfig.WinServiceServer.Split(':')[1], out serverPort);
                }

                TcpClient client = new TcpClient(serverIP, serverPort);
                Stream    s      = client.GetStream();

                StreamWriter sw = new StreamWriter(s);
                StreamReader sr = new StreamReader(s);
                sw.AutoFlush = true;

                sw.WriteLine(comand);
                string result = sr.ReadLine(); //000-OK
                Write("", rpl.Session.ToString(), rpl.UserID, "==STEP1==: Start Protocol :" + result + ",UserName:"******"");
                result = sr.ReadLine();        //000-Begin Send
                Write("", rpl.Session.ToString(), rpl.UserID, "==STEP2==: Begin Receive :" + result + ",UserName:"******"");

                if (result.StartsWith("000-"))
                {
                    result = sr.ReadLine();
                    Write("", rpl.Session.ToString(), rpl.UserID, "==STEP2==: Receive Content :" + result.Substring(0, 100) + ",UserName:"******"");
                    byte[] buffer = CBinaryUtils.Base64ToBinary(result);
                    rpt.Content     = buffer;
                    rpt.Description = "Success";
                }
                else
                {
                    result          = sr.ReadLine();
                    rpt.Description = result;
                }

                s.Close();

                rpt.ExportName = "application/pdf";
                return(rpt);
            }
            catch (Exception ex)
            {
                rpt = new CReport()
                {
                    Description = ex.Message
                };
                Write("", rpl.Session.ToString(), rpl.UserID, "==STEP2==: Error Receive :" + ex.Message + ",UserName:"******"");
            }
            return(rpt);
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string expdata = "";

            if (Page.Request.Form["data"] != null)
            {
                expdata = Page.Request.Form["data"].ToString();
                if (expdata != "")
                {
                    string filetype = "xls";
                    if (Page.Request.Form["filetype"] != null && Page.Request.Form["filetype"].ToString() != "")
                    {
                        filetype = Page.Request.Form["filetype"].ToString();
                    }
                    string fileName = "excel_export_" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "." + filetype;

                    Page.Response.ContentType = "text/plain";
                    Page.Response.ClearHeaders();
                    Page.Response.ClearContent();
                    Page.Response.Clear();
                    if (filetype == "csv")
                    {
                        Page.Response.ContentType = "application/ms-excel";// "text/csv";
                    }
                    else if (filetype == "xls")
                    {
                        Page.Response.ContentType = "application/vnd.ms-excel";
                    }
                    Page.Response.ContentEncoding = Encoding.UTF8;
                    Page.Response.Charset         = "UTF-8";
                    Page.Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\";inline Filename=\"{0}\";", fileName));

                    //Them cac byte thieu trong du lieu de danh dau encoding la UTF-8
                    var bBOM = new byte[] { 0xEF, 0xBB, 0xBF };
                    //var bBOM = new byte[] { 254, 255 };
                    Page.Response.OutputStream.Write(bBOM, 0, bBOM.Length);

                    Page.Response.Write(expdata);
                    Page.Response.End();
                }
            }
            else if (Page.Request.QueryString["request"] != null)
            {
                string          request = Page.Request.QueryString["request"].ToString();
                TemplateService service = new TemplateService();
                string          result  = service.ShopSignSummary(System.Configuration.ConfigurationManager.AppSettings["FWS.VnAccounting.ClientKey"].ToString(), request);
                if (result.StartsWith("00"))
                {
                    result = result.Substring(3);
                    byte[] buffer     = CBinaryUtils.Base64ToBinary(result);
                    string exportFile = "excel_export_" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + ".xlsx";
                    Page.Response.ContentType     = "application/ms-excel";// "text/csv";
                    Page.Response.ContentEncoding = Encoding.UTF8;
                    Page.Response.Charset         = "UTF-8";
                    Page.Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\";inline Filename=\"{0}\";", exportFile));
                    Page.Response.OutputStream.Write(buffer, 0, buffer.Length);
                    Page.Response.Flush();
                    Page.Response.End();
                    return;
                }
                //string result = new CSaleSummary
            }



            //else
            //{
            //    Page.Response.ContentType = "text/plain";
            //    Page.Response.Write("page request is invalid!!!");
            //    Page.Response.End();
            //}
        }