二开案例.单据插件.手动补号
【应用场景】
使用手动补号方式获取单据编号。
(优先计算补号,有补号时优先使用补号的编号,没有补号可用时,流水号+1生成新的单据编号)
【案例演示】
采购订单,演示单据编号字段和普通文本字段如何使用手动补号方式获取单据编号。
【实现步骤】
<1>编写单据插件,代码如下。
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.BusinessEntity.BillType;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.ElementMetadata;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace Jac.XkDemo.BOS.Business.PlugIn
{
/// <summary>
/// 【单据插件】手动补号
/// </summary>
[Description("【单据插件】手动补号"), HotUpdate]
public class GetBillNoByRepairBillPlugIn : AbstractBillPlugIn
{
public override void AfterBindData(EventArgs e)
{
base.AfterBindData(e);
BindBillCodeRules();
}
/// <summary>
/// 主菜单点击事件
/// </summary>
/// <param name="e"></param>
public override void BarItemClick(BarItemClickEventArgs e)
{
base.BarItemClick(e);
if (e.BarItemKey.EqualsIgnoreCase("GetBillNoByRepair_BillNoField"))
{
#region 给单据编号字段获取新的单据编号(优先手动补号)
var ruleId = GetCodeRuleByBillType();
var billNoField = this.View.BusinessInfo.GetBillNoField();
var sBillNo = BusinessDataServiceHelper.GetNextBillNoByRepair(this.Context
, this.View.BusinessInfo
, new[] { this.Model.DataObject }
, ruleId
, null);
this.Model.SetValue(billNoField.Key, sBillNo);
this.View.ShowMessage("获取到新的单据编号为:" + sBillNo);
return;
#endregion
}
if (e.BarItemKey.EqualsIgnoreCase("GetBillNoByRepair_TextField"))
{
#region 给指定的文本字段获取新的单据编号(优先手动补号)
// 一次性获取10个单据编号
var ruleId = this.Model.GetValue("F_Jac_Combo") as string;
if (string.IsNullOrWhiteSpace(ruleId))
{
this.View.ShowMessage("请选择编码规则!");
return;
}
var textField = this.View.BusinessInfo.GetField("F_Jac_Text");
var sBillNo = BusinessDataServiceHelper.GetNextBillNoByRepair(this.Context
, this.View.BusinessInfo
, new[] { this.Model.DataObject }
, ruleId
, null
, textField.Key // 用于存储编号的文本字段
, textField.Entity.TableName); // 文本字段所在表名
this.Model.SetValue(textField.Key, sBillNo);
this.View.ShowMessage("获取到新的单据编号为:" + sBillNo);
return;
#endregion
}
}
/// <summary>
/// 根据单据类型获取编码规则
/// </summary>
/// <returns></returns>
private string GetCodeRuleByBillType()
{
var ruleID = string.Empty;
var billNoFiled = this.View.BusinessInfo.GetBillNoField();
if (billNoFiled == null)
{
return ruleID;
}
var fields = this.View.BusinessInfo.GetFieldList();
//获取单据类型字段
var billForm = this.View.BusinessInfo.GetForm();
BillTypeField billTypeField = null;
if (billForm.ElementType == ElementType.ELEMENTTYPE_BILL)
{
billTypeField = fields.Find(p => p is BillTypeField) as BillTypeField;
}
if (billTypeField != null && billTypeField.BillTypeInfo.Count > 0)
{
var oBillType = this.Model.GetValue(billTypeField.Key) as DynamicObject;
if (oBillType != null && !oBillType["Id"].IsNullOrEmptyOrWhiteSpace())
{
var dyObject = billTypeField.BillTypeInfo.Find(p => p["Id"].ToString().Equals(oBillType["Id"].ToString()));
if (dyObject != null)
{
var billType = (BillType)dyObject;
if (billType.BillCodeRuleID != null && billType.BillCodeRuleID["Id"] != null)
{
ruleID = billType.BillCodeRuleID["Id"].ToString();
}
}
}
}
return ruleID;
}
/// <summary>
/// 绑定编码规则下拉列表
/// </summary>
private void BindBillCodeRules()
{
var enumList = new List<EnumItem>();
enumList.Add(new EnumItem { Caption = new LocaleValue(""), Value = "" });
var sql = string.Format(@"SELECT a.FRULEID,b.FNAME FROM T_BAS_BILLCODERULE a
LEFT JOIN T_BAS_BILLCODERULE_L b ON a.FRULEID=b.FRULEID AND b.FLOCALEID={0}
WHERE a.FBILLFORMID='{1}'", Context.UserLocale.LCID, this.View.BusinessInfo.GetForm().Id);
var objs = DBUtils.ExecuteDynamicObject(this.Context, sql);
if (objs != null && objs.Count > 0)
{
foreach (var obj in objs)
{
var enumItem = new EnumItem();
enumItem.Caption = new LocaleValue(obj["FNAME"].ToString());
//enumItem.EnumId = obj["FRULEID"].ToString();
//enumItem.Invalid = false;
enumItem.Value = obj["FRULEID"].ToString();
enumList.Add(enumItem);
}
}
var comboList = this.View.GetFieldEditor<ComboFieldEditor>("F_Jac_Combo", 0);
if (comboList != null)
{
comboList.SetComboItems(enumList);
this.Model.SetValue("F_Jac_Combo", enumList[1].Value);
}
}
}
}
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展采购订单,新增下拉列表字段和文本字段,菜单集合新增菜单项,注册表单插件,保存元数据,开发完毕。
【功能验证】
<1>登录业务站点,打开采购订单新增界面,点击补号菜单,即可生成补号单号。
单据编号字段手动补号:
普通文本字段用指定的编码规则进行手动补号:
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.单据插件.手动补号
本文2024-09-23 04:08:23发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-163389.html