/// <summary> /// 上传多个文件 /// </summary> /// <param name="saveForm"></param> /// <returns></returns> public string SaveMultipleUploadFiles(FormCollection saveForm) { string tableName = PageReq.GetForm("tableName"); tableName = !string.IsNullOrEmpty(PageReq.GetForm("tableName")) ? PageReq.GetForm("tableName") : PageReq.GetForm("tbName"); var formKeys = saveForm.AllKeys; if (tableName == "" && formKeys.Contains("tableName")) { tableName = saveForm["tableName"]; } if (tableName == "" && formKeys.Contains("tbName")) { tableName = saveForm["tbName"]; } string keyName = formKeys.Contains("keyName") ? saveForm["keyName"] : PageReq.GetForm("keyName"); string keyValue = formKeys.Contains("keyValue") ? saveForm["keyValue"] : PageReq.GetForm("keyValue"); if (string.IsNullOrEmpty(keyName)) { keyName = saveForm["keyName"]; } if (string.IsNullOrEmpty(keyValue) || keyValue == "0") { keyValue = saveForm["keyValue"]; } string localPath = saveForm.AllKeys.Contains("uploadFileList") ? saveForm["uploadFileList"] : PageReq.GetForm("uploadFileList"); string fileSaveType = saveForm["fileSaveType"] != null ? saveForm["fileSaveType"] : "multiply"; int fileTypeId = PageReq.GetFormInt("fileTypeId"); if (formKeys.Contains("fileTypeId")) { int.TryParse(saveForm["fileTypeId"], out fileTypeId); } int fileObjId = PageReq.GetFormInt("fileObjId"); if (formKeys.Contains("fileObjId")) { int.TryParse(saveForm["fileObjId"], out fileObjId); } int uploadType = PageReq.GetFormInt("uploadType"); if (formKeys.Contains("uploadType")) { int.TryParse(saveForm["uploadType"], out uploadType); } int fileRel_profId = PageReq.GetFormInt("fileRel_profId"); if (formKeys.Contains("fileRel_profId")) { int.TryParse(saveForm["fileRel_profId"], out fileRel_profId); } int fileRel_stageId = PageReq.GetFormInt("fileRel_stageId"); if (formKeys.Contains("fileRel_stageId")) { int.TryParse(saveForm["fileRel_stageId"], out fileRel_stageId); } int fileRel_fileCatId = PageReq.GetFormInt("fileRel_fileCatId"); if (formKeys.Contains("fileRel_fileCatId")) { int.TryParse(saveForm["fileRel_fileCatId"], out fileRel_fileCatId); } int structId = PageReq.GetFormInt("structId"); if (formKeys.Contains("structId")) { int.TryParse(saveForm["structId"], out structId); } bool isPreDefine = saveForm["isPreDefine"] != null?bool.Parse(saveForm["isPreDefine"]) : false; Dictionary <string, string> propDic = new Dictionary <string, string>(); FileOperationHelper opHelper = new FileOperationHelper(); List <InvokeResult <FileUploadSaveResult> > result = new List <InvokeResult <FileUploadSaveResult> >(); //替换会到之网络路径错误,如:\\192.168.1.150\D\A\1.jpg //localPath = localPath.Replace("\\\\", "\\"); #region 如果保存类型为单个single 则删除旧的所有关联文件 if (!string.IsNullOrEmpty(fileSaveType)) { if (fileSaveType == "single") { //opHelper.DeleteFile(tableName, keyName, keyValue); opHelper.DeleteFile(tableName, keyName, keyValue, fileObjId.ToString()); } } #endregion #region 通过关联读取对象属性 if (!string.IsNullOrEmpty(localPath.Trim())) { string[] fileStr = Regex.Split(localPath, @"\|H\|", RegexOptions.IgnoreCase); Dictionary <string, string> filePath = new Dictionary <string, string>(); Dictionary <string, string> filePathInfo = new Dictionary <string, string>(); string s = fileSaveType.Length.ToString(); foreach (string file in fileStr) { if (string.IsNullOrEmpty(file)) { continue; // 防止空数据插入的情况 } string[] filePaths = Regex.Split(file, @"\|Y\|", RegexOptions.IgnoreCase); if (filePaths.Length > 0) { string[] subfile = Regex.Split(filePaths[0], @"\|Z\|", RegexOptions.IgnoreCase); if (subfile.Length > 0) { if (!filePath.Keys.Contains(subfile[0])) { if (filePaths.Length == 3) { filePath.Add(subfile[0], filePaths[1]); filePathInfo.Add(subfile[0], filePaths[2]); } else if (filePaths.Length == 2 || filePaths.Length > 3) { filePath.Add(subfile[0], filePaths[1]); } else { filePath.Add(subfile[0], ""); } } } } } if (fileObjId != 0) { List <BsonDocument> docs = new List <BsonDocument>(); docs = dataOp.FindAllByKeyVal("FileObjPropertyRelation", "fileObjId", fileObjId.ToString()).ToList(); List <string> strList = new List <string>(); strList = docs.Select(t => t.Text("filePropId")).Distinct().ToList(); var doccList = dataOp.FindAllByKeyValList("FileProperty", "filePropId", strList); foreach (var item in doccList) { var formValue = saveForm[item.Text("dataKey")]; if (formValue != null) { propDic.Add(item.Text("dataKey"), formValue.ToString()); } } } #region 文档直接关联属性 foreach (var tempKey in saveForm.AllKeys) { if (!string.IsNullOrEmpty(tempKey) && tempKey.Contains("Property_")) { var formValue = saveForm[tempKey]; propDic.Add(tempKey, formValue.ToString()); } } #endregion List <FileUploadObject> singleList = new List <FileUploadObject>(); //纯文档上传 List <FileUploadObject> objList = new List <FileUploadObject>(); //当前传入类型文件上传 foreach (var str in filePath) { FileUploadObject obj = new FileUploadObject(); List <string> infoList = new List <string>(); Dictionary <string, string> infoDc = new Dictionary <string, string>(); if (filePathInfo.ContainsKey(str.Key)) { infoList = Regex.Split(filePathInfo[str.Key], @"\|N\|", RegexOptions.IgnoreCase).ToList(); foreach (var tempInfo in infoList) { string[] tempSingleInfo = Regex.Split(tempInfo, @"\|-\|", RegexOptions.IgnoreCase); if (tempSingleInfo.Length == 2) { infoDc.Add(tempSingleInfo[0], tempSingleInfo[1]); } } } if (infoDc.ContainsKey("fileTypeId")) { obj.fileTypeId = Convert.ToInt32(infoDc["fileTypeId"]); } else { obj.fileTypeId = fileTypeId; } if (infoDc.ContainsKey("fileObjId")) { obj.fileObjId = Convert.ToInt32(infoDc["fileObjId"]); } else { obj.fileObjId = fileObjId; } if (filePathInfo.ContainsKey(str.Key)) { obj.localPath = Regex.Split(str.Key, @"\|N\|", RegexOptions.IgnoreCase)[0]; } else { obj.localPath = str.Key; } if (infoDc.ContainsKey("tableName")) { obj.tableName = infoDc["tableName"]; } else { obj.tableName = tableName; } if (infoDc.ContainsKey("keyName")) { obj.keyName = infoDc["keyName"]; } else { obj.keyName = keyName; } if (infoDc.ContainsKey("keyValue")) { if (infoDc["keyValue"] != "0") { obj.keyValue = infoDc["keyValue"]; } else { obj.keyValue = keyValue; } } else { obj.keyValue = keyValue; } if (infoDc.ContainsKey("uploadType")) { if (infoDc["uploadType"] != null && infoDc["uploadType"] != "undefined") { obj.uploadType = Convert.ToInt32(infoDc["uploadType"]); } else { obj.uploadType = uploadType; } } else { obj.uploadType = uploadType; } obj.isPreDefine = isPreDefine; if (infoDc.ContainsKey("isCover")) { if (infoDc["isCover"] == "Yes") { obj.isCover = true; } else { obj.isCover = false; } } else { obj.propvalueDic = propDic; } if (infoDc.ContainsKey("structId")) { obj.structId = Convert.ToInt32(infoDc["structId"]); } else { obj.structId = structId; } obj.rootDir = str.Value; obj.fileRel_profId = fileRel_profId.ToString(); obj.fileRel_stageId = fileRel_stageId.ToString(); obj.fileRel_fileCatId = fileRel_fileCatId.ToString(); if (uploadType != 0 && (obj.rootDir == "null" || obj.rootDir.Trim() == "")) { singleList.Add(obj); } else { objList.Add(obj); } } result = opHelper.UploadMultipleFiles(objList, (UploadType)uploadType);//(UploadType)uploadType if (singleList.Count > 0) { //result = opHelper.UploadMultipleFiles(singleList, (UploadType)0); result.AddRange(opHelper.UploadMultipleFiles(singleList, (UploadType)0)); } } else { PageJson jsonone = new PageJson(); jsonone.Success = false; return(jsonone.ToString() + "|"); } #endregion PageJson json = new PageJson(); var ret = opHelper.ResultConver(result); json.Success = ret.Status == Status.Successful ? true : false; var strResult = json.ToString() + "|" + ret.Value; return(strResult); }
/// <summary> /// 图纸包单个下载与批量下载 /// </summary> /// <returns></returns> public string GetFilePackageInfo() { PageJson json = new PageJson(); string tbName = PageReq.GetParam("tableName"); //关联表 string keyName = PageReq.GetParam("keyName"); string fileObjStr = PageReq.GetParam("fileObjStr"); //文档对象 string fileInfoStr = PageReq.GetForm("packInfoStr").Trim(); //图纸包Id var packageArray = fileInfoStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //图纸包数组 var fileObjIdList = fileObjStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //图纸包文档类型数组 var fileObjList = dataOp.FindAllByKeyValList("FileObject", "fileObjId", fileObjIdList); var fileInfo = string.Empty; var fileNameList = new List <string>(); foreach (var packId in packageArray) { //循环图纸包,获取待下载文件信息 int fileCount = 0; try { BsonDocument curPackage = new BsonDocument(); //当前图纸包 curPackage = dataOp.FindOneByQuery(tbName, Query.EQ(keyName, packId)); //当前图纸包 string PathFirstStr = curPackage.Text("name"); //图纸包下载路径 foreach (var fileObj in fileObjList) //下载图纸包下所有的文件类型 { List <BsonDocument> showStructList = new List <BsonDocument>(); List <BsonDocument> showFileList = new List <BsonDocument>(); List <BsonDocument> fileRelList = dataOp.FindAllByQueryStr("FileRelation", "tableName=" + tbName + "&fileObjId=" + fileObj.Text("fileObjId") + "&keyValue=" + packId).ToList(); //所有当前节点下文档关联 fileCount = fileRelList.Count(); List <string> structIdList = fileRelList.Select(t => t.String("structId")).ToList(); //节点下的所有目录结构 List <string> fileIdList = fileRelList.Select(t => t.String("fileId")).ToList(); //节点下所有非目录文档 showStructList = dataOp.FindAllByKeyValList("FileStructure", "structId", structIdList).ToList(); //所有要展示的目录 showFileList = dataOp.FindAllByKeyValList("FileLibrary", "fileId", fileIdList).Where(c => c.Text("structId") == "").ToList(); //所有要展示的非目录文档 List <BsonDocument> allStructList = new List <BsonDocument>(); //所有目录结构 allStructList.AddRange(showStructList); foreach (var showStruct in showStructList) { allStructList.AddRange(dataOp.FindChildNodes("FileStructure", showStruct.String("structId"))); } List <string> allDirIdList = allStructList.Select(t => t.String("structId")).ToList(); //所有的目录结构文档的目录Id structId List <BsonDocument> allDirFileList = dataOp.FindAllByKeyValList("FileLibrary", "structId", allDirIdList).ToList(); //所有目录结构的文件 foreach (var showStruct in allStructList.OrderBy(t => t.String("nodeKey"))) //所有要展示的目录 { var parentStrList = allStructList.Where(c => showStruct.Text("nodeKey").IndexOf(c.Text("nodeKey")) == 0).OrderBy(c => c.Text("nodeKey")).Select(c => c.Text("name")).ToArray(); //目录列表 var curPathStr = PathFirstStr + "\\" + fileObj.Text("name") + "\\"; if (parentStrList.Count() > 0) { curPathStr += string.Join("\\", parentStrList) + "\\"; } List <BsonDocument> subFileList = allDirFileList.Where(t => t.Int("structId") == showStruct.Int("structId")).ToList(); foreach (var file in subFileList) { fileInfo += ",{\"name\":\"" + file.Text("name").Replace("\\", "\\\\") + "\", \"ext\":\"" + file.Text("ext") + "\", \"fileId\":\"" + file.Text("fileId") + "\", \"filePath\":\"" + curPathStr.Replace("\\", "\\\\") + "\", \"guid\":\"" + file.Text("guid") + "\"}"; } } foreach (var file in showFileList) { var curPathStr = PathFirstStr + "\\" + fileObj.Text("name") + "\\"; fileInfo += ",{\"name\":\"" + file.Text("name").Replace("\\", "\\\\") + "\", \"ext\":\"" + file.Text("ext") + "\", \"fileId\":\"" + file.Text("fileId") + "\", \"filePath\":\"" + curPathStr.Replace("\\", "\\\\") + "\", \"guid\":\"" + file.Text("guid") + "\"}"; } } } catch (InvalidCastException ex) { json.Success = false; json.Message = "传入参数有误"; return(json.ToString()); } catch (System.Exception ex) { json.Success = false; json.Message = "传入参数有误"; return(json.ToString()); } #region 更新图纸包下载次数 if (fileCount > 0) { DownLoadCount(Convert.ToInt32(packId)); } #endregion } json.Success = true; if (!string.IsNullOrEmpty(fileInfo)) { fileInfo = "[" + fileInfo.Remove(0, 1) + "]"; } var picResult = json.ToString() + "|" + fileInfo; return(picResult); }