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))); }
public ActionResult SavePostInfo(FormCollection saveForm) { InvokeResult result = new InvokeResult(); DataOperation dataOp = new DataOperation(); #region 构建数据 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.")) { continue; } dataStr += string.Format("{0}={1}&", tempKey, saveForm[tempKey]); } } #endregion #region 保存数据 BsonDocument curData = new BsonDocument(); //当前数据,即操作前数据 if (queryStr.Trim() != "") { curData = dataOp.FindOneByQuery(tbName, TypeConvert.NativeQueryToQuery(queryStr)); } result = dataOp.Save(tbName, queryStr, dataStr); #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) { string str = result.BsonInfo.Text(keyName); saveForm["keyValue"] = result.BsonInfo.Text(keyName); string t = saveForm["keyValue"].ToString(); string c = result.BsonInfo.String(keyName); t = ""; } } 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 保存日志 if (result.Status == Status.Successful) { //dataOp.LogDataStorage(tbName, queryStr.Trim() == "" ? StorageType.Insert : StorageType.Update, curData, result.BsonInfo); } #endregion return(Json(TypeConvert.InvokeResultToPageJson(result))); }
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 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)); }
/// <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))); }