二开案例.文件服务.获取创建时间并更新关联单据

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

二开案例.文件服务.获取创建时间并更新关联单据

**【应用场景】** 想要直接将附件列表中的最新字段(如创建时间)更新到单据上,方便进行查看。 **【案例演示】** 获取附件上传时间并更新到单据头上 <1>编写列表插件,代码如下。 ``` csharp using Kingdee.BOS.Core; using Kingdee.BOS.Core.Attachment; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.List; using Kingdee.BOS.Core.List.PlugIn; using Kingdee.BOS.Core.Metadata.EntityElement; using Kingdee.BOS.Core.Metadata.FieldElement; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; namespace Kingdee.BOS.PlugInTest { /// <summary> /// 【列表插件】自定义附件列表插件 /// </summary> [Description("【列表插件】自定义附件列表插件"), HotUpdate] public class CustomAttachmentListPlugIn : AbstractListPlugIn { /// <summary> /// 页面准备关闭事件 /// </summary> /// <param name="e">页面准备关闭参数</param> public override void BeforeClosed(BeforeClosedEventArgs e) { base.BeforeClosed(e); if (this.View == null || this.View.ParentFormView == null) return; if (this.Model == null) return; if ((this.View is IListView) == false) return; // 这里演示的是取附件明细列表第一条的创建时间,如果有另外的逻辑,要取列表外的数据,可以访问数据库附件表获取需要的值 string strCreateTime = string.Empty; var listView = this.View as IListView; var rowList = listView.CurrentPageRowsInfo; if (rowList != null && rowList.Count > 0) { var firstRow = rowList[0]; DynamicObject rowData = (firstRow.DataRow as DynamicObjectDataRow).DynamicObject; if (rowData != null && rowData.DynamicObjectType.Properties.ContainsKey("FCREATETIME")) { strCreateTime = rowData["FCREATETIME"].GetString(); } } AttachmentKey attachmentKey = GetAttachmentKey(); if (attachmentKey == null) return; IDynamicFormView relateBillView = View.ParentFormView; UpdateAttachmentDate(relateBillView, attachmentKey, strCreateTime); } /// <summary> /// 获取附件标识 /// </summary> /// <returns></returns> private AttachmentKey GetAttachmentKey() { AttachmentKey attachmentKey = null; if (this.View.OpenParameter.GetCustomParameter(KeyConst.AttachmentKey) != null) { string json = this.View.OpenParameter.GetCustomParameter(KeyConst.AttachmentKey).ToString(); attachmentKey = AttachmentKey.ConvertFromString(json); } return attachmentKey; } /// <summary> /// 更新附件数据 /// </summary> /// <param name="relateBillView">关联的单据视图</param> /// <param name="attachmentKey">附件标识</param> /// <param name="strTime">需要展示的创建时间</param> private void UpdateAttachmentDate(IDynamicFormView relateBillView, AttachmentKey attachmentKey, string strTime) { bool dataChanged = relateBillView.Model.DataChanged; try { Field attachmentDateField = relateBillView.BillBusinessInfo.GetField("FAttachmentDate"); if (attachmentDateField == null) return; string billPkValue = string.Empty; if (relateBillView is IListView) { //从列表中打开附件列表,单据ID则取操作传过来的ID billPkValue = attachmentKey.BillInterID; } else { Entity entity = relateBillView.BillBusinessInfo.GetEntity(attachmentDateField.EntityKey); if (entity == null || entity.DynamicObjectType == null || entity.DynamicObjectType.PrimaryKey == null) return; string pkValueId = entity.DynamicObjectType.PrimaryKey.Name; billPkValue = relateBillView.Model.GetEntityDataObject(entity, attachmentKey.RowIndex)[pkValueId].ToString(); } // 单据表格名称 string billTableName = attachmentDateField.TableName; // 单据表格主键字段名称 string billPkFieldName = attachmentDateField.Entity.EntryPkFieldName; // 字段名称 string attachmentDateFieldName = attachmentDateField.FieldName; string sql = string.Format("update {0} set {1} = @date where {2} = @pkId", billTableName, attachmentDateFieldName, billPkFieldName); List<SqlParam> sqlParams = new List<SqlParam>(); sqlParams.Add(new SqlParam("@date", KDDbType.DateTime2, string.IsNullOrWhiteSpace(strTime) ? null : strTime)); sqlParams.Add(new SqlParam("@pkId", KDDbType.String, billPkValue)); DBServiceHelper.Execute(this.View.Context, sql, sqlParams); // 更新数据库成功后,更新界面值 if (relateBillView is IListView) { // 关联单据视图,则直接刷新 relateBillView.Refresh(); } else { relateBillView.Model.SetValue(attachmentDateField.Key, strTime, attachmentKey.RowIndex); // 保持单据原来的状态 relateBillView.Model.DataChanged = dataChanged; } } catch (Exception) { throw; } } } } ``` <2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。 <3>修改附件列表排序方式为按创建时间倒叙 ![设置排序.webp](/download/0100b855f4b1c43344109d1ac3ab5e0fb642.webp) <4>注册插件 ![注册插件.webp](/download/0100fc2a9767906846beae25cad31b8fa184.webp) <5>现在可以登业务站点,打开单据,上传附件,验证一下结果。 ![表单获取附件字段信息.webp](/download/0100dd1bbf3bd1924655942d639c0a5d953a.webp)

二开案例.文件服务.获取创建时间并更新关联单据

**【应用场景】**想要直接将附件列表中的最新字段(如创建时间)更新到单据上,方便进行查看。**【案例演示】**获取附件上传时间并更新到单据...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息