Exemple #1
0
        /// <summary>
        /// 获得数字档案文件路径+名称
        /// </summary>
        /// <returns></returns>
        public string GetDocFileName(DocService docService, string sourceFilePath)
        {
            string rentDoccode       = Request["rentDoccode"];
            string rentDocProp       = Request["rentDocProp"];
            string rentdocType       = Request["rentdocType"];
            string rentdoctbDetailId = Request["rentdoctbDetailId"];

            var imagerName = (rentDoccode + "_" + rentDocProp + "_" + rentdocType);

            imagerName = imagerName.Replace(".", "0");  // 替换带有点的

            var filePath = HMSUtil.GetDocPath() + DateTime.Today.ToString("yyyyMMdd");

            DicCreate(filePath);
            var fileIndex = Request["setIndex"];

            if (string.IsNullOrEmpty(fileIndex))
            {
                #region 生成最新的的文件下标

                if (rentdoctbDetailId.HasRealValue())
                {
                    //TODO:需要开启单线程
                    var currentMaxCount = docService.GetDetailMaxFileIndex(rentdoctbDetailId);
                    fileIndex = (currentMaxCount + 1).ToString().PadLeft(4, '0');
                }
                else
                {
                    // 循环取磁盘上最大的临时文件
                    DirectoryInfo dir     = new DirectoryInfo(filePath);
                    FileInfo[]    filearr = dir.GetFiles("*" + imagerName + ".kyee");
                    if (filearr.Any())
                    {
                        var indexList = new List <int>();
                        foreach (var item in filearr)
                        {
                            if (!item.Name.HasRealValue())
                            {
                                continue;
                            }
                            indexList.Add(item.Name.Split('.').FirstOrDefault().Split('_').LastOrDefault().ToInt());
                        }
                        fileIndex = (indexList.Max() + 1).ToString().PadLeft(4, '0');
                    }
                    else
                    {
                        fileIndex = "0001";
                    }
                }

                #endregion
            }

            var fileName        = imagerName + "_" + fileIndex + Path.GetExtension(sourceFilePath);
            var newFileNamePath = filePath + "\\" + fileName;

            // 如果强制改名时,出现重复文件,则直接返回
            if (fileIndex.HasRealValue())
            {
                if (System.IO.File.Exists(newFileNamePath))
                {
                    return("FileExists");
                }
            }

            // 如果是没有保存过的,则需要生成 .kyee 后缀的临时文件
            if (string.IsNullOrEmpty(rentdoctbDetailId))
            {
                newFileNamePath = newFileNamePath + "." + imagerName + ".kyee";
            }

            if (System.IO.File.Exists(newFileNamePath))
            {
                System.IO.File.Delete(newFileNamePath);
            }

            return(newFileNamePath);
        }