二开案例.账表.预览附件文件

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-23浏览:1

二开案例.账表.预览附件文件

**【应用场景】** 账表中显示单据附件,双击对应列的时候,预览单据附件。 **【案例演示】** <1>编写账表服务插件,查询单据关联的附件,代码如下。 ``` csharp using Kingdee.BOS.App.Data; using Kingdee.BOS.Contracts.Report; using Kingdee.BOS.Core.Report; using Kingdee.BOS.Util; using System.Collections.Generic; using System.ComponentModel; namespace Kingdee.BOS.PlugInTest { [Description("【账表服务器插件】附件报表"), HotUpdate] public class AttachmentReportService : SysReportBaseService { /// <summary> /// 插件初始化 /// </summary> public override void Initialize() { base.Initialize(); // 简单账表类型:普通、树形、分页 this.ReportProperty.ReportType = ReportType.REPORTTYPE_NORMAL; // 报表名称 this.ReportProperty.ReportName = new LocaleValue("附件报表", base.Context.UserLocale.LCID); // 是否由插件创建临时表 this.IsCreateTempTableByPlugin = true; // 报表列是否通过UI设计 this.ReportProperty.IsUIDesignerColumns = false; // 报表是否支持分组汇总 this.ReportProperty.IsGroupSummary = true; // 是否锁定表格列 this.ReportProperty.SimpleAllCols = false; // 报表是否默认只现实合计和明细数据 this.ReportProperty.IsDefaultOnlyDspSumAndDetailData = true; } /// <summary> /// 获取报表列头 /// </summary> /// <param name="filter"></param> /// <returns></returns> public override ReportHeader GetReportHeaders(IRptParams filter) { ReportHeader header = base.GetReportHeaders(filter); header.AddChild("FID", new LocaleValue("单据内码")); header.AddChild("FBILLNO", new LocaleValue("单据编号")); header.AddChild("FATTACHID", new LocaleValue("附件内码")); header.AddChild("FATTACHMENTNAME", new LocaleValue("附件名称")); header.AddChild("FATTACHMENTSIZE", new LocaleValue("附件大小")); header.AddChild("FFILEID", new LocaleValue("文件内码")); return header; } /// <summary> /// 构建报表SQL和临时表 /// </summary> /// <param name="filter"></param> /// <param name="tableName"></param> public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName) { base.BuilderReportSqlAndTempTable(filter, tableName); // 取数SQL string sql = string.Format(@"/*dialect*/ select ROW_NUMBER() over (order by FID) as FIDENTITYID, * into {0} from ( select bill.FID, bill.FBILLNO, att.FID as FATTACHID, att.FATTACHMENTNAME, att.FATTACHMENTSIZE, att.FFILEID from t_PUR_POOrder bill inner join T_BAS_ATTACHMENT att on att.FINTERID=CONVERT(varchar(50), bill.FID) and att.FBILLTYPE='PUR_PurchaseOrder' where att.FFILEID is not null ) T", tableName); DBUtils.ExecuteDynamicObject(this.Context, sql); } } } ``` <2>编写账表表单插件,用于预览文件,代码如下。 ``` csharp using Kingdee.BOS.Core; using Kingdee.BOS.Core.Bill; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Core.Report; using Kingdee.BOS.Core.Report.PlugIn; using Kingdee.BOS.Core.Report.PlugIn.Args; using Kingdee.BOS.JSON; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.ServiceHelper.FileServer; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Web; namespace Kingdee.BOS.PlugInTest { /// <summary> /// 【账表表单插件】附件账表表单插件 /// </summary> [Description("【账表表单插件】附件账表表单插件"), HotUpdate] public class AttachmentSysReportPlugIn : AbstractSysReportPlugIn { /// <summary> /// 附件数据包字典 /// </summary> private Dictionary<string, DynamicObject> attachDic = new Dictionary<string, DynamicObject>(StringComparer.OrdinalIgnoreCase); public override void CellDbClick(CellEventArgs Args) { base.CellDbClick(Args); if ("FATTACHMENTNAME".EqualsIgnoreCase(Args.Header.FieldName) == false) return; var sysView = this.View as ISysReportViewService; // 获取附件信息 string attachId = sysView.GetCurrentRowValue("FATTACHID").GetString(); // 使用本地预览 this.OnLineViewFileLocal(attachId); } /// <summary> /// 本地预览 /// </summary> /// <param name="attachId">附件明细内码</param> private void OnLineViewFileLocal(string attachId) { if (attachDic.ContainsKey(attachId) == false) { OQLFilter filter = OQLFilter.CreateHeadEntityFilter(string.Format("FID = {0}", attachId)); DynamicObject currAttachment = BusinessDataServiceHelper.Load(this.Context, FormIdConst.BOS_Attachment, null, filter).FirstOrDefault(); attachDic.Add(attachId, currAttachment); } DynamicObject dyn = attachDic[attachId]; if (dyn == null) { return; } JSONObject webobj = new JSONObject(); string fileId = ObjectUtils.Object2String(dyn["FileId"]); webobj["action"] = "OpenRes"; string url = FileServerHelper.GetAppSiteOuterNetUrl(this.Context, HttpContext.Current.Request); Dictionary<string, object> payload = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); payload["token"] = this.Context.UserToken; payload["sid"] = this.View.Context.SessionId; payload["attachmentId"] = attachId; payload["pv"] = 1; // preview payload["pvl"] = 1; // preview local var tk = PathUtils.EncodeJsonWebToken(payload); string filepath = string.Format("{0}FileUpLoadServices/downloadfile.ashx?tk={1}", url, tk); webobj["filepath"] = filepath; webobj["fileid"] = attachId + "_" + (fileId.IsNullOrEmptyOrWhiteSpace() ? "Db" : fileId); webobj["targetfilename"] = HttpUtility.UrlEncode(ObjectUtils.Object2String(dyn["AttachmentName"])); webobj["pageid"] = this.View.PageId; this.View.AddAction("OpenClientLocalResource", webobj); this.View.SendDynamicFormAction(this.View); this.View.ShowMessage("附件正在加载中.."); } } } ``` <3>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。 <4>注册插件。 ![注册账表服务器插件.webp](/download/01009b381bb8a0dd4262902aec9ccdb45ac2.webp) ![注册账表表单插件.webp](/download/0100076ff883af2f417ba884d6d549ba25f5.webp) <4>现在可以登业务站点,验证一下结果。 ![预览附件文件.webp](/download/010051fc97edefd54fc391a29f634cc45a4e.webp)

二开案例.账表.预览附件文件

**【应用场景】** 账表中显示单据附件,双击对应列的时候,预览单据附件。**【案例演示】** <1>编写账表服务插件,查询单据关联...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息