掌上报销V3添加单据体附件二开方案原创
6人赞赏了该文章
2,276次浏览
编辑于2021年12月06日 10:56:49
步骤一:在BOSIDE中对掌上报销V3单体移动表单进行扩展,扩展后添加附件控件
出差申请单或者差旅报销单单据体中加附件先扩展ER_MBReimb_TravelPlanV3; 费用申请和费用报销需扩展ER_MBReimb_ExpItemV3
步骤二:VS中开发DLL插件(实现附件上传、附件与单据体关联)
A.继承Kingdee.K3.FIN.ER.Mobile.Business.PlugIn.MobileReimbV3.MBReimbExpReimbItemEdit 并且需要在BOSIDE中去掉表单原有的插件Kingdee.K3.FIN.ER.Mobile.Business.PlugIn.MobileReimbV3.MBReimbExpReimbItemEdit B.插件中重写AfterButtonClick事件,在这个事件中需要完成几个事情: a.获取当前单据的fid,源单单据的formid(PC端单据的formid),以及当前分录的entryid,单据体的标识(PC端单体明细的标识,FEntity) 可以对单据做一次暂存拿到这些参数,如果单据是创建状态就需要做一次保存,不然新增的单据体没有存到数据库就没有entryid b.调用用附件控件的UploadFieldBatch()方法,把附件控件中的附件上传到服务器临时目录:this.View.GetControl<FileUploadControl>("FFileUpdate").UploadFieldBatch(); c.调用base.AfterButtonClick事件,切记此方法要放在最后执行。 示例代码: 有些引用要添加进来的的 Kingdee.K3.BD.Common.Business.Plugin; Kingdee.BOS.Orm(Kingdee.BOS.DataEntity) ; public override void AfterButtonClick(AfterButtonClickEventArgs e) { //确定按钮 if(e.Key.EqualsIgnoreCase("FBtnSaveEntry")) { //先判断当前单据是否有标识(有了标识才可以上传附件),没有标识时先做一次暂存然后上传附件 if (BillView.Model.GetPKValue().IsNullOrEmptyOrWhiteSpace()) { try { //设置FFormId的默认值 BillView.Model.SetSystemData(); var draftResult = Kingdee.BOS.ServiceHelper.BusinessDataServiceHelper.Draft(this.Context, BillView.BusinessInfo, BillView.Model.DataObject); BillView.Model.DataChanged = false; if (draftResult.IsSuccess) { MobBillArgs.PKValue = Convert.ToString(BillView.Model.DataObject.GetPrimaryKeyValue(false)); BillView.Model.SetPKValue(MobBillArgs.PKValue); } } catch (Exception ex) { Logger.Error("", Kingdee.BOS.Resource.SubSystemType.FIN), ex); } } try { //调用附件控件的上传FFileUpdate为你单据体附件的控件 this.View.GetControl<FileUploadControl>("FFileUpdate").UploadFieldBatch(); } catch (Exception ex) { Logger.Error("Kingdee.K3.FIN.ER.Mobile.Business.PlugIn.MobileReimbV3.MBReimbEditBase", Kingdee.BOS.Resource.ResManager.LoadKDString("附件上传至临时目录失败!", "0033365000023037", Kingdee.BOS.Resource.SubSystemType.FIN), ex); } //在执行完这些之后调用base.AfterButtonClick(e) base.AfterButtonClick(e) } } C.重写AfterMobileUpload()方法在此方法中要实现附件与单体体的关联及附件由临时目录固化到数据库/亚马逊云盘/金蝶云盘(根据文件服务器配置固化到相应的地方)的操作,切记此方法中不能调用base.AfterMobileUpload()
代码示例: //这里是上传整单附件,分录附件上传,请注意EntryKey和EntryInterID的赋值 AttachmentKey attachmentKey = new AttachmentKey(); attachmentKey.BillType = BillView.BusinessInfo.GetForm().Id; attachmentKey.BillInterID = Convert.ToString(BillView.Model.GetPKValue()); attachmentKey.EntryKey = "FNETIRY";//单据体标识,单体附件需要把这个值赋上 attachmentKey.EntryInterID = Convert.ToString( 当前分录的内码,不是行号)//单据体当前分录内码 string fileUploadFolder = 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) { errFileNames.Add(fileUploadEntity.OldName); } else { 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<long, File> dic = ExtendFieldUtil.UploadAttachFile(this.Context, physicalPaths, attachmentKey, newName_oldName_map); } catch(Exception ex) { //异常处理 } } D.单据体分录的附件赋值(编辑分录时如果此分录已经添加了附件需要把附件显示出来)
/// <summary> /// 设置附件控件值 /// </summary> private void SetAttachment() { if (!BillView.Model.GetPKValue().IsNullOrEmptyOrWhiteSpace()) { LastAttachFile = MoveAttachmentToTemp( Convert.ToString(BillView.Model.GetPKValue()), BillView.BusinessInfo.GetForm().Id,"FENTITY",Convert.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("FFileUpdate").SetValue(_accessoryData); this.View.UpdateView("FFileUpdate"); } } //获取附件 private Dictionary<string, File> MoveAttachmentToTemp(string interID, string formId, string entryId, string 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; } 如有不明之处请留言,我会尽快回复!!
推荐阅读