原帖来自于:二开案例.Python插件.表单插件执行SQL
业务场景模拟:采购订单根据选择的供应商获取供应商的已下单次数
BOS新建一个整数类型的字段和一个按钮
#单据头菜单点击事件,从参数e中获取菜单标识,来判断是哪个菜单发生了点击
def BarItemClick(e):
key=e.BarItemKey.ToUpperInvariant();#菜单标识大写
if(key=="TESTBTN1".ToUpperInvariant()):#替换成自己添加的按钮标识
msg=("菜单[{0}]点击事件捕捉到了,可以继续菜单的功能啦!").format(key);
this.View.ShowMessage(msg);
获取供应商字段标识,绑定实体属性
billObj = this.View.Model.DataObject;
supplierObj = billObj['supplierid'];
判断供应商是否选择
if supplierObj == None:
this.View.ShowWarnningMessage('请先选择供应商!');
return
根据结果进行判断
if count == 0:
this.Model.SetValue('F_VSZN_OrderCount',dbs);
this.View.ShowWarnningMessage('供应商'+format(supplierObj["NAME"])+'目前没有采购记录。');
else:
this.Model.SetValue('F_VSZN_OrderCount',dbs);
this.View.ShowMessage('下单次数已获取到,供应商是:'+format(supplierObj["NAME"]));
完整代码
#引入clr运行库 import clr #添加对cloud插件开发的常用组件的引用 clr.AddReference('System') clr.AddReference('System.Data') clr.AddReference('Kingdee.BOS') clr.AddReference('Kingdee.BOS.DataEntity') clr.AddReference('Kingdee.BOS.Core') clr.AddReference('Kingdee.BOS.App') clr.AddReference('Kingdee.BOS.App.Core') clr.AddReference('Kingdee.BOS.ServiceHelper') #导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入) from Kingdee.BOS import * from Kingdee.BOS.Core import * from Kingdee.BOS.Core.DependencyRules import * from Kingdee.BOS.Core.Bill import * from Kingdee.BOS.Core.DynamicForm.PlugIn import * from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import * from System import * from System.Data import * from Kingdee.BOS.App.Data import * from System.Collections.Generic import List from Kingdee.BOS.ServiceHelper import * from Kingdee.BOS.Core.DynamicForm import * from Kingdee.BOS.Core.Metadata.EntityElement import * from Kingdee.BOS.Core.Metadata.FieldElement import * from Kingdee.BOS.Orm.DataEntity import * def BarItemClick(e): key=e.BarItemKey.ToUpperInvariant();#菜单标识大写 if(key=="VSZN_tbGetOrderCount".ToUpperInvariant()): msg=("菜单[{0}]点击事件捕捉到了,可以继续菜单的功能啦!").format(key); billObj = this.View.Model.DataObject; supplierObj = billObj['supplierid']; if supplierObj == None: this.View.ShowWarnningMessage('请先选择供应商!'); return if supplierObj != None: supplierNum=("{0}").format(supplierObj["Number"]); sql = """/*dialect*/ SELECT COALESCE(COUNT(TPP.FBILLNO), 0) AS 采购次数 FROM t_BD_Supplier_L TBSL INNER JOIN T_PUR_POORDER TPP ON TBSL.FSupplierId = TPP.FSUPPLIERID LEFT JOIN t_BD_Supplier TBS ON TBS.FSupplierId = TBSL.FSupplierId LEFT JOIN t_BD_SupplierBase TBSB ON TBS.FSUPPLIERID = TBSB.FSUPPLIERID LEFT JOIN t_org_organizations TOO ON TPP.FPURCHASEORGID = TOO.FORGID LEFT JOIN T_ORG_ORGANIZATIONS_L TOOL ON TOO.FORGID = TOOL.FORGID WHERE TPP.FDOCUMENTSTATUS = 'C' AND TBS.FNUMBER='{0}' """.format(supplierNum); dbs = DBUtils.ExecuteScalar(this.Context, sql, 0); count = dbs if count == 0: this.Model.SetValue('F_VSZN_OrderCount',dbs); this.View.ShowWarnningMessage('供应商'+format(supplierObj["NAME"])+'目前没有采购记录。'); else: this.Model.SetValue('F_VSZN_OrderCount',dbs); this.View.ShowMessage('下单次数已获取到,供应商是:'+format(supplierObj["NAME"]));
注册表单插件看效果
未选择供应商点击按钮则提示请先选择供应商!
选择供应商后返回下单次数和成功的信息
若未找到供应商下单记录则提示供应商目前没有采购记录
推荐阅读