问一个KDTransactionScope 范围包含单据保存、提交、审核的问题,我们项目中经常碰到如下问题
1、 KDTransactionScope 范围包含单据保存、提交、审核 操作,如下代码,
经常有单据操作冲突不能释放,操作
2、如果在KDTransactionScope 范围再包含一个单据转换,保存,提交,审核,就会有反写操作冲突产生,不会释放
是否不能一个KDTransactionScope 包含 保存、提交、审核 三个操作,也没有意义
#region 具体创建代码
Kingdee.BOS.Orm.OperateOption saveOption = Kingdee.BOS.Orm.OperateOption.Create();
long receiveFID = 0;
IBillView billViewPush = null;
returnFlag = true;
try
{
if (FID > 0)
ClearNetWorkCtrlRS("PUR_PurchaseOrder", FID);
ConvertOption convertOption = new BHR.K3.Common.Core.ParamOption.ConvertOption();
convertOption.sourceFormId = "PUR_PurchaseOrder";
convertOption.targetFormId = "PUR_ReceiveBill";
convertOption.ConvertRuleKey = "PUR_PurchaseOrder-PUR_ReceiveBill";
convertOption.IsDraft = true;
convertOption.IsSave = false;
convertOption.IsAudit = false;
convertOption.Option = OperateOption.Create();
convertOption.BizSelectRows = selectedRows.ToArray();
IOperationResult operationResult = AppServiceContext.BillConvertService.ConvertBills2(ctx, convertOption);
if (!operationResult.IsSuccess)
{
actionResult.Code = "1";
if (operationResult.ValidationErrors != null && operationResult.ValidationErrors.Count > 0)
actionResult.Message = "下推采购收料单失败,原因是" + operationResult.ValidationErrors.FirstOrDefault().Message;
return Newtonsoft.Json.JsonConvert.SerializeObject(actionResult);
}
object[] deleteFids = operationResult.SuccessDataEnity.Select(item => ((Object)(Convert.ToInt64(item["Id"])))).ToArray();
receiveFID = Convert.ToInt64(deleteFids[0]);
if (FID > 0)
ClearNetWorkCtrlRS("PUR_PurchaseOrder", FID);
if (receiveFID > 0)
ClearNetWorkCtrlRS("PUR_ReceiveBill", receiveFID);
//保存,先释放网络
//ClearNetWorkCtrl("T_PUR_RECEIVE", "收料通知单", Convert.ToInt64(deleteFids[0]));
using (KDTransactionScope trans = new KDTransactionScope(System.Transactions.TransactionScopeOption.Required))
{
returnFlag = false;
billViewPush = FourSDataManagerUtil.CreateBillView(ctx, "PUR_ReceiveBill", receiveFID);
((IBillViewService)billViewPush).LoadData();
DynamicFormViewPlugInProxy eventProxyPush = billViewPush.GetService
eventProxyPush.FireOnLoad();
//填充属性
IDynamicFormViewService dynamicFormViewPush = billViewPush as IDynamicFormViewService;
dynamicFormViewPush.SetItemValueByNumber("FReceiveDeptId", data.K3FReceiveDeptId, 0);//收料部门
dynamicFormViewPush.SetItemValueByID("FReceiverId", SLY, 0);//收料员
int rowIndex1 = 0;
foreach (var item in data.Details)
{ //dynamicFormViewPush.UpdateValue("FBillNo", 0, data.Name);//采购订单编号
dynamicFormViewPush.SetItemValueByNumber("FStockID", item.FStockCode, rowIndex1);//收料仓库
dynamicFormViewPush.UpdateValue("FActReceiveQty", rowIndex1, item.FQty);//数量
rowIndex1++;
}
result = FourSDataManagerUtil.SaveBill(ctx, billViewPush, saveOption);
if (!result.IsSuccess)
{
if (result.ValidationErrors==null || (result.ValidationErrors.Count == 0))
{
actionResult.Code = "1";
actionResult.Message = result.OperateResult.FirstOrDefault().Message;
}
else
{
actionResult.Code = "1";
actionResult.Message = result.ValidationErrors.FirstOrDefault().Message;
}
returnFlag = false;
return Newtonsoft.Json.JsonConvert.SerializeObject(actionResult);
}
if (FID > 0)
ClearNetWorkCtrlRS("PUR_PurchaseOrder", FID);
if (receiveFID > 0)
ClearNetWorkCtrlRS("PUR_ReceiveBill", receiveFID);
IOperationResult SumbitResult = AppServiceContext.SubmitService.Submit(ctx,
billViewPush.BusinessInfo, new object[] { billViewPush.Model.DataObject["Id"] }, "Submit", OperateOption.Create());
if (!SumbitResult.IsSuccess)
{
if (result.ValidationErrors.Count == 0)
{
actionResult.Code = "1";
actionResult.Message = result.OperateResult.FirstOrDefault().Message;
}
else
{
actionResult.Code = "1";
actionResult.Message = result.ValidationErrors.FirstOrDefault().Message;
}
returnFlag = false;
return Newtonsoft.Json.JsonConvert.SerializeObject(actionResult);
}
if (FID > 0)
ClearNetWorkCtrlRS("PUR_PurchaseOrder", FID);
if (receiveFID > 0)
ClearNetWorkCtrlRS("PUR_ReceiveBill", receiveFID);
List
keyValuePairPush.Add(new KeyValuePair
if (FID > 0)
ClearNetWorkCtrlRS("PUR_PurchaseOrder", FID);
if (receiveFID > 0)
ClearNetWorkCtrlRS("PUR_ReceiveBill", receiveFID);
string BillNo = Convert.ToString(billViewPush.Model.DataObject["BillNo"]);
actionResult.Code = "0";
actionResult.Message = BillNo;
trans.Complete();
returnFlag = true;
}
}
catch (Exception e)
{
returnFlag = false;
actionResult.Code = "1";
actionResult.Message = e.Message.ToString();
return Newtonsoft.Json.JsonConvert.SerializeObject(actionResult);
}
finally
{
if (billViewPush != null)
billViewPush.Close();
if (!returnFlag)
{
object[] fids = new object[1];
fids[0] = receiveFID;
AppServiceContext.DeleteService.Delete(ctx, "PUR_ReceiveBill", fids);
}
if(FID>0)
ClearNetWorkCtrlRS("PUR_PurchaseOrder", FID);
if (receiveFID > 0)
ClearNetWorkCtrlRS("PUR_ReceiveBill", receiveFID);
}
#endregion
推荐阅读