/// <summary> /// 文件查看次数 /// </summary> /// <param name="saveForm"></param> /// <returns></returns> public ActionResult FileViewCount(FormCollection saveForm) { PageJson json = new PageJson(); string fileId = PageReq.GetForm("fileId"); string version = PageReq.GetForm("version"); try { var file = dataOp.FindOneByQuery("FileLibrary", Query.EQ("_id", ObjectId.Parse(fileId))); var fileVer = dataOp.FindOneByQuery("FileLibVersion", Query.And( Query.EQ("fileId", file.String("fileId")), Query.EQ("version", version) ) ); var viewCount = fileVer.Int("viewCount"); var data = new BsonDocument().Set("viewCount", ++viewCount); dataOp.Update("FileLibVersion", Query.EQ("fileVerId", fileVer.Text("fileVerId")), data); json.Success = true; } catch (Exception ex) { json.Success = false; json.Message = ex.Message; } return(Json(json)); }
/// <summary> /// 获取工程下的子工程 /// </summary> /// <returns></returns> public JsonResult GetSubProject() { int catId = PageReq.GetParamInt("catId"); List <BsonDocument> metaObjList = dataOp.FindAllByQuery("XH_DesignManage_ProjEngineering", Query.EQ("nodePid", catId.ToString())).ToList(); List <object> metaObjListInfo = new List <object>(); foreach (var metaObj in metaObjList) { metaObjListInfo.Add(new { metaObjId = metaObj.Text("projEngId"), metaObjName = metaObj.Text("name") }); } PageJson json = new PageJson(); JavaScriptSerializer script = new JavaScriptSerializer(); string strJson = script.Serialize(metaObjListInfo); if (metaObjListInfo != null && metaObjListInfo.Count > 0) { json.AddInfo("CatList", strJson); json.Success = true; } else { json.AddInfo("CatList", ""); json.Success = true; } return(Json(json)); }
public ActionResult SaveResultMatRelInfo() { InvokeResult result = new InvokeResult(); PageJson json = new PageJson(); int retId = PageReq.GetFormInt("retId"); string matIds = PageReq.GetForm("matIds"); //材料Id列表 List <StorageData> allDataList = new List <StorageData>(); List <string> matIdList = matIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (var matId in matIdList) { BsonDocument tempBson = new BsonDocument(); tempBson.Add("retId", retId.ToString()); tempBson.Add("matId", matId); StorageData tempData = new StorageData(); tempData.Document = tempBson; tempData.Name = "StandardResult_ResultMatRelation"; tempData.Type = StorageType.Insert; allDataList.Add(tempData); } result = dataOp.BatchSaveStorageData(allDataList); json = TypeConvert.InvokeResultToPageJson(result); return(Json(json)); }
/// <summary> /// 创建Excel文件 /// </summary> /// <param name="htmlCode"></param> /// <param name="sheetName"></param> /// <returns>生成文件的路径</returns> public string CreateExcel(string htmlCode, string sheetName, string fileName) { PageJson result = new PageJson(); string fullFileName = string.Empty; try { if (string.IsNullOrEmpty(sheetName)) { sheetName = "sheet1"; } htmlCode = Server.UrlDecode(htmlCode); sheetName = Server.UrlDecode(sheetName); fileName = Server.UrlDecode(fileName); ExcelWriter myExcel = new ExcelWriter(sheetName); myExcel.WriteData(htmlCode); string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tempFiles"); fullFileName = myExcel.SaveAsFile(path, fileName); } catch { result.Success = false; result.Message = "未知原因导致生成表格失败!"; return(result.ToJsonString()); } result.Success = true; result.Message = fullFileName; string str = result.ToJsonString(); str = Regex.Replace(str, @"\\", "/"); //删除临时生成的文件 ThreadStart deleTempFile = () => { Thread.Sleep(1000 * 30); System.IO.File.Delete(fullFileName); }; Thread newThread = new Thread(deleTempFile); newThread.Start(); return(str); }
/// <summary> /// 文件下载次数 /// </summary> /// <param name="saveForm"></param> /// <returns></returns> public ActionResult FileDownloadCount(FormCollection saveForm) { PageJson json = new PageJson(); string fileIds = PageReq.GetForm("fileIds"); try { string[] fileIdArray; if (fileIds.Length > 0) { fileIdArray = fileIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (var tempId in fileIdArray) { var tempArray = tempId.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); if (tempArray.Length != 2) { continue; } var fileId = tempArray[0]; var version = tempArray[1]; var file = dataOp.FindOneByQuery("FileLibrary", Query.EQ("_id", ObjectId.Parse(fileId))); var fileVer = dataOp.FindOneByQuery("FileLibVersion", Query.And( Query.EQ("fileId", file.String("fileId")), Query.EQ("version", version))); var downloadCount = fileVer.Int("downloadCount"); var data = new BsonDocument().Set("downloadCount", ++downloadCount); dataOp.Update("FileLibVersion", Query.EQ("fileVerId", fileVer.String("fileVerId")), data); } } json.Success = true; } catch (Exception ex) { json.Success = false; json.Message = ex.Message; } return(Json(json)); }
public ActionResult DownLoadCount(int id) { PageJson json = new PageJson(); var packageObj = dataOp.FindOneByKeyVal("ProjDocPackage", "packageId", id.ToString()); InvokeResult result = new InvokeResult(); if (packageObj == null) { json.Success = false; json.Message = "图纸包不存在!"; } else { int count = packageObj.Int("downLoadCount") + 1; BsonDocument dataBson = new BsonDocument(); dataBson.Add("downLoadCount", count); //result = dataOp.Save("ProjDocPackage", Query.EQ("packageId",id.ToString()), dataBson); //通用方法 result = dataOp.Update(packageObj, dataBson); json = TypeConvert.InvokeResultToPageJson(result); } return(Json(json)); }
/// <summary> /// 生成客户session code /// </summary> /// <returns></returns> public ActionResult GetSystemCodeSession() { PageJson json = new PageJson(); var customerCode = PageReq.GetString("customerCode"); if (string.IsNullOrEmpty(customerCode)) { json.Success = false; json.Message = "客户代码为设置"; return(Json(json)); } //Session["CustomerCode"] = customerCode; if (!string.IsNullOrEmpty(PageReq.GetSession("sessionToken"))) { var cacheKey = $"CustomerCode_{PageReq.GetSession("sessionToken")}"; RedisCacheHelper.SetCache(cacheKey, customerCode, DateTime.Now.AddDays(30)); PageReq.SetSession("CustomerCode", customerCode); } json.Success = true; return(Json(json)); }
public string AddSaleInfo() { Response.ContentType = "text/html; charset=utf-8;"; var json = new PageJson(false); var excelId = PageReq.GetForm("excelId"); var title = PageReq.GetForm("title"); var type = PageReq.GetForm("type"); var date = PageReq.GetForm("date"); string clientFilePath = PageReq.GetForm("filePath"); var result = new InvokeResult() { Status = Status.Failed }; var allExelList = dataOp.FindAll("LuxuriousHouse_ImportExcelFile").ToList(); var curMapObj = allExelList.Where(c => c.String("excelId") == excelId).FirstOrDefault(); string serverFilePath = string.Empty; var hasExist = allExelList.Where(c => c.String("excelId") != excelId && c.String("title") == title).Count() > 0; bool isSave = !hasExist; if (!isSave) { json.Message = "名字重复已存在!"; return(json.ToJsonString()); } else { if (Request.Files.Count != 0) { try { #region 保存文件到服务器 HttpPostedFileBase file = Request.Files[0]; string fileName = "Luxurious_" + title + Path.GetExtension(file.FileName); string directory = @"\Content\ExcelFile\"; string filePath = Server.MapPath(directory); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } serverFilePath = Path.Combine(directory, fileName); string fullFilePath = Path.Combine(filePath, fileName); if (!CheckFileExt(fullFilePath, "doc")) { json.Message = "文件格式不正确!"; return(json.ToJsonString()); } file.SaveAs(fullFilePath); curMapObj = new BsonDocument(); curMapObj.Add("title", title); curMapObj.Add("type", type); curMapObj.Add("date", date); if (clientFilePath != "") { curMapObj.Add("clientPath", clientFilePath); } if (serverFilePath != "") { curMapObj.Add("serverPath", serverFilePath); } result = dataOp.Insert("LuxuriousHouse_ImportExcelFile", curMapObj); #endregion //写入数据 DataTable dt = GetDataTable(fullFilePath); WriteLuxuryData(dt, result.BsonInfo.String("excelId"), "increment"); } catch (Exception ex) { json.Message = ex.Message; return(json.ToJsonString()); } } else { var updateBson = new BsonDocument(); updateBson.Add("title", title); updateBson.Add("type", type); updateBson.Add("date", date); result = dataOp.Update(curMapObj, updateBson); } json.Success = true; json.Message = "保存成功"; } return(json.ToJsonString()); }
public ActionResult saveProgEval(FormCollection saveForm) { InvokeResult result = new InvokeResult(); #region 构建数据 string tbName = PageReq.GetForm("tbName"); string queryStr = PageReq.GetForm("queryStr"); string dataStr = PageReq.GetForm("dataStr"); int saveStatus = PageReq.GetFormInt("saveStatus");//0:保存 1:提交 List <string> filterStrList = new List <string>() { "tbName", "queryStr", "actionUserStr", "flowId", "stepIds", "fileTypeId", "fileObjId", "tableName", "keyName", "keyValue", "delFileRelIds", "uploadFileList", "fileSaveType", "skipStepIds" }; BsonDocument dataBson = new BsonDocument(); var allKeys = saveForm.AllKeys.Where(i => !filterStrList.Contains(i)); if (dataStr.Trim() == "") { foreach (var tempKey in allKeys) { if (tempKey == "tbName" || tempKey == "queryStr" || tempKey.Contains("fileList[") || tempKey.Contains("param.")) { continue; } dataBson.Add(tempKey, PageReq.GetForm(tempKey)); } } else { dataBson = TypeConvert.ParamStrToBsonDocument(dataStr); } #endregion #region 验证参数 string flowId = PageReq.GetForm("flowId"); BsonDocument flowObj = dataOp.FindOneByQuery("BusFlow", Query.EQ("flowId", flowId)); if (flowObj.IsNullOrEmpty()) { result.Message = "无效的流程模板"; result.Status = Status.Failed; return(Json(TypeConvert.InvokeResultToPageJson(result))); } var stepList = dataOp.FindAllByKeyVal("BusFlowStep", "flowId", flowId).OrderBy(c => c.Int("stepOrder")).ToList(); BsonDocument bootStep = stepList.Where(c => c.Int("actTypeId") == (int)FlowActionType.Launch).FirstOrDefault(); if (saveStatus == 1 && bootStep.IsNullOrEmpty())//提交时才判断 { result.Message = "该流程缺少发起步骤"; result.Status = Status.Failed; return(Json(TypeConvert.InvokeResultToPageJson(result))); } var activeStepIdList = PageReq.GetFormIntList("stepIds"); List <int> hitEnslavedStepOrder = dataOp.FindAllByKeyVal("BusFlowStep", "enslavedStepId", bootStep.Text("stepId")).OrderBy(c => c.Int("stepOrder")).Select(c => c.Int("stepOrder")).Distinct().ToList(); List <int> hitStepIds = stepList.Where(c => hitEnslavedStepOrder.Contains(c.Int("stepOrder"))).Select(c => c.Int("stepId")).ToList(); if (saveStatus == 1 && activeStepIdList.Count() <= 0 && hitEnslavedStepOrder.Count() > 0)//提交时才判断 { result.Status = Status.Failed; result.Message = "请先选定会签部门"; return(Json(TypeConvert.InvokeResultToPageJson(result))); } #endregion TableRule rule = new TableRule(tbName); ColumnRule columnRule = rule.ColumnRules.Where(t => t.IsPrimary == true).FirstOrDefault(); string keyName = columnRule != null ? columnRule.Name : ""; #region 验证重名 string newName = PageReq.GetForm("name").Trim(); BsonDocument curChange = dataOp.FindOneByQuery(tbName, TypeConvert.NativeQueryToQuery(queryStr)); BsonDocument oldChange = dataOp.FindOneByQuery(tbName, Query.EQ("name", newName)); if (!oldChange.IsNullOrEmpty() && oldChange.Int(keyName) != curChange.Int(keyName)) { result.Message = "已经存在该名称的方案评审"; result.Status = Status.Failed; return(Json(TypeConvert.InvokeResultToPageJson(result))); } #endregion #region 保存数据 result = dataOp.Save(tbName, queryStr != "" ? TypeConvert.NativeQueryToQuery(queryStr) : Query.Null, dataBson); if (result.Status == Status.Failed) { result.Message = "保存方案评审失败"; return(Json(TypeConvert.InvokeResultToPageJson(result))); } #endregion #region 文件上传 int primaryKey = 0; if (!string.IsNullOrEmpty(queryStr)) { var query = TypeConvert.NativeQueryToQuery(queryStr); var recordDoc = dataOp.FindOneByQuery(tbName, query); saveForm["keyValue"] = result.BsonInfo.Text(keyName); if (recordDoc != null) { primaryKey = recordDoc.Int(keyName); } } if (primaryKey == 0)//新建 { if (saveForm["tableName"] != null) { saveForm["keyValue"] = result.BsonInfo.Text(keyName); } } else//编辑 { #region 除文件 string delFileRelIds = saveForm["delFileRelIds"] != null ? saveForm["delFileRelIds"] : ""; if (!string.IsNullOrEmpty(delFileRelIds)) { FileOperationHelper opHelper = new FileOperationHelper(); try { string[] fileArray; if (delFileRelIds.Length > 0) { fileArray = delFileRelIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (fileArray.Length > 0) { foreach (var item in fileArray) { var result1 = opHelper.DeleteFileByRelId(int.Parse(item)); if (result1.Status == Status.Failed) { break; } } } } } catch (Exception ex) { result.Status = Status.Failed; result.Message = ex.Message; return(Json(TypeConvert.InvokeResultToPageJson(result))); } } #endregion saveForm["keyValue"] = primaryKey.ToString(); } result.FileInfo = SaveMultipleUploadFiles(saveForm); #endregion #region 保存审批人员 InvokeResult tempResult = new InvokeResult(); int proEvalId = result.BsonInfo.Int(keyName); BsonDocument proEvalObj = result.BsonInfo; PageJson json = new PageJson(); json.AddInfo("proEvalId", proEvalId.ToString()); var actionUserStr = PageReq.GetForm("actionUserStr"); #region 查找方案评审流程模板关联,没有则添加 BsonDocument proEvalFlowRel = dataOp.FindOneByQuery("ProgrammeEvaluationBusFlow", Query.EQ("proEvalId", proEvalId.ToString())); if (proEvalFlowRel.IsNullOrEmpty()) { tempResult = dataOp.Insert("ProgrammeEvaluationBusFlow", "proEvalId=" + proEvalId.ToString() + "&flowId=" + flowId); if (tempResult.Status == Status.Failed) { json.Success = false; json.Message = "插入流程关联失败"; return(Json(json)); } else { proEvalFlowRel = tempResult.BsonInfo; } } #endregion #region 初始化流程实例 var helper = new Yinhe.ProcessingCenter.BusinessFlow.FlowInstanceHelper(dataOp); var flowUserHelper = new Yinhe.ProcessingCenter.BusinessFlow.FlowUserHelper(dataOp); //当前步骤 BsonDocument curStep = null; var hasOperateRight = false; //是否可以跳转步骤 var hasEditRight = false; //是否可以编辑表单 var canForceComplete = false; //是否可以强制结束当前步骤 string curAvaiableUserName = string.Empty; //当前可执行人 BsonDocument curFlowInstance = dataOp.FindAllByQuery("BusFlowInstance", Query.And( Query.EQ("tableName", "ProgrammeEvaluation"), Query.EQ("referFieldName", "proEvalId"), Query.EQ("referFieldValue", proEvalId.ToString()) ) ).OrderByDescending(i => i.Date("createDate")).FirstOrDefault(); if (curFlowInstance.IsNullOrEmpty() == false) { //初始化流程状态 curStep = helper.InitialExecuteCondition(flowObj.Text("flowId"), curFlowInstance.Text("flowInstanceId"), dataOp.GetCurrentUserId(), ref hasOperateRight, ref hasEditRight, ref canForceComplete, ref curAvaiableUserName); if (curStep == null) { curStep = curFlowInstance.SourceBson("stepId"); } } else { curStep = bootStep; //初始化流程实例 if (flowObj != null && curStep != null) { curFlowInstance = new BsonDocument(); curFlowInstance.Add("flowId", flowObj.Text("flowId")); curFlowInstance.Add("stepId", curStep.Text("stepId")); curFlowInstance.Add("tableName", "ProgrammeEvaluation"); curFlowInstance.Add("referFieldName", "proEvalId"); curFlowInstance.Add("referFieldValue", proEvalId); curFlowInstance.Add("instanceStatus", "0"); curFlowInstance.Add("instanceName", proEvalObj.Text("name")); tempResult = helper.CreateInstance(curFlowInstance); if (tempResult.Status == Status.Successful) { curFlowInstance = tempResult.BsonInfo; } else { json.Success = false; json.Message = "创建流程实例失败:" + tempResult.Message; return(Json(json)); } helper.InitialExecuteCondition(flowObj.Text("flowId"), curFlowInstance.Text("flowInstanceId"), dataOp.GetCurrentUserId(), ref hasOperateRight, ref hasEditRight, ref canForceComplete, ref curAvaiableUserName); } if (curStep == null) { curStep = stepList.FirstOrDefault(); } } #endregion #region 保存流程实例步骤人员 List <BsonDocument> allStepList = dataOp.FindAllByKeyVal("BusFlowStep", "flowId", flowId).ToList(); //所有步骤 //获取可控制的会签步骤 string curStepId = curStep.Text("stepId"); var oldRelList = dataOp.FindAllByKeyVal("InstanceActionUser", "flowInstanceId", curFlowInstance.Text("flowInstanceId")).ToList(); //所有的审批人 //stepId + "|Y|" + uid +"|N|"+ status + "|H|"; var arrActionUserStrUserStr = actionUserStr.Split(new string[] { "|H|" }, StringSplitOptions.RemoveEmptyEntries); var storageList = new List <StorageData>(); //不需要审批的所有步骤的id--袁辉 var skipStepIds = PageReq.GetForm("skipStepIds"); var flowHelper = new FlowInstanceHelper(); foreach (var userStr in arrActionUserStrUserStr) { var arrUserStatusStr = userStr.Split(new string[] { "|N|" }, StringSplitOptions.None); if (arrUserStatusStr.Length <= 1) { continue; } string status = arrUserStatusStr[1];//该流程步骤人员是否有效 0:有效 1:无效 var arrUserStr = arrUserStatusStr[0].Split(new string[] { "|Y|" }, StringSplitOptions.RemoveEmptyEntries); var stepId = int.Parse(arrUserStr[0]); var curStepObj = allStepList.Where(c => c.Int("stepId") == stepId).FirstOrDefault(); if (curStepObj == null) { continue; } if (arrUserStr.Length <= 1) { //如果被跳过的审批没有选择人员,则在这里进行保存 var oldRels = oldRelList.Where(t => t.Int("stepId") == stepId).ToList(); if (oldRels.Count > 0) { var skipStr = "1"; if (skipStepIds.Contains(stepId.ToString())) { oldRels = oldRels.Where(t => t.Int("isSkip") == 0).ToList(); } else { oldRels = oldRels.Where(t => t.Int("isSkip") == 1).ToList(); skipStr = "0"; } if (oldRels.Count > 0) { foreach (var oldRel in oldRels) { var tempData = new StorageData(); tempData.Name = "InstanceActionUser"; tempData.Type = StorageType.Update; tempData.Query = Query.EQ("inActId", oldRel.Text("inActId")); tempData.Document = new BsonDocument().Add("isSkip", skipStr); storageList.Add(tempData); } } } else if (skipStepIds.Contains(stepId.ToString())) { var tempData = new StorageData(); tempData.Name = "InstanceActionUser"; tempData.Type = StorageType.Insert; BsonDocument actionUser = new BsonDocument(); actionUser.Add("flowInstanceId", curFlowInstance.Text("flowInstanceId")); actionUser.Add("actionConditionId", curFlowInstance.Text("flowInstanceId")); actionUser.Add("userId", ""); actionUser.Add("stepId", stepId); actionUser.Add("isSkip", "1"); //新增模板属性对象 flowHelper.CopyFlowStepProperty(actionUser, curStepObj); tempData.Document = actionUser; storageList.Add(tempData); } continue; } var userArrayIds = arrUserStr[1]; var userIds = userArrayIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (var userId in userIds) { var oldRel = oldRelList.FirstOrDefault(i => i.Int("stepId") == stepId && i.Text("userId") == userId); if (oldRel.IsNullOrEmpty()) { var tempData = new StorageData(); tempData.Name = "InstanceActionUser"; tempData.Type = StorageType.Insert; BsonDocument actionUser = new BsonDocument(); actionUser.Add("flowInstanceId", curFlowInstance.Text("flowInstanceId")); actionUser.Add("actionConditionId", curFlowInstance.Text("flowInstanceId")); actionUser.Add("userId", userId); actionUser.Add("stepId", stepId); //新增模板属性对象 flowHelper.CopyFlowStepProperty(actionUser, curStepObj); if (curStepObj.Int("actTypeId") == 2)//如果是会签步骤 { actionUser.Set("status", status); } //判断步骤是否跳过审批--袁辉 if (skipStepIds.Contains(stepId.ToString())) { actionUser.Add("isSkip", "1"); } else { actionUser.Add("isSkip", "0"); } tempData.Document = actionUser; storageList.Add(tempData); } else { var tempData = new StorageData(); tempData.Name = "InstanceActionUser"; tempData.Type = StorageType.Update; tempData.Query = Query.EQ("inActId", oldRel.Text("inActId")); BsonDocument actionUser = new BsonDocument(); if (hitStepIds.Contains(stepId)) { actionUser.Add("status", status); } actionUser.Add("converseRefuseStepId", ""); actionUser.Add("actionAvaiable", ""); flowHelper.CopyFlowStepProperty(actionUser, curStepObj); //判断步骤是否跳过审批--袁辉 if (skipStepIds.Contains(stepId.ToString())) { actionUser.Add("isSkip", "1"); } else { actionUser.Add("isSkip", "0"); } tempData.Document = actionUser; storageList.Add(tempData); oldRelList.Remove(oldRel); } } } foreach (var oldRel in oldRelList) { var tempData = new StorageData(); tempData.Name = "InstanceActionUser"; tempData.Type = StorageType.Delete; tempData.Query = Query.EQ("inActId", oldRel.Text("inActId")); storageList.Add(tempData); } tempResult = dataOp.BatchSaveStorageData(storageList); if (tempResult.Status == Status.Failed) { json.Success = false; json.Message = "保存审批人员失败"; return(Json(json)); } #endregion #endregion #region 提交时保存提交信息并跳转 if (saveStatus == 1)//提交时直接发起 { //保存发起人 BsonDocument tempData = new BsonDocument().Add("approvalUserId", dataOp.GetCurrentUserId().ToString()).Add("instanceStatus", "0"); tempResult = dataOp.Save("BusFlowInstance", Query.EQ("flowInstanceId", curFlowInstance.Text("flowInstanceId")), tempData); if (tempResult.Status == Status.Failed) { json.Success = false; json.Message = "保存发起人失败"; return(Json(json)); } //保存发起时间 var timeFormat = "yyyy-MM-dd HH:mm:ss"; tempData = new BsonDocument() { { "startTime", DateTime.Now.ToString(timeFormat) } }; tempResult = dataOp.Save("ProgrammeEvaluation", Query.EQ("proEvalId", proEvalId.ToString()), tempData); if (tempResult.Status == Status.Failed) { json.Success = false; json.Message = "保存发起时间失败"; return(Json(json)); } //跳转步骤 BsonDocument act = dataOp.FindAllByKeyVal("BusFlowAction", "type", "0").FirstOrDefault(); tempResult = helper.ExecAction(curFlowInstance, act.Int("actId"), null, bootStep.Int("stepId")); if (tempResult.Status == Status.Failed) { json.Success = false; json.Message = "流程跳转失败:" + tempResult.Message; return(Json(json)); } } #endregion return(Json(TypeConvert.InvokeResultToPageJson(result))); }
/// <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); }
public ActionResult ProjCatModelInsert() { PageJson json = new PageJson(); InvokeResult result = new InvokeResult() { Status = Status.Successful }; int engId = PageReq.GetParamInt("engId"); //获取当前地块Id var engObj = dataOp.FindOneByQuery("XH_DesignManage_Engineering", Query.EQ("engId", engId.ToString())); //地块对象 int projCatModelId = PageReq.GetParamInt("projCatModelId"); //需要导入的模板 var modelObj = dataOp.FindOneByQuery("ProjDocCategoryModel", Query.EQ("projCatModelId", projCatModelId.ToString())); //模板对象 var modelItemList = dataOp.FindAllByKeyVal("ProjDocCategory", "projCatModelId", projCatModelId.ToString()).ToList(); //模板下的目录 var ObjIdsList = new Dictionary <int, int>(); //用于存储新增的旧keyId 与新keyId对应字典 if (modelObj == null || engObj == null) { result.Message = "模板创建失败,请重试!"; json = TypeConvert.InvokeResultToPageJson(result); return(Json(json)); } #region 创建目录 try { foreach (var modelVauleObj in modelItemList.OrderBy(c => c.Text("nodeKey"))) //遍历模板数据 { var uniqueKey = modelVauleObj.Int("projDocCatId"); var curTtemValueObj = new BsonDocument(); var nodePid = modelVauleObj.Int("nodePid"); //获取父节点 var ParentId = 0; var name = modelVauleObj.Text("name"); if (nodePid != 0) { if (!ObjIdsList.ContainsKey(nodePid)) { continue; } ParentId = ObjIdsList[nodePid]; } else { name = engObj.Text("name") + "根目录"; } curTtemValueObj.Add("engId", engId.ToString()); //地块Id curTtemValueObj.Add("srcprojCatModelId", projCatModelId.ToString()); //来源模板Id curTtemValueObj.Add("srcprojDocCatId", modelVauleObj.Text("projDocCatId")); //来源目录Id curTtemValueObj.Add("name", name); curTtemValueObj.Add("nodePid", ParentId); curTtemValueObj.Add("catTypeId", modelVauleObj.Text("catTypeId")); curTtemValueObj.Add("status", modelVauleObj.Text("status")); curTtemValueObj.Add("viewLevel", modelVauleObj.Text("viewLevel")); curTtemValueObj.Add("isAllowUpload", modelVauleObj.Text("isAllowUpload")); curTtemValueObj.Add("isNeedHide", modelVauleObj.Text("isNeedHide")); curTtemValueObj.Add("isHideProjEng", modelVauleObj.Text("isHideProjEng")); curTtemValueObj.Add("isNeedVersion", modelVauleObj.Text("isNeedVersion")); curTtemValueObj.Add("isHideSupplier", modelVauleObj.Text("isHideSupplier")); curTtemValueObj.Add("firstTagName", modelVauleObj.Text("firstTagName")); curTtemValueObj.Add("SecendTagName", modelVauleObj.Text("SecendTagName")); result = dataOp.Insert("ProjDocCategory", curTtemValueObj); //插入 ObjIdsList.Add(uniqueKey, result.BsonInfo.Int("projDocCatId")); } } catch (Exception ex) { result.Message = ex.Message; } #endregion json = TypeConvert.InvokeResultToPageJson(result); return(Json(json)); }
/// <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); }
public ActionResult SaveResultItemMatRelInfoXC(FormCollection saveForm) { InvokeResult result = new InvokeResult(); PageJson json = new PageJson(); string tbName = "XH_StandardResult_ResultItemMatRelation"; //表名 string queryStr = PageReq.GetForm("queryStr"); //定位记录 string matIds = PageReq.GetForm("matIds"); //材料Id列表 if (PageReq.GetForm("retId").Trim() == "" || PageReq.GetForm("itemId").Trim() == "") { json.Success = false; json.Message = "传入参数有空值!"; return(Json(json)); } BsonDocument dataBson = new BsonDocument(); //数据 foreach (var tempKey in saveForm.AllKeys) { if (tempKey == "tbName" || tempKey == "queryStr" || tempKey.Contains("matIds")) { continue; } dataBson.Add(tempKey, saveForm[tempKey]); } var query = TypeConvert.NativeQueryToQuery(queryStr); //定位关联 if (queryStr != "") //编辑材料记录 { result = dataOp.Save(tbName, query, dataBson); //保存关联 } else if (matIds.Trim() != "") //有选择材料 { List <StorageData> allDataList = new List <StorageData>(); List <string> matIdList = matIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (var matId in matIdList) { BsonDocument tempBson = new BsonDocument(); tempBson.Add("retId", dataBson.String("retId")); tempBson.Add("typeId", dataBson.String("typeId")); tempBson.Add("itemId", dataBson.String("itemId")); tempBson.Add("matId", matId); StorageData tempData = new StorageData(); tempData.Document = tempBson; tempData.Name = tbName; tempData.Type = StorageType.Insert; allDataList.Add(tempData); } result = dataOp.BatchSaveStorageData(allDataList); } else { result = dataOp.Save(tbName, query, dataBson); //保存关联 } json = TypeConvert.InvokeResultToPageJson(result); return(Json(json)); }
/// <summary> /// 保存外部项目基本信息 /// </summary> /// <param name="saveForm"></param> /// <returns></returns> public ActionResult SaveOutProjInfo(FormCollection saveForm) { PageJson json = new PageJson(); InvokeResult result = new InvokeResult(); string tbName = PageReq.GetForm("tbName"); string queryStr = PageReq.GetForm("queryStr"); string propertyStr = PageReq.GetForm("propertyIdArray");//物业形态 BsonDocument projInfo = new BsonDocument(); List <string> propertyIdList = new List <string>(); if (!string.IsNullOrEmpty(propertyStr)) { propertyIdList = propertyStr.SplitParam(StringSplitOptions.RemoveEmptyEntries, ",").ToList(); } List <StorageData> dataSource = new List <StorageData>(); if (!string.IsNullOrEmpty(queryStr)) { projInfo = dataOp.FindOneByQuery("StandardResult_OutSideProject", TypeConvert.NativeQueryToQuery(queryStr)); if (projInfo != null) { foreach (var tempKey in saveForm.AllKeys) { if (tempKey == "tbName" || tempKey == "queryStr" || tempKey == "str" || tempKey == "propertyIdArray" || tempKey == "" || tempKey.Contains("fileList[") || tempKey.Contains("param.")) { continue; } if (projInfo.Contains(tempKey)) { projInfo[tempKey] = PageReq.GetForm(tempKey); } else { projInfo.Add(tempKey, PageReq.GetForm(tempKey)); } } StorageData tempData1 = new StorageData(); tempData1.Name = "StandardResult_OutSideProject"; tempData1.Type = StorageType.Update; tempData1.Document = projInfo; tempData1.Query = Query.EQ("OutProjId", projInfo.String("OutProjId")); dataSource.Add(tempData1); var exitProperty = dataOp.FindAllByQuery("OutProjectProperty", Query.EQ("OutProjId", projInfo.String("OutProjId"))).ToList(); foreach (var tempProperty in propertyIdList) { var temp = exitProperty.Where(x => x.String("propertyId") == tempProperty).FirstOrDefault(); if (temp != null) { exitProperty.Remove(temp); } else { BsonDocument tempProper = new BsonDocument(); tempProper.Add("OutProjId", projInfo.String("OutProjId")); tempProper.Add("propertyId", tempProperty); StorageData tempData = new StorageData(); tempData.Name = "OutProjectProperty"; tempData.Type = StorageType.Insert; tempData.Document = tempProper; dataSource.Add(tempData); // newPropertyIdList.Add(tempProperty); } } if (exitProperty.Count() > 0) { foreach (var tempProperty in exitProperty) { StorageData tempData = new StorageData(); tempData.Name = "OutProjectProperty"; tempData.Type = StorageType.Delete; tempData.Query = Query.EQ("outProjPropertyId", tempProperty.String("outProjPropertyId")); tempData.Document = tempProperty; dataSource.Add(tempData); //delPropertyId.Add(tempProperty.String("propertyId")); } } result = dataOp.BatchSaveStorageData(dataSource); } } else { foreach (var tempKey in saveForm.AllKeys) { if (tempKey == "tbName" || tempKey == "queryStr" || tempKey == "str" || tempKey == "propertyIdArray") { continue; } if (projInfo.Contains(tempKey)) { projInfo[tempKey] = PageReq.GetForm(tempKey); } else { projInfo.Add(tempKey, PageReq.GetForm(tempKey)); } } result = dataOp.Insert("StandardResult_OutSideProject", projInfo); if (result.Status == Status.Successful) { projInfo = result.BsonInfo; projInfo = result.BsonInfo; try { foreach (var tempProperty in propertyIdList) { BsonDocument tempProper = new BsonDocument(); tempProper.Add("OutProjId", projInfo.String("OutProjId")); tempProper.Add("propertyId", tempProperty); StorageData tempData = new StorageData(); tempData.Name = "OutProjectProperty"; tempData.Type = StorageType.Insert; tempData.Document = tempProper; dataSource.Add(tempData); } result = dataOp.BatchSaveStorageData(dataSource); } catch (Exception ex) { } } } if (result.Status == Status.Successful) { json.htInfo = new System.Collections.Hashtable();; json.htInfo.Add("OutProjId", projInfo.String("OutProjId")); json.Success = true; } else { json = TypeConvert.InvokeResultToPageJson(result); } return(Json(json)); }