通过表单插件复制物料
using Kingdee.BOS;
using Kingdee.BOS.App.Core.Utils;
using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.Util;
using Kingdee.BOS.Util;
using Kingdee.BOS.Web.Bill;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace EXT.Business.PlugIn
{
[Description("物料复制表单插件"), HotUpdate]
public class TestCopyMaterial : AbstractBillPlugIn
{
public override void EntryBarItemClick(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e)
{
base.EntryBarItemClick(e);
//if条件判断,当点击复制物料这个按钮时候触发
if (e.BarItemKey == "tbCopyMaterial")
{
string EntityKey = "FTreeEntity";
//选中行索引
var eRow = this.Model.GetEntryCurrentRowIndex(EntityKey);
//实体对象
var entity = this.View.BillBusinessInfo.GetEntity(EntityKey);
//获取选中行数据
var thisRowentity = this.Model.GetEntityDataObject(entity, eRow);
long materialId = thisRowentity.GetDynamicObjectItemValue<long>("MATERIALIDCHILD_Id");
var billView = CreateBillView(this.Context, "BD_MATERIAL", null, null);
billView.Model.Copy(materialId);
//根据自己逻辑调整
billView.Model.SetValue("FNumber", "Test0001");
billView.Model.Save();
var resSubmit = billView.InvokeFormOperation("Submit");
var resAudit = billView.InvokeFormOperation("Audit");
if (resAudit)
{
this.View.ShowMessage("创建物料成功");
}
else
{
this.View.ShowErrMessage("创建物料失败");
}
}
}
/// <summary>
/// 创建单据视图
/// </summary>
/// <param name="ctx"></param>
/// <param name="formId">单据唯一标识</param>
/// <param name="layoutId"></param>
/// <param name="pkId">单据主键内码FID</param>
/// <returns></returns>
private static BillView CreateBillView(Context ctx, string formId, string layoutId = null, object pkId = null)
{
var meta = (FormMetadata)Kingdee.BOS.ServiceHelper.MetaDataServiceHelper.Load(ctx, formId); //单据唯一标识
var form = meta.BusinessInfo.GetForm();
var param = new BillOpenParameter(formId, layoutId);
param.Context = ctx;
param.FormMetaData = meta;
if (pkId != null && !string.IsNullOrWhiteSpace(pkId.ToString()))
{
param.Status = OperationStatus.EDIT;
param.InitStatus = OperationStatus.EDIT;
param.PkValue = pkId; //单据主键内码FID
}
else
{
param.Status = OperationStatus.ADDNEW;
param.InitStatus = OperationStatus.ADDNEW;
}
param.SetCustomParameter("formID", form.Id);
param.SetCustomParameter("PlugIns", form.CreateFormPlugIns()); //插件实例模型
param.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);
param.NetCtrlDisable = true; // 禁用网控
var provider = form.GetFormServiceProvider();
var billview = (BillView)provider.GetService(typeof(IDynamicFormView));
billview.Initialize(param, provider); //初始化
billview.LoadData(); //加载单据数据
return billview;
}
}
}
通过表单插件复制物料
本文2024-09-16 19:09:07发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-26734.html