掌上报销单据体附件二开方案

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

掌上报销单据体附件二开方案

【应用场景】

费用报销PC端相关单据,单据体可通过配置菜单点击事件关联(单据体附件管理)的操作可以实现单据体附件功能,移动端需要二开实现


【注意事项】

该实现方案目前只支持掌上报销5类单据的费用明细,差旅费报销单2019新政行程明细的单据体暂不支持


【案例演示】

PC端费用报销与掌上报销单据头与单据体的映射关系:https://vip.kingdee.com/article/439370655386174720?productLineId=1&isKnowledge=2


【实现步骤】

<1>根据上面的映射关系找到对应的移动表单,以费用报销单为例:

费用报销单分录编辑(单据体)=》ER_MBReimb_ExpItemV3(掌上报销V3_申请/报销单分录)

在BOS设计器中找到ER_MBReimb_ExpItemV3(掌上报销V3_申请/报销单分录)这个表单,然后添加附件布局。

由于是共用表单,附件布局的高度设置为0,由具体的业务插件去设置重新高度。




<2>二开ER_MBReimb_ExpItemV3(掌上报销V3_申请/报销单分录)表单插件

using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Attachment;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Interaction;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Mobile.Metadata.ControlDataEntity;
using Kingdee.BOS.Mobile.PlugIn.Args;
using Kingdee.BOS.Orm;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using Kingdee.K3.Core.Mobile.Utils;
using Kingdee.K3.FIN.Core.Mobile;
using Kingdee.K3.FIN.ER.Mobile.Business.PlugIn.MobileReimbV3;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Kingdee.XYZ.Mobile.Business.PlugIn
{
    [Description("测试掌上报销V3_申请/报销明细插件")]
    public class TestMBReimbExpReimbItemEdit : MBReimbExpReimbItemEdit
    {

        public override void OnInitialize(InitializeEventArgs e)
        {
            base.OnInitialize(e);
            if (BillView.GetFormId().Equals("ER_ExpReimbursement") || BillView.GetFormId().Equals("ER_ExpReimbursement_Travel"))
            {
                this.View.GetControl("F_bzsz_FlowLayout").SetCustomPropertyValue("height", 75);
                SetAttachment();
            }
        }

        /// <summary>
        /// 设置附件控件值
        /// </summary>
        private void SetAttachment()
        {
            if (!BillView.Model.GetPKValue().IsNullOrEmptyOrWhiteSpace())
            {
                Entity ty = BillView.BillBusinessInfo.GetEntity(_entityKey);
                var lastAttachFile = MoveAttachmentToTemp(Convert.ToString(BillView.Model.GetPKValue()), BillView.BusinessInfo.GetForm().Id, _entityKey, BillView.Model.GetEntityDataObject(ty, base.MobBillArgs.EntryRow)["Id"].ToString());
                AccessoryData _accessoryData = new AccessoryData();
                _accessoryData.FormId = BillView.BusinessInfo.GetForm().Id;
                _accessoryData.BillId = Convert.ToString(BillView.Model.GetPKValue());
                _accessoryData.Data = lastAttachFile.Values.ToList();
                this.View.GetControl("FFileUpdateEntry").SetValue(_accessoryData);
                this.View.UpdateView("FFileUpdateEntry");
            }
        }
        //获取附件
        private Dictionary<string, File> MoveAttachmentToTemp(string interID, string formId, string entryId, string entryInterid)
        {
            entryId = entryId.IsNullOrEmptyOrWhiteSpace() ? " " : entryId;
            entryInterid = entryInterid.IsNullOrEmptyOrWhiteSpace() ? "-1" : entryInterid;
            // 加载数据库中附件数据            
            var filter = Kingdee.BOS.Core.Metadata.OQLFilter.CreateHeadEntityFilter(string.Format("FInterID = '{0}' AND FBILLTYPE = '{1}' AND FENTRYKEY = '{2}' AND FENTRYINTERID = '{3}'", interID, formId, entryId, entryInterid));
            var dyns = Kingdee.BOS.ServiceHelper.BusinessDataServiceHelper.Load(this.Context, FormIdConst.BOS_Attachment, null, filter);
            Dictionary<string, File> fileList = new Dictionary<string, File>();
            if (dyns != null && dyns.Count() > 0)
            {
                foreach (var dyn in dyns)
                {
                    fileList.Add(Convert.ToString(dyn["Id"]), new File() { FileID = Convert.ToString(dyn["Id"]), Name = Convert.ToString(dyn["AttachmentName"]), Type = Convert.ToString(dyn["ExtName"]) });
                }
            }
            return fileList;
        }
        public override void AfterMobileUpload(MobileUploadEventArgs e)
        {

            if (e.Key.ToUpper() == "FFILEUPDATEENTRY")
            {
                base.AutoDraft(true);
                UploadAttachFiles(e);
            }
            else
            {
                base.AfterMobileUpload(e);
            }
        }

        public override void MobileDeleteFile(MobileDeleteFileEventArgs e)
        {
            //获取附件ID
            var ids = e.FileNameArray.Select(p => p.FileID.TryPareValue<long>()).ToList();
            if (ids == null || ids.Count == 0)
                return;
            var formMetadata = (FormMetadata)MetaDataServiceHelper.Load(this.Context, FormIdConst.BOS_Attachment);
            var option = OperateOption.Create();
            option.SetIgnoreWarning(true);
            option.SetIgnoreInteractionFlag(true);
            option.SetIgnoreScopeValidateFlag(true);
            BusinessDataServiceHelper.Delete(this.Context, formMetadata.BusinessInfo, ids.ConvertAll(x => (object)x).ToArray(), option);
        }

        private void UploadAttachFiles(MobileUploadEventArgs e)
        {
            Entity ty = BillView.BillBusinessInfo.GetEntity(_entityKey);
            //这里是上传整单附件,分录附件上传,请注意EntryKey和EntryInterID的赋值
            AttachmentKey attachmentKey = new AttachmentKey();
            attachmentKey.BillType = BillView.BusinessInfo.GetForm().Id;
            attachmentKey.BillInterID = Convert.ToString(BillView.Model.GetPKValue());
            attachmentKey.EntryKey = _entityKey;//单据体标识,单体附件需要把这个值赋上                
                                                //attachmentKey.EntryInterID = Convert.ToString(base.MobBillArgs.PKValue);//单据体当前分录内码
            if (BillView.Model.GetEntityDataObject(ty, base.MobBillArgs.EntryRow) != null)
            {
                attachmentKey.EntryInterID = BillView.Model.GetEntityDataObject(ty, base.MobBillArgs.EntryRow)["Id"].ToString();
            }

            string fileUploadFolder = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, KeyConst.TEMPFILEPATH);
            List<string> physicalPaths = new List<string>();
            List<FiledUploadEntity> entityList = e.FileNameArray;
            //文件名映射(修改后的名称和原名)		 
            Dictionary<string, string> newName_oldName_map = new Dictionary<string, string>();
            foreach (FiledUploadEntity fileUploadEntity in entityList)
            {
                if (!fileUploadEntity.IsSuccess) 
                {
                    continue;
                }

                // 检查文件是否存在
                var fileName = System.IO.Path.Combine(fileUploadFolder, fileUploadEntity.FileName);
                if (!System.IO.File.Exists(fileName)) 
                {
                    continue;
                }
                var physicalPath = PathUtils.GetPhysicalPath(fileUploadFolder, fileUploadEntity.FileName);
                physicalPaths.Add(physicalPath);
                newName_oldName_map.Add(fileUploadEntity.FileName, fileUploadEntity.OldName);
            }
            //physicalPaths                
            if (physicalPaths.Count > 0)
            {
                try
                {
                    ///上传附件   返回成功上传的附件  需要引用Kingdee.K3.FIN.Core.Mobile                        
                    Dictionary<string, File> dic = ExtendFieldUtil.UploadAttachFile(this.Context, physicalPaths, attachmentKey, newName_oldName_map);
                }
                catch
                {
                    //异常处理
                    //this.View.ShowErrMessage(ex.ToString());
                }
            }
        }
    }
}

<3>由于底层针对单据头的附件加载的时候,会拿到单据头和单据体所有的附件展示,所以针对具体需要增加单据体附件的单据,需要二开移动表单重写单据头的附件加载方案和删除方案,以费用报销单为例:

费用报销单编辑(单据头)=》ER_MBReimb_ExpReimbV3(掌上报销V3_费用报销单) 

using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Interaction;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Mobile.Metadata.ControlDataEntity;
using Kingdee.BOS.Mobile.PlugIn.Args;
using Kingdee.BOS.Orm;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using Kingdee.K3.Core.Mobile.Utils;
using Kingdee.K3.FIN.Core.Mobile;
using Kingdee.K3.FIN.ER.Mobile.Business.PlugIn.MobileReimbV3;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Kingdee.XYZ.Mobile.Business.PlugIn
{
    [Description("测试掌上报销V3_费用报销单插件")]
    public class TestMBReimbExpReimbEdit : MBReimbExpReimbEdit
    {
        public override void AfterBindData(EventArgs e)
        {
            base.AfterBindData(e);
            if (!BillView.Model.GetPKValue().IsNullOrEmptyOrWhiteSpace())
            {
                //清除单据头附件控件视图重新绑定
                LastAttachFile = ExtendFieldUtil.GetBillAttachFile(this.Context, Convert.ToString(BillView.Model.GetPKValue()), BillView.BusinessInfo.GetForm().Id, "");
                var accessoryData = new AccessoryData
                {
                    FormId = BillView.BusinessInfo.GetForm().Id,
                    BillId = Convert.ToString(BillView.Model.GetPKValue()),
                    Data = LastAttachFile.Values.ToList()
                };
                this.View.GetControl("FFileUpdate").SetValue(accessoryData);
                this.View.UpdateView("FFileUpdate");
                AttachProvider.LastAttachFile.Clear();
            }
        }

        public override void MobileDeleteFile(MobileDeleteFileEventArgs e)
        {
            //base.MobileDeleteFile(e);
            //获取附件ID
            var ids = e.FileNameArray.Select(file => AttachProvider.FileIdMaps.ContainsKey(file.FileID) ? AttachProvider.FileIdMaps[file.FileID] : file.FileID.TryPareValue<long>()).ToList();
            if (ids == null || ids.Count == 0)
                return;
            var formMetadata = (FormMetadata)MetaDataServiceHelper.Load(this.Context, FormIdConst.BOS_Attachment);
            var option = OperateOption.Create();
            option.SetIgnoreWarning(true);
            option.SetIgnoreInteractionFlag(true);
            option.SetIgnoreScopeValidateFlag(true);
            BusinessDataServiceHelper.Delete(this.Context, formMetadata.BusinessInfo, ids.ConvertAll(x => (object)x).ToArray(), option);
        }
    }
}

<4>其他单据与上面费用报销单单据类似,具体表单映射关系参考:https://vip.kingdee.com/article/439370655386174720?productLineId=1&isKnowledge=2




【功能验证】

在电脑端调试移动端轻应用参考帖子:https://vip.kingdee.com/article/343300265727936512



【金蝶云星空BOS二次开发案例演示】

https://vip.kingdee.com/article/94751030918525696



掌上报销单据体附件二开方案

【应用场景】费用报销PC端相关单据,单据体可通过配置菜单点击事件关联(单据体附件管理)的操作可以实现单据体附件功能,移动端需要二开实...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息