普通列表批量复制二开示例
批量复制的功能,标准产品不提供,是有很多原因,其中就包含了前端显示多个页签问题、复制单据量多出现系统效率低等问题,所以建议谨慎使用。普通的列表(不适用树形列表等)的批量复制单据的二开,不包含权限控制,示例如下:
以采购申请单为例,首先在BOS设计器中找到采购申请单,拓展,然后添加列表菜单“批量复制”。
挂上列表插件。列表插件代码如下:
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.Core.Const;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.List.PlugIn;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kingdee.BOS.Core.Metadata.FormElement;
using Kingdee.BOS.Core.List;
namespace Kingdee.BOS.Printing.PlugIn.Test
{
public class CopyListPlugIn : AbstractListPlugIn
{
public override void BarItemClick(Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e)
{
base.BarItemClick(e);
if (e.BarItemKey == "BthBacthCopy")
{
var ids = ((IListView)this.View).SelectedRowsInfo.GetPrimaryKeyValues();
foreach (string id in ids)
{
ListNewOrCopy(id);
}
}
}
private void ListNewOrCopy(string pk)
{
BillShowParameter param = new BillShowParameter();
param.PKey = pk;
Form form = ((IListView)this.View).BillBusinessInfo.GetForm();
Appearance ap = ((IListView)this.View).BillLayoutInfo.GetFormAppearance();
param.FormId = form.Id;
if (string.IsNullOrEmpty(((IListView)this.View).CurrentSelectedRowInfo.FormID) == false)
{
param.FormId = ((IListView)this.View).CurrentSelectedRowInfo.FormID;
}
param.CreateFrom = CreateFrom.Copy;
param.Width = ap.Width;
param.Height = ap.Height;
if (IsCopyLinkEntry())
{
param.CustomParams.Add("IsCopyLinkEntry", "1");
}
SetFormOpenStyle(param);
param.Status = OperationStatus.ADDNEW;
//列表发布单据类型参数
object cusBillType = this.View.OpenParameter.GetCustomParameter(BOSConst.CustomBillTypeID);
//列表发布视图参数
object cusLayoutId = this.View.OpenParameter.GetCustomParameter(BOSConst.OpenLayoutId);
this.SetLayOutId(cusBillType, cusLayoutId, param);
this.ShowBillNewForm(this.View, param);
}
protected void SetFormOpenStyle(DynamicFormShowParameter param)
{
if (param == null) return;
if (this.View.ParentFormView != null)
{
if (ViewUtils.IsParentViewConsole(this.View))
{
// 主控台使用页签方式
param.OpenStyle.ShowType = ShowType.MainNewTabPage;
}
else
{
// 根据父窗口风格决定子窗口现实风格
OpenStyle openStyle = this.View.OpenParameter.GetCustomParameter("openstyle") as OpenStyle;
if (openStyle != null)
{
if (openStyle.ShowType == ShowType.MainNewTabPage || (openStyle.TagetKey != null && openStyle.TagetKey.ToUpper() == "FMAINTAB"))
{
param.OpenStyle.ShowType = ShowType.MainNewTabPage;
}
param.OpenStyle.TagetKey = openStyle.TagetKey;
}
else
{
param.OpenStyle.ShowType = ShowType.Default;
}
}
}
}
private void SetLayOutId(object cusBillType, object cusLayoutId, DynamicFormShowParameter param)
{
//当前选中单据单据类型值
string billTypeId = ((Kingdee.BOS.Core.List.IListView)this.View).CurrentSelectedRowInfo.BillTypeID;
//当前选中单据单据类型对应视图的值
string layoutId = ((Kingdee.BOS.Core.List.IListView)this.View).CurrentSelectedRowInfo.LayoutID;
if (!cusBillType.IsNullOrEmptyOrWhiteSpace())
{
if (billTypeId == cusBillType.ToString())
{
if (null != cusLayoutId)
{
param.LayoutId = cusLayoutId.ToString();
}
else
{
param.LayoutId = layoutId;
}
}
else
{
param.LayoutId = GetLayoutID(billTypeId);
}
}
else if (!cusLayoutId.IsNullOrEmptyOrWhiteSpace())
{
param.LayoutId = cusLayoutId.ToString();
}
else
{
param.LayoutId = layoutId;
}
}
private string GetLayoutID(string defaultBillTypeId)
{
var ret = string.Empty;
BillTypeField billTypeField = this.View.BillBusinessInfo.GetFieldList().FirstOrDefault(p => p is BillTypeField) as BillTypeField;
if (billTypeField != null)
{
DynamicObject defBillType = null;
if (billTypeField.BillTypeInfo.Count > 0)
{
// 优选参数中指定的单据类型
if (!string.IsNullOrWhiteSpace(defaultBillTypeId))
{
defBillType = billTypeField.BillTypeInfo.FirstOrDefault(
p => p["Id"].ToString().Equals(defaultBillTypeId.Trim()));
// 参数指定的单据类型,必须是正常可用的,否则,不允许使用
if (!billTypeField.BillTypeIsNormal(defBillType))
{
defBillType = null;
}
}
// 次选配置了"默认单据类型"选项的单据类型
if (defBillType == null)
{
defBillType = billTypeField.GetDefaultBillTypeInfo();
}
if (defBillType == null)
{//如果没有设置默认单据类型时,应当默认第一个
//defBillType = billTypeField.BillTypeInfo[0];
List<EnumItem> items = billTypeField.BuildEnumList(false);
if (items != null && items.Count > 0)
defBillType = billTypeField.BillTypeInfo.Find(p => p["Id"].Equals(items[0].EnumId));
}
if (defBillType != null)
{
DynamicObject layoutSolutionObj = defBillType["LayoutSolution"] as DynamicObject;
if (layoutSolutionObj != null)
{
ret = layoutSolutionObj["Id"].ToString();
}
}
}
}
return ret;
}
protected virtual void ShowBillNewForm(IDynamicFormView view, DynamicFormShowParameter param)
{
view.ShowForm(param, new Action<FormResult>((result) =>
{
#region 回调函数代码,根据子窗体要求,决定是否刷新表格
object data = result.ReturnData;
if (data is JSONObject)
{
JSONObject retData = data as JSONObject;
object value = retData.Get("refresh");
bool refreshGrid = false;
if (null != value)
{
bool.TryParse(value.ToString(), out refreshGrid);
}
if (refreshGrid && !this.ListView.GetForbidOpRefleshData())
{
this.ListView.Refresh();
}
}
#endregion
}));
}
private bool IsCopyLinkEntry()
{
FormOperation formOperation= this.View.BillBusinessInfo.GetForm().GetOperation("Copy");
if (formOperation==null||formOperation.Parmeter == null) return false;
return Kingdee.BOS.Business.Bill.Utils.CommonUtils.GetIsCopyLinkEntryParam(formOperation.Parmeter);
}
}
}
普通列表批量复制二开示例
本文2024-09-23 04:19:04发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-164535.html