예제 #1
0
        /// <summary>
        /// 附件文件分片全部上传好后保存
        /// </summary>
        /// <param name="addFileName"></param>
        /// <param name="flowId"></param>
        /// <returns></returns>
        public FileUploadInfo SaveAccessoryFileOrdinaryChunk(string addFileName)
        {
            if (!addFileName.HasRealValue())
            {
                throw new Exception("请选择文件");
            }

            string fileName = Request["filename"];

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = Server.UrlDecode(fileName);
            }
            var locationid   = Request["locationid"];
            var location     = Request["location"];
            var LocationType = Request["LocationType"];

            if (!LocationType.HasRealValue())
            {
                LocationType = location;
            }
            var basePath = HMSUtil.GetDocPath(LocationType);
            var filePath = basePath + DateTime.Today.ToString("yyyyMMdd");

            DicCreate(filePath);

            int      sysMaxLength  = HMSUtil.GetConfig(EnuInitCode.MaxAttFileSize.ToString()).ToInt(30);
            int      MaxFileLength = 1024 * 1024 * sysMaxLength;
            FileInfo file          = new FileInfo(addFileName);

            var  userToken = AMSAuthentication.GetAuthToken();
            var  service   = new HMSServiceBase();
            var  db        = service.Init();
            long fileSize  = 0;

            try
            {
                if (file.Length > MaxFileLength)
                {
                    file.Delete();
                    throw new Exception($"上传的文件的大小超过限制{sysMaxLength}M");
                }

                fileSize = file.Length;
                var newFileName = fileName.Split('.').FirstOrDefault() + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") + Path.GetExtension(fileName);

                string destinationPath = Path.Combine(filePath, newFileName);
                if (System.IO.File.Exists(destinationPath))
                {
                    System.IO.File.Delete(destinationPath);
                }
                file.MoveTo(destinationPath);

                var accessoryService = new AccessoryService();
                var accessory        = accessoryService.GetBy(location, locationid, fileName);
                if (accessory == null || !accessory.AccessoryId.HasRealValue())
                {
                    accessory = new AccessoryEntity()
                    {
                        AccessoryLocation   = location,
                        AccessoryLocationId = locationid,
                        AccessoryName       = fileName,
                        CreateTime          = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                        CreateUser          = AMSAuthentication.GetAuthToken().UserId,
                        CreateUserName      = AMSAuthentication.GetAuthToken().RealName,
                        CompanyId           = AMSAuthentication.GetAuthToken().CompanyId,
                        OwnerId             = "12345678"
                    };
                }
                else
                {
                    // 如果已经存在,是修改,则删除之前的文件
                    var deletePath = basePath + accessory.FileName;
                    if (System.IO.File.Exists(deletePath))
                    {
                        System.IO.File.Delete(deletePath);
                    }
                }

                // 修改和更新都需要的共用部分
                accessory.FileName = DateTime.Today.ToString("yyyyMMdd") + "/" + newFileName;
                accessory.FileSize = fileSize;
                accessory.LastestAccessDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                return(accessoryService.SaveAccessory(accessory));
            }
            catch (Exception ex)
            {
                file.Delete();
                WebLogger.Log($"FileExp:{ex.Message}");
                throw new Exception(ex.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// 附件文件分片全部上传好后保存
        /// </summary>
        /// <param name="addFileName"></param>
        /// <param name="flowId"></param>
        /// <returns></returns>
        public FileUploadInfo SavePressDetailFileOrdinaryChunk(string addFileName)
        {
            if (!addFileName.HasRealValue())
            {
                throw new Exception("请选择文件");
            }

            string fileName = Request["filename"];

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = Server.UrlDecode(fileName);
            }
            var locationid   = Request["locationid"];
            var location     = Request["location"];
            var LocationType = Request["LocationType"];

            if (!LocationType.HasRealValue())
            {
                LocationType = location;
            }
            var basePath = HMSUtil.GetDocPath(LocationType);
            var filePath = basePath + DateTime.Today.ToString("yyyyMMdd");

            DicCreate(filePath);

            int      sysMaxLength  = HMSUtil.GetConfig(EnuInitCode.MaxAttFileSize.ToString()).ToInt(30);
            int      MaxFileLength = 1024 * 1024 * sysMaxLength;
            FileInfo file          = new FileInfo(addFileName);

            var  userToken = AMSAuthentication.GetAuthToken();
            var  service   = new HMSServiceBase();
            var  db        = service.Init();
            long fileSize  = 0;

            try
            {
                if (!fileName.HasRealValue())
                {
                    throw new Exception("文件不能为空");
                }

                if (file.Length > MaxFileLength)
                {
                    file.Delete();
                    throw new Exception($"上传的文件的大小超过限制{sysMaxLength}M");
                }

                var fileNameSplits = fileName.Split('.');

                fileSize = file.Length;
                var newFileName = fileNameSplits.FirstOrDefault() + "-" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + Path.GetExtension(fileName);

                string destinationPath = Path.Combine(filePath, newFileName);
                file.MoveTo(destinationPath);

                //对指定格式才会对其进行缩略图的整合
                if (new Regex(@"\.(?:jpg|bmp|gif|png)$", RegexOptions.IgnoreCase).IsMatch(fileName.Trim()))
                {
                    var targetfilename = destinationPath.Insert(destinationPath.LastIndexOf("."), "-Thum");
                    if (System.IO.File.Exists(targetfilename))
                    {
                        System.IO.File.Delete(targetfilename);
                    }

                    ImageHelper.MakeThumbnail(destinationPath, targetfilename, 100, 100, "Cut", fileNameSplits.LastOrDefault());
                }

                var accessoryService = new AccessoryService();
                var accessory        = accessoryService.GetBy(location, locationid, "签收证明", fileNameSplits.FirstOrDefault(), fileNameSplits.LastOrDefault());
                if (accessory == null || !accessory.AccessoryId.HasRealValue())
                {
                    accessory = new AccessoryEntity()
                    {
                        AccessoryLocation   = location,
                        AccessoryLocationId = locationid,
                        AccessoryName       = "签收证明",
                        CreateTime          = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                        CreateUser          = AMSAuthentication.GetAuthToken().UserId,
                        CreateUserName      = AMSAuthentication.GetAuthToken().RealName,
                        OwnerId             = "12345678"
                    };
                }
                else
                {
                    // 如果已经存在,是修改,则删除之前的文件
                    var deletePath = basePath + accessory.FileName;
                    if (System.IO.File.Exists(deletePath))
                    {
                        System.IO.File.Delete(deletePath);
                    }
                }

                // 修改和更新都需要的共用部分
                accessory.FileName = DateTime.Today.ToString("yyyyMMdd") + "/" + newFileName;
                accessory.FileSize = fileSize;
                accessory.LastestAccessDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                return(accessoryService.SavePresstbDetailAccessory(accessory));
            }
            catch (Exception ex)
            {
                file.Delete();
                WebLogger.Log($"FileExp:{ex.Message}");
                //  return JResult.Error("上传未成功,请联系网站管理员");
                throw new Exception(ex.Message);
            }
        }