客户需求:开发一个单据,按照周期录入数据,二开插件,把开发的单据物料,数量等字段写入到预测单的表体
代码实现:
# 引入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 *
from Kingdee.BOS.Util import *
from Kingdee.BOS.Log import *
button_clicked = False;
def BarItemClick(e):
global button_clicked # 声明 button_clicked 是全局变量
key = e.BarItemKey.ToUpperInvariant() # 菜单标识大写
# 定义一个自定义按钮
if key == "Button".ToUpperInvariant():
# 检查标志变量
if not button_clicked:
# SQL查询
msg = ("""select FMATERIALID, B from V_Custom_MZYCD """)
# SQL查询赋值到doc
doc = DBUtils.ExecuteDynamicObject(this.Context, msg)
# 循环查询
for dr in doc:
# 新增一行
this.View.Model.CreateNewEntryRow("FEntity")
# 单据体标识赋值
RowCounts = this.Model.GetEntryRowCount("FEntity")
# 单据体字段赋值
this.View.Model.SetValue("FMATERIALID", str(dr["FMATERIALID"]), RowCounts - 1)
this.View.Model.SetValue("FQty", str(dr["B"]), RowCounts - 1)
this.View.UpdateView()
button_clicked = True
this.View.ShowMessage(str('数据只能录入一次,多次点击无效')) # 在更新视图后显示 button_clicked 的值
代码分享.rar(1.04KB)