public ActionResult SaveSysUser(FormCollection saveForm) { InvokeResult result = new InvokeResult(); string tbName = saveForm["tbName"] != null ? saveForm["tbName"] : ""; string queryStr = saveForm["queryStr"] != null ? saveForm["queryStr"] : ""; string dataStr = ""; string loginName = saveForm["loginName"]; if (loginName != "") { var user = dataOp.FindOneByKeyVal("SysUser", "loginName", loginName); if (user != null && string.IsNullOrEmpty(queryStr)) { result.Message = "系统已经存在同名用户!"; result.Status = Status.Failed; return(Json(TypeConvert.InvokeResultToPageJson(result), JsonRequestBehavior.AllowGet)); } } foreach (var tempKey in saveForm.AllKeys) { if (tempKey == "tbName" || tempKey == "queryStr" || tempKey.Contains("fileList[") || tempKey.Contains("param.") || tempKey.Contains("postIds") || tempKey.Contains("projRoleId") || tempKey.Contains("sysRoleId")) { continue; } dataStr += string.Format("{0}={1}&", tempKey, saveForm[tempKey]); } result = dataOp.Save(tbName, queryStr, dataStr); if (result.Status == Status.Successful) { #region 插入部门关联 List <StorageData> saveList = new List <StorageData>(); string postIdStr = PageReq.GetForm("postIds"); List <string> postIdList = postIdStr.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList(); List <BsonDocument> oldRelList = dataOp.FindAllByKeyVal("UserOrgPost", "userId", result.BsonInfo.String("userId")).ToList(); //旧的关联 foreach (var postId in postIdList) { BsonDocument tempRel = oldRelList.Where(t => t.String("postId") == postId.Trim()).FirstOrDefault(); //旧的关联 if (tempRel == null) //如果不存在,则添加 { StorageData tempSave = new StorageData(); tempSave.Name = "UserOrgPost"; tempSave.Type = StorageType.Insert; tempSave.Document = new BsonDocument().Add("userId", result.BsonInfo.String("userId")).Add("postId", postId.Trim().ToString()); saveList.Add(tempSave); } } foreach (var tempRel in oldRelList) { if (postIdList.Contains(tempRel.String("postId")) == false) //如果不存在,则删除 { StorageData tempSave = new StorageData(); tempSave.Name = "UserOrgPost"; tempSave.Type = StorageType.Delete; tempSave.Query = Query.EQ("relId", tempRel.String("relId")); saveList.Add(tempSave); } } dataOp.BatchSaveStorageData(saveList); #endregion #region 角色关联 string projRoleId = PageReq.GetForm("projRoleId"); string sysRoleId = PageReq.GetForm("sysRoleId"); string allStr = string.Format("{0},{1}", projRoleId, sysRoleId); SaveUserRole(allStr, result.BsonInfo.Text("userId"), 0); #endregion #region 文件上传 int primaryKey = 0; TableRule rule = new TableRule(tbName); string keyName = rule.ColumnRules.Where(t => t.IsPrimary == true).FirstOrDefault().Name; 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) { result = opHelper.DeleteFileByRelId(int.Parse(item)); if (result.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 } return(Json(TypeConvert.InvokeResultToPageJson(result), JsonRequestBehavior.AllowGet)); }
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)); }
public ActionResult SaveDocPackage(FormCollection saveForm) { InvokeResult result = new InvokeResult() { Status = Status.Successful }; #region 构建数据 string tbName = PageReq.GetForm("tbName"); string queryStr = PageReq.GetForm("queryStr"); string dataStr = PageReq.GetForm("dataStr"); BsonDocument dataBson = new BsonDocument(); if (dataStr.Trim() == "") { foreach (var tempKey in saveForm.AllKeys) { if (tempKey == "tbName" || tempKey == "queryStr" || tempKey.Contains("fileList[") || tempKey.Contains("param.") || tempKey == "PackageRe") { continue; } dataBson.Add(tempKey, PageReq.GetForm(tempKey)); } } else { dataBson = TypeConvert.ParamStrToBsonDocument(dataStr); } #endregion #region 保存数据 var packageId = PageReq.GetForm("packageId"); var curObj = dataOp.FindOneByKeyVal("ProjDocPackage", "packageId", packageId); var projId = PageReq.GetForm("projId"); var engId = PageReq.GetForm("engId"); var catTypeId = PageReq.GetForm("catTypeId"); var projDocCatId = PageReq.GetForm("projDocCatId"); var projEngId = PageReq.GetForm("projEngId"); var supplierId = PageReq.GetForm("supplierId"); var name = PageReq.GetForm("name"); var completedDate = PageReq.GetForm("completedDate"); var profId = PageReq.GetForm("profId"); var stageId = PageReq.GetForm("stageId"); var docType = PageReq.GetForm("docType"); var remark = PageReq.GetForm("remark"); var firstCatId = PageReq.GetForm("firstCatId"); //当前地块下类别对应的一级分类Id var isShowProjEng = PageReq.GetParamInt("isShowProjEng"); //是否展示工程 var isShowSupplier = PageReq.GetParamInt("isShowSupplier"); //是否展示供应商 var isShowCat = PageReq.GetParamInt("isShowCat"); //是否展示目录 var dngChangeId = PageReq.GetForm("dngChangeId"); //记录关联的设计变更单 //if (isShowProjEng == 0) projEngId = ""; //改为必填和非必填,不是可选和不可选 //if (isShowSupplier == 0) supplierId = "";// if (isShowCat == 0) //针对政府报文类别 需要存地块中对应的一级分类 { profId = ""; stageId = ""; projDocCatId = firstCatId; } var catTypeObj = dataOp.FindOneByQuery("ProjCategoryType", Query.EQ("catTypeId", catTypeId)); var updateBosn = new BsonDocument(); updateBosn.Add("projId", projId); updateBosn.Add("engId", engId); updateBosn.Add("catTypeId", catTypeId); updateBosn.Add("projDocCatId", projDocCatId); updateBosn.Add("projEngId", projEngId); updateBosn.Add("supplierId", supplierId); //bool propertyChanged = false; //if (curObj.Text("catTypeId") != catTypeId || curObj.Text("completedDate") != completedDate || curObj.Text("projEngId") != projEngId) //{ // propertyChanged = true; //} //if ((catTypeObj.Int("isNeedHide") != 1 && propertyChanged)||curObj.IsNullOrEmpty()) //{ // name = GetDocTitle(packageId, projEngId, catTypeId, completedDate); //} updateBosn.Add("name", name); updateBosn.Add("completedDate", completedDate); updateBosn.Add("profId", profId); updateBosn.Add("stageId", stageId); updateBosn.Add("docType", docType); updateBosn.Set("remark", remark); updateBosn.Add("firstCatId", firstCatId); updateBosn.Add("dngChangeId", dngChangeId); //var hasExistObj = dataOp.FindAllByQuery("ProjDocPackage", Query.And(Query.EQ("projDocCatId", projDocCatId.ToString()), Query.EQ("name", name.Trim()))).Where(c => c.Text("packageId") != packageId).Count() > 0; //if (hasExistObj) //{ // result.Status = Status.Failed; // result.Message = "不能创建重名的对象"; // return Json(TypeConvert.InvokeResultToPageJson(result)); //} #region 修改工程下其他图纸包的版本 (确保当前项目-当前工程-当前分类下只有一个最终版本) if (PageReq.GetForm("docType") == "1" && PageReq.GetForm("projId") != "") { List <StorageData> updateList = new List <StorageData>(); var QueryHit = Query.And(Query.EQ("projId", PageReq.GetForm("projId")), Query.EQ("projEngId", projEngId), Query.EQ("catTypeId", PageReq.GetForm("catTypeId")), Query.EQ("projDocCatId", projDocCatId)); List <BsonDocument> needUpdateList = dataOp.FindAllByQuery("ProjDocPackage", QueryHit).ToList(); foreach (var updateObj in needUpdateList) { StorageData relData = new StorageData(); updateObj.Set("docType", "0"); relData.Name = "ProjDocPackage"; relData.Document = updateObj; relData.Type = StorageType.Update; relData.Query = Query.EQ("packageId", updateObj.String("packageId")); updateList.Add(relData); } dataOp.BatchSaveStorageData(updateList); } //地块资料 if (PageReq.GetForm("docType") == "1" && PageReq.GetForm("engId") != "") { List <StorageData> updateList = new List <StorageData>(); var QueryHit = Query.And(Query.EQ("engId", PageReq.GetForm("engId")), Query.EQ("projEngId", projEngId), Query.EQ("catTypeId", PageReq.GetForm("catTypeId")), Query.EQ("projDocCatId", projDocCatId)); List <BsonDocument> needUpdateList = dataOp.FindAllByQuery("ProjDocPackage", QueryHit).ToList(); foreach (var updateObj in needUpdateList) { StorageData relData = new StorageData(); updateObj.Set("docType", "0"); relData.Name = "ProjDocPackage"; relData.Document = updateObj; relData.Type = StorageType.Update; relData.Query = Query.EQ("packageId", updateObj.String("packageId")); updateList.Add(relData); } dataOp.BatchSaveStorageData(updateList); } #endregion if (curObj != null) { result = dataOp.Update(curObj, updateBosn); } else { result = dataOp.Insert("ProjDocPackage", updateBosn); } //result = dataOp.Save(tbName, queryStr != "" ? TypeConvert.NativeQueryToQuery(queryStr) : Query.Null, dataBson); #endregion #region 文件上传 int primaryKey = 0; TableRule rule = new TableRule(tbName); ColumnRule columnRule = rule.ColumnRules.Where(t => t.IsPrimary == true).FirstOrDefault(); string keyName = columnRule != null ? columnRule.Name : ""; 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 保存图纸包关联 string packageRel = PageReq.GetForm("PackageRe"); //图纸包关联 List <string> teamRelArray = packageRel.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList(); string packId = result.BsonInfo.Text("packageId"); if (result.Status == Status.Successful) { List <StorageData> saveList = new List <StorageData>(); List <BsonDocument> oldTeamRelList = dataOp.FindAllByKeyVal("ProjDocPackageRelation", "curPackId", packId).ToList(); //所有旧的图纸包关联 foreach (var teamRel in teamRelArray) //循环新的关联,已存在则不添加,不存在则添加新的 { BsonDocument oldRel = oldTeamRelList.Where(t => t.String("refPackId") == teamRel).FirstOrDefault(); BsonDocument packAgeObj = dataOp.FindOneByQuery("ProjDocPackage", Query.EQ("packageId", teamRel)); //查找图纸包对象 if (oldRel == null && packAgeObj != null) { StorageData tempData = new StorageData(); tempData.Name = "ProjDocPackageRelation"; tempData.Document = TypeConvert.ParamStrToBsonDocument("curPackId=" + packId + "&refPackId=" + teamRel + "&catTypeId=" + packAgeObj.Text("catTypeId") + "&status=0"); tempData.Type = StorageType.Insert; saveList.Add(tempData); } } foreach (var oldRel in oldTeamRelList) //删除旧数据 { if (!teamRelArray.Contains(oldRel.Text("refPackId"))) { StorageData tempData = new StorageData(); tempData.Name = "ProjDocPackageRelation"; tempData.Query = Query.EQ("relationId", oldRel.String("relationId")); tempData.Type = StorageType.Delete; saveList.Add(tempData); } } dataOp.BatchSaveStorageData(saveList); } #endregion return(Json(TypeConvert.InvokeResultToPageJson(result))); }
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)); }
/// <summary> /// 保存成果与户型的关联 (新,修改户型保存的结构) /// </summary> /// <param name="saveForm"></param> /// <returns></returns> public ActionResult SaveStandardResultUnitNew(FormCollection saveForm) { string tbName = saveForm["tbName"] != null ? saveForm["tbName"] : ""; string queryStr = saveForm["queryStr"] != null ? saveForm["queryStr"] : ""; string dataStr = saveForm["dataStr"] != null ? saveForm["dataStr"] : ""; if (dataStr.Trim() == "") { foreach (var tempKey in saveForm.AllKeys) { if (tempKey == "tbName" || tempKey == "queryStr" || tempKey.Contains("fileList[") || tempKey.Contains("param.") || tempKey.Contains("supRels") || tempKey.Contains("teamRels")) { continue; } dataStr += string.Format("{0}={1}&", tempKey, saveForm[tempKey]); } } InvokeResult result = dataOp.Save(tbName, queryStr, dataStr); if (result.Status == Status.Successful) { #region 文件上传 int primaryKey = 0; TableRule rule = new TableRule(tbName); string keyName = rule.ColumnRules.Where(t => t.IsPrimary == true).FirstOrDefault().Name; 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) { result = opHelper.DeleteFileByRelId(int.Parse(item)); if (result.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 合作伙伴关联 string retId = result.BsonInfo.String("retId"); string teamRels = saveForm["teamRels"] != null ? saveForm["teamRels"] : ""; List <StorageData> saveList = new List <StorageData>(); #region 保存户型 List <string> teamRelArray = teamRels.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList(); List <BsonDocument> oldTeamRelList = dataOp.FindAllByKeyVal("StandardResult_Apartment", "retId", retId).ToList(); foreach (var teamRel in teamRelArray) //循环新的关联,已存在则不添加,不存在则添加新的 { string[] infoArr = teamRel.Split(new string[] { ":" }, StringSplitOptions.None); if (infoArr.Count() >= 3 && infoArr[0].Trim() != "") //完整资料才会保存 { string apartmentName = infoArr[0]; string room = infoArr[1]; string apartmentArea = infoArr[2]; BsonDocument oldRel = oldTeamRelList.Where(t => t.String("apartmentName") == apartmentName && t.String("room") == room && t.String("apartmentArea") == apartmentArea).FirstOrDefault(); if (oldRel == null) { StorageData tempData = new StorageData(); tempData.Name = "StandardResult_Apartment"; tempData.Document = new BsonDocument().Add("retId", retId.ToString()) .Add("apartmentName", apartmentName.ToString()) .Add("room", room.ToString()) .Add("apartmentArea", apartmentArea.ToString()); tempData.Type = StorageType.Insert; saveList.Add(tempData); } } } foreach (var oldRel in oldTeamRelList) { if (!teamRelArray.Contains(string.Format("{0}:{1}:{2}", oldRel.String("apartmentName"), oldRel.String("room"), oldRel.String("apartmentArea")))) { StorageData tempData = new StorageData(); tempData.Name = "StandardResult_Apartment"; tempData.Query = Query.EQ("ApaId", oldRel.String("ApaId")); tempData.Type = StorageType.Delete; saveList.Add(tempData); } } #endregion dataOp.BatchSaveStorageData(saveList); #endregion } return(Json(TypeConvert.InvokeResultToPageJson(result))); }