二开案例.表单插件.单据体上移下移数据行
【案例演示】采购订单,针对明细信息单据体,上移下移数据行。
【实现步骤】
<1>编写表单插件,代码如下。
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;
namespace Jac.XkDemo.BOS.Business.PlugIn
{
/// <summary>
/// 【表单插件】单据体上移下移数据行
/// </summary>
[Description("【表单插件】单据体上移下移数据行"), HotUpdate]
public class MoveUpAndMoveDownPlugIn : AbstractDynamicFormPlugIn
{
#region var
/// <summary>
/// 单据体的Key
/// </summary>
private string EntryEntityKey = "FPOOrderEntry";
#endregion
/// <summary>
/// 分录行菜单点击事件
/// </summary>
/// <param name="e"></param>
public override void EntryBarItemClick(BarItemClickEventArgs e)
{
base.EntryBarItemClick(e);
if (e.BarItemKey.Equals("tbMoveUp", StringComparison.OrdinalIgnoreCase))
{
if (string.IsNullOrEmpty(this.View.BillBusinessInfo.GetEntity(EntryEntityKey).SeqFieldKey))
{
MoveEntryRow(this.View, EntryEntityKey, true);
}
else
{
MoveEntryRowBySeq(this.View, EntryEntityKey, true);
}
}
if (e.BarItemKey.Equals("tbMoveDown", StringComparison.OrdinalIgnoreCase))
{
if (string.IsNullOrEmpty(this.View.BillBusinessInfo.GetEntity(EntryEntityKey).SeqFieldKey))
{
MoveEntryRow(this.View, EntryEntityKey, false);
}
else
{
MoveEntryRowBySeq(this.View, EntryEntityKey, false);
}
}
}
/// <summary>
/// 移动分录行
/// </summary>
/// <param name="view"></param>
/// <param name="key"></param>
/// <param name="isUp"></param>
private static void MoveEntryRow(IDynamicFormView view, string key, bool isUp)
{
var rowIndex = view.Model.GetEntryCurrentRowIndex(key);
if (isUp)
{
// 上移
if (rowIndex <= 0)
{
return;
}
view.Model.MoveUpEntryRow(key, rowIndex);
view.GetControl<EntryGrid>(key).SetFocusRowIndex(rowIndex - 1);
view.ShowMessage("数据行已上移");
return;
}
else
{
// 下移
var rowCount = view.Model.GetEntryRowCount(key);
if (rowIndex < 0 || rowIndex >= rowCount - 1)
{
return;
}
view.Model.MoveDownEntryRow(key, rowIndex);
view.GetControl<EntryGrid>(key).SetFocusRowIndex(rowIndex + 1);
view.ShowMessage("数据行已下移");
return;
}
}
/// <summary>
/// 移动分录行
/// </summary>
/// <param name="view"></param>
/// <param name="key"></param>
/// <param name="isUp"></param>
private static void MoveEntryRowBySeq(IDynamicFormView view, string key, bool isUp)
{
var rowIndex = view.GetControl<EntryGrid>(key).GetFocusRowIndex();
if (isUp)
{
// 上移
if (rowIndex <= 0)
{
return;
}
var entity = view.BillBusinessInfo.GetEntity(key);
var rowData = view.Model.GetEntityDataObject(entity, rowIndex);
view.Model.DeleteEntryRow(key, rowIndex);
rowIndex--;
view.Model.CreateNewEntryRow(entity, rowIndex, rowData);
view.GetControl<EntryGrid>(key).SetFocusRowIndex(rowIndex);
view.ShowMessage("数据行已上移");
return;
}
else
{
// 下移
var rowCount = view.Model.GetEntryRowCount(key);
if (rowIndex < 0 || rowIndex >= rowCount - 1)
{
return;
}
var entity = view.BillBusinessInfo.GetEntity(key);
var rowData = view.Model.GetEntityDataObject(entity, rowIndex);
view.Model.DeleteEntryRow(key, rowIndex);
rowIndex++;
view.Model.CreateNewEntryRow(entity, rowIndex, rowData);
view.GetControl<EntryGrid>(key).SetFocusRowIndex(rowIndex);
view.ShowMessage("数据行已下移");
return;
}
}
}
}
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展采购订单,单据体菜单集合添加新菜单,注册表单插件,保存元数据,开发完毕。
【功能验证】
登录业务站点,打开采购订单编辑界面,点击上移下移,就可以移动数据行啦。
---------------------------------------------------------------------------------------------------------
【知识点】
<1>如果单据体设置了序号列,移动数据行将重置相关行的序号,保存单据数据后,会最终影响数据行的排序(单据界面的单据体数据行始终按序号顺序显示)。
<2>如果单据体没设置序号列,移动数据行仅在当前界面有效,并不能改变数据行的真实排序(保存并关闭当前界面后,再次打开单据编辑界面时,数据行还是调整前的)。
---------------------------------------------------------------------------------------------------------
【参考资料】
【二开案例.表单插件.树形单据体】https://vip.kingdee.com/article/165462548668510976
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.表单插件.单据体上移下移数据行
本文2024-09-23 04:19:49发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-164612.html