知识分享 - 在单据维护界面仅下推选中的单据体行
金蝶云社区-JohnnyDing
JohnnyDing
4人赞赏了该文章 5408次浏览 未经作者许可,禁止转载编辑于2015年12月03日 09:39:55

案例背景:
在单据JDA的维护界面,下推到目标单JDB时,默认是整单下推。
现在需要修改为仅下推选中的单据体焦点行;

实现方案:
二开单据JDA的插件,在OnGetConvertRule事件,调整下推所选行参数,这样随后执行的下推服务,就只会下推插件为其选择的数据行。

目标效果:
图一:在源单查看界面,选中需下推的单据体行

图二:点击下推,选择目标单

图三:生成的目标单,仅仅把源单单据体焦点行下推过来

插件代码:
需挂在上游单据JDA的表单插件上
//************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;


using Kingdee.BOS;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.List.PlugIn;
using Kingdee.BOS.Core.List.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.Orm.DataEntity;

using Kingdee.BOS.Core.Metadata.EntityElement;

namespace JDSample.FormPlugIn.Bill
{
[Description("在单据上仅下推选中行")]
public class S151203PushEntryRowEdit : AbstractBillPlugIn
{
///


/// 下推(或选单)处理,确定好目标单后,开始下推时,触发此事件:
/// 可以在此事件中,调整转换规则,调整实际需下推的单据
///

///
public override void OnGetConvertRule(GetConvertRuleEventArgs e)
{
if (e.ConvertOperation == Kingdee.BOS.Core.DynamicForm.FormOperationEnum.Push
&& e.RuleElement.TargetFormId.EqualsIgnoreCase("6926e2833d9c40cda44cc95b74208aca"))
{// 执行的是下推处理,且下推的是JDB

// 获取当前单据内码
string pkValue = Convert.ToString(this.View.Model.GetPKValue());

Entity entity = this.View.BillBusinessInfo.GetEntity("FEntity");
// 获取单据体当前所选行
EntryGrid grid = this.View.GetControl("FEntity");
var selectRowIndexs = grid.GetSelectedRows();

// 把所选行,全部添加到下推参数中
List selectedRows = new List();
DynamicObjectCollection rows = this.Model.GetEntityDataObject(entity);
foreach (var rowIndex in selectRowIndexs)
{
DynamicObject activeRow = rows[rowIndex];
string entityId = Convert.ToString(activeRow[0]);
if (entityId == "0") continue;

// 重新构建下推操作构建的选中行参数
ListSelectedRow newSelectedRow = new ListSelectedRow(
pkValue, entityId, 0, this.View.BillBusinessInfo.GetForm().Id);
newSelectedRow.EntryEntityKey = "FEntity";

selectedRows.Add(newSelectedRow);
}

// 替换掉原下推服务上的选中行参数
e.SelectedRows = selectedRows.ToArray();

}
}
}
}