小技巧 - 如何在目标单据上,显示源单附件
金蝶云社区-JohnnyDing
JohnnyDing
2人赞赏了该文章 3,524次浏览 未经作者许可,禁止转载编辑于2015年09月18日 17:42:08

背景介绍:
当前K/3 Cloud不支持把源单的附件列表,携带到目标单。
但实际业务中,却需要在目标单上,直接看到源单的附件列表。

解决方案:
在目标单,增加一个菜单,用户点击菜单时,读取本单的直接源单,显示其附件列表。

示例代码(特别说明:示例代码并非用于显示跨级源单的附件):
//*************************************************

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.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Attachment;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Core.List;

namespace JDSample.FormPlugIn.Bill
{
///


/// 在下游单据上,显示源单附件列表
///

///
/// 案例背景:
/// 销售订单下推到发货通知单,
/// 需要在发货通知单上,增加一个菜单,调出销售订单的附件列表
///

[Description("在目标单据上,显示源单附件")]
public class S150918ShowSrcBillAttEdit : AbstractBillPlugIn
{
///
/// 菜单点击事件,在验权通过之后触发
///

///
public override void AfterBarItemClick(AfterBarItemClickEventArgs e)
{
if (e.BarItemKey.EqualsIgnoreCase("tbShowSrcAttachment"))
{
string srcFormId = string.Empty;
HashSet srcBillIds = new HashSet();
// 读取源单内码
this.GetSrcBillIds(ref srcFormId, ref srcBillIds);

if (srcBillIds.Count == 0)
{
this.View.ShowMessage("本单没有源单!");
return;
}

// 显示指定源单的附件列表
this.ShowAttachmentList(srcFormId, srcBillIds);
}
}


///
/// 获取本单据的全部源单内码
///

///
///
private void GetSrcBillIds(ref string srcFormId, ref HashSet srcBillIds)
{
var form = this.Model.BillBusinessInfo.GetForm();
if (form.LinkSet == null
|| form.LinkSet.LinkEntitys == null
|| form.LinkSet.LinkEntitys.Count == 0)
{
return;
}


ExtendedDataEntitySet dataEntitySet = new ExtendedDataEntitySet();
dataEntitySet.Parse(
new DynamicObject[] { this.Model.DataObject },
this.Model.BillBusinessInfo);


// 获取单据的关联子单据体
var linkRows = dataEntitySet.FindByEntityKey(form.LinkSet.LinkEntitys[0].Key);
foreach (var linkRow in linkRows)
{
long srcBillId = Convert.ToInt64(linkRow["SBillId"]);
// 源单内码已经存在,忽略
if (srcBillId == 0 || srcBillIds.Contains(srcBillId))
{
continue;
}

// 把源单内码加入到集合中
srcBillIds.Add(srcBillId);

if (string.IsNullOrWhiteSpace(srcFormId))
{// 取源单FormId
string srcTableNumber = Convert.ToString(linkRow["STableName"]);
srcFormId = Kingdee.BOS.ServiceHelper.BusinessFlowServiceHelper.LoadTableDefine(
this.Context, srcTableNumber).FormId;
}
}
}


///
/// 显示源单附件列表
///

///
///
private void ShowAttachmentList(string formId, HashSet srcBillIds)
{
// 构建附件列表过滤条件
AttachmentKey attachmentKey = new AttachmentKey();
attachmentKey.BillType = formId;
attachmentKey.BillNo = string.Empty;
attachmentKey.BillInterID = Convert.ToString(srcBillIds.ElementAt(0));
// 设置为查看状态,禁止修改源单附件列表
attachmentKey.OperationStatus = Kingdee.BOS.Core.Metadata.OperationStatus.VIEW;

// 本案例不显示单据体附件,如下单据体行参数全部设置为空白
attachmentKey.EntryKey = " ";
attachmentKey.EntryInterID = "-1";
attachmentKey.RowIndex = 0;


// 列表过滤条件
string filter = string.Format(@"FBILLTYPE='{0}' and FINTERID IN ('{1}') and FENTRYKEY='{2}' and FENTRYINTERID='{3}'",
attachmentKey.BillType,
string.Join("','", srcBillIds),
attachmentKey.EntryKey,
attachmentKey.EntryInterID);


// 构建列表显示参数
ListShowParameter listpara = new ListShowParameter();
listpara.IsLookUp = false;
listpara.CustomParams.Add(KeyConst.AttachmentKey, AttachmentKey.ConvertToString(attachmentKey));
listpara.OpenStyle.ShowType = ShowType.Floating;
listpara.Caption = "附件管理";
listpara.FormId = FormIdConst.BOS_Attachment;
listpara.MultiSelect = false;
listpara.PageId = string.Format("{0}_{1}_F7", this.View.PageId, listpara.FormId);

listpara.ListFilterParameter.Filter = filter;
listpara.IsShowQuickFilter = false;


this.View.ShowForm(listpara);

}
}
}