移动单据自动下推保存篇

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

移动单据自动下推保存篇

一、概述:

本篇主要介绍通过二开插件完成移动单据下推,涉及到的主要知识点主要包括:

1. 单据转换配置

2. 单据转换调用

3. 单据保存

 

二、详细介绍:

这里我们将以 销售订单 下推 发货通知单 为例。

1. 单据转换配置

打开BOSIDE-》单据转换,配置 销售订单 下推 发货通知单 转换规则,具体和PC端一样,不做具体讲解。


2. 在移动单据中配置下推的按钮,标识“XT”;


3. 二开插件关键代码

    3.1获取单据转换规则:

    var rules=ConvertServiceHelper.GetConvertRules(this.View.Context,sourceFormId, targetFormId);

 

    3.2调用下推服务:

  operationResult=ConvertServiceHelper.Push(this.View.Context,pushArgs, OperateOption.Create());

 

    3.3单据保存

    var saveResult = BusinessDataServiceHelper.Save(this.View.Context, targetBillMeta.BusinessInfo, targetBillObjs,saveOption,"Save");


4.  注册插件



完整代码如下,供大家参考:

using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.DataEntity;
using Kingdee.BOS.Mobile.PlugIn;
using Kingdee.BOS.Mobile.PlugIn.Args;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Dynamic;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Core.Report.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.DynamicForm.Operation;
using Kingdee.BOS;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core.Interaction;
using Kingdee.BOS.Core.DynamicForm;
 
namespace BOS.Debug.MobilePlugIn
{
     /// <summary>
     /// 移动表单继承:AbstractMobilePlugin, 移动单据继承:AbstractMobileBillPlugin
     /// 演示单据下推: 演示销售订单 =》发货通知单
     /// </summary>
     [System.ComponentModel.Description("移动单据--下推DEMO")]
     public class MobileBillPlugIn_XiaTui : AbstractMobileBillPlugin
     {
         public override void ButtonClick(ButtonClickEventArgs e)
         {
              if (e.Key == "XT")
              {
                   try
                   {
                       //本次演示的是销售订单=》发货通知单
                       //单据内码
                       var pkVale = this.View.BillModel.GetPKValue().ToString();
                       //上游PC单据 销售订单FormId
                       var sourceFormId = "SAL_SaleOrder";
                       //下游PC单据 销售出库单FormId
                       var targetFormId = "SAL_DELIVERYNOTICE";
                       if (string.IsNullOrWhiteSpace(pkVale))
                       {
                            this.View.ShowErrMessage("当前单据内码为空,无法下推!");
                            return;
                       }
 
                       //获取单据转换规则
                       var rules = ConvertServiceHelper.GetConvertRules(this.View.Context, sourceFormId, targetFormId);
                       if (rules == null || rules.Count == 0)
                       {
                            this.View.ShowErrMessage("未找到启用的转换规则,无法下推!");
                            return;
                       }
                       var rule = rules.FirstOrDefault(t => t.IsDefault);
                       rule = rule == null ? rules[0] : rule;
 
                       //构建待下推的源单数据行(这里我们只演示整单下推)
                       ListSelectedRow row = new ListSelectedRow(pkVale, string.Empty, 0, sourceFormId);
                       //如果下推的是指定单据体行,请参照下句代码,在ListSelectedRow中,指定EntryId以及EntryEntityKey
                       //ListSelectedRow row = new ListSelectedRow(pkVale, EntryId, 0, sourceFormId) { EntryEntityKey = "FEntity" };
                       ListSelectedRow[] selectedRows = new ListSelectedRow[] { row };
 
                       //调用下推服务,生成下游单据数据包
                       ConvertOperationResult operationResult = null;
                       Dictionary<string, object> custParams = new Dictionary<string, object>();
                       PushArgs pushArgs = new PushArgs(rule, selectedRows)
                       {
                            //设定目标单据单据类型。如无单据类型,可以空字符
                            TargetBillTypeId = "",
                             //设定目标单据主业务组织。如无主业务组织,可以为0,建议在转换规则中,配置好主业务组织字段的映射关系:运行时,由系统根据映射关系,自动从上游单据取主业务组织,避免由插件指定
                            TargetOrgId = 0,
                             //可以传递额外附加的参数给单据转换插件,如无此需求,可以忽略
                            CustomParams = custParams,
                       };
                       //执行下推操作,并获取下推结果
                       operationResult = ConvertServiceHelper.Push(this.View.Context, pushArgs, OperateOption.Create());
 
 
                       //开始处理下推结果:
                       //获取下推生成的下游单据数据包
                       Kingdee.BOS.Orm.DataEntity.DynamicObject[] targetBillObjs = (from p in operationResult.TargetDataEntities select p.DataEntity).ToArray();
                       if (targetBillObjs.Length == 0)
                       {
                            throw new KDBusinessException("", string.Format("由{0}自动下推{1},没有成功生成数据包,自动下推失败!", sourceFormId, targetFormId));
                       }
                       // 读取目标单据元数据
                       var targetBillMeta = MetaDataServiceHelper.Load(this.View.Context, targetFormId) as FormMetadata;
                       OperateOption saveOption = OperateOption.Create();
                      
                       //TODO:数据修改,必录数据设置
                       //.......
                       
                       //保存下推数据
                       var saveResult = BusinessDataServiceHelper.Save(this.View.Context, targetBillMeta.BusinessInfo, targetBillObjs, saveOption, "Save");
                       /// 判断操作结果是否成功,如果不成功,则直接抛错中断进程
                       var result=CheckOpResult(saveResult, saveOption);
                       this.View.ShowMessage(string.Format("由{0}自动下推{1}成功!", sourceFormId, targetFormId));
                   }
                   catch (KDExceptionValidate ex)
                   {
                       this.View.ShowErrMessage(ex.Message, ex.ValidateString);
                   }
                   catch (KDException ex)
                   {
                       this.View.ShowErrMessage(ex.Message);
                   }
              }
              base.ButtonClick(e);
         }
 
         private bool CheckOpResult(IOperationResult opResult, OperateOption opOption)
         {
              bool isSuccess = false;
              if (opResult.IsSuccess == true)
              {
                   // 操作成功
                   isSuccess = true;
              } else
              {
                   if (opResult.InteractionContext != null && opResult.InteractionContext.Option.GetInteractionFlag().Count>0)
                   {
                       // 有交互性提示
                       // 传出交互提示完整信息对象
                       opResult.InteractionContext = opResult.InteractionContext;
                       // 传出本次交互的标识,
                       // 用户在确认继续后,会重新进入操作;
                       // 将以此标识取本交互是否已经确认过,避免重复交互
                       opResult.Sponsor = opResult.Sponsor;
                       // 抛出交互错误,把交互信息传递给前端
                       new KDInteractionException(opOption, opResult.Sponsor);
                   } else
                   {
                       // 操作失败,拼接失败原因,然后抛出中断
                       opResult.MergeValidateErrors();
                       if (opResult.OperateResult == null)
                       {
                            // 未知原因导致提交失败
                            throw new KDBusinessException("", "未知原因导致自动提交、审核失败!");
                       } else
                       {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine("自动操作失败:");
                            foreach (var operateResult in opResult.OperateResult)
                            {
                                 sb.AppendLine(operateResult.Message);
                            }
                            throw new KDBusinessException("", sb.ToString());
                       }
                   }
              }
              return isSuccess;
         }
     }
}


移动单据自动下推保存篇

一、概述:本篇主要介绍通过二开插件完成移动单据下推,涉及到的主要知识点主要包括:1. 单据转换配置2. 单据转换调用3. 单据保存 二、详细...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息