我公司业务助理要求在从销售订单下推发货通知单后,销售订单列表那里可以看到每个订单中已经通知发货的数量对应的金额(就是这个订单已经通知仓库那边发了多少钱的货了),系统默认只能反写数量,没有金额,所以我写了如下代码,黄色是我新增的using Kingdee.BOS.App.Data;
using Kingdee.BOS.BusinessEntity.BusinessFlow;
using Kingdee.BOS.Core.BusinessFlow;
using Kingdee.BOS.Core.BusinessFlow.PlugIn;
using Kingdee.BOS.Core.BusinessFlow.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;
using Kingdee.BOS;
namespace WriteBackNew_Test
{
[Description("发货通知单的反写插件 V1.0正式版添加反写金额")]
public class Class1 : AbstractBusinessFlowServicePlugIn
{
private void AddSaleOrderField(AfterCustomReadFieldsEventArgs e)
{
e.AddFieldKey("FBaseDeliJoinQty");
e.AddFieldKey("FTaxPrice");
e.AddFieldKey("F_FDA_Amount");
}
public override void AfterCommitAmount(AfterCommitAmountEventArgs e)
{
if (e.OperationName.EqualsIgnoreCase("Save"))
{
string id = e.SourceBusinessInfo.GetForm().Id;
decimal val = ((WSRow
if (id.EqualsIgnoreCase("SAL_SaleOrder") && e.SourceCommitField.Key.EqualsIgnoreCase("FBaseCanOutQty"))
{
e.SourceActiveRow["BaseDeliJoinQty"] = Convert.ToDecimal(e.SourceActiveRow["BaseDeliJoinQty"]) + val;
e.SourceActiveRow["F_FDA_Amount"] = Convert.ToDecimal(e.SourceActiveRow["F_FDA_Amount"]) + Convert.ToDecimal(e.SourceActiveRow["BaseDeliJoinQty"]) * Convert.ToDecimal(e.SourceActiveRow["TaxPrice"]);
}
}
else if (e.OperationName.EqualsIgnoreCase("Delete") || e.OperationName.EqualsIgnoreCase("Cancel"))
{
e.SourceActiveRow["BaseDeliJoinQty"] = 0;
e.SourceActiveRow["F_FDA_Amount"] = 0;
}
}
public override void AfterCustomReadFields(AfterCustomReadFieldsEventArgs e)
{
if (e.SourceBusinessInfo.GetForm().Id.EqualsIgnoreCase("SAL_SaleOrder"))
{
this.AddSaleOrderField(e);
}
}
public override void RuleFirstRunning(RuleFirstRunningEventArgs e)
{
DynamicObject sourceActiveRow = e.SourceActiveRow;
Field sourceCommitField = e.SourceCommitField;
WriteBackRuleElement element = e.Rule;
WRule
if (element.Id == "1cf507df-097c-40db-a983-50df5856ff1f")
{
long eId = writeBackRuleRow.Row.Id.EId;
long num2 = writeBackRuleRow.Row.SId.EId;
decimal num3 = DBUtils.ExecuteScalar
decimal num4 = Convert.ToDecimal(sourceCommitField.DynamicProperty.GetValue(sourceActiveRow));
sourceCommitField.DynamicProperty.SetValue(sourceActiveRow, num4 + num3);
}
}
}
}
执行后,发货通知单保存后,能看到金额:
但是,发货通知单反审核后,数量减少了金额没变,必须删除掉这个发货通知单后,已通知金额那里才会清除
请问代码有什么地方不对,怎么修改才能实现和反写数量一样的效果。
推荐阅读