有时候我们的表单可能很简单,只是一个简单交互的表单,但有可能还是要劳师动众的给它建个工程写个插件,是不是很不爽?例如我有如下一个表单:
功能很简单就是选个业务对象,收集绑定几个字段名,然后确定返回一个对象而已。我不想写插件,因为K3Cloud是基于.net 4.0的,它对动态语言有了支持,于是我选择使用python来实现这个简单逻辑,以下是我的py插件,有注释,小伙伴们应该读得懂:
#引入clr运行库
import clr
#添加对cloud插件开发的常用组件的引用
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.K3.Core')
clr.AddReference('LUTAI.K3.BOS.Core')
clr.AddReference('Kingdee.BOS.ServiceHelper')
#导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入)
from Kingdee.BOS import *
from Kingdee.BOS.Util import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.DynamicForm import *
from Kingdee.BOS.Core.DynamicForm.PlugIn import *
from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import *
from Kingdee.BOS.Core.Interaction import *
from Kingdee.BOS.Core.Metadata import *
from Kingdee.BOS.Core.Metadata.EntityElement import *
from Kingdee.BOS.Core.Metadata.FieldElement import *
from Kingdee.BOS.ServiceHelper import *
from Kingdee.K3.Core import *
from LUTAI.K3.BOS.Core import *
from LUTAI.K3.BOS.Core.Metadata.Operation import *
from System import *
from System.Collections.Generic import *
#这里是重载cloud插件模型的按钮点击事件,其它事件的重写也一样
def ButtonClick(e):
if e.Key=="FOK":
#这里是实例化C#中的实体对象
selParams = BatchEditBomOpParams();
#这里就是取表单模型里某字段的模型对象了
selFormIdField = this.View.BillBusinessInfo.GetField("FSelFormId");
mtrlFieldKeyField = this.View.BillBusinessInfo.GetField("FMtrlIdFieldKey");
auxPropIdFieldKeyField = this.View.BillBusinessInfo.GetField("FAuxPropIdFieldKey");
bomIdFieldKeyField = this.View.BillBusinessInfo.GetField("FBomIdFieldKey");
#从模型取值赋值给C#实体对象
selParams.FormId=selFormIdField.RefIDDynamicProperty.GetValue(this.Model.DataObject);
selParams.MaterialIdFieldKey=mtrlFieldKeyField.DynamicProperty.GetValue(this.Model.DataObject);
selParams.AuxPropIdFieldKey=auxPropIdFieldKeyField.DynamicProperty.GetValue(this.Model.DataObject);
selParams.BomIdFieldKey=bomIdFieldKeyField.DynamicProperty.GetValue(this.Model.DataObject);
if len(selParams.FormId)<=0:
this.View.ShowMessage("表单对象字段必录!");
return;
if len(selParams.MaterialIdFieldKey)<=0:
this.View.ShowMessage("成品编码字段必录!");
return;
if len(selParams.BomIdFieldKey)<=0:
this.View.ShowMessage("BOM版本字段必录!");
return;
this.View.ReturnToParentWindow(selParams);
this.View.Close();
def DataChanged(e):
if e.Key=="FSelFormId":
if len(e.NewValue)>0:
#这里要注意的是,使用this.Context获取上下文,不要使用this.View.get_Context(),这是智能感知的,被害死了
metadata = MetaDataServiceHelper.Load(this.Context, e.NewValue);
lstMtrlFieldItems = List[EnumItem]();
lstAuxPropIdFieldItems = List[EnumItem]();
lstBomIdFieldItems = List[EnumItem]();
lstAuxPropIdFieldItems.Add(EnumItem());
if e.NewValue == "ENG_BOM":
enumItem=EnumItem();
enumItem.Caption=LocaleValue("物料清单内码", this.Context.UserLocale.LCID);
enumItem.Value=metadata.BusinessInfo.GetForm().PkFieldName;
enumItem.Seq=0;
enumItem.EnumId=Guid.NewGuid().ToString();
lstBomIdFieldItems.Add(enumItem);
iFlag = 0;
for field in metadata.BusinessInfo.GetFieldList():
enumItem2 = EnumItem();
enumItem2.Seq = iFlag;
enumItem2.Caption = field.Name;
enumItem2.Value = field.Key;
enumItem2.EnumId = Guid.NewGuid().ToString();
iFlag=iFlag+1;
if isinstance(field,BaseDataField):
lookupObjId = field.LookUpObject.FormId;
if lookupObjId=="ENG_BOM":
lstBomIdFieldItems.Add(enumItem2);
if lookupObjId=="BD_MATERIAL":
lstMtrlFieldItems.Add(enumItem2);
if isinstance(field,RelatedFlexGroupField):
lstAuxPropIdFieldItems.Add(enumItem2);
if lstMtrlFieldItems.Count>0:
fieldEditor = this.View.GetControl("FMtrlIdFieldKey");
fieldEditor.SetComboItems(lstMtrlFieldItems);
this.Model.SetValue("FMtrlIdFieldKey",lstMtrlFieldItems[0].Value);
if lstAuxPropIdFieldItems.Count>0:
fieldEditor = this.View.GetControl("FAuxPropIdFieldKey");
fieldEditor.SetComboItems(lstAuxPropIdFieldItems);
this.Model.SetValue("FAuxPropIdFieldKey",lstAuxPropIdFieldItems[0].Value);
if lstBomIdFieldItems.Count>0:
fieldEditor = this.View.GetControl("FBomIdFieldKey");
fieldEditor.SetComboItems(lstBomIdFieldItems);
this.Model.SetValue("FBomIdFieldKey",lstBomIdFieldItems[0].Value);
晕掉,复制过来都是带颜色的,可是一保存不高亮了,没颜色了,手动编辑了几种颜色,但太多了,麻烦。凑合看吧。希望这个编辑控件可以改进支持高亮代码显示才好。