编码生成随机数
星空企业版和标准版没有生成随机码的功能,但是可以单据编码的编码规则可以使用文本字段,这样我们生成一个随机数放入到文本字段中,在更改编码规则拼接这个文本字段,就可以做到随机数的功能。
首先,现在对应单据上面添加一个文本字段,我放入到单据头中
上代码
# 引入clr运行库 import clr # 添加对cloud插件开发的常用组件的引用 clr.AddReference("System") clr.AddReference("System.Data") clr.AddReference("Kingdee.BOS") clr.AddReference("Kingdee.BOS.Core") clr.AddReference("Kingdee.BOS.App") clr.AddReference("Kingdee.BOS.ServiceHelper") from Kingdee.BOS import * from Kingdee.BOS.Core 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 Kingdee.BOS import * from System.Data import * from Kingdee.BOS.App.Data import * from System.Collections.Generic import List from Kingdee.BOS.ServiceHelper import * from System import Random # 定义字符串中包含的字符集 random = Random() chars = ["q","w","e","r","t","y","u","i","o","p","l","k","j","h","g","f","d","s","a","z","x","c","v","b","n","m","1","2","3","4","5","6", "7","8","9","0","Q","A","Z","W","S","X","E","D","C","E","D","C","R","F","V","T","G","B","Y","H","N", "U", "J", "M", "I", "k", "O", "P", "L",] # 获取当前单据的Fid def gain_fid(): fid = this.View.BillBusinessInfo.GetForm().Id return fid # 根据Fid 找到表名 def Fid_tableName(fid): sql = ( "/*dialect*/select FKERNELXML.query('//HeadEntity/TableName').value('(TableName)[1]','varchar(max)') as '单据头表名'from T_META_OBJECTTYPE where FID='{0}'" ).format(fid) ds = DBUtils.ExecuteDataSet(this.Context, sql) tab = ds.Tables[0] tabName = "" for dr in tab.Rows: tabName = dr["单据头表名"] return tabName # 生成指定长度的随机字符串 def generate_random_string(length): str1 = "" for i in range(length): XuHao = random.Next(0, 62) str1 = str1 + chars[XuHao] return str1 # 查询是否生成该随机数 现在是表名固定的,需要做到可以查询到根据不同单据类型可以查询到不同的表名 def ChaXunSql(suiJi): fid = gain_fid() tabName = Fid_tableName(fid) sql = ("SELECT F_XWWP_SuiJiShu from {1} where F_XWWP_SuiJiShu='{0}' ").format( suiJi, tabName ) ds = DBUtils.ExecuteDataSet(this.Context, sql) tab = ds.Tables[0] return tab # 在创建阶段将随机数赋值进去 做个循环,判断是否随机数生成重复 def AfterCreateNewData(e): billObj = this.Model.DataObject while 1 > 0: i = 1 i = i + 1 str2 = generate_random_string(10) tab = ChaXunSql(str2) if tab.Rows.Count <= 0: this.View.Model.SetValue("F_XWWP_SuiJiShu", str2) return if i > 1000: return
将代码放入到表单插件里面,注册python脚本,复制进去就好了,这样随机数就会生成在随机数文本框中
效果
最后到编码规则里面更改就可以了
最终效果
复制单据也不会影响随机数生成
编码生成随机数
星空企业版和标准版没有生成随机码的功能,但是可以单据编码的编码规则可以使用文本字段,这样我们生成一个随机数放入到文本字段中,在更改...
点击下载文档
上一篇:审批页面的标题 显示视图对应的标题下一篇:修复种子
本文2024-09-16 17:43:51发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-17586.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章