public bool Checked(UpdateContext context, ColumnRule mc, object data, string key, string realKey) { var eval = mc.Value.ToString(); var action = context.ContentParams.CreateOrGet <string, object, Delegate>(eval, expression => { return(EvalHelper.GetDelegate(context, expression, data)); }); return((bool)action.DynamicInvoke(data)); }
/// <summary> /// 获取主键字段名 /// </summary> /// <param name="?"></param> /// <returns></returns> public static string KeyField(this BsonDocument bsonDoc) { var tbName = bsonDoc.TableName(); var keyField = string.Empty; TableRule childTable = new TableRule(tbName); //获取子表的表结构 ColumnRule foreignColumn = childTable.ColumnRules.Where(t => t.IsPrimary == true).FirstOrDefault(); //子表指向源表的外键字段 if (foreignColumn != null) { keyField = foreignColumn.Name; } return(keyField); }
public void Return_False_When_3_Positions_Have_Same_Symbol_In_A_Column() { var board = new int?[3][]; board[0] = new int?[3] { 1, null, 1 }; board[1] = new int?[3] { 2, 2, null }; board[2] = new int?[3] { null, 1, 1 }; var rule = new ColumnRule(); Assert.IsFalse(rule.IsWinning(board)); }
/// <summary> /// 获取字段对应的主表记录 /// </summary> /// <param name="bsonDoc"></param> /// <param name="name">字段名称</param> /// <returns></returns> public static List <BsonDocument> ChildBsonList(this BsonDocument bsonDoc, string tbName) { List <BsonDocument> childBsonList = new List <BsonDocument>(); if (bsonDoc != null && bsonDoc.String("underTable") != "") { string curTbName = bsonDoc.String("underTable"); //当前记录所属表 TableRule childTable = new TableRule(tbName); //获取子表的表结构 ColumnRule foreignColumn = childTable.ColumnRules.Where(t => t.SourceTable == curTbName).FirstOrDefault(); //子表指向源表的外键字段 if (foreignColumn != null && foreignColumn.SourceTable != "" && foreignColumn.SourceColumn != "") //外键不为空,且有对应表,对应字段 { childBsonList = new DataOperation(tbName).FindAllByKeyVal(foreignColumn.Name, bsonDoc.String(foreignColumn.SourceColumn)).ToList(); } } return(childBsonList); }
public bool Checked(UpdateContext updateContext, ColumnRule mc, object data, string key, string realKey) { var lenStrs = mc.Value.ToString().Split(SqlKeyWorld.Split3); bool result; if (lenStrs.Length == 1) { result = DoCheckMax(decimal.Parse(lenStrs[0]), data); return(result); } result = DoCheckMax(decimal.Parse(lenStrs[1]), data); if (result == false) { return(false); } result = DoCheckMin(decimal.Parse(lenStrs[0]), data); return(result); }
public void WhenValueDoesNotExist_ReturnTrue() { var value = 8; var board = new MatrixBoard(new int[9, 9] { { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 } }); var sut = new ColumnRule(); var actual = sut.Test(board, new Point(6, 4), value); actual.Should().BeTrue(); }
/// <summary> /// 获取字段对应的主表记录 /// </summary> /// <param name="bsonDoc"></param> /// <param name="foreignFieldName"> 外键字段名称</param> /// <returns></returns> public static BsonDocument SourceBson(this BsonDocument bsonDoc, string foreignFieldName) { BsonDocument sourceDoc = null; if (bsonDoc != null && bsonDoc.Contains(foreignFieldName) && bsonDoc.Contains("underTable")) { string tbName = bsonDoc.GetValue("underTable").ToString(); //当前记录所属表 TableRule tableEntity = new TableRule(tbName); //获取表结构 ColumnRule columnEntity = tableEntity.ColumnRules.Where(t => t.Name == foreignFieldName).FirstOrDefault(); //获取对应字段 if (columnEntity != null && columnEntity.SourceTable != "" && columnEntity.SourceColumn != "") //如果字段有标记外键,则返回对应源记录 { sourceDoc = new DataOperation(columnEntity.SourceTable).FindOneByKeyVal(columnEntity.SourceColumn, bsonDoc.GetValue(foreignFieldName).ToString()); } } return(sourceDoc); }
public static object GetColumnValue(string dbKey, string tableName, ColumnRule columnRule, object paramData) { switch (columnRule.ValueType) { case ColumnValueType.Interface: { var typeStrs = columnRule.Value.ToString().Split(SqlKeyWorld.Split3); var valueGetter = (IUpdateValueGetter)ReflectUtil.ReflectUtil.CreateInstance(typeStrs[0], typeStrs[1]); return(valueGetter.Get(dbKey, tableName, columnRule, paramData)); } case ColumnValueType.Func: { var func = (Func <string, string, ColumnRule, object, object>)columnRule.Value; return(func.Invoke(dbKey, tableName, columnRule, paramData)); } default: return(columnRule.Value); } }
public ActionResult SavePostInfo(FormCollection saveForm) { NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); InvokeResult result = new InvokeResult(); #region 构建数据 var formKeys = saveForm.AllKeys; string tbName = formKeys.Contains("tbName") ? saveForm["tbName"] : PageReq.GetForm("tbName"); string queryStr = formKeys.Contains("queryStr") ? saveForm["queryStr"] : PageReq.GetForm("queryStr"); string dataStr = formKeys.Contains("dataStr") ? saveForm["dataStr"] : PageReq.GetForm("dataStr"); TableRule rule = new TableRule(tbName); BsonDocument dataBson = new BsonDocument(); bool columnNeedConvert = false; if (dataStr.Trim() == "") { if (saveForm.AllKeys.Contains("fileObjId")) { columnNeedConvert = true; } foreach (var tempKey in saveForm.AllKeys) { if (tempKey == "tbName" || tempKey == "queryStr" || tempKey.Contains("fileList[") || tempKey.Contains("param.")) { continue; } //2016.1.25添加数据转换过滤, //由于前端通用TableManage需要上传可能会内置tableName字段,如果表中页游tableName字段可能会冲突保存不了 //目前做法前段替换,后端转化COLUMNNEEDCONVERT_ var curFormValue = saveForm[tempKey]; var curColumnName = tempKey; if (columnNeedConvert && tempKey.Contains("COLUMNNEEDCONVERT_")) { curColumnName = curColumnName.Replace("COLUMNNEEDCONVERT_", string.Empty); } dataBson.Set(curColumnName, curFormValue); } } else { dataBson = TypeConvert.ParamStrToBsonDocument(dataStr); } #endregion #region 保存数据 result = dataOp.Save(tbName, queryStr != "" ? TypeConvert.NativeQueryToQuery(queryStr) : Query.Null, dataBson); #endregion #region 文件上传 int primaryKey = 0; 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) { var fileRelIdList = fileArray.Select(t => (BsonValue)t).ToList(); var result1 = opHelper.DeleteFileByRelIdList(fileRelIdList); } } } 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))); }
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 bool Checked(UpdateContext updateContext, ColumnRule mc, object data, string key, string realKey) { return(mc.Value.ToString() == data.ToString()); }
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 bool Checked(UpdateContext updateContext, ColumnRule mc, object data, string key, string realKey) { IEnumerable <object> array = (IEnumerable <object>)mc.Value; return(array.Any(a => a.ToString() == data.ToString())); }