二开实现单据保存序列号备注写入序列号主档原创
9人赞赏了该文章
3,500次浏览
编辑于2022年01月05日 17:21:26
【问题背景】
入库单上输入序列号、备注,实现单据保存序列号备注写入序列号主档备注字段
【说明】
1、单据在"保存"操作中配置有"保存并更新序列号主档"服务,该通用服务无法修改,只能二开保存插件写入数据
2、按照服务的执行顺序,保存操作先执行"保存并更新序列号主档"服务,该服务会生成序列号主档资料,并返回相关序列号信息填充子单据体。后执行保存插件中的逻辑,在插件中拿到保存的序列号内码及备注信息,以此作为更新的条件
【二开实现】:这里以"其他入库单"为例,说明具体的二开逻辑
序列号单据体 一般有个字段:一个序列号文本 (可编辑录入),一个序列号基础资料(隐藏)。 单据保存后会根据文本编码生产主档 反填对应的内码至 序列号基础资料字段, 通过这个序列号内码+备注信息,实现序列号主档资料更新
using Kingdee.BOS; using Kingdee.BOS.App.Data; using Kingdee.BOS.Contracts; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Orm.DataEntity; using System; using System.Collections.Generic; using System.Data; using System.Transactions; namespace Kingdee.K3.SCM.App.Stock.ServicePlugIn.StockSerialMainFileService { public class SerialSaveEx : AbstractOperationServicePlugIn { public override void AfterExecuteOperationTransaction(BOS.Core.DynamicForm.PlugIn.Args.AfterExecuteOperationTransaction e) { if (!this.OperationResult.IsSuccess) { return; } if (e.DataEntitys == null || e.DataEntitys.Length == 0) { return; } Dictionary<long, string> havaUpdateSerials = new Dictionary<long, string>(); foreach (DynamicObject bill in e.DataEntitys) { DynamicObjectCollection billEntry = bill["STK_MISCELLANEOUSENTRY"] as DynamicObjectCollection; foreach(DynamicObject entry in billEntry) { DynamicObjectCollection snEntrys = entry["STK_MISCELLANEOUSSERIAL"] as DynamicObjectCollection; foreach(DynamicObject sn in snEntrys) { long serialId = Convert.ToInt64(sn["SerialId_Id"]); string serialNote = Convert.ToString(sn["SerialNote"]); if (!string.IsNullOrEmpty(serialNote)) { havaUpdateSerials[serialId] = serialNote; } } } } #region 将单据中的序列号备注, 更新到调入序列号主档中 if (havaUpdateSerials.Count > 0) { List<SqlObject> lstSqlObj = new List<SqlObject>(); IDBService service = ServiceHelper.GetService<IDBService>(); string lotTmpTable = service.CreateTemporaryTableName(this.Context); BuildUpdateDestSerialTmpTable(this.Context, lotTmpTable); DataTable serialDt = new DataTable(lotTmpTable); serialDt.Columns.Add(new DataColumn() { ColumnName = "FSERIALID", DataType = typeof(long), AllowDBNull = false, DefaultValue = 0 }); serialDt.Columns.Add(new DataColumn() { ColumnName = "FDESCRIPTION", DataType = typeof(string), AllowDBNull = true, DefaultValue = "" }); foreach (KeyValuePair<long, string> billEntrySerial in havaUpdateSerials) { DataRow dr = serialDt.NewRow(); dr["FSERIALID"] = billEntrySerial.Key; dr["FDESCRIPTION"] = billEntrySerial.Value; serialDt.Rows.Add(dr); } DBUtils.BulkInserts(this.Context, serialDt); string sql = string.Format(@"MERGE INTO T_BD_SERIALMASTER_L IT USING ( SELECT T1.FSERIALID, T1.FDESCRIPTION FROM {0} T1 JOIN T_BD_SERIALMASTER T2 ON T1.FSERIALID = T2.FSERIALID ) UT ON (IT.FSERIALID = UT.FSERIALID) WHEN MATCHED THEN UPDATE SET IT.FDESCRIPTION = UT.FDESCRIPTION ", lotTmpTable); List<SqlParam> paras = new List<SqlParam>(); lstSqlObj.Add(new SqlObject(sql, paras)); if (lstSqlObj.Count > 0) { using (KDTransactionScope trans = new KDTransactionScope(System.Transactions.TransactionScopeOption.Required)) { DBUtils.ExecuteBatch(this.Context, lstSqlObj); if (!string.IsNullOrWhiteSpace(lotTmpTable)) { service.DeleteTemporaryTableName(this.Context, new string[1] { lotTmpTable }); } trans.Complete(); } } } #endregion } /// <summary> /// 构造更新序列号信息临时表 /// </summary> /// <param name="ctx"></param> /// <param name="tempTableName"></param> private void BuildUpdateDestSerialTmpTable(Context ctx, string tempTableName) { string sqlTM = @" ( FSERIALID INT NOT NULL DEFAULT(0), FDESCRIPTION NVARCHAR(255) NULL)"; string sql = string.Format(" CREATE TABLE {0} {1} " , tempTableName, sqlTM); List<string> sqls = new List<string>(); sqls.Add(sql); //为临时表创建索引 System.Guid guid = Guid.NewGuid(); string idxName = guid.ToString("N").Substring(0, 10); sql = string.Format(" CREATE INDEX IDX_SERIALID{0} ON {1} ({2}) ", idxName, tempTableName, "FSERIALID"); sqls.Add(sql); using (KDTransactionScope trans = new KDTransactionScope(TransactionScopeOption.Suppress)) { DBUtils.ExecuteBatchWithTime(ctx, sqls, sqls.Count, 120); trans.Complete(); } } } }
【实现效果】
SerialSaveEx.rar(1.77KB)
赞 9
9人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读