Ejemplo n.º 1
0
        /// <summary>
        /// 封装报文文件
        /// </summary>
        /// yaoy    16.07.06
        /// <param name="fileId"></param>
        /// <returns></returns>
        public string CombinaReportData(int fileId)
        {
            int    i          = 0;
            string reportData = string.Empty;

            ICombinaData combinaComData = new CombinaComMessageData();
            ICombinaData combinaPerData = new CombinaPerMessageData();

            ReportFilesInfo reportFilesInfo = GetReportFilesInfoById(fileId);

            int messageFileId = reportFilesInfo == null ? 0 : reportFilesInfo.MessageFileId;
            // 获取服务对象
            int serviceObj = reportFilesInfo == null ? 0 : reportFilesInfo.ServiceObj;

            List <MessageTypeInfo> messageTypeList = GetMessageTypeList(messageFileId);

            if (messageTypeList != null)
            {
                foreach (MessageTypeInfo messageTypeInfo in messageTypeList)
                {
                    if (serviceObj == 1)
                    {
                        string temp = combinaComData.BuildMessageBody(fileId, messageTypeInfo.MessageTypeId, out i);

                        if (temp == "")
                        {
                            reportData += combinaComData.BuildMessageTop(fileId, messageTypeInfo.MessageTypeId, i) + "\r\n" + new DataUtil().BuildMessageTail(i) + "\r\n\r\n";
                        }
                        else
                        {
                            reportData += combinaComData.BuildMessageTop(fileId, messageTypeInfo.MessageTypeId, i) + "\r\n" + temp + new DataUtil().BuildMessageTail(i) + "\r\n\r\n";
                        }
                    }
                    if (serviceObj == 2)
                    {
                        string temp = combinaPerData.BuildMessageBody(fileId, messageTypeInfo.MessageTypeId, out i);

                        if (temp != "")
                        {
                            reportData += combinaPerData.BuildMessageTop(fileId, messageTypeInfo.MessageTypeId, i) + "\r\n\r\n" + temp + "\r\n";
                        }
                    }
                }
                // 去掉最后一个换行符("\r\n")
                reportData = reportData.Substring(0, reportData.Length - 4);
            }

            return(reportData);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 生成txt文件
        /// </summary>
        /// yaoy    16.07.06
        /// <param name="fileId"></param>
        /// <returns></returns>
        public string CreateTxtFile(int fileId, string message)
        {
            string fileName    = string.Empty;
            string txtFileName = string.Empty;
            // 文件路径
            string dirPath = HttpContext.Current.Server.MapPath(path);

            ICombinaData combinaComData = new CombinaComMessageData();
            ICombinaData combinaPerData = new CombinaPerMessageData();

            ReportFilesInfo reportFilesInfo = new DataRule().GetReportFilesInfoById(fileId);

            // 获取服务对象
            int serviceObj = reportFilesInfo == null ? 0 : reportFilesInfo.ServiceObj;

            // 企业报文
            if (serviceObj == 1)
            {
                txtFileName = combinaComData.BuildMessageName(fileId);
            }
            // 个人报文
            if (serviceObj == 2)
            {
                txtFileName = combinaPerData.BuildMessageName(fileId);
            }

            if (!DirFile.IsExistDirectory(dirPath))
            {
                DirFile.CreateDirectory(dirPath);
            }

            if (txtFileName != string.Empty)
            {
                fileName = txtFileName + ".txt";
                string filePath = dirPath + fileName;

                DirFile.CreateFile(filePath);
                DirFile.WriteText(filePath, message, Encoding.GetEncoding("gb2312"));
            }

            return(fileName);
        }