二开案例.列表插件.备选支持按子单据体分录行记录
【场景】备选目前仅支持按照单据体分录行记录,如果在列表能够显示子单据体分录行的单据(如工序计划),添加一行会把对应单据体所有子分录行都记忆
针对存在子单据体分录的单据,在选单时希望能够使用备选,支持按子单据体分录行记录;
【案例】在工序计划列表,通过列表插件实现自定义备选功能
<1>在对应表单挂设新的菜单,完全自定义备选功能
tb_CustomAddDataCollection——添加备选
tb_CustomReturnDataCollection——返回备选
![A1BCBAMG66VU~F0EFH5.webp](/download/010032937a85d309456cae500316ec59185f.webp)
<2>通过列表插件实现备选
核心逻辑:
①支持按子单据体行记录勾选顺序
②能够对已勾选的数据进行标记
③数据返回时能够仅返回已勾选的数据
```csharp
using Kingdee.BOS.Core.CommonFilter;
using Kingdee.BOS.Core.Const;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.List.PlugIn;
using Kingdee.BOS.Core.List.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Model.List;
using Kingdee.BOS.Util;
using System.Collections.Generic;
using System.Linq;
namespace DynamicFormPlugIn.Test
{
public class KeyConst
{
//对应数据的选中行信息
public static string DataColl = "Custom_Data_Collection";
//勾选顺序
public static string Detail = "Custom_Detail_Data_Collection";
}
[Kingdee.BOS.Util.HotUpdate]
[System.ComponentModel.Description("备选支持子单据体")]
public class CustomListPlugIn : AbstractListPlugIn
{
/// <summary>
/// 添加备选后列表数据背景颜色,暂定为黄色
/// </summary>
private string color = "#FFF6D1";
public override void BarItemClick(BarItemClickEventArgs e)
{
base.BarItemClick(e);
if (string.Equals(e.BarItemKey, "tb_CustomAddDataCollection"))
{
//添加备选
AddDatCollection();
this.ListView.Refresh();//刷新历史选中行
}
if (string.Equals(e.BarItemKey, "tb_CustomReturnDataCollection"))
{
//备选返回
ReturnDataCollection();
}
}
/// <summary>
/// 选中行格式化
/// </summary>
/// <param name="args"></param>
public override void OnFormatRowConditions(ListFormatConditionArgs args)
{
List<string> lstSelPKValue = null;
if (this.ListView.Session.ContainsKey(KeyConst.DataColl))
{
var dataColl = this.ListView.Session[KeyConst.DataColl] as Dictionary<string, ListSelectedRow>;
lstSelPKValue = dataColl.Keys.ToList();
}
//如果没有添加备选的数据的则直接返回
if (lstSelPKValue == null || lstSelPKValue.Count <= 0) return;
ListModel listModel = this.Model as ListModel;
if (listModel == null || args.DataRow == null || args.FormatConditions == null) return;
//已添加的备选数据添加背景色
string key = ObjectUtils.Object2String(args.DataRow[listModel.PkFieldName]);
string strEntryPk = listModel.PKEntryFieldName;
string subEntryEntityKey = string.Empty;
if (this.ListView.Model.FilterParameter.SelectedEntities.FirstOrDefault(x => x.EntityType == Kingdee.BOS.Core.Enums.BOSEnums.Enum_EntityType.SubEntity) != null)
{
subEntryEntityKey = this.ListView.Model.FilterParameter.SelectedEntities.FirstOrDefault(x => x.EntityType == Kingdee.BOS.Core.Enums.BOSEnums.Enum_EntityType.SubEntity).Key;
}
if (!string.IsNullOrWhiteSpace(strEntryPk))
{
key = key + "&" + ObjectUtils.Object2String(args.DataRow[strEntryPk]);
}
if (subEntryEntityKey != string.Empty)
{
key += "&" + args.DataRow["t2_FDetailID"];
}
FormatCondition fc = new FormatCondition { ApplayRow = true };
if (lstSelPKValue.Contains(key))
{
fc.BackColor = color;
}
args.FormatConditions.Add(fc);
}
/// <summary>
/// 添加备选
/// </summary>
private void AddDatCollection()
{
//第一次添加备选时保存列表头信息,后续添加的备选数据以该表头为准
if (!this.ListView.Session.ContainsKey(BOSConst.CST_LISTHEADERS))
{
this.ListView.Session[BOSConst.CST_LISTHEADERS] = this.ListView.Model.Header.GetChilds();
}
int listType = (int)this.View.OpenParameter.GetCustomParameter("listtype");
ListSelectedRowCollection curSelectedRows = this.ListView.SelectedRowsInfo;
//将列表选中的数据添加到缓存中,这里缓存简单信息,用于返回数据
Dictionary<string, ListSelectedRow> dctSelectedRowInfo = new Dictionary<string, ListSelectedRow>();
if (this.ListView.Session.ContainsKey(KeyConst.DataColl))
{
dctSelectedRowInfo = this.ListView.Session[KeyConst.DataColl] as Dictionary<string, ListSelectedRow>;
}
if (curSelectedRows != null && curSelectedRows.Count > 0)
{
AddSelectRowInfo(this.ListView.Model.FilterParameter.SelectedEntities, dctSelectedRowInfo, listType, curSelectedRows);
}
this.ListView.Session[KeyConst.DataColl] = dctSelectedRowInfo;
if (curSelectedRows != null && curSelectedRows.Count > 0)
{
List<string> selectInfos = new List<string>();
if (this.ListView.Session.ContainsKey(KeyConst.Detail))
{
selectInfos = this.ListView.Session[KeyConst.Detail] as List<string>;
}
foreach (ListSelectedRow curSelectedItem in curSelectedRows)
{
string strKey = GenerateRowKey(curSelectedItem, this.ListView.Model.FilterParameter.SelectedEntities);
selectInfos.Add(strKey);
}
this.ListView.Session[KeyConst.Detail] = selectInfos;
}
}
/// <summary>
/// 备选返回
/// </summary>
private void ReturnDataCollection()
{
ListSelectedRowCollection lstDataCollection = new ListSelectedRowCollection();
object objDetailDataCollection; // 来自备选列表(表格中显示的且已经排序好了的)
object objDataCollection;// 来自F8列表中被加入到备选集合中的完整行集
if (this.ListView.Session.TryGetValue(KeyConst.Detail, out objDetailDataCollection)
&& this.ListView.Session.TryGetValue(KeyConst.DataColl, out objDataCollection))
{
var dctDetailSelectedRows = objDetailDataCollection as List<string>;
var dctSelectedRows = objDataCollection as Dictionary<string, ListSelectedRow>;
// 既然是排序敏感型数据,为什么要用Dictionary来存储呢,现在只好按有数据顺序的集合再排序一次了
if (dctDetailSelectedRows != null && dctSelectedRows != null)
{
foreach (var fid in dctDetailSelectedRows)
{
if (dctSelectedRows.ContainsKey(fid))
{
lstDataCollection.Add(dctSelectedRows[fid]);
}
}
}
}
if (lstDataCollection.Count > 0)
{
this.View.ReturnToParentWindow(lstDataCollection);
}
this.View.Close();
}
/// <summary>
/// 增加选中数据
/// </summary>
/// <param name="dicSelRow"></param>
/// <param name="listType"></param>
/// <param name="curLstSelRow"></param>
private static void AddSelectRowInfo(List<FilterEntity> selectEntitnes, Dictionary<string, ListSelectedRow> dicSelRow, int listType, ListSelectedRowCollection curLstSelRow)
{
if (listType == (int)Kingdee.BOS.Core.Enums.BOSEnums.Enu_ListType.BaseList)
{
foreach (ListSelectedRow curSelectedItem in curLstSelRow)
{
if (!dicSelRow.ContainsKey(curSelectedItem.PrimaryKeyValue))
{
dicSelRow[curSelectedItem.PrimaryKeyValue] = curSelectedItem;
}
}
}
else
{
foreach (ListSelectedRow curSelectedItem in curLstSelRow)
{
string strKey = GenerateRowKey(curSelectedItem, selectEntitnes);
if (!dicSelRow.ContainsKey(strKey))
{
dicSelRow[strKey] = curSelectedItem;
}
}
}
}
/// <summary>
/// 生成子单据体行唯一标记( 主键&分录主键&子分录主键)
/// </summary>
/// <param name="curSelectedItem"></param>
/// <param name="selectEntitnes"></param>
/// <returns></returns>
private static string GenerateRowKey(ListSelectedRow curSelectedItem, List<FilterEntity> selectEntitnes)
{
string subEntryEntityKey = string.Empty;
if (selectEntitnes.FirstOrDefault(x => x.EntityType == Kingdee.BOS.Core.Enums.BOSEnums.Enum_EntityType.SubEntity) != null)
{
subEntryEntityKey = selectEntitnes.FirstOrDefault(x => x.EntityType == Kingdee.BOS.Core.Enums.BOSEnums.Enum_EntityType.SubEntity).Key;
}
string strKey = curSelectedItem.PrimaryKeyValue;
if (!string.IsNullOrWhiteSpace(curSelectedItem.EntryPrimaryKeyValue))
{
strKey += "&" + curSelectedItem.EntryPrimaryKeyValue;
}
if (subEntryEntityKey != string.Empty)
{
strKey += "&" + curSelectedItem.FieldValues[subEntryEntityKey];
}
return strKey;
}
}
}
```
代码讲解:
①点击添加备选时,会记录选中行的数据包,已经将选中行加到已选列表中this.ListView.Session[KeyConst.Detail]
②添加备选完成后,会刷新视图,将已经选择行进行行格式化OnFormatRowConditions
③点返回的时候,根据已选列表和数据包,返回对应的按顺序排序的数据包
【效果】选单,备选按照子分录行返回
仅返回了对应子分录行的数据,对应工序序列单据体还存在其他子分录行不会返回
![Image_20221222183134.webp](/download/0100a97a958393da4df58eaf1c88a73f7e0b.webp)
二开案例.列表插件.备选支持按子单据体分录行记录
【场景】备选目前仅支持按照单据体分录行记录,如果在列表能够显示子单据体分录行的单据(如工序计划),添加一行会把对应单据体所有子分录...
点击下载文档
本文2024-09-16 18:34:20发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-23024.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章