コード例 #1
0
ファイル: CReportFunction.cs プロジェクト: phinamcn03/ttdk
        public static List <CReportImage> GetListImagesBySession(string pSessionName)
        {
            List <CReportImage> list = new List <CReportImage>();

            try
            {
                DirectoryInfo dirInfo = new DirectoryInfo(CReportConfig.Images_Url);
                if (dirInfo.Exists)
                {
                    FileInfo[] files = dirInfo.GetFiles();
                    foreach (FileInfo file in files)
                    {
                        if (file.Name.IndexOf(pSessionName) != -1)
                        {
                            byte[]       content = GetBytesFromFile(file.FullName);
                            CReportImage image   = new CReportImage();
                            image.Content  = content;
                            image.FileName = file.Name;
                            image.Location = file.DirectoryName;
                            list.Add(image);
                            File.Delete(file.FullName);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CLogManager.WritePL("ReportFunction.GetFilesByName", ex.Message);
            }
            return(list);
        }
コード例 #2
0
ファイル: CReportFunction.cs プロジェクト: phinamcn03/ttdk
        public static string GetDirrectoryInfo(string pDirectoryUrl)
        {
            StringBuilder ret = new StringBuilder();

            try
            {
                string[] dir = Directory.GetDirectories(pDirectoryUrl);
                ret.Append("{");
                if (dir.Length > 0)
                {
                    for (int i = 0; i < dir.Length; i++)
                    {
                        DirectoryInfo dirInfo = new DirectoryInfo(dir[i]);
                        ret.AppendFormat("[\"Name\":\"{0}\"]", dirInfo.Name);
                        if (i != dir.Length - 1)
                        {
                            ret.Append(",");
                        }
                    }
                }
                ret.Append("}");
            }
            catch (Exception ex)
            {
                CLogManager.WritePL("ReportFunction.GetDirrectoryInfo", ex.Message);
            }
            return(ret.ToString());
        }
コード例 #3
0
        private bool ExecuteImport(string ClientKey, string inputValue)
        {
            try
            {
                System.Data.DataSet ds = new CCoreDao().ExecuteAction(ClientKey, inputValue);
                if (ds == null || ds.Tables.Count < 2)
                {
                    return(false);
                }
                if (ds.Tables[1].Rows.Count == 0)
                {
                    return(false);
                }
                if (!ds.Tables[0].Columns.Contains("Result"))
                {
                    return(false);
                }
                var result = ds.Tables[0].Rows[0]["Result"];
                if (result == null || result.ToString() == "0")
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                CLogManager.WritePL("ExecuteImport", ex.ToString());
            }
            return(false);
        }
コード例 #4
0
        protected T CallFunction <T>(int functionID, string inputValue) where T : new()
        {
            try
            {
                DataSet ds = CallFunction(functionID, inputValue);
                //List<T> list = new List<T>();
                if (ds == null)
                {
                    return(default(T));
                }
                if (ds.Tables.Count == 0)
                {
                    return(default(T));
                }

                return(CDb.Map <T>(ds.Tables[0]));
            }
            catch (Exception ex)
            {
                CLogManager.WritePL("CallFunction", ex.Message + " " + ex.StackTrace);
                if (typeof(T) == typeof(CApplicationMessage))
                {
                    return(CDb.Map <T>("<Message Code=\"SYSTEM_ERROR\" Name = \"Unknow Error\" Result=\"0\" Description = \"" + ex.Message + "\" />"));
                    //return (T)new CApplicationMessage() { Code = "SYSTEM_ERROR", Name = "Unknow Error", Description = ex.Message };
                }
            }
            return(default(T));
        }
コード例 #5
0
ファイル: CReportFunction.cs プロジェクト: phinamcn03/ttdk
        public static string CreateFolder(string pFolderName)
        {
            StringBuilder ret      = new StringBuilder();
            string        template = "{{\"Code\":\"{0}\", \"Desc\":\"{1}\"}}";

            try
            {
                string        path    = CReportConfig.Report_Url + "/" + pFolderName;
                DirectoryInfo dirInfo = new DirectoryInfo(path);
                if (!dirInfo.Exists)
                {
                    DirectoryInfo dir = Directory.CreateDirectory(path);
                    if (dir.Exists)
                    {
                        ret.AppendFormat(template, "00", "Folder create successful!");
                    }
                    else
                    {
                        ret.AppendFormat(template, "11", "Folder create false!");
                    }
                }
                else
                {
                    ret.AppendFormat(template, "01", "Folder is exist!");
                }
            }
            catch (Exception ex)
            {
                ret.AppendFormat(template, "99", "Error system!!!: " + ex.Message);
                CLogManager.WritePL("ReportFunction.CreateFolder", ex.Message);
            }
            return(ret.ToString());
        }
コード例 #6
0
ファイル: CGrid.cs プロジェクト: phinamcn03/ttdk
        private static string GetModelsConfig(int userId, int gridId, int languageId)
        {
            string ret = "";

            try
            {
                string inputValue       = string.Format("<InputValue UserID='{0}' GridID='{1}' />", userId, gridId);
                CGridColumnConfig[] lst = service.GetGridConfigColumn(inputValue);
                strColNames = "";
                foreach (CGridColumnConfig cfg in lst)
                {
                    ret         += cfg.ToString();
                    strColNames += "'" + cfg.Heading + "'";
                    if (cfg != lst[lst.Length - 1])
                    {
                        ret         += ",\n";
                        strColNames += ",";
                    }
                }
            }
            catch (Exception ex)
            {
                CLogManager.WritePL("PMSA.iMarkets.Presentation.WebApp.Mods.PriceBoard.Class.GetModelsConfig", ex.Message);
            }
            return(ret);
        }
コード例 #7
0
ファイル: CCoreService.cs プロジェクト: phinamcn03/ttdk
        public string GetContextData(string ClientKey, string inputValue)
        {
            inputValue = CXML.HtmlDecode(inputValue);
            CLogManager.WritePL("GetContextData", "End write response");
            DataSet ds = new CCoreDao().GetContextData(ClientKey, inputValue);

            CLogManager.WritePL("GetContextData", "End write response");
            return(CDataParser.DataSetToCSV(ds));
        }
コード例 #8
0
ファイル: CReport.cs プロジェクト: phinamcn03/ttdk
        private void SetReportParameter(ReportDocument _reportDoc, int pUserID, string pReportSession, int pLanguageID)
        {
            if (_reportDoc == null)
            {
                return;
            }

            try
            {
                if (_reportDoc.ParameterFields.Count > 0)
                {
                    for (int i = 0; i < _reportDoc.ParameterFields.Count; i++)
                    {
                        switch (_reportDoc.ParameterFields[i].Name.ToLower())
                        {
                        case "@userid":
                            _reportDoc.SetParameterValue(i, pUserID);
                            break;

                        case "@session":
                            //su dung cho du lieu la Table, Store, Function
                            _reportDoc.SetParameterValue(i, "" + pReportSession.Replace("'", "") + "");
                            //Su dung cho du lieu la Command
                            //reportDoc.SetParameterValue(reportDoc.ParameterFields[i].Name, "'" + rpl.Session.Replace("'", "") + "'");
                            break;

                        case "@languageid":
                            _reportDoc.SetParameterValue(i, pLanguageID);
                            break;

                        default:
                            if (_reportDoc.ParameterFields[i].DefaultValues != null && _reportDoc.ParameterFields[i].DefaultValues.Count > 0)
                            {
                                _reportDoc.SetParameterValue(i, _reportDoc.ParameterFields[i].DefaultValues[0]);
                            }
                            else
                            {
                                _reportDoc.SetParameterValue(_reportDoc.ParameterFields[i].Name, null);
                            }
                            break;
                        }
                    }
                    //Verifydatabase
                    //_reportDoc.VerifyDatabase();
                }
            }
            catch (Exception ex)
            {
                CLogManager.WritePL("CReport.SetReportParameter Ex", ex.ToString() + ex.StackTrace);
            }
            //if (_reportDoc.IsSubreport) return;
            //for (int i = 0; i < _reportDoc.Subreports.Count; i++)
            //{
            //    SetReportParameter(_reportDoc.Subreports[i], pUserID, pReportSession, pLanguageID);
            //}
        }
コード例 #9
0
ファイル: CGrid.cs プロジェクト: phinamcn03/ttdk
 public static CGridColumnConfig[] GetColumnNameGrid(int userId, int gridId)
 {
     CGridColumnConfig[] ret = null;
     try
     {
         string inputValue = string.Format("<InputValue UserID='{0}' GridID='{1}' />", userId, gridId);
         ret = service.GetGridConfigColumn(inputValue);
     }
     catch (Exception ex)
     {
         CLogManager.WritePL("PMSA.iMarkets.Presentation.WebApp.Mods.PriceBoard.Class.GetModelsConfig", ex.Message);
     }
     return(ret);
 }
コード例 #10
0
ファイル: CReportFunction.cs プロジェクト: phinamcn03/ttdk
 public static byte[] GetBytesFromFile(string filename)
 {
     byte[] buffer = null;
     try
     {
         FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
         buffer = StreamToByteArray(fs);
         fs.Close();
         File.Delete(filename);
     }
     catch (Exception ex)
     {
         CLogManager.WritePL("ReportFunction.GetBytesFromFile", ex.Message);
     }
     return(buffer);
 }
コード例 #11
0
ファイル: CGrid.cs プロジェクト: phinamcn03/ttdk
        /// <summary>
        /// public function
        /// </summary>
        /// <param name="templateid"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        private static string GetGridConfig(int userId, int gridId)
        {
            string ret = "";

            try
            {
                string        inputValue = string.Format("<InputValue UserID='{0}' GridID='{1}' />", userId.ToString(), gridId.ToString());
                CGridConfig[] lst        = service.GetGridConfig(inputValue);
                foreach (CGridConfig cfgtable in lst)
                {
                    ret += cfgtable.ToString();
                }
            }
            catch (Exception ex)
            {
                CLogManager.WritePL("PMSA.iMarkets.Presentation.WebApp.Mods.PriceBoard.Class.GetGridConfig", ex.Message);
            }
            return(ret);
        }
コード例 #12
0
ファイル: CReport.cs プロジェクト: phinamcn03/ttdk
        private static ReportDocument GetReportDocument(string pReportName)
        {
            ReportDocument _reportDoc = new ReportDocument();

            try
            {
                if (pReportName.Trim() != "")
                {
                    string reportUrl = Path.Combine(CReportConfig.Report_Url, pReportName);
                    CLogManager.WritePL("CReport.GetReportDocument Inf", "File report " + reportUrl + "");
                    FileInfo _file = new FileInfo(reportUrl);
                    if (_file.Exists)
                    {
                        _reportDoc.Load(reportUrl, OpenReportMethod.OpenReportByTempCopy);
                        if (_reportDoc.DataSourceConnections != null && _reportDoc.DataSourceConnections.Count > 0)
                        {
                            for (int i = 0; i < _reportDoc.DataSourceConnections.Count; i++)
                            {
                                _reportDoc.DataSourceConnections[i].SetConnection(CReportConfig.ServerIP_Login, CReportConfig.Database_Login, false);// _reportDoc.DataSourceConnections[i].DatabaseName, false);
                                _reportDoc.DataSourceConnections[i].SetLogon(CReportConfig.UserName_Login, CReportConfig.Password_Login);
                            }
                        }
                        //Verify database co the khong can thiet, nen dua vao option de tang toc do
                        if (CReportConfig.RequestVerifyDatabase == "1")
                        {
                            _reportDoc.VerifyDatabase();
                        }
                    }
                    else
                    {
                        CLogManager.WritePL("CReport.GetReportDocument Inf", "File report " + pReportName + " not found.");
                    }
                }
            }
            catch (Exception ex)
            {
                CLogManager.WritePL("CReport.GetReportDocument Ex", ex.ToString());
            }
            return(_reportDoc);
        }
コード例 #13
0
        public static CReport GetReport(int pUserID, string pSession, int pLanguageID, string xmlData, string pExportType)
        {
            CReport report = null;

            try
            {
                CReportDao  face = new CReportDao();
                CReportList rpl  = face.InitReport(xmlData);

                if (!string.IsNullOrEmpty(rpl.OutputFormat))
                {
                    pExportType = rpl.OutputFormat;
                }

                CLogManager.WritePL("GetReport", xmlData);
                if (CReportConfig.UseWinservice == "1")
                {
                    report = new CReport(rpl.Name, rpl.Description, rpl.ReportFileName);
                    //report = new CReport();
                    CReport itemTemp = GetReportFromWinService(rpl, pExportType);
                    report.Content = itemTemp.Content;

                    report.Description = itemTemp.Description;
                    report.ExportName  = itemTemp.ExportName;
                    report.ExportType  = itemTemp.ExportType;
                    return(report);
                }


                CReport _report = new CReport(rpl.Name, rpl.Description, rpl.ReportFileName, pExportType);
                report = _report.GetReportContent(rpl.UserID, rpl.Session, pLanguageID, rpl.ID);
            }
            catch (Exception ex)
            {
                report             = new CReport();
                report.Description = "09 - Read file report error Or Report error. Please check report preview and conntact admin!" + ex.ToString();
                CLogManager.WritePL("CReportUI Ex", "09 - Read file report error Or Report error. Please check report preview and conntact admin!");
            }
            return(report);
        }
コード例 #14
0
ファイル: ReportHandler.ashx.cs プロジェクト: phinamcn03/ttdk
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                context.Response.ContentType = "text/plain";
                string instantid = "";
                if (context.Request["instantid"] != null)
                {
                    instantid = context.Request["instantid"].ToString();
                }

                string file        = context.Server.MapPath("Js/Mods.Report.Filter.js");
                string fileContent = CFile.Read(file);
                fileContent = fileContent.Replace("[INSTANT]", instantid);
                context.Response.Write(fileContent);
                context.Response.Flush();
            }
            catch (Exception ex)
            {
                CLogManager.WritePL("ReportHandler", ex.ToString());
            }
        }
コード例 #15
0
ファイル: CReportFunction.cs プロジェクト: phinamcn03/ttdk
        public static string SaveReport(byte[] pBuffer, string pLocation, string pFileName)
        {
            StringBuilder ret      = new StringBuilder();
            string        template = "{0}|{1}";

            try
            {
                if (pFileName != "") //New
                {
                    DeleteReport(pFileName, pLocation);
                    string url = CReportConfig.Report_Url;
                    if (pLocation != "")
                    {
                        url += "\\" + pLocation;
                    }
                    url += "\\" + pFileName;
                    if (pBuffer.Length > 0)
                    {
                        using (FileStream fs = new FileStream(url, FileMode.Create))
                        {
                            fs.Write(pBuffer, 0, pBuffer.Length);
                            fs.Flush();
                            fs.Close();
                        }
                    }
                    ret.AppendFormat(template, "00", "Create file successful!");
                }
                else //Edit
                {
                    ret.AppendFormat(template, "01", "Update file successful!");
                }
            }
            catch (Exception ex)
            {
                ret.AppendFormat(template, "99", "Error system!!!" + ex.Message);
                CLogManager.WritePL("ReportFunction.SaveReport", ex.Message);
            }
            return(ret.ToString());
        }
コード例 #16
0
ファイル: CReportFunction.cs プロジェクト: phinamcn03/ttdk
        public static string DeleteReport(string pFileName, string pLocation)
        {
            string ret = "09";

            try
            {
                string _path = "";
                if (pLocation.Trim() == "")
                {
                    _path = CReportConfig.Report_Url;
                }
                else
                {
                    _path = CReportConfig.Report_Url + pLocation + "/";
                }
                _path = Path.Combine(_path, pFileName);
                if (CReportConfig.IsDebug)
                {
                    CLogManager.Write("ReportFunction.DeleteReport", "Filename: " + _path, "Report");
                }
                if (File.Exists(_path))
                {
                    File.Delete(_path);
                    ret = "00|Delete " + pFileName + " sucessful";
                }
                else
                {
                    ret = "01|File " + pFileName + " not exits";
                }
            }
            catch (Exception ex)
            {
                ret = "99|Delete file " + pFileName + " error.";
                CLogManager.WritePL("ReportFunction.DeleteReport", ex.Message);
            }
            return(ret);
        }
コード例 #17
0
ファイル: CReportServiceUI.cs プロジェクト: phinamcn03/ttdk
        public static string SaveFile(byte[] buffer, string location, string filename)
        {
            StringBuilder ret  = new StringBuilder();
            string        temp = "{{\"Code\":\"{0}\", \"Desc\":\"{1}\"}}";

            try
            {
                if (filename != "") //New
                {
                    string url = AppDomain.CurrentDomain.BaseDirectory + "Mods/Report/Images/";
                    if (location != "")
                    {
                        url += "\\" + location;
                    }
                    url += "\\" + filename;
                    if (buffer.Length > 0)
                    {
                        using (FileStream fs = new FileStream(url, FileMode.Create))
                        {
                            fs.Write(buffer, 0, buffer.Length);
                        }
                    }
                    ret.AppendFormat(temp, "00", "Create file successful!");
                }
                else //Edit
                {
                    ret.AppendFormat(temp, "00", "Update file successful!");
                }
            }
            catch (Exception ex)
            {
                ret.AppendFormat(temp, "99", "Error system!!!");
                CLogManager.WritePL("ReportFunction.GetDirrectory", ex.Message);
            }
            return(ret.ToString());
        }
コード例 #18
0
        private void ExcelPlusExport(DataTable sData, HttpContext context)
        {
            try
            {
                //CLogManager.WritePL("ExcelPlusExport", "Input Data::" + sData);
                //build Input <InputValue FileJSonData="StrinInBase64"/>
                string inputXml     = "<InputValue />";
                string dataInBase64 = "";// PMSA.Framework.Utils.CBinaryUtils.BinaryToBase64(System.Text.Encoding.UTF8.GetBytes(sData));
                //   inputXml = PMSA.Framework.Utils.CXmlUtils.AddXmlAttribute(inputXml, "InputValue", "FileJSonData", dataInBase64);

                CLogManager.WritePL("ExcelPlusExport", "Input Value::" + inputXml);
                string outputXml = PMSA.iMarkets.Service.Core.Class.CExcelUtilEx.MakeExcelOnlineSub(inputXml, sData);

                CLogManager.WritePL("ExcelPlusExport", "Output Value::" + outputXml);
                // Xy ly output
                string result = PMSA.Framework.Utils.CXmlUtils.GetXmlNodeValue(outputXml, "OutputValue/@Result");
                if (result == "1")
                {
                    dataInBase64 = PMSA.Framework.Utils.CXmlUtils.GetXmlNodeValue(outputXml, "OutputValue/@FileContent");
                    if (!string.IsNullOrEmpty(dataInBase64))
                    {
                        byte[] buffer   = PMSA.Framework.Utils.CBinaryUtils.Base64ToBinary(dataInBase64);
                        string fileName = string.Format("ExportData_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss"));
                        Response.Clear();
                        Response.ClearHeaders();
                        Response.ClearContent();
                        Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
                        Response.AddHeader("Content-Type", "application/Excel");
                        Response.ContentType = "application/vnd.xls";
                        Response.AddHeader("Content-Length", buffer.Length.ToString());
                        byte[] bufferwriter = new byte[1024];
                        int    srcOffset    = 0;
                        int    block        = 1024;
                        while (srcOffset < buffer.Length)
                        {
                            if (srcOffset + 1024 > buffer.Length)
                            {
                                block = buffer.Length - srcOffset;
                            }
                            System.Buffer.BlockCopy(buffer, srcOffset, bufferwriter, 0, block);
                            srcOffset += 1024;
                            Response.BinaryWrite(bufferwriter);
                        }
                        //Response.End();
                        //File.Delete(filePath);
                    }
                }
                else
                {
                    string message = PMSA.Framework.Utils.CXmlUtils.GetXmlNodeValue(outputXml, "OutputValue/@ErrorMessage");
                    //Response.Write(message);
                    throw new Exception(message);
                }
                Context.ApplicationInstance.CompleteRequest();
            }
            catch (Exception ex)
            {
                CLogManager.WritePL("ExcelPlusExport", ex.ToString());
                throw ex;
            }
        }
コード例 #19
0
ファイル: CReport.cs プロジェクト: phinamcn03/ttdk
        public CReport GetReportContent(int pUserID, string pReportSession, int pLanguageID, int ReportID)
        {
            CReport _report = new CReport();

            _report.Name       = this.Name;
            _report.Title      = this.Title;
            _report.ReportUrl  = this.ReportUrl;
            _report.ExportName = this.ExportName;
            _report.ExportType = this.ExportType;
            _report.Session    = pReportSession;

            try
            {
                //Neu file template la HTML
                if (_report.ReportUrl.EndsWith(".htm") || _report.ReportUrl.EndsWith(".html"))
                {
                    return(new CHTMLReport().GetReport(_report));
                }

                string _htmlFileName = "";
                if (_report.ReportUrl.Trim() != "" && _report.ReportUrl.ToLower().IndexOf("rpt") != -1)
                {
                    CLogManager.WritePL("CReport.GetReportContent", "Beg GetReportDocument ");
                    ReportDocument _reportDoc = GetReportDocument(_report.ReportUrl);
                    CLogManager.WritePL("CReport.GetReportContent", "End GetReportDocument ");
                    SetReportParameter(_reportDoc, pUserID, pReportSession, pLanguageID);
                    CLogManager.WritePL("CReport.GetReportContent", "End SetReportParameter ");
                    if (_reportDoc != null)
                    {
                        /*if (_reportDoc.ParameterFields.Count > 0)
                         * {
                         *  for (int i = 0; i < _reportDoc.ParameterFields.Count; i++)
                         *  {
                         *      switch (_reportDoc.ParameterFields[i].Name.ToLower())
                         *      {
                         *          case "@userid":
                         *              _reportDoc.SetParameterValue(_reportDoc.ParameterFields[i].Name, pUserID);
                         *              break;
                         *          case "@session":
                         *              //su dung cho du lieu la Table, Store, Function
                         *              _reportDoc.SetParameterValue(_reportDoc.ParameterFields[i].Name, "" + pReportSession.Replace("'", "") + "");
                         *              //Su dung cho du lieu la Command
                         *              //reportDoc.SetParameterValue(reportDoc.ParameterFields[i].Name, "'" + rpl.Session.Replace("'", "") + "'");
                         *              break;
                         *          case "@languageid":
                         *              _reportDoc.SetParameterValue(_reportDoc.ParameterFields[i].Name, pLanguageID);
                         *              break;
                         *          default:
                         *              if (_reportDoc.ParameterFields[i].DefaultValues != null && _reportDoc.ParameterFields[i].DefaultValues.Count > 0)
                         *                  _reportDoc.SetParameterValue(_reportDoc.ParameterFields[i].Name, _reportDoc.ParameterFields[i].DefaultValues[0]);
                         *              break;
                         *      }
                         *  }
                         * }
                         * */

                        _reportDoc.PrintOptions.Dispose();
                        Stream _stream = null;
                        CLogManager.WritePL("CReport.GetReportContent", "Beg Export ");
                        switch (this.ExportName.ToLower())
                        {
                        case CExportName.Document:
                            _report.ExportName = CExportContentType.Document;
                            _stream            = _reportDoc.ExportToStream(ExportFormatType.WordForWindows);
                            _reportDoc.Close();
                            break;

                        case CExportName.Excel:
                            _report.ExportName = CExportContentType.Excel;
                            _stream            = _reportDoc.ExportToStream(ExportFormatType.Excel);

                            _reportDoc.Close();
                            break;

                        case CExportName.Html:
                            _report.ExportName = CExportContentType.Html;
                            _htmlFileName      = AppDomain.CurrentDomain.BaseDirectory + pReportSession + ".htm";
                            /*Export to HTML*/
                            _reportDoc.ExportToDisk(ExportFormatType.HTML40, _htmlFileName);     /*Sinh ra the DIV*/
                            //reportDoc.ExportToDisk(ExportFormatType.HTML32, filename); /*Sinh ra the Table*/
                            _reportDoc.Close();

                            /*Get HTML Content to byte array*/
                            _report.Content         = CReportFunction.GetBytesFromFile(_htmlFileName);
                            _report.ListReportImage = CReportFunction.GetListImagesBySession(pReportSession);
                            break;

                        case CExportName.Report:
                            _report.ExportName = CExportContentType.Document;
                            _stream            = _reportDoc.ExportToStream(ExportFormatType.CrystalReport);
                            _reportDoc.Close();
                            break;

                        default:     //PDF
                            _report.ExportName = CExportContentType.PDF;
                            _stream            = _reportDoc.ExportToStream(ExportFormatType.PortableDocFormat);
                            _reportDoc.Close();
                            break;
                        }
                        CLogManager.WritePL("CReport.GetReportContent", "End Export ");
                        if (_stream != null && _htmlFileName == "") //Not HTML
                        {
                            _report.Content = CReportFunction.StreamToByteArray(_stream);
                        }
                    }
                    else
                    {
                        _report.Description = "03 - Report file is not exits Or Load report data fail.";
                        CLogManager.WritePL("User:"******"ReportSession" + pReportSession + ", 03 - Report file is not exits Or Load report fail.");
                    }
                }
                else
                {
                    _report.Description = "01 - ReportFileName is null. Check database again!";
                    CLogManager.WritePL("User:"******"ReportID " + pReportSession + ", 01 - ReportFileName is null. Check database again!");
                }
            }
            catch (Exception ex)
            {
                CLogManager.WritePL("CReport.GetReportContent Ex", ex.ToString() + ex.StackTrace);
            }
            return(_report);
        }
コード例 #20
0
ファイル: ReportViewer.ashx.cs プロジェクト: phinamcn03/ttdk
        public void ProcessRequest(HttpContext context)
        {
            HttpResponse response = context.Response;
            HttpRequest  request  = context.Request;

            try
            {
                string exportTo    = "pdf",
                       requestFrom = "0",
                       inputValue  = "<InputValue ReportID=\"1\" UserID=\"1\"/>",
                       filedlid    = "",
                       rsid        = "";
                int languageid     = 129;

                CSession session = new CSession();
                try
                {
                    if (request.Form["ExportTo"] != null)
                    {
                        exportTo = request.Form["ExportTo"].ToString();
                    }
                    else if (request.QueryString["ExportTo"] != null)
                    {
                        exportTo = HttpUtility.HtmlDecode(request.QueryString["ExportTo"].ToString());
                    }

                    if (request.Form["InputValue"] != null)
                    {
                        inputValue = request.Form["InputValue"].ToString();
                    }
                    else if (request.QueryString["InputValue"] != null)
                    {
                        inputValue = HttpUtility.UrlDecode(request.QueryString["InputValue"].ToString());
                    }

                    if (request.QueryString["filedlid"] != null)
                    {
                        filedlid = request.QueryString["filedlid"].ToString();
                    }
                    if (request.QueryString["rsid"] != null)
                    {
                        rsid = request.QueryString["rsid"].ToString();
                    }

                    HttpContext.Current.Session.Timeout = 1 * 60 * 6;
                    //download file excel
                    if (filedlid != "")
                    {
                        if (filedlid == session.Session && HttpContext.Current.Session[session.Session + rsid] != null)
                        {
                            ExcelResponse excl     = (ExcelResponse)HttpContext.Current.Session[session.Session + rsid];
                            string        fileName = excl.Name + excl.Session + "." + excl.ExportType;
                            response.ClearHeaders();
                            response.ClearContent();
                            response.ContentType = excl.ExportName;
                            response.Charset     = "";
                            response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\";inline Filename=\"{0}\";", fileName));
                            response.BinaryWrite(excl.Content);
                            HttpContext.Current.Session[session.Session + rsid] = null;
                        }
                        else
                        {
                            string messageInfo = "Report session expired or export file has download. Please run new export again.";
                            response.ClearHeaders();
                            response.ClearContent();
                            response.ContentType = "text/html";
                            response.AddHeader("Content-Length", messageInfo.Length.ToString());
                            response.Charset = "";
                            response.Write(messageInfo);
                        }
                        return;
                    }

                    try
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(inputValue);
                        XmlAttribute xmlUser = doc.CreateAttribute("UserID");
                        xmlUser.Value = session.UserID.ToString();
                        doc.DocumentElement.SetAttributeNode(xmlUser);
                        XmlAttribute xmlSession = doc.CreateAttribute("Session");
                        xmlSession.Value = session.Session;
                        doc.DocumentElement.SetAttributeNode(xmlSession);

                        inputValue = doc.OuterXml;

                        XmlElement node = (XmlElement)doc.SelectSingleNode("/InputValue");
                        languageid  = int.Parse(node.Attributes["LanguageID"].Value);
                        requestFrom = node.Attributes["RequestFrom"].Value;
                    }
                    catch (Exception ex)
                    {
                        string s = ex.Message;
                    }
                }
                catch (Exception ex)
                {
                    CLogManager.WritePL("CReportViewerUI.Request", ex.Message);
                }

                CReportService rfs     = new CReportService();
                CReport        item    = null;
                byte[]         jsBytes = null;
                //Set time out call service
                rfs.Timeout = 1000 * 60 * 15;
                item        = rfs.GetReport(session.UserID, session.Session, languageid, inputValue, exportTo);

                if (item != null && item.Content != null && item.Content.Length > 0)
                {
                    if (item.ExportType != null)
                    {
                        exportTo = item.ExportType;
                    }

                    response.ClearHeaders();
                    response.ClearContent();
                    response.ContentType = item.ExportName;
                    response.Charset     = "";
                    response.AddHeader("Content-Disposition", String.Format("filename=\"{0}\";inline Filename=\"{0}\";", HttpUtility.UrlEncode(item.Name.Replace(',', ' ') + session.Session + "." + item.ExportType))); //Parse out the file name in path here

                    int ContentLength = item.Content.Length;
                    //Add js to html: resize window, show image for browsers
                    if (exportTo.ToLower() == "html")
                    {
                        string js = CReportServiceUI.GetHtmlFunction(requestFrom);
                        jsBytes = new byte[js.Length];
                        System.Text.Encoding.ASCII.GetBytes(js.ToCharArray(), 0, js.Length, jsBytes, 0);
                        ContentLength += jsBytes.Length;
                        response.AddHeader("Content-Length", ContentLength.ToString());

                        //write js include header
                        response.OutputStream.Write(jsBytes, 0, jsBytes.Length);
                        response.Flush();
                    }
                    else if (exportTo.ToLower() == "xls" || exportTo.ToLower() == "xlsx")
                    {
                        //write text description when file download is excel
                        ExcelResponse excelResponse = new ExcelResponse(item);
                        HttpContext.Current.Session[session.Session + item.Session] = excelResponse;
                        //write html file: export done and link download
                        if (response.StatusCode == 200)
                        {
                            response.ClearHeaders();
                            response.ClearContent();
                            response.ContentType = "text/html";
                            response.AddHeader("Content-Disposition", "inline Filename=\"" + session.Session + ".htm\";");
                            response.Charset = "";
                            //response.AddHeader("Content-Length", ContentLength.ToString());
                            string _link = "ReportViewer.ashx?filedlid=" + session.Session + "&rsid=" + item.Session;
                            response.Write("Export to EXCEL done..., <a href=\"" + _link + "\" target=\"_blank\">download</a>.");
                        }
                        return;
                    }
                    else
                    {
                        response.AddHeader("Content-Length", ContentLength.ToString());
                    }

                    //load data block 10MB
                    int count = 1024 * 1024 * 1;
                    if (ContentLength < count)
                    {
                        response.BinaryWrite(item.Content);
                    }
                    else
                    {
                        Stream s      = new MemoryStream(item.Content);
                        byte[] buffer = new byte[count];
                        while (ContentLength > 0 && response.IsClientConnected)
                        {
                            int lengthRead = s.Read(buffer, 0, count);
                            response.OutputStream.Write(buffer, 0, lengthRead);
                            response.Flush();
                            ContentLength -= lengthRead;
                        }
                    }

                    //write image to web server
                    if (exportTo.ToLower() == "html" && item.ListReportImage.Length > 0)
                    {
                        for (int i = 0; i < item.ListReportImage.Length; i++)
                        {
                            CReportImage image = item.ListReportImage[i];
                            CReportServiceUI.SaveFile(image.Content, "", image.FileName);
                        }
                    }
                }
                else
                {
                    response.ContentType = "text/plain";
                    response.Write(item.Description);
                }
            }
            catch (Exception ex)
            {
                response.ClearHeaders();
                response.ClearContent();
                response.Charset     = "";
                response.ContentType = "text/plain";
                response.Write("99. Export error exception:: " + ex.Message + "\n" + ex.ToString());
                CLogManager.WritePL("CReportViewerUI.GetReportDataById", ex.Message);
            }
        }
コード例 #21
0
ファイル: PrintPreview.aspx.cs プロジェクト: phinamcn03/ttdk
        protected void Page_Load(object sender, EventArgs e)
        {
            string expdata = "";

            try
            {
                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.Flush();
                        Page.Response.SuppressContent = true;
                        HttpContext.Current.ApplicationInstance.CompleteRequest();
                        //Page.Response.End();
                    }
                }
                else if (Page.Request.QueryString["request"] != null)
                {
                    string      request  = Page.Request.QueryString["request"].ToString();
                    string      fileName = "excel_export_" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + ".csv";
                    CoreService core     = new CoreService();
                    core.Timeout = 360 * 1000 * 60;
                    CLogManager.WritePL("ExportExcel", "Begin call data");
                    string csv = core.GetContextData(System.Configuration.ConfigurationManager.AppSettings["FWS.VnAccounting.ClientKey"].ToString(), request);
                    CLogManager.WritePL("ExportExcel", "End call data");
                    csv = csv.Substring(csv.IndexOf("\n###\n") + 5);
                    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}\";", 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);
                    CLogManager.WritePL("ExportExcel", "Begin write response");
                    Page.Response.Write(csv);
                    CLogManager.WritePL("ExportExcel", "End write response");
                    Page.Response.Flush();
                    Page.Response.SuppressContent = true;
                    HttpContext.Current.ApplicationInstance.CompleteRequest();
                    //Page.Response.End();
                }
                //else
                //{
                //    Page.Response.ContentType = "text/plain";
                //    Page.Response.Write("page request is invalid!!!");
                //    Page.Response.End();
                //}
            }
            catch (Exception ex)
            {
                CLogManager.WritePL("ExportExcel", ex.ToString());
                Page.Response.ContentType = "text/plain";
                Page.Response.Write(ex.Message);
                //Page.Response.Write(ex.ToString());
                //Page.Response.Write(ex.StackTrace);
            }
        }
コード例 #22
0
ファイル: ReportService.ashx.cs プロジェクト: phinamcn03/ttdk
        public void ProcessRequest(HttpContext context)
        {
            HttpResponse response = context.Response;
            HttpRequest  request  = context.Request;

            try
            {
                string   session = "", exportTo = "pdf", inputValue = "<InputValue ReportID=\"1\" UserID=\"1\"/>";
                int      userid = 1, languageid = 129;
                string   requestFrom = "0";
                CSession ses         = new CSession();
                try
                {
                    if (request.QueryString["ExportTo"] != null)
                    {
                        exportTo = request.QueryString["ExportTo"].ToString();
                    }
                    if (request.QueryString["InputValue"] != null)
                    {
                        inputValue = request.QueryString["InputValue"].ToString();
                    }

                    userid  = ses.UserID;
                    session = ses.Session;
                    try
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(inputValue);
                        XmlAttribute xmlUser = doc.CreateAttribute("UserID");
                        xmlUser.Value = userid.ToString();
                        doc.DocumentElement.SetAttributeNode(xmlUser);
                        XmlAttribute xmlSession = doc.CreateAttribute("Session");
                        xmlSession.Value = session;
                        doc.DocumentElement.SetAttributeNode(xmlSession);

                        XmlElement node = (XmlElement)doc.SelectSingleNode("/InputValue");
                        languageid  = int.Parse(node.Attributes["LanguageID"].Value);
                        requestFrom = node.Attributes["RequestFrom"].Value;
                    }
                    catch (Exception ex)
                    {
                        string s = ex.Message;
                    }
                }
                catch (Exception ex)
                {
                    CLogManager.WritePL("CReportViewerUI.Request", ex.Message);
                }

                CReportService rfs     = new CReportService();
                CReport        item    = null;
                byte[]         jsBytes = null;
                //Set time out call service
                rfs.Timeout = 1000 * 60 * 15;
                item        = rfs.GetReport(userid, session, languageid, inputValue, exportTo);

                if (item != null && item.Content != null && item.Content.Length > 0)
                {
                    response.ClearHeaders();
                    response.ClearContent();
                    response.ContentType = item.ExportName;
                    response.Charset     = "";
                    response.AddHeader("Content-Disposition", "inline Filename=" + item.Name.Replace(',', ' ') + session + "." + item.ExportType + ";"); //Parse out the file name in path here

                    int ContentLength = item.Content.Length;
                    //Add js to html: resize window, show image for browsers
                    if (exportTo.ToLower() == "html")
                    {
                        string js = CReportServiceUI.GetHtmlFunction(requestFrom);
                        jsBytes = new byte[js.Length];
                        System.Text.Encoding.ASCII.GetBytes(js.ToCharArray(), 0, js.Length, jsBytes, 0);
                        ContentLength += jsBytes.Length;
                        response.AddHeader("Content-Length", ContentLength.ToString());

                        //write js include header
                        response.OutputStream.Write(jsBytes, 0, jsBytes.Length);
                        response.Flush();
                    }
                    else
                    {
                        response.AddHeader("Content-Length", ContentLength.ToString());
                    }

                    //load data block 10MB
                    int count = 1024 * 1024 * 10;
                    if (ContentLength < count)
                    {
                        response.BinaryWrite(item.Content);
                    }
                    else
                    {
                        Stream s      = new MemoryStream(item.Content);
                        byte[] buffer = new byte[count];
                        while (ContentLength > 0 && response.IsClientConnected)
                        {
                            int lengthRead = s.Read(buffer, 0, count);
                            response.OutputStream.Write(buffer, 0, lengthRead);
                            response.Flush();
                            ContentLength -= lengthRead;
                        }
                    }
                    //write image to web server
                    if (exportTo.ToLower() == "html" && item.ListReportImage.Length > 0)
                    {
                        for (int i = 0; i < item.ListReportImage.Length; i++)
                        {
                            CReportImage image = item.ListReportImage[i];
                            CReportServiceUI.SaveFile(image.Content, "", image.FileName);
                        }
                    }
                }
                else
                {
                    response.ContentType = "text/plain";
                    response.Write(item.Description);
                }
            }
            catch (Exception ex)
            {
                response.ClearHeaders();
                response.ClearContent();
                response.Charset     = "";
                response.ContentType = "text/plain";
                response.Write("99. Report not found, please check again!!!");
                CLogManager.WritePL("CReportViewerUI.GetReportDataById", ex.Message);
            }
        }
コード例 #23
0
 private static void Write(string userName, string session, int userId, string value)
 {
     CLogManager.WritePL("ReportExportDocument", value);
 }