private ActionResult ValidateData(Data.DataLogicType logicType, BizRuleGlossaryViewModel model) { System.Type realType = OThinker.H3.Data.DataLogicTypeConvertor.ToRealType(logicType); ActionResult result = new ActionResult(true, ""); if (string.IsNullOrEmpty(model.ElementName) || string.IsNullOrEmpty(model.ElementName)) { result.Success = false; result.Message = "BizRule.InvalidName"; return(result); } // 验证默认值是否合法 if (!string.IsNullOrEmpty(model.DefaultValue)) { object DefaultValue = model.DefaultValue; if (realType.FullName == typeof(string[]).FullName) { DefaultValue = model.DefaultValue.Split(';'); result.Message = DefaultValue.ToString(); return(result); } if (!OThinker.Data.Convertor.Check(realType, model.DefaultValue)) { result.Success = false; result.Message = "BizRule.InvalidDefaultValue"; return(result); } } return(result); }
/// <summary> /// 数据校验 /// </summary> /// <param name="model">数据项</param> /// <param name="propertyName">属性名称</param> /// <param name="logicType">属性类型</param> /// <param name="defaultValue">输出:默认值</param> /// <param name="result">输出:检验结果</param> /// <returns是否成功></returns> private bool DataValidator(BizObjectSchemaPropertyViewModel model, string propertyName, Data.DataLogicType logicType, out object defaultValue, out ActionResult result) { Type realType = Data.DataLogicTypeConvertor.ToRealType(logicType); if (!(logicType == Data.DataLogicType.Double || logicType == Data.DataLogicType.Int || logicType == Data.DataLogicType.Long )) { defaultValue = OThinker.Data.Convertor.GetDefaultValue(realType);//默认值 } else { defaultValue = null; } result = new ActionResult(); if (string.IsNullOrEmpty(propertyName)) { //属性名称不能为空 result.Success = false; result.Message = "EditBizObjectSchemaProperty.Msg10"; return(false); } if (propertyName.Length > BizObjectSchema.MaxPropertyNameLength) { result.Success = false; result.Message = "EditBizObjectSchemaProperty.Msg3"; result.Extend = BizObjectSchema.MaxPropertyNameLength; return(false); } // 数据项必须以字母开始,不让创建到数据库表字段时报错 // System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[A-Za-z][A-Za-z0-9_]*$"); System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[a-zA-Z\\u4e00-\\u9fa5][0-9a-zA-Z\\u4e00-\\u9fa5_]*$"); if (!regex.Match(propertyName).Success) { result.Success = false; result.Message = "EditBizObjectSchemaProperty.Msg4"; return(false); } if (OThinker.Data.Database.Database.IsDBKeyWord(propertyName)) { result.Success = false; result.Message = "EditBizObjectSchemaProperty.Msg5"; return(false); } if (DataModel.BizObjectSchema.IsReservedProperty(propertyName) || propertyName.ToUpper() == "T") { //不能添加保留属性 result.Success = false; result.Message = "EditBizObjectSchemaProperty.Msg6"; result.Extend = propertyName; return(false); } else if (!string.IsNullOrEmpty(model.DefaultValue)) { if (logicType != DataLogicType.GlobalData && !OThinker.Data.Convertor.Convert(model.DefaultValue, realType, ref defaultValue)) { // 转换失败,无法将默认值转换成选中的类型 result.Success = false; result.Message = "EditBizObjectSchemaProperty.Msg7"; return(false); } } if (PublishedSchema != null && this.SelectedProperty != propertyName && this.PublishedSchema.GetProperty(propertyName) != null) { result.Success = false; result.Message = "EditBizObjectSchemaProperty.Msg9"; return(false); } if (logicType == Data.DataLogicType.Association && string.IsNullOrEmpty(model.DefaultValue)) { result.Success = false; result.Message = "EditBizObjectSchemaProperty.AssociationCodeRequired"; return(false); } // 业务对象数组时,判断子业务对象编码是否已经被其他的数据模型占用 if (logicType == Data.DataLogicType.BizObject || logicType == Data.DataLogicType.BizObjectArray) { string childSchemaCode = model.PropertyName; // this.txtChildSchemaCode.Text.Trim(); // 修改时,子业务对象编码不能修改,所以只在新增时进行验证 if (string.IsNullOrEmpty(this.SelectedProperty)) { if (this.CurrentSchema.Properties.Any(p => p.LogicType == logicType && p.ChildSchema.SchemaCode == childSchemaCode)) { result.Success = false; result.Message = "EditBizObjectSchemaProperty.Msg8"; return(false); } string msg = ""; if (!this.Engine.BizObjectManager.CheckSchemaCodeDuplicated(childSchemaCode, out msg)) { result.Success = false; result.Message = "EditBizObjectSchemaProperty.Msg8"; return(false); } } } return(true); }
/// <summary> /// 执行保存 /// </summary> /// <returns>是否保存成功</returns> private bool SaveBizObjectSchemaProperty(BizObjectSchemaPropertyViewModel model, out ActionResult actionResult) { actionResult = new ActionResult(); string propertyName = model.PropertyName; string displayName = string.IsNullOrWhiteSpace(model.DisplayName) ? propertyName : model.DisplayName; // 检查选中的参数 Data.DataLogicType logicType = (Data.DataLogicType)Enum.Parse(typeof(Data.DataLogicType), model.LogicType); object defaultValue;//默认值 if (model.DefaultValue == string.Empty) { defaultValue = null; } else if (!DataValidator(model, propertyName, logicType, out defaultValue, out actionResult)) {//数据校验 return(false); } // 校验编码规范 System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(BizObjectSchema.CodeRegex); if (!regex.IsMatch(propertyName)) { actionResult.Success = false; actionResult.Message = "EditBizObjectSchemaProperty.Msg2"; return(false); } DataModel.PropertySchema newItem = null; if (logicType == Data.DataLogicType.BizObject || logicType == Data.DataLogicType.BizObjectArray) { //业务对象或业务对象数组 H3.DataModel.BizObjectSchema childSchema = CreateChildSchema(model.PropertyName); newItem = new DataModel.PropertySchema( propertyName, displayName, logicType, childSchema); } else { PropertySerializeMethod method = PropertySerializeMethod.None; int maxLength = 0; if (!model.VirtualField) { DataLogicTypeConvertor.GetSerializeMethod(logicType, ref method, ref maxLength); if (logicType == DataLogicType.Attachment && this.RootSchema.SchemaCode != this.CurrentSchema.SchemaCode) { method = PropertySerializeMethod.Xml; } } SourceType sourceType = logicType == DataLogicType.GlobalData ? SourceType.Metadata : SourceType.Normal; newItem = new DataModel.PropertySchema( propertyName, sourceType, method, model.Global, model.Indexed, displayName, logicType == DataLogicType.GlobalData ? DataLogicType.ShortString : logicType, maxLength, defaultValue, model.Formula, string.Empty, //this.txtDisplayValueFormula.Text, // 显示值公式没有实际作用,已注释 model.RecordTrail, model.Searchable, false, // this.chkAbstract.Checked // 摘要没有实际作用,已注释 false ); } bool result = true; if (!string.IsNullOrEmpty(this.SelectedProperty)) {//更新 DataModel.PropertySchema oldPropertySchema = this.CurrentSchema.GetProperty(this.SelectedProperty); DataModel.BizObjectSchema published = this.Engine.BizObjectManager.GetPublishedSchema(this.RootSchema.SchemaCode); if (published != null && published.GetProperty(propertyName) != null && !Data.DataLogicTypeConvertor.CanConvert(oldPropertySchema.LogicType, newItem.LogicType)) { actionResult.Success = false; actionResult.Message = "EditBizObjectSchemaProperty.Msg1"; return(false); } result = this.CurrentSchema.UpdateProperty(this.SelectedProperty, newItem); } else { result = this.CurrentSchema.AddProperty(newItem); } if (!result) { // 保存失败 actionResult.Success = false; actionResult.Message = "EditBizObjectSchemaProperty.Msg9"; return(false); } // 保存 if (!this.Engine.BizObjectManager.UpdateDraftSchema(this.RootSchema)) { // 保存失败 actionResult.Success = false; actionResult.Message = "msgGlobalString.SaveFailed"; return(false); } return(true); }
EditSimulationViewModel ShowDataItems(string workflowCode, DataModel.BizObjectSchema Schema, InstanceSimulation simulation, Dictionary <string, object> valueTable, EditSimulationViewModel model) { if (Schema == null || Schema.Properties == null) { return(model); } //<ItemName,Values> WorkflowTemplate.PublishedWorkflowTemplate tempalte = this.Engine.WorkflowManager.GetDefaultWorkflow(workflowCode); Dictionary <string, string[]> ExistItems = new Dictionary <string, string[]>(); Dictionary <string, bool> ActivityIgnore = new Dictionary <string, bool>(); if (valueTable != null) { foreach (string key in valueTable.Keys) { string[] values = new string[1]; values[0] = valueTable[key] + string.Empty; ExistItems.Add(key, values); } } else if (simulation != null && simulation.DataItems != null && simulation.DataItems.Length > 0) { foreach (InstanceSimulationDataItem item in simulation.DataItems) { if (!ExistItems.ContainsKey(item.ItemName)) { ExistItems.Add(item.ItemName, item.ItemValues); } if (!ActivityIgnore.ContainsKey(item.ItemName)) { ActivityIgnore.Add(item.ItemName, item.Ignore); } } } //可设置的类型 Data.DataLogicType[] SetableLogicTypes = new Data.DataLogicType[] { Data.DataLogicType.Bool, //Data.DataLogicType.Comment, Data.DataLogicType.DateTime, Data.DataLogicType.Decimal, Data.DataLogicType.Double, //Data.DataLogicType.Html, Data.DataLogicType.Int, Data.DataLogicType.Long, Data.DataLogicType.MultiParticipant, Data.DataLogicType.ShortString, Data.DataLogicType.SingleParticipant, Data.DataLogicType.String, Data.DataLogicType.TimeSpan//, //Data.DataLogicType.Xml }; List <string> UserIDs = new List <string>(); foreach (DataModel.PropertySchema p in Schema.Properties) { if (!DataModel.BizObjectSchema.IsReservedProperty(p.Name) && (p.LogicType == Data.DataLogicType.SingleParticipant || p.LogicType == Data.DataLogicType.MultiParticipant) && ExistItems.ContainsKey(p.Name) && ExistItems[p.Name] != null) { foreach (string id in ExistItems[p.Name]) { UserIDs.Add(id); } } } foreach (WorkflowTemplate.Activity activity in tempalte.Activities) { if (activity.ActivityType == WorkflowTemplate.ActivityType.Start || activity.ActivityType == WorkflowTemplate.ActivityType.End) { continue; } if (activity.ActivityCode == tempalte.StartActivityCode) { continue; } if (ExistItems.ContainsKey(activity.ActivityCode)) { foreach (string id in ExistItems[activity.ActivityCode]) { UserIDs.Add(id); } } } OThinker.Organization.Unit[] Units = this.Engine.Organization.GetUnits(UserIDs.ToArray()).ToArray(); //<UserID,UserName> Dictionary <string, string> DicUnits = new Dictionary <string, string>(); if (Units != null) { foreach (OThinker.Organization.Unit u in Units) { if (!DicUnits.ContainsKey(u.ObjectID)) { DicUnits.Add(u.ObjectID, u.Name); } } } List <object> lstDataItems = new List <object>(); foreach (DataModel.PropertySchema p in Schema.Properties) { if (DataModel.BizObjectSchema.IsReservedProperty(p.Name)) { continue; } if (!SetableLogicTypes.Contains(p.LogicType)) { continue; } string DisplayValueString = string.Empty; if (ExistItems.ContainsKey(p.Name) && ExistItems[p.Name] != null && ExistItems[p.Name].Length > 0) { if (p.LogicType == Data.DataLogicType.SingleParticipant || p.LogicType == Data.DataLogicType.MultiParticipant) { foreach (string _Value in ExistItems[p.Name]) { if (DicUnits.ContainsKey(_Value)) { DisplayValueString += DicUnits[_Value] + ";"; } else { DisplayValueString += ";"; } } } else { DisplayValueString = string.Join(";", ExistItems[p.Name]); } } lstDataItems.Add(new { ItemName = p.Name, ItemValues = ExistItems.ContainsKey(p.Name) ? ExistItems[p.Name] : null, DisplayValueString = DisplayValueString, LogicType = OThinker.H3.Data.DataLogicTypeConvertor.ToLogicTypeName(p.LogicType), Editable = SetableLogicTypes.Contains(p.LogicType) }); } List <object> lstActivitys = new List <object>(); foreach (WorkflowTemplate.Activity activity in tempalte.Activities) { if (activity.ActivityType == WorkflowTemplate.ActivityType.Start || activity.ActivityType == WorkflowTemplate.ActivityType.End) { continue; } if (activity.ActivityCode == tempalte.StartActivityCode) { continue; } string DisplayValueString = string.Empty; if (ExistItems.ContainsKey(activity.ActivityCode) && ExistItems[activity.ActivityCode] != null && ExistItems[activity.ActivityCode].Length > 0) { foreach (string _Value in ExistItems[activity.ActivityCode]) { if (DicUnits.ContainsKey(_Value)) { DisplayValueString += DicUnits[_Value] + ";"; } else { DisplayValueString += ";"; } } } lstActivitys.Add(new { WorkflowTemplate = workflowCode, ActivityCode = activity.ActivityCode, ActivityName = activity.DisplayName, Participants = ExistItems.ContainsKey(activity.ActivityCode) ? ExistItems[activity.ActivityCode] : null, DisplayValueString = DisplayValueString, Ignore = ActivityIgnore.ContainsKey(activity.ActivityCode) ? ActivityIgnore[activity.ActivityCode] : false, Editable = true }); } model.DataItems = CreateLigerUIGridData(lstDataItems.ToArray()); model.Activitys = CreateLigerUIGridData(lstActivitys.ToArray()); return(model); }
/// <summary> /// 保存业务规则词汇 /// </summary> /// <param name="model"></param> /// <returns></returns> public JsonResult Save(BizRuleGlossaryViewModel model) { Data.DataLogicType logicType = (Data.DataLogicType)Enum.Parse(typeof(Data.DataLogicType), model.LogicType); string defaultValue = string.IsNullOrEmpty(model.DefaultValue)?"":model.DefaultValue; bool IsCreate = string.IsNullOrEmpty(model.ObjectID); ActionResult result = ValidateData(logicType, model); if (!result.Success) { return(Json(result)); } OThinker.H3.BizBus.BizRule.BizRuleDataElement Element; OThinker.H3.BizBus.BizRule.BizRuleTable Rule = this.Engine.BizBus.GetBizRule(model.RuleCode); if (IsCreate) { // 数据项必须以字母开始,不让创建到数据库表字段时报错 // System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[A-Za-z][A-Za-z0-9_]*$"); System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[a-zA-Z\\u4e00-\\u9fa5][0-9a-zA-Z\\u4e00-\\u9fa5_]*$"); if (!regex.Match(model.ElementName).Success) { result.Success = false; result.Message = "EditBizObjectSchemaProperty.Msg4"; return(Json(result)); } //检测是否重名 if (Rule.GetDataElement(model.ElementName) != null) { result.Success = false; result.Message = "msgGlobalString.CodeDuplicate"; return(Json(result)); } Element = new OThinker.H3.BizBus.BizRule.BizRuleDataElement(); Element.ElementName = model.ElementName; Element.DisplayName = model.DisplayName; Element.Description = model.Description; Element.LogicType = logicType; Element.ParamType = (H3.BizBus.BizRule.InOutType)Enum.Parse(typeof(H3.BizBus.BizRule.InOutType), model.ParamType); Element.DefaultValue = defaultValue; if (!Rule.AddDataElement(Element)) { result.Success = false; result.Message = "msgGlobalString.SaveFailed"; return(Json(result)); } } else { Element = Rule.GetDataElement(model.ElementName); Element.DisplayName = model.DisplayName; Element.Description = model.Description; Element.LogicType = logicType; Element.ParamType = (H3.BizBus.BizRule.InOutType)Enum.Parse(typeof(H3.BizBus.BizRule.InOutType), model.ParamType); Element.DefaultValue = defaultValue; } if (!Engine.BizBus.UpdateBizRule(Rule)) { //ShowWarningMessage(PortalResource.GetString("EditBizRuleTableDataElement_SaveFailed")); result.Success = false; result.Message = "msgGlobalString.SaveFailed"; return(Json(result)); } result.Success = true; result.Message = "msgGlobalString.SaveSucced"; return(Json(result)); }
/// <summary> /// 获取方法列 /// </summary> /// <param name="serviceCode"></param> /// <param name="methodName"></param> /// <param name="sql"></param> /// <param name="parameters"></param> /// <returns></returns> public JsonResult GetMethodColumns(string serviceCode, string methodName, string sql, string parameters) { return(ExecuteFunctionRun(() => { ActionResult result = new ActionResult(true, ""); OThinker.H3.BizBus.BizService.BizService Service = GetService(serviceCode); Settings.BizDbConnectionConfig DbConnectionConfig = GetDbConnectionConfig(Service); if (DbConnectionConfig != null) { try { string[] ParameterNames = (string[])JsonConvert.DeserializeObject <string[]>(parameters);//前端组合的XML中的Parameters List <OThinker.Data.Database.Parameter> lstParameters = new List <OThinker.Data.Database.Parameter>(); if (ParameterNames != null) { foreach (string p in ParameterNames) { lstParameters.Add(new OThinker.Data.Database.Parameter(p, System.Data.DbType.String, null)); } } OThinker.Data.Database.ICommand Command = new OThinker.Data.Database.CommandFactory(DbConnectionConfig.DbType, DbConnectionConfig.DbConnectionString).CreateCommand(); System.Data.DataTable dt = Command.ExecuteDataTable(sql, lstParameters.ToArray()); if (dt != null) { Dictionary <string, string> ColumnDictionary = new Dictionary <string, string>(); string StringType = typeof(string).FullName + string.Empty; foreach (System.Data.DataColumn c in dt.Columns) { if (!ColumnDictionary.ContainsKey(c.ColumnName)) { Data.DataLogicType LogicType = Data.DataLogicType.ShortString; switch (c.DataType.ToString().ToLower()) { case "system.boolean": LogicType = Data.DataLogicType.Bool; break; case "system.char": case "system.byte": case "system.sbyte": LogicType = Data.DataLogicType.ShortString; break; case "system.int": case "system.int16": case "system.int32": case "system.int64": case "system.uint16": case "system.uint32": case "system.uint64": LogicType = Data.DataLogicType.Int; break; case "system.decimal": case "system.double": case "system.single": LogicType = Data.DataLogicType.Decimal; break; case "system.object": break; case "system.string": LogicType = Data.DataLogicType.String; break; default: break; } ColumnDictionary.Add(c.ColumnName, LogicType.ToString()); } } result.Extend = ColumnDictionary; } } catch (Exception ex) { result.Success = false; result.Extend = ex.Message; } return Json(result, JsonRequestBehavior.AllowGet); } return null; })); }