/// <summary> /// 上传多个文件 /// </summary> /// <param name="saveForm"></param> /// <returns></returns> public string SaveMultipleUploadFiles(FormCollection saveForm) { DataOperation dataOp = new DataOperation(); string tableName = PageReq.GetForm("tableName"); string keyName = PageReq.GetForm("keyName"); string keyValue = saveForm["keyValue"].ToString(); string localPath = PageReq.GetForm("uploadFileList"); string fileSaveType = saveForm["fileSaveType"] != null ? saveForm["fileSaveType"] : "multiply"; int fileTypeId = PageReq.GetFormInt("fileTypeId"); int fileObjId = PageReq.GetFormInt("fileObjId"); int uploadType = PageReq.GetFormInt("uploadType"); string subMapParam = PageReq.GetForm("subMapParam"); string guid2d = PageReq.GetForm("guid2d"); string oldGuid2d = PageReq.GetForm("oldguid2d"); 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> >(); localPath = localPath.Replace("\\\\", "\\"); #region 如果保存类型为单个single 则删除旧的所有关联文件 if (!string.IsNullOrEmpty(fileSaveType)) { if (fileSaveType == "single") { opHelper.DeleteFile(tableName, keyName, keyValue); } } #endregion #region 通过关联读取对象属性 if (!string.IsNullOrEmpty(localPath.Trim())) { string[] fileStr = Regex.Split(localPath, @"\|H\|", RegexOptions.IgnoreCase); Dictionary <string, string> filePath = new Dictionary <string, string>(); foreach (string file in fileStr) { 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 >= 2) { 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()); } } } List <FileUploadObject> singleList = new List <FileUploadObject>(); //纯文档上传 List <FileUploadObject> objList = new List <FileUploadObject>(); //当前传入类型文件上传 foreach (var str in filePath) { FileUploadObject obj = new FileUploadObject(); obj.fileTypeId = fileTypeId; obj.fileObjId = fileObjId; obj.localPath = str.Key; obj.tableName = tableName; obj.keyName = keyName; obj.keyValue = keyValue; obj.uploadType = uploadType; obj.isPreDefine = isPreDefine; obj.isCover = false; obj.propvalueDic = propDic; obj.rootDir = str.Value; obj.subMapParam = subMapParam; obj.guid2d = guid2d; 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); } } else { PageJson jsonone = new PageJson(); jsonone.Success = false; return(jsonone.ToString() + "|"); } #endregion PageJson json = new PageJson(); var ret = opHelper.ResultConver(result); #region 如果有关联的文件Id列表,则保存关联记录 string fileVerIds = PageReq.GetForm("fileVerIds"); List <int> fileVerIdList = fileVerIds.SplitToIntList(","); if (ret.Status == Status.Successful && fileVerIdList.Count > 0) { List <StorageData> saveList = new List <StorageData>(); foreach (var tempVerId in fileVerIdList) { StorageData tempData = new StorageData(); tempData.Name = "FileAlterRelation"; tempData.Type = StorageType.Insert; tempData.Document = new BsonDocument().Add("alterFileId", result.FirstOrDefault().Value.fileId.ToString()) .Add("fileVerId", tempVerId); saveList.Add(tempData); } dataOp.BatchSaveStorageData(saveList); } #endregion json.Success = ret.Status == Status.Successful ? true : false; var strResult = json.ToString() + "|" + ret.Value + "|" + keyValue; return(strResult); }
/// <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); }