在服务端插件新建物料
客户需求: 在服务端插件新建物料。
解决方案: 创建DynamicObject数据包,调用Save服务。此方法也可用于创建单据并保存。
代码演示了设置普通字段、多语言字段、基础资料字段、子单据头字段的值。
演示了创建单据体行数据包的方法。
public void SaveMaterial() { var materailMetadata = ServiceHelper.GetService<Kingdee.BOS.Contracts.IMetaDataService>().Load(this.Context, "BD_MATERIAL") as FormMetadata; var materailBiz=materailMetadata.BusinessInfo; DynamicObject dynObj = new DynamicObject(materailMetadata.BusinessInfo.GetDynamicObjectType()); //初始化子单据头 InitSubHeadEntity(materailBiz, dynObj, "SubHeadEntity"); InitSubHeadEntity(materailBiz, dynObj, "SubHeadEntity1"); InitSubHeadEntity(materailBiz, dynObj, "SubHeadEntity6"); InitSubHeadEntity(materailBiz, dynObj, "SubHeadEntity2"); InitSubHeadEntity(materailBiz, dynObj, "SubHeadEntity3"); InitSubHeadEntity(materailBiz, dynObj, "SubHeadEntity4"); InitSubHeadEntity(materailBiz, dynObj, "SubHeadEntity5"); InitSubHeadEntity(materailBiz, dynObj, "SubHeadEntity7"); //设置单据头、子单据头字段的值 SetFieldValue(materailBiz, dynObj, "FNumber", "test001.001");//编码 SetFieldValue(materailBiz, dynObj, "FName", new LocaleValue("物料名称01"));//名称 SetFieldValue(materailBiz, dynObj, "FErpClsID", "1");//物料属性 SetBasedataFieldByNumber(materailBiz, dynObj, "FBaseUnitId", "pcs");//基本单位 SetFieldValue(materailBiz, dynObj, "FDocumentStatus", "A");// 数据状态 SetFieldValue(materailBiz, dynObj, "FForbidStatus", "A");// 禁用状态 SetFieldValue(materailBiz, dynObj, "FCreateOrgId", 100001);//创建组织 SetFieldValue(materailBiz, dynObj, "FUseOrgId", 100001);//使用组织 SetFieldValue(materailBiz, dynObj, "FCreatorId", 16394);//创建人 SetFieldValue(materailBiz, dynObj, "FModifierId", 16394);//修改人 var now = ServiceHelper.GetService<Kingdee.BOS.Contracts.ITimeService>().GetSystemDateTime(this.Context); SetFieldValue(materailBiz, dynObj, "FCreateDate", now);// 创建时间 SetFieldValue(materailBiz, dynObj, "FModifyDate", now);// 修改时间 //设置单据体-库存 var entityInvPty = materailBiz.GetEntity("FEntityInvPty"); var entityInvPtyData = dynObj[entityInvPty.EntryName] as DynamicObjectCollection; //增加单据体第一行数据 var entityInvPtyRow1 = new DynamicObject(entityInvPty.DynamicObjectType); entityInvPtyRow1["IsAffectPrice"] = true; entityInvPtyData.Add(entityInvPtyRow1); ServiceHelper.GetService<Kingdee.BOS.Contracts.ISaveService>().Save(this.Context, materailBiz, new[] { dynObj }); } /// <summary> /// 初始化子单据头数据包 /// </summary> /// <param name="bizInfo"></param> /// <param name="dynObj"></param> /// <param name="entityKey"></param> private void InitSubHeadEntity(BusinessInfo bizInfo, DynamicObject dynObj, string entityKey) { var subEntity = bizInfo.GetEntity(entityKey); if (subEntity is Kingdee.BOS.Core.Metadata.EntityElement.SubHeadEntity) { var subData = dynObj[subEntity.EntryName] as DynamicObjectCollection; if (subData.Count == 0) { subData.Add(new DynamicObject(subEntity.DynamicObjectType)); } } } /// <summary> /// 设置字段的值 /// </summary> /// <param name="bizInfo">物料元数据</param> /// <param name="dynObj">物料数据包</param> /// <param name="fieldKey">字段Key</param> /// <param name="fieldValue">字段值/基础资料内码</param> private void SetFieldValue(BusinessInfo bizInfo, DynamicObject dynObj, string fieldKey, object fieldValue) { var field = bizInfo.GetField(fieldKey); //基础资料字段 BaseDataField bdField = field as BaseDataField; if (bdField != null) { SetBasedataFieldValue(dynObj, bdField, fieldValue); return; } if (field.Entity is Kingdee.BOS.Core.Metadata.EntityElement.SubHeadEntity) { //子单据头字段 var subData = dynObj[bdField.Entity.EntryName] as DynamicObjectCollection; if (subData.Count == 0) { subData.Add(new DynamicObject(bdField.Entity.DynamicObjectType)); } field.DynamicProperty.SetValue(subData[0], fieldValue); } else { //单据头字段 dynObj[field.PropertyName] = fieldValue; } } /// <summary> /// 设置基础资料字段的值 /// </summary> /// <param name="dynObj"></param> /// <param name="bdField"></param> /// <param name="fieldValue"></param> private void SetBasedataFieldValue(DynamicObject dynObj, BaseDataField bdField, object fieldValue) { DynamicObject[] bdObjs = ServiceHelper.GetService<Kingdee.BOS.Contracts.IViewService>().LoadFromCache(this.Context, new object[] { fieldValue }, bdField.RefFormDynamicObjectType); if (bdObjs.IsEmpty()) return;//查不到基础资料,记录日志或报异常 if (bdField.Entity is Kingdee.BOS.Core.Metadata.EntityElement.SubHeadEntity) { var subData = dynObj[bdField.Entity.EntryName] as DynamicObjectCollection; if (subData.Count == 0) { subData.Add(new DynamicObject(bdField.Entity.DynamicObjectType)); } bdField.RefIDDynamicProperty.SetValue(subData[0], fieldValue); bdField.DynamicProperty.SetValue(subData[0], bdObjs[0]); } else { bdField.RefIDDynamicProperty.SetValue(dynObj, fieldValue); bdField.DynamicProperty.SetValue(dynObj, bdObjs[0]); } } /// <summary> /// 用编码设置基础资料字段 /// </summary> /// <param name="bizInfo">物料元数据</param> /// <param name="dynObj">物料数据包</param> /// <param name="fieldKey">基础资料字段Key</param> /// <param name="number">基础资料编码</param> private void SetBasedataFieldByNumber(BusinessInfo bizInfo, DynamicObject dynObj, string fieldKey,string number) { //基础资料字段 BaseDataField bdField = bizInfo.GetField(fieldKey) as BaseDataField; if (bdField == null || bdField.LookUpObject == null) return; QueryBuilderParemeter query = new QueryBuilderParemeter() { FormId = bdField.LookUpObject.FormId, FilterClauseWihtKey = string.Format("FNUMBER='{0}'", number) }; DynamicObject[] bdObjs = ServiceHelper.GetService<Kingdee.BOS.Contracts.IViewService>().LoadFromCache(this.Context, bdField.RefFormDynamicObjectType, query); if (bdObjs.IsEmpty()) return;//查不到基础资料,记录日志或报异常 if (bdField.Entity is Kingdee.BOS.Core.Metadata.EntityElement.SubHeadEntity) { var subData = dynObj[bdField.Entity.EntryName] as DynamicObjectCollection; if (subData.Count == 0) { subData.Add(new DynamicObject(bdField.Entity.DynamicObjectType)); } bdField.RefIDDynamicProperty.SetValue(subData[0], bdObjs[0][0]); bdField.DynamicProperty.SetValue(subData[0], bdObjs[0]); } else { bdField.RefIDDynamicProperty.SetValue(dynObj, bdObjs[0][0]); bdField.DynamicProperty.SetValue(dynObj, bdObjs[0]); } }
在服务端插件新建物料
客户需求: 在服务端插件新建物料。解决方案: 创建DynamicObject数据包,调用Save服务。此方法也可用于创建单据并保存。代码演示了设置...
点击下载文档
上一篇:基础资料批改操作增加批改字段(二开方案)下一篇:员工单据姓名为空问题
本文2024-09-23 03:40:06发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-160325.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章