}//end static method

        public static void MergeFromOption(this IOperationResult result, OperateOption option)
        {
            var inner = option.GetVariableValue <IOperationResult>(BOSConst.CST_KEY_OperationResultKey);

            if (inner != null)
            {
                result.MergeResult(inner);
            }
        }//end static method
        public override void OnAfterCreateLink(CreateLinkEventArgs e)
        {
            base.OnAfterCreateLink(e);
            OperateOption  Option = base.Option;
            List <decimal> amount = new List <decimal>();

            if (Option.TryGetVariableValue <List <decimal> >("OutStockAmount", out amount))
            {
                List <int> srcbillseq = Option.GetVariableValue <List <int> >("srcbillseq");
                DateTime   FDATE      = Option.GetVariableValue <DateTime>("FDATE");
                (e.TargetExtendedDataEntities.FindByEntityKey("FBillHead"))[0].DataEntity["Date"] = FDATE;
                for (int i = 0; i < e.TargetExtendedDataEntities.FindByEntityKey("FEntity").Count(); i++)
                {
                    (e.TargetExtendedDataEntities.FindByEntityKey("FEntity"))[i].DataEntity["SALBASEQTY"]   = amount[i];
                    (e.TargetExtendedDataEntities.FindByEntityKey("FEntity"))[i].DataEntity["BaseUnitQty"]  = amount[i];
                    (e.TargetExtendedDataEntities.FindByEntityKey("FEntity"))[i].DataEntity["PRICEBASEQTY"] = amount[i];
                    (e.TargetExtendedDataEntities.FindByEntityKey("FEntity"))[i].DataEntity["Fsrcbillseq"]  = srcbillseq[i];
                }
            }
        }
        public DynamicObject[] ConvertBillsWithEntry(Context ctx, List <ConvertOption> options, string SourceFormId, string TargetFormId, string targetBillTypeId, string SourceEntryEntityKey, OperateOption operateOption)
        {
            //List<DynamicObject[]> result = new List<DynamicObject[]>();
            List <DynamicObject> before = new List <DynamicObject>();
            //IEnumerable<DynamicObject> targetDatas = null;
            IConvertService convertService = ServiceHelper.GetService <IConvertService>();
            var             rules          = convertService.GetConvertRules(ctx, SourceFormId, TargetFormId);
            string          rulekey        = operateOption.GetVariableValue("ruleKey", string.Empty);//单据转换规则 key 指定 ID
            var             rule           = rules.FirstOrDefault(t => t.IsDefault);

            if (rules == null || rules.Count == 0)
            {
                throw new KDBusinessException("", string.Format("未找到{0}到{1}之间,启用的转换规则,无法自动下推!", SourceFormId, TargetFormId));
            }
            //如果指定 规则
            if (rulekey.Equals(string.Empty) == false)
            {
                foreach (var ervryrule in rules)
                {
                    if (ervryrule.Key.Equals(rulekey))
                    {
                        rule = ervryrule;
                        break;
                    }
                }
            }

            if (rule == null)
            {
                rule = rules[0];
            }

            foreach (ConvertOption option in options)
            {
                // 开始构建下推参数:
                // 待下推的源单数据行
                List <ListSelectedRow> srcSelectedRows = new List <ListSelectedRow>();
                // Dictionary<long, List<Tuple<string, int>>> dic = new Dictionary<long, List<Tuple<string, int>>>();
                foreach (long billId in option.SourceBillIds)
                {
                    srcSelectedRows = new List <ListSelectedRow>();
                    int rowKey = -1;
                    for (int i = 0; i < option.SourceBillEntryIds.Count(); i++)
                    {
                        ListSelectedRow row = new ListSelectedRow(billId.ToString(), option.SourceBillEntryIds[i].ToString(), rowKey++, SourceFormId);
                        row.EntryEntityKey = SourceEntryEntityKey;
                        Dictionary <string, string> fieldValues = new Dictionary <string, string>();
                        fieldValues.Add(SourceEntryEntityKey, option.SourceBillEntryIds[i].ToString());
                        row.FieldValues = fieldValues;
                        srcSelectedRows.Add(row);
                        //dic.Add(option.SourceBillEntryIds[i], new List<Tuple<string, int>> { new Tuple<string, int>(" ", option.mount[i]) });
                    }
                }
                // 指定目标单单据类型:情况比较复杂,直接留空,会下推到默认的单据类型
                if (targetBillTypeId == null)
                {
                    targetBillTypeId = string.Empty;
                }
                // 指定目标单据主业务组织:情况更加复杂,
                // 建议在转换规则中,配置好主业务组织字段的映射关系:运行时,由系统根据映射关系,自动从上游单据取主业务组织,避免由插件指定
                long targetOrgId = 0;
                // 自定义参数字典:把一些自定义参数,传递到转换插件中;转换插件再根据这些参数,进行特定处理
                Dictionary <string, object> custParams = new Dictionary <string, object>();
                //custParams.Add("1", 1);
                //custParams.Add("2", 2);
                // 组装下推参数对象
                PushArgs pushArgs = new PushArgs(rule, srcSelectedRows.ToArray())
                {
                    TargetBillTypeId = targetBillTypeId,
                    TargetOrgId      = targetOrgId,
                    CustomParams     = custParams
                };
                // 调用下推服务,生成下游单据数据包
                //OperateOption option1 = OperateOption.Create();
                //option1.SetVariableValue("OutStockAmount", option.mount);
                //option1.SetVariableValue("srcbillseq", option.srcbillseq);
                //option1.SetVariableValue("FDATE", Convert.ToDateTime(option.FDATE));

                ConvertOperationResult operationResult = convertService.Push(ctx, pushArgs, operateOption);
                // 开始处理下推结果:
                // 获取下推生成的下游单据数据包
                DynamicObject[] targetBillObjs = (from p in operationResult.TargetDataEntities select p.DataEntity).ToArray();
                foreach (DynamicObject cc in targetBillObjs)
                {
                    DynamicObjectCollection rpt = cc["FPAYAPPLYENTRY"] as DynamicObjectCollection;
                    foreach (DynamicObject item in rpt)
                    {
                        // item["FDETABLEINID"] = option.dic[Convert.ToString(item["SoorDerno"]) + Convert.ToString(item["Fsrcbillseq"])];
                    }
                    before.Add(cc);
                }
                if (targetBillObjs.Length == 0)
                {
                    // 未下推成功目标单,抛出错误,中断审核
                    throw new KDBusinessException("", string.Format("由{0}自动下推{1},没有成功生成数据包,自动下推失败!", SourceFormId, TargetFormId));
                }
            }
            DynamicObject[] aa = before.Select(p => p).ToArray() as DynamicObject[];

            return(aa);
        }