二开-自动批号:批号=单号+行号
很多情况下,都想:批号=单号,用系统自带[调用表单操作--批号编码规则应用]配置起来有点烦琐,复用性不高,且在实际应用中是:批号=单号+行号 更为合理,所以提供自用的自动批号功能代码,供有需要的人员参考:
```language
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Util;
using System.ComponentModel;
using System;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.ServiceHelper;using System.Collections.Generic;
using System.Linq;
namespace Hjt.Kingdee.PlugIn
{
/// <summary>
/// 【单据插件】保存前事件
/// 批号字段一定要设置为“批号主档+文本”
/// </summary>
[Description("【单据插件】保存前设置批号=bom版本/单号+行号(批号为空时)"), HotUpdate]
public class BeforeSaveSetFlotToBOM : AbstractBillPlugIn
{
public override void BeforeSave(BeforeSaveEventArgs e)
{
base.BeforeSave(e);
DynamicObject billObj = this.Model.DataObject;// 单据的数据包
string entityForm = "";
string formTitle = this.View.GetFormTitle();//单据标题
String fBillNo = Convert.ToString(this.View.Model.GetValue("FBillNo"));//单据编号
if (fBillNo.IsNullOrEmptyOrWhiteSpace())//单号为空时根据编码规则获取单号
{
#region 给指定业务对象的单据编号字段获取新的单据编号
var billNoField = this.View.BillBusinessInfo.GetBillNoField();
var options = new Dictionary<string, object>();
options["CodeTime"] = 1; // 执行时机,0表示新增时获取单据编号,1表示保存时获取单据编号
options["UpdateMaxNum"] = 1; // 是否更新最大流水号
this.Model.DataObject[billNoField.PropertyName] = "";
var billNos = BusinessDataServiceHelper.GetBillNo(this.Context, this.View.BillBusinessInfo, new[] { this.Model.DataObject }, options);
this.View.UpdateView(billNoField.Key);
fBillNo = string.Join(",", billNos.Select(o => o.BillNo));
#endregion
}
switch (formTitle)//根据单据名称取子单据体名称
{
case "销售订单新变更单":
entityForm = "FSaleOrderEntry";
break;
case "销售订单":
entityForm = "FSaleOrderEntry";
break;
case "采购订单":
entityForm = "FPOOrderEntry";
break;
case "采购入库单":
entityForm = "FInStockEntry";
break;
case "简单生产入库单":
case "生产入库单":
entityForm = "FEntity";
break;
case "生产订单":
entityForm = "FTreeEntity";
break;
}
if (formTitle == "销售订单新变更单")//销售订单新变更单的中转单号转换为单号+后两位变更版本
{
fBillNo = fBillNo.Replace("_V00", "_0");
}
Entity entity = this.View.BillBusinessInfo.GetEntity(entityForm);
// 单据体的字段
DynamicObjectCollection entityRows = entity.DynamicProperty.GetValue(billObj) as DynamicObjectCollection;
int rowCount = this.View.Model.GetEntryRowCount(entityForm);
for (int rowindex = rowCount - 1; rowindex >= 0; rowindex--)
{
DynamicObject fLot = (DynamicObject)entityRows[rowindex]["LOT"];
DynamicObject fMaterialID = (DynamicObject)entityRows[rowindex]["MaterialID"];
String fMATERIALNumber = fMaterialID["Number"].ToString();//主物料编码
//String fMATERIALName = fMaterialID["Name"].ToString();//物料名称
try
{
if (!fMaterialID.IsNullOrEmptyOrWhiteSpace())//判断新增行是否为空行
{
DynamicObjectCollection fMaterialStock = (DynamicObjectCollection)fMaterialID["MaterialStock"];//取物料的库存属性包
bool fIsBatchManage = (bool)fMaterialStock[0]["IsBatchManage"];//是否启用批号
if (fIsBatchManage)//判断是否启用批号
{
LotField lotA = this.View.Model.BillBusinessInfo.GetField("FLot") as LotField;//批号录入模式
if ( lotA.InputModel != LotField.Enum_InputModel.OnlySelect && fLot.IsNullOrEmptyOrWhiteSpace())//如果批号为空,且 批号录入模式不为批号主档
{
#region 根据需求改动
DynamicObject fBOMID = (DynamicObject)entityRows[rowindex]["FBomId"];//取BOM版本
if (fBOMID != null)
{
String fBOMIDName = fBOMID["Number"].ToString();//取BOM名称
this.View.Model.SetValue("FLot", fBOMIDName, rowindex);//批号=BOM版本
this.View.UpdateView("FLot");//一定要先刷新
}
else
{
this.View.Model.SetValue("FLot", fBillNo + "-" + (rowindex + 1), rowindex);//批号=单号+行号
this.View.UpdateView("FLot");//一定要先刷新
}
#endregion
}
}
}
}
catch
{
}
}
}
}
}
```
值更新可以做吗?
二开-自动批号:批号=单号+行号
很多情况下,都想:批号=单号,用系统自带[调用表单操作--批号编码规则应用]配置起来有点烦琐,复用性不高,且在实际应用中是:批号=单号...
点击下载文档
本文2024-09-16 18:19:55发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-21453.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章