private ActionResult ParseParam(string schemaCode, string associationName) { this.SchemaCode = schemaCode; this.AssociationName = associationName; ActionResult result = new ActionResult(); if (string.IsNullOrEmpty(this.SchemaCode)) { this.Schema = null; } else { this.Schema = this.Engine.BizObjectManager.GetDraftSchema(this.SchemaCode); } if (this.Schema == null) { //业务对象模式不存在,或者已经被删除 result.Message = "BizObjectSchemaAssociation.Msg0"; result.Success = false; return(result); } if (!string.IsNullOrWhiteSpace(AssociationName)) { this.Association = this.Schema.GetAssociation(AssociationName); } result.Success = true; return(result); }
/// <summary> /// 获取关联表表格数据 /// </summary> /// <param name="associationName"关联的业务对象</param> /// <returns>关联表表格数据</returns> private List <AssociatedObjectRowViewModel> GetAssociatedObjectGrid(string associationName) { List <AssociatedObjectRowViewModel> list = new List <AssociatedObjectRowViewModel>(); if (string.IsNullOrEmpty(associationName)) { return(list); } OThinker.H3.DataModel.BizObjectAssociation asso = this.Schema.GetAssociation(associationName); // 获得关联对象的模式 this.AssociatedSchema = this.Engine.BizObjectManager.GetPublishedSchema(asso.AssociatedSchemaCode); if (this.BizObject != null) { BizObject[] objs = null; if (asso.AssociationType == H3.DataModel.AssociationType.OneOne) { BizObject obj = (BizObject)this.BizObject.GetValue(asso.Name); if (obj != null) { objs = new BizObject[] { obj }; } } else { objs = (BizObject[])this.BizObject.GetValue(asso.Name); } if (null != objs) { PropertySchema[] names = Schema.Properties; foreach (BizObject obj in objs) { if (names != null) { AssociatedObjectRowViewModel model = new AssociatedObjectRowViewModel(); model.Values = new List <Item>(); foreach (PropertySchema name in names) { if (Data.DataLogicTypeConvertor.IsSubDataTableSupported(name.RealType)) { //值不为Null时直接赋值,值为Null时可转为DBNull或不赋值 if (obj[name.Name] != null) { model.Values.Add(new Item(obj[name.Name].ToString(), obj[name.Name].ToString())); } } } list.Add(model); } } } } foreach (var item in list) { // 组合主键参数 Dictionary <string, string> vt = new Dictionary <string, string>(); PropertySchema[] names = this.AssociatedSchema.Properties; for (int count = 0; count < item.Values.Count - 1; count++) { string name = names[count].Name; string v = item.Values[count].Value; vt.Add(name, v); } string url = GetTestBizObjectUrl(this.AssociatedSchema.SchemaCode, 1, vt); //lnkEdit.Attributes["onclick"] = WorkSheet.SheetUtility.GetOpenWindowScript(url, false); //lnkEdit.Attributes["style"] = "cursor: hand"; //e.Item.Cells[e.Item.Cells.Count - 1].Controls.Add(lnkEdit); } return(list); }
/// <summary> /// 保存关联对象信息 /// </summary> /// <param name="model">关联对象信息</param> /// <returns>是否成功</returns> public JsonResult SaveAssociation(ObjectSchemaAssociationViewModel model) { return(ExecuteFunctionRun(() => { ActionResult result = new ActionResult(); result = ParseParam(model.SchemaCode, model.RelationName); if (!result.Success) { return Json(result, JsonRequestBehavior.AllowGet); } OThinker.H3.DataModel.BizObjectSchema schema = null; if (string.IsNullOrEmpty(model.WorkflowID) || string.IsNullOrEmpty(model.RelationName) || (schema = this.Engine.BizObjectManager.GetDraftSchema(model.WorkflowID)) == null) { //输入的名称或者要关联的业务对象模式不正确 result.Message = "BizObjectSchemaAssociation.Msg1"; result.Success = false; return Json(result, JsonRequestBehavior.AllowGet); } //if(){} if (this.Association == null) { this.Association = new DataModel.BizObjectAssociation( model.RelationName, model.DisplayName, (H3.DataModel.AssociationType)Enum.Parse(typeof(AssociationType), model.Type), schema, model.FilterMethod); } OThinker.H3.DataModel.DataMap[] maps = this.Association.Maps.ToArray(); if (maps != null) { List <AssociationDataMap> propertys = null; if (!string.IsNullOrEmpty(model.PropertyMap)) { propertys = JsonConvert.DeserializeObject <AssociationDataMap[]>((model.PropertyMap)).ToList(); } if (propertys == null) { propertys = new List <AssociationDataMap>(); } if (propertys.Count == 0) { propertys.Add(new AssociationDataMap() { ItemName = model.ItemName, MapTo = model.MapTo, MapType = model.MapType }); } foreach (OThinker.H3.DataModel.DataMap map in maps) { // 影射关系 AssociationDataMap property = propertys == null ? null : propertys.Where(p => p.ItemName == map.ItemName).FirstOrDefault(); if (property == null) { map.MapType = H3.DataModel.DataMapType.None; } else { map.MapTo = property.MapTo; map.MapType = (OThinker.H3.DataModel.DataMapType)Enum.Parse(typeof(OThinker.H3.DataModel.DataMapType), property.MapType); } } } if (string.IsNullOrWhiteSpace(model.ObjectID)) { //添加 if (!this.Schema.AddAssociation(this.Association)) { //添加失败 result.Message = "BizObjectSchemaAssociation.Msg2"; result.Success = false; return Json(result, JsonRequestBehavior.AllowGet); } } //更新 if (!this.Engine.BizObjectManager.UpdateDraftSchema(this.Schema)) { //保存业务对象模式失败 result.Message = "BizObjectSchemaAssociation.Msg3"; result.Success = false; return Json(result, JsonRequestBehavior.AllowGet); } result.Success = true; return Json(result, JsonRequestBehavior.AllowGet); })); }