public ActionResult ReadCert(string Id)
        {
            int certId = UtilsHelper.Decrypt2Int(Id);

            Global.Common.Models.AttachmentModel model = Global.Business.ServiceProvider.AttachmentService.GetById(certId);
            string tempPath      = "/tempFile/";
            string tempFileName  = string.Format("{0}.swf", Guid.NewGuid().ToString());
            string webFileServer = WebUtils.GetSettingsValue("WebFileServer");
            string userId        = WebUtils.GetSettingsValue("WebFileServerUser");
            string pwd           = WebUtils.GetSettingsValue("WebFileServerPwd");
            string oldFileSwf    = model.FileVirtualPath.Replace(".pdf", ".swf");

            try
            {
                if (!UtilsHelper.IsExistInFSServer(webFileServer, oldFileSwf, userId, pwd))
                {
                    if (UtilsHelper.IsExistInFSServer(webFileServer, model.FileVirtualPath, userId, pwd))
                    {
                        Stream swfStream  = UtilsHelper.FileDownload(model.FileAccessPrefix, model.FileVirtualPath, UtilConstants.ServerType.WebFileService);
                        string pdfFilestr = CommonUtils.GetPhysicsPath(string.Format("{0}{1}.pdf", tempPath, Guid.NewGuid()));
                        ToolsLib.FileService.NormalFile.SaveInfoToFile(swfStream, pdfFilestr);
                        string swfSourceFile = UtilsHelper.PdfToSwf(pdfFilestr, tempFileName);
                        model.FileVirtualPath = string.Format("{0}{1}", tempPath, Path.GetFileName(swfSourceFile));
                        UtilsHelper.FileUpload(model.FileAccessPrefix, swfSourceFile, oldFileSwf, UtilConstants.ServerType.WebFileService);
                    }
                }
                else
                {
                    Stream swfStream  = UtilsHelper.FileDownload(model.FileAccessPrefix, oldFileSwf, UtilConstants.ServerType.WebFileService);
                    string swfFilestr = CommonUtils.GetPhysicsPath(string.Format("{0}{1}", tempPath, tempFileName));
                    ToolsLib.FileService.NormalFile.SaveInfoToFile(swfStream, swfFilestr);
                    model.FileVirtualPath = string.Format("{0}{1}", tempPath, tempFileName);
                }
            }
            catch (Exception e)
            {
                return(Content("浏览的文件已经顺坏或者加密"));
            }
            return(RedirectToAction("ReadPdf", "SysManage/Common", new { filePath = model.FileVirtualPath }));
        }
Esempio n. 2
0
        /// <summary>
        /// 上传仪器证书
        /// </summary>
        /// <param name="businessNumber"></param>
        /// <param name="model"></param>
        /// <param name="Files"></param>
        public string UploadCerts(HttpPostedFileBase Files, ref string LogFiledName)
        {
            string Msg       = "无匹配证书!";
            string targetDir = WebUtils.GetSettingsValue("InstrumentCertificationPath");
            //获取后缀名
            string Extension = System.IO.Path.GetExtension(Files.FileName).ToLower();

            ToolsLib.FileService.FileCompress fc = new ToolsLib.FileService.FileCompress();
            //解压包的路径
            string newFile = ToolsLib.Utility.CommonUtils.GetPhysicsPath("/tempFile/" + Guid.NewGuid().ToString() + Extension);

            //保存
            Files.SaveAs(newFile);
            string ExtractDir = ToolsLib.Utility.CommonUtils.GetPhysicsPath("/tempFile/" + Guid.NewGuid().ToString());
            string ext        = fc.Extract(newFile, ExtractDir);

            //解压后删除临时文件
            File.Delete(newFile);
            //获取目录下的文件
            string[]          fileList   = Directory.GetFiles(ExtractDir, "*", SearchOption.AllDirectories);
            IList <Hashtable> Recordlist = new List <Hashtable>();

            Global.Common.Models.AttachmentModel attachment = null;
            string CertName = string.Empty;

            foreach (var file in fileList)
            {
                Hashtable ht = new Hashtable();
                CertName = Path.GetFileNameWithoutExtension(file);
                if (System.IO.Path.GetExtension(file).ToLower() == ".pdf")
                {
                    IList <InstrumentCertificationModel> list = ServiceProvider.InstrumentCertificationService.GetListByCertificationCode(CertName);
                    if (list.Count > 0)
                    {
                        attachment = new Global.Common.Models.AttachmentModel();
                        string fileName       = Guid.NewGuid().ToString();
                        string targetFileName = string.Format(@"{0}/{1}{2}", targetDir, fileName, Path.GetExtension(file));
                        try
                        {
                            //原始记录上传操作
                            attachment = UtilsHelper.FileUpload(file, targetFileName, (UtilConstants.ServerType)Convert.ToInt32(WebUtils.GetSettingsValue("WebFileType") == null ? "1" : WebUtils.GetSettingsValue("WebFileType")));
                            //入库
                            Global.Business.ServiceProvider.AttachmentService.Save(attachment);
                            ServiceProvider.InstrumentCertificationService.UpdateCertFile(list, attachment);
                            Msg = "OK";
                            Recordlist.Add(setUploadLog(Path.GetFileName(file), "成功", ""));
                        }
                        catch (Exception ex)
                        {
                            Recordlist.Add(setUploadLog(Path.GetFileName(file), "失败", "上传证书出现异常"));
                            log.ErrorFormat("{0},证书上传出现异常:{1}", Path.GetFileName(file), ex);
                            continue;
                        }
                    }
                    else
                    {
                        Recordlist.Add(setUploadLog(Path.GetFileName(file), "失败", "证书信息不存在"));
                    }
                }
                else
                {
                    Recordlist.Add(setUploadLog(Path.GetFileName(file), "失败", "文件格式不正确"));
                }
                File.Delete(file);
            }
            LogFiledName = SetCertsLog(Recordlist);
            //删除目录
            Directory.Delete(ExtractDir, true);
            return(Msg);
        }