描述一下场景:
3张单子:出口报关单证,出运明细单,销售出库单
出口报关单证点击【离岸】按钮触发表单插件,在表单插件中调用“出运明细单”到“销售出库单”的单据转换规则,并且打开下游单据;
“出运明细单”到“销售出库单”是一对一的转换关系;
当出现多张“出运明细单”下推“销售出库单”的时候,只有一张销售出库单有数据,其他几张都是空的
下面是我的代码:[code]//1.获取需要反写的出运明细单id集合
string shipIdSql = "SELECT DISTINCT FSOURCEBILLID FROM TPT_FZH_STORAGEGOODSENTRY WHERE FID = " + Convert.ToInt64(this.View.Model.GetValue("FSourceBillId"));
DynamicObjectCollection shipIdCol = DBUtils.ExecuteDynamicObject(this.Context, shipIdSql);
for (int i = 0; i < shipIdCol.Count; i++)
{
// 获取源单与目标单直接的转换规则,如果规则未启用,则返回为空,注意容错
List
ConvertRuleElement rule = rules[0];// rules.FirstOrDefault((ConvertRuleElement t) => t.IsDefault);
//出运明细单内码
string primaryKeyValue = Convert.ToString(shipIdCol[i]["FSOURCEBILLID"]);
ListSelectedRow row = new ListSelectedRow(primaryKeyValue, string.Empty, 0, "TP_FZC_ShipDetail");
ListSelectedRow[] selectedRows = new ListSelectedRow[] { row };
// 调用下推服务,生成下游单据数据包
ConvertOperationResult operationResult = null;
Dictionary
try
{
PushArgs pushArgs = new PushArgs(rule, selectedRows)
{
TargetBillTypeId = "ad0779a4685a43a08f08d2e42d7bf3e9", //单据类型 = 标准销售出库单
TargetOrgId = 1, // 请设定目标单据主业务组织。如无主业务组织,可以为0
CustomParams = custParams, // 可以传递额外附加的参数给单据转换插件,如无此需求,可以忽略
};
//执行下推操作,并获取下推结果
operationResult = ConvertServiceHelper.Push(this.View.Context, pushArgs, OperateOption.Create());
}
catch (KDExceptionValidate ex)
{
this.View.ShowErrMessage(ex.Message, ex.ValidateString);
return;
}
catch (KDException ex)
{
this.View.ShowErrMessage(ex.Message);
return;
}
catch
{
throw;
}
// 获取生成的目标单据数据包
DynamicObject[] objs = (from p in operationResult.TargetDataEntities
select p.DataEntity).ToArray();
// 显示下推的目标单编辑界面
this.ShowPushResult("SAL_OUTSTOCK", operationResult, objs);
}
///
/// 显示下推的目标单编辑界面:调用下推服务的代码略
///
/// 下游单据FormId
/// 下推服务返回的结果对象
/// 下推生成的全部下游单据
public void ShowPushResult(
string targetFormId,
ConvertOperationResult pushResult,
DynamicObject[] objs)
{
// 构建界面显示参数
BillShowParameter param = new BillShowParameter
{
ParentPageId = this.View.PageId
};
if (objs.Length == 1)
{
// 如果下推生成的目标单仅仅只有一张,则直接打开下游单据的编辑界面
param.FormId = targetFormId; // formId
param.Status = OperationStatus.ADDNEW; // 新建状态
param.CreateFrom = CreateFrom.Push; // 标志:下推创建的单据
param.AllowNavigation = false; // 不显示导航菜单
// 把下推结果放在缓存交换区
string customParamKey = "_ConvertSessionKey";
string sessionKey_Result = "ConverOneResult";
string sessionKey_ErrorInfo = "ConvertValidationInfo";
param.CustomParams.Add(customParamKey, sessionKey_Result);
this.View.Session[sessionKey_ErrorInfo] = pushResult.ValidationErrors;
this.View.Session[sessionKey_Result] = objs[0];
}
else if (objs.Length > 1)
{
// 如果下推生成的目标单有多行,则打开批量编辑界面
param.FormId = "BOS_ConvertResultForm";
// 把下推结果放在缓存交换区
string sessionKey_Result = "ConvertResults";
string sessionKey_ErrorInfo = "ConvertValidationInfo";
this.View.Session[sessionKey_Result] = objs;
this.View.Session[sessionKey_ErrorInfo] = pushResult.ValidationErrors;
param.CustomParams.Add("_ConvertResultFormId", targetFormId);
}
else
{
return;
}
// 显示界面
param.OpenStyle.ShowType = ShowType.MainNewTabPage;
this.View.ShowForm(param);
}[/code]
推荐阅读