通过二开实现单据上显示附件列表的附件原创
5人赞赏了该文章
1,135次浏览
未经作者许可,禁止转载编辑于2023年05月06日 20:20:11
【应用场景】
在选项下上传的附件,想要在单据列表可以直接看到上传的附件名称。
【案例演示】
币别单据可以直接在列表上看到上传的附件名称。
【实现步骤】
<1>编写列表插件,代码如下。
using Kingdee.BOS; using Kingdee.BOS.App.Data; using Kingdee.BOS.Core.Bill; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.List; using Kingdee.BOS.Core.List.PlugIn; using Kingdee.BOS.Core.Metadata.FormElement; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; namespace DemoPlugin { /// <summary> /// 【表单插件】暂存操作后刷新字段 /// </summary> [Description("修改附件列表时,同步更新单据的附件名"), HotUpdate] public class ShowAttachmentName : AbstractListPlugIn { public override void AfterDoOperation(AfterDoOperationEventArgs e) { base.AfterDoOperation(e); if (e.Operation.OperationId == FormOperation.Operation_Close) { var relateView = this.View.ParentFormView; if (relateView == null) { return; } object billFid; if (relateView is IBillView) { billFid = relateView.Model.DataObject[0]; } else if (relateView is IListView) { var currRow = (relateView as IListView).CurrentSelectedRowInfo; if (currRow == null) { return; } billFid = currRow.PrimaryKeyValue; } else { return; } // 用于显示附件文件名的字段标识 string nameFieldKey = "FAttachmentFileNames"; var form = relateView.BillBusinessInfo.GetForm(); var nameField = relateView.BillBusinessInfo.GetField(nameFieldKey); if (form == null || nameField == null) { return; } bool preStatus = relateView.Model.DataChanged; var sql = "select FATTACHMENTNAME from T_BAS_Attachment where FBILLTYPE=@FBILLTYPE and FINTERID=@FINTERID"; var paramList = new List<SqlParam> { new SqlParam("@FBILLTYPE", KDDbType.AnsiString, form.Id), new SqlParam("@FINTERID", KDDbType.AnsiString, billFid), }; var attachmentNames = new List<string>(); using (var dr = DBUtils.ExecuteReader(this.Context, sql, paramList)) { while (dr.Read()) { attachmentNames.Add(dr.GetValue<string>(0)); } } // 将从数据库中找到的多个附件文件名处理成界面上要显示的内容 string namesForShow = string.Join("|", attachmentNames); var updateSql = string.Format("update {0} set {1}=@FieldValue where {2}=@EntryPkFieldValue", nameField.TableName, nameField.FieldName, nameField.Entity.EntryPkFieldName); var updateParams = new List<SqlParam> { new SqlParam("@FieldValue", KDDbType.AnsiString, namesForShow), new SqlParam("@EntryPkFieldValue", KDDbType.AnsiString, billFid), }; var count = DBUtils.Execute(this.Context, updateSql, updateParams); if (relateView is IBillView) { relateView.Model.SetValue(nameFieldKey, namesForShow); } if (!preStatus) { relateView.Model.DataChanged = false; } } /* sql server 单据附件名更新 sql 如下 T_BD_CURRENCY:单据头表名 FCURRENCYID:单据头表的主键名 FAttachmentFileNames:单据头中用来保存附件名的字段名 MERGE INTO T_BD_CURRENCY a using(select FBILLTYPE,FINTERID,FileNames= stuff((SELECT '|' + FATTACHMENTNAME FROM T_BAS_Attachment WHERE FBILLTYPE=A.FBILLTYPE AND FINTERID=A.FINTERID and FATTACHMENTNAME <> '' FOR XML path('')),1,1,'') from T_BAS_Attachment A GROUP BY FBILLTYPE,FINTERID HAVING A.FBILLTYPE='BD_Currency') b ON (a.FCURRENCYID = b.finterid) WHEN MATCHED THEN UPDATE SET FAttachmentFileNames=b.FileNames; */ } } }
<2>拷贝插件组件dll到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展币别单据,在单据头新增文本字段,标识、字段名、绑定实体属性都设为FAttachmentFileNames,编辑长度适当调长,以免文件名太长存不下;
保存元数据。
<4>BOSIDE扩展附件明细(BOS_Attachment)单据,注册列表插件
【功能验证】
<1>登录业务站点,打开币别列表,选择一条数据上传附件,关闭附件列表后刷新数据
【旧数据升级】
按照上面的操作做完后,需要打开并关闭附件列表后,才能直接在单据上看到附件的文件名。
当然针对这种情况也有解决办法,对于 sql server 数据库,可以使用下面的脚本更新单据中附件名的值。
-- T_BD_CURRENCY:单据头表名 -- FCURRENCYID:单据头表的主键名 -- FAttachmentFileNames:单据头中用来保存附件名的字段名 MERGE INTO T_BD_CURRENCY a using(select FBILLTYPE,FINTERID,FileNames = stuff((SELECT '|' + FATTACHMENTNAME FROM T_BAS_Attachment WHERE FBILLTYPE=A.FBILLTYPE AND FINTERID=A.FINTERID and FATTACHMENTNAME <> '' FOR XML path('')),1,1,'') from T_BAS_Attachment A GROUP BY FBILLTYPE,FINTERID HAVING A.FBILLTYPE='BD_Currency') b ON (a.FCURRENCYID = b.finterid) WHEN MATCHED THEN UPDATE SET FAttachmentFileNames=b.FileNames;
赞 5
5人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读