Exemplo n.º 1
0
        /// <summary>
        /// 上传业务附件-自动解压 Add by Raven 2014-12-31
        /// </summary>
        /// <param name="businessNumber"></param>
        /// <param name="model"></param>
        /// <param name="Files"></param>
        public void UploadBusinessAttachmentbyExtract(string businessNumber, BusinessAttachmentModel model, HttpFileCollectionBase Files)
        {
            string targetDir = GetByBusinessTypeAndId((Constants.AttachmentBusinessType)model.BusinessType, businessNumber);
            //获取后缀名
            string Extension = System.IO.Path.GetExtension(Files[0].FileName).ToLower();

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

            //保存
            Files[0].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);

            AttachmentModel         attachment = null;
            BusinessAttachmentModel newmodel   = null;

            foreach (var file in fileList)
            {
                attachment             = new AttachmentModel();
                newmodel               = new BusinessAttachmentModel();
                newmodel.BusinessKeyId = model.BusinessKeyId;
                newmodel.BusinessType  = model.BusinessType;
                newmodel.UserName      = LoginHelper.LoginUser.UserName;
                string fileName       = Guid.NewGuid().ToString();
                string targetFileName = string.Format(@"{0}{1}{2}", targetDir, fileName, Path.GetExtension(file));

                //原始记录上传操作
                attachment = UtilsHelper.FileUpload(file, targetFileName, (UtilConstants.ServerType)Convert.ToInt32(WebUtils.GetSettingsValue("WebFileType") == null ? "1" : WebUtils.GetSettingsValue("WebFileType")));
                //入库
                Global.Business.ServiceProvider.AttachmentService.Save(attachment);
                newmodel.FileId   = attachment.FileId;
                newmodel.FileName = attachment.FileName;
                Save(newmodel);
                //删除临时文件
                File.Delete(file);
            }
            //删除目录
            Directory.Delete(ExtractDir, true);
        }
Exemplo 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);
        }