移动单据下推暂存,跳转

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

移动单据下推暂存,跳转

移动单据下推移动单据,暂存生成的下游单据,然后自动跳转打开生成的下游单据并进行编辑。

在原链接--移动单据自动下推上修改https://wenku.my7c.com/link/s/lK50I

                   //暂存下推数据
                    var draftResult = BusinessDataServiceHelper.Draft(this.View.Context, targetBillMeta.BusinessInfo, targetBillObjs, saveOption, "draft");
                    //打开暂存的单据
                    MobileShowParameter paramBill = new MobileShowParameter();
                    paramBill.FormId = "VBGU_YHMMDH_BOS";// 移动单据标识
                    paramBill.PKey = Convert.ToString(targetBillObjs[0]["id"]) ;
                    paramBill.Status = OperationStatus.EDIT;//新增为 OperationStatus.ADDNEW
                    this.View.ShowForm(paramBill);
完整代码如下:
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;
using Kingdee.BOS.Mobile;

namespace XT01
{
    /// <summary>
     /// 移动表单继承:AbstractMobilePlugin, 移动单据继承:AbstractMobileBillPlugin
     /// 演示单据下推: 苗木申请单——》苗木到货单
     /// </summary>
     [System.ComponentModel.Description("移动单据--下推")]


    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 = "VBGU_YHMMSQD";
                    //下游PC单据 苗木到货单FormId
                    var targetFormId = "VBGU_YHMMDHD";
                    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 = "64c7652dbcfcd7",
                        //设定目标单据主业务组织。如无主业务组织,可以为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();


                    //暂存下推数据
                    var draftResult = BusinessDataServiceHelper.Draft(this.View.Context, targetBillMeta.BusinessInfo, targetBillObjs, saveOption, "draft");
                    //打开暂存的单据
                    MobileShowParameter paramBill = new MobileShowParameter();
                    paramBill.FormId = "VBGU_YHMMDH_BOS";// 移动单据标识
                    paramBill.PKey = Convert.ToString(targetBillObjs[0]["id"]) ;
                    paramBill.Status = OperationStatus.EDIT;//新增为 OperationStatus.ADDNEW
                    this.View.ShowForm(paramBill);

                    /// 判断操作结果是否成功,如果不成功,则直接抛错中断进程
                    var result = CheckOpResult(draftResult, 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;
          
        }
        
    }
}


移动单据下推暂存,跳转

移动单据下推移动单据,暂存生成的下游单据,然后自动跳转打开生成的下游单据并进行编辑。在原链接--移动单据自动下推上修改https://wenku....
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息