using Kingdee.BOS; using Kingdee.BOS.Core; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Util; using System; using System.Collections; using System.ComponentModel; namespace MyCompany.MyProject.OperationPlugIn { /// /// 操作服务插件骨架。 /// 访问位:FieldKeys.Add → Key;e.DataEntitys / entry 索引 → PropertyName。 /// 见 skills/_shared/api-surface-contract.md、three-identifiers.md。 /// [Description("操作服务插件"), HotUpdate] public class OperationPluginTemplate : AbstractOperationServicePlugIn { public override void OnPrepareOperationServiceOption(OnPrepareOperationServiceEventArgs e) { base.OnPrepareOperationServiceOption(e); e.SupportTransaction = true; e.SurportBatchTransaction = false; } public override void OnPreparePropertys(PreparePropertysEventArgs e) { base.OnPreparePropertys(e); // 预加载位 → Key(标识) e.FieldKeys.Add("FQty"); e.FieldKeys.Add("FAmount"); } public override void OnAddValidators(AddValidatorsEventArgs e) { base.OnAddValidators(e); } public override void BeforeExecuteOperationTransaction(BeforeExecuteOperationTransaction e) { base.BeforeExecuteOperationTransaction(e); if (e.DataEntitys == null) return; foreach (var entity in e.DataEntitys) { // 数据包位 → PropertyName(以元数据为准;下例为假设,勿口算去 F) // 假设 PropertyName: Amount, SaleOrderEntry, Qty decimal amount = Convert.ToDecimal(entity["Amount"] ?? 0); if (amount <= 0) throw new KDException("", "金额必须大于零"); var entries = entity["SaleOrderEntry"] as IEnumerable; if (entries == null) continue; int row = 0; foreach (var rowObj in entries) { var entry = rowObj as DynamicObject; if (entry == null) { row++; continue; } decimal qty = Convert.ToDecimal(entry["Qty"] ?? 0); if (qty <= 0) throw new KDException("", $"第 {row + 1} 行数量必须大于零"); row++; } } } public override void BeginOperationTransaction(BeginOperationTransactionArgs e) { base.BeginOperationTransaction(e); foreach (var billObj in e.DataEntitys) { string billId = Convert.ToString(billObj["Id"]); string billNo = Convert.ToString(billObj["BillNo"]); // PropertyName } } public override void EndOperationTransaction(EndOperationTransactionArgs e) { base.EndOperationTransaction(e); } public override void RollbackData(OperationRollbackDataArgs e) { base.RollbackData(e); } public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e) { base.AfterExecuteOperationTransaction(e); foreach (var billObj in e.DataEntitys) { var result = new OperateResult { SuccessStatus = true, Message = "完成" }; this.OperationResult.OperateResult.Add(result); } } } }