Пример #1
0
 /// <summary>
 ///保存知识库
 /// </summary>
 /// <param name="model"></param>
 /// <param name="Files"></param>
 public void Save(KnowledgesModel model, HttpFileCollectionBase Files)
 {
     if (Files.Count > 0 && Files[0].ContentLength > 0)
     {
         int fileServerType = Convert.ToInt32(WebUtils.GetSettingsValue("WebFileType") == null ? "1" : WebUtils.GetSettingsValue("WebFileType"));
         HttpPostedFileBase file = Files[0];
         string             targetPath = WebUtils.GetSettingsValue("KnowledgesPDFFilePath");
         string             SwfFilePath = WebUtils.GetSettingsValue("KnowledgesSwfFilePath");
         string             targetFileName = StrUtils.GetUniqueFileName(null);
         string             targetFile = string.Format(@"{0}/{1}{2}", targetPath, targetFileName, Path.GetExtension(Files[0].FileName));
         string             targetSwfPath, pdfFilestr, srcSwfFile, tempFileName;
         AttachmentModel    attModel   = null;
         Stream             fileStream = null;
         try
         {
             attModel     = UtilsHelper.FileUpload(WebUtils.GetSettingsValue("WebFileServer"), Files[0], targetFile, (UtilConstants.ServerType)fileServerType);
             fileStream   = UtilsHelper.FileDownload(WebUtils.GetSettingsValue("WebFileServer"), attModel.FileVirtualPath, (UtilConstants.ServerType)fileServerType);
             tempFileName = Guid.NewGuid().ToString();
             pdfFilestr   = CommonUtils.GetPhysicsPath(string.Format("{0}/{1}.pdf", "/tempFile", tempFileName));
             ToolsLib.FileService.NormalFile.SaveInfoToFile(fileStream, pdfFilestr);
             srcSwfFile    = UtilsHelper.PdfToSwf(pdfFilestr, tempFileName + ".swf");
             targetSwfPath = string.Format("{0}/{1}.swf", Path.GetDirectoryName(attModel.FileVirtualPath).Replace("Pdf", "Swf"), Path.GetFileNameWithoutExtension(attModel.FileVirtualPath));
             if (fileServerType == 1)
             {
                 fileStream = new FileStream(srcSwfFile, FileMode.Open);
                 ToolsLib.FileService.NormalFile.SaveInfoToFile(fileStream, targetSwfPath);
             }
             else
             {
                 UtilsHelper.FileUpload(WebUtils.GetSettingsValue("WebFileServer"), srcSwfFile, targetSwfPath, (UtilConstants.ServerType)fileServerType);
             }
             File.Delete(pdfFilestr);
             File.Delete(srcSwfFile);
         }
         catch (Exception e)
         { }
         attModel.FileType = (int)Instrument.Common.Constants.AttachmentBusinessType.本地知识库.GetHashCode();
         attModel.UserId   = LoginHelper.LoginUser.UserId;
         attModel.UserName = LoginHelper.LoginUser.UserName;
         if (model.FileId != 0)//重新上传删除原来文件
         {
             Global.Business.ServiceProvider.AttachmentService.DeleteById(model.FileId);
         }
         Global.Business.ServiceProvider.AttachmentService.Save(attModel);
         model.FileId = attModel.FileId;//新文件位置
     }
     if (model.KnowledgeId == 0)
     {
         model.Creator = LoginHelper.LoginUser.UserName;
         DBProvider.KnowledgesDao.Add(model);
     }
     else
     {
         DBProvider.KnowledgesDao.Update(model);
     }
 }
Пример #2
0
        public void SaveLogandAttach(Sys_BusinessLogModel businessLog)
        {
            if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
            {
                string url = WebUtils.GetSettingsValue("BusinessLogFilePath") + @"/" + StrUtils.GetUniqueFileName(null) + System.IO.Path.GetExtension(Request.Files[0].FileName);

                //上传文件
                var AttachmentModel = UtilsHelper.FileUpload(Request.Files[0], url, (UtilConstants.ServerType)Convert.ToInt32(WebUtils.GetSettingsValue("WebFileType") == null ? "1" : WebUtils.GetSettingsValue("WebFileType")));;

                Global.Business.ServiceProvider.AttachmentService.Save(AttachmentModel);

                businessLog.FileId   = AttachmentModel.FileId;
                businessLog.FileName = Request.Files[0].FileName;
            }
            Global.Business.ServiceProvider.Sys_BusinessLogService.Save(businessLog);
        }
Пример #3
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);
        }
Пример #4
0
        /// <summary>
        /// 保存实体数据.
        /// </summary>
        public void Save(InstrumentCertificationModel model, HttpFileCollectionBase Files)
        {
            if (Files.Count > 0 && Files[0].ContentLength > 0)
            {
                string          targetPath = WebUtils.GetSettingsValue("InstrumentCertificationPath");
                string          targetFile = string.Format(@"{0}/{1}{2}", targetPath, StrUtils.GetUniqueFileName(null), Path.GetExtension(Files[0].FileName));
                AttachmentModel attModel   = UtilsHelper.FileUpload(Files[0], targetFile, (UtilConstants.ServerType)Convert.ToInt32(WebUtils.GetSettingsValue("WebFileType") == null ? "1" : WebUtils.GetSettingsValue("WebFileType")));
                attModel.FileType = (int)UtilConstants.AttachmentType.仪器周检证书;
                attModel.UserId   = LoginHelper.LoginUser.UserId;
                attModel.UserName = LoginHelper.LoginUser.UserName;
                if (model.LogId != 0)//重新上传删除原来文件
                {
                    Global.Business.ServiceProvider.AttachmentService.DeleteById(model.FileId);
                }
                Global.Business.ServiceProvider.AttachmentService.Save(attModel);
                model.FileId = attModel.FileId;//新文件位置
                //model.FileVirtualPath = WebUtils.GetSettingsValue("WebFileServer")+targetFile;
            }
            if (model.LogId == 0)
            {
                model.CreateUser = LoginHelper.LoginUser.UserName;
                model.ItemCode   = Guid.NewGuid().ToString();
                DBProvider.InstrumentCertificationDAO.Add(model);
            }
            else
            {
                DBProvider.InstrumentCertificationDAO.Update(model);
            }
            //找出仪器下到期日期最大并且当前日期在有效期之内同时完成周检的证书记录并更新
            UpdateCertificationAndState(model.InstrumentId);
            //更新上次修改人和修改时间
            Instrument.Common.Models.InstrumentModel instrumentModel = new Instrument.Common.Models.InstrumentModel();
            instrumentModel.InstrumentId   = model.InstrumentId;
            instrumentModel.LastUpdateUser = LoginHelper.LoginUser.UserName;
            ServiceProvider.InstrumentService.UpdateLastUpdateInfo(instrumentModel);

            if (LoginHelper.LoginUserAuthorize.Contains("/Instrument/SynInstrument".ToLower()))
            {
                ServiceProvider.InstrumentService.BeginSynInstrument(model.InstrumentId);
            }
        }
Пример #5
0
        /// <summary>
        /// 上传业务附件
        /// </summary>
        /// <param name="businessNumber"></param>
        /// <param name="model"></param>
        /// <param name="Files"></param>
        public void UploadBusinessAttachment(string businessNumber, BusinessAttachmentModel model, HttpFileCollectionBase Files)
        {
            AttachmentModel attachment = new AttachmentModel();
            string          targetDir  = GetByBusinessTypeAndId((Constants.AttachmentBusinessType)model.BusinessType, businessNumber);


            //默认随机名
            string fileName = Guid.NewGuid().ToString();

            string targetFile = string.Format(@"{0}{1}{2}", targetDir, fileName, System.IO.Path.GetExtension(Files[0].FileName));

            //原始记录上传操作
            attachment = UtilsHelper.FileUpload(Files[0].InputStream, Files[0].FileName, targetFile, (UtilConstants.ServerType)Convert.ToInt32(WebUtils.GetSettingsValue("WebFileType") == null ? "1" : WebUtils.GetSettingsValue("WebFileType")));

            //入库
            Global.Business.ServiceProvider.AttachmentService.Save(attachment);
            model.FileId   = attachment.FileId;
            model.FileName = attachment.FileName;

            Save(model);
        }
Пример #6
0
 //保存仪器照片
 public void SaveInstrumentPic(HttpFileCollectionBase Files, int instrumentId)
 {
     if (Files["InstrumentPic"] != null)
     {
         //保存仪器图片
         string          targetPath = WebUtils.GetSettingsValue("InstrumentPicFilePath");
         string          targetFile = string.Format(@"{0}/{1}{2}", targetPath, StrUtils.GetUniqueFileName(null), Path.GetExtension(Files["InstrumentPic"].FileName));
         AttachmentModel attModel   = UtilsHelper.FileUpload(Files["InstrumentPic"], targetFile, (UtilConstants.ServerType)Convert.ToInt32(WebUtils.GetSettingsValue("WebFileType") == null ? "1" : WebUtils.GetSettingsValue("WebFileType")));
         attModel.FileType = (int)Instrument.Common.Constants.AttachmentBusinessType.仪器照片;
         attModel.UserId   = LoginHelper.LoginUser.UserId;
         attModel.UserName = LoginHelper.LoginUser.UserName;
         Global.Business.ServiceProvider.AttachmentService.Save(attModel);
         BusinessAttachmentModel businessAttachmentModel = new BusinessAttachmentModel();
         businessAttachmentModel.BusinessKeyId = instrumentId;
         businessAttachmentModel.BusinessType  = attModel.FileType;
         businessAttachmentModel.UserName      = LoginHelper.LoginUser.UserName;
         businessAttachmentModel.FileName      = attModel.FileName;
         businessAttachmentModel.FileId        = attModel.FileId;
         Instrument.Business.ServiceProvider.BusinessAttachmentService.Save(businessAttachmentModel);
     }
 }
Пример #7
0
        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 }));
        }
Пример #8
0
        public ActionResult Save(DocumentModel documentModel, FormCollection collection)
        {
            ParamModel documentTypeModel = Global.Business.ServiceProvider.ParamService.GetAll().SingleOrDefault(S => S.ParamCode == Constants.SysParamType.DocumentType);

            if (Request.Files.Count > 0)//有文件上传(新增或修改)
            {
                HttpPostedFileBase fileData = Request.Files[0];
                if (null != fileData && 0 != fileData.ContentLength)
                {
                    string url             = WebUtils.GetSettingsValue("InstrumentDocumentFilePath") + @"/" + StrUtils.GetUniqueFileName(null) + System.IO.Path.GetExtension(Request.Files[0].FileName);
                    var    AttachmentModel = UtilsHelper.FileUpload(Request.Files[0], url, (UtilConstants.ServerType)Convert.ToInt32(WebUtils.GetSettingsValue("WebFileType") == null ? "1" : WebUtils.GetSettingsValue("WebFileType")));
                    Global.Business.ServiceProvider.AttachmentService.Save(AttachmentModel);
                    documentModel.FileId      = AttachmentModel.FileId;
                    documentModel.FileName    = fileData.FileName;
                    documentModel.DocCategory = int.Parse(documentTypeModel.itemsList.SingleOrDefault(S => S.ParamItemName == collection["DocCategory"]).ParamItemValue);
                    documentModel.Remark      = collection["Remark"];
                    documentModel.CreateDate  = System.DateTime.Now;
                    documentModel.Creator     = LoginHelper.LoginUser.UserName;
                    ServiceProvider.DocumentService.Save(documentModel);
                    return(Content("OK"));
                }
                else
                {
                    return(Content("体系文件无效!"));
                }
            }
            else if (documentModel.DocumentId != 0)//修改
            {
                documentModel.DocCategory = int.Parse(documentTypeModel.itemsList.SingleOrDefault(S => S.ParamItemName == collection["DocCategory"]).ParamItemValue);
                documentModel.Remark      = collection["Remark"];
                documentModel.CreateDate  = System.DateTime.Now;
                documentModel.Creator     = LoginHelper.LoginUser.UserName;
                ServiceProvider.DocumentService.Save(documentModel);
                return(Content("OK"));
            }//新增
            else
            {
                return(Content("体系文件无效!"));
            }
        }
Пример #9
0
        public void Synchronous(InstrumentCertificationModel model, Stream stream, string fileName, string targetFileName)
        {
            //(System.IO.Stream inputStream, string sourceFileName, string targetFileName, UtilConstants.ServerType targetServer)
            if (stream != null)
            {
                AttachmentModel attModel = UtilsHelper.FileUpload(stream, fileName, targetFileName, (UtilConstants.ServerType)Convert.ToInt32(WebUtils.GetSettingsValue("WebFileType") == null ? "1" : WebUtils.GetSettingsValue("WebFileType")));
                attModel.FileType = (int)UtilConstants.AttachmentType.仪器周检证书;
                attModel.UserId   = LoginHelper.LoginUser.UserId;
                attModel.UserName = LoginHelper.LoginUser.UserName;
                if (model.LogId != 0)//重新上传删除原来文件
                {
                    Global.Business.ServiceProvider.AttachmentService.DeleteById(model.FileId);
                }
                Global.Business.ServiceProvider.AttachmentService.Save(attModel);
                model.FileId = attModel.FileId;//新文件位置
            }
            if (model.LogId == 0)
            {
                model.CreateUser = LoginHelper.LoginUser.UserName;
                model.ItemCode   = Guid.NewGuid().ToString();
                DBProvider.InstrumentCertificationDAO.Add(model);
            }
            else
            {
                DBProvider.InstrumentCertificationDAO.Update(model);
            }
            //找出仪器下到期日期最大并且当前日期在有效期之内同时完成周检的证书记录并更新
            UpdateCertificationAndState(model.InstrumentId);
            //更新上次修改人和修改时间
            Instrument.Common.Models.InstrumentModel instrumentModel = new Instrument.Common.Models.InstrumentModel();
            instrumentModel.InstrumentId   = model.InstrumentId;
            instrumentModel.LastUpdateUser = LoginHelper.LoginUser.UserName;
            ServiceProvider.InstrumentService.UpdateLastUpdateInfo(instrumentModel);

            if (LoginHelper.LoginUserAuthorize.Contains("/Instrument/SynInstrument".ToLower()))
            {
                ServiceProvider.InstrumentService.BeginSynInstrument(model.InstrumentId);
            }
        }
Пример #10
0
        public ActionResult UploadMutiFile(HttpPostedFileBase fileData, string targetPath)
        {
            string ASPSESSID = Request["ASPSESSID"];
            string retureMsg = "true";

            try
            {
                AttachmentModel model = new AttachmentModel();
                if (UtilConstants.UploadSession == null)
                {
                    UtilConstants.UploadSession = new Hashtable();
                }
                if (!UtilConstants.UploadSession.ContainsKey(ASPSESSID))
                {
                    UtilConstants.UploadSession.Add(ASPSESSID, new List <AttachmentModel>());
                }

                string targetFile = "";
                //Hashtable ht = null;

                //string targetFile = string.Format(@"{0}/", WebUtils.GetSettingsValue("CertificateTemplateFilePath"));
                //Hashtable ht = UtilsHelper.FileUpload(fileData, targetFile, UtilConstants.ServerType.WebFileService);

                //targetFile = string.Format(@"{0}/{1}", targetPath, fileData.FileName);
                //targetFile = string.Format(@"{0}/", targetPath);
                targetFile = string.Format(@"{0}/{1}{2}", targetPath, StrUtils.GetUniqueFileName(null), Path.GetExtension(fileData.FileName));
                model      = UtilsHelper.FileUpload(fileData, targetFile, (UtilConstants.ServerType)Convert.ToInt32(WebUtils.GetSettingsValue("WebFileType") == null ? "1" : WebUtils.GetSettingsValue("WebFileType")));
                //UserModel user = new UserModel();
                //model = Utils.GetAttachmentModel(ht, user);
                ((List <AttachmentModel>)UtilConstants.UploadSession[ASPSESSID]).Add(model);
            }
            catch
            {
                retureMsg = "false";
            }
            return(Content(retureMsg));
        }
Пример #11
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);
        }