c# - 有条件地自动编号发货(即在创建之前更改发货编号)
问题描述
我们有一个案例,我们希望根据货物是通过 API 还是通过 UI 创建有条件地自动编号。我已经弄清楚了那部分,但我想不出设置 ShipmentNbr 的最佳方法。我知道我可以在将 RowPersisting 事件保存到数据库之前更新 ShipmentNbr(如下所示),但这不会更新其他相关表(SOOrderShipment、SOShipLine、SOShipLineSplit 等)中的 ShipmentNbr。我还尝试遍历相关记录并单独更新它们,但这也不起作用。我可以在 RowInserting 事件中执行此操作,但这会在处理并发时导致问题。有什么方法可以更新货件的 ShipmentNbr 及其相关记录?
public void SOShipment_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
SOShipment row = (SOShipment)e.Row;
if (row.ShipmentNbr.Trim() == "<NEW>")
{
row.ShipmentNbr = AutoNumberAttribute.GetNextNumber(sender, row, "SOSHIPMENT", DateTime.Now);
// this works, but doesn't update related records
}
}
解决方案
嗯,我想通了。我有一些损坏的数据导致 RowPersisting 事件无法正常工作。在此感谢 Sergey https://asiablog.acumatica.com/2018/05/auto-numbering-customization.html
如果其他人需要这样做,我是这样做的:
namespace PX.Objects.SO
{
public class SOShipmentEntry_Extension : PXGraphExtension<SOShipmentEntry>
{
#region Event Handlers
[PXDBString(15, IsKey = true, IsUnicode = true, InputMask = ">CCCCCCCCCCCCCCC")]
[PXDefault()]
[PXUIField(DisplayName = "Shipment Nbr.", Visibility = PXUIVisibility.SelectorVisible, IsReadOnly = true)]
// [AutoNumber(typeof(SOSetup.shipmentNumberingID), typeof(SOShipment.shipDate))]
[PXSelector(typeof(Search2<SOShipment.shipmentNbr,
InnerJoin<INSite, On<SOShipment.FK.Site>,
LeftJoinSingleTable<Customer, On<SOShipment.customerID, Equal<Customer.bAccountID>>>>,
Where2<Match<INSite, Current<AccessInfo.userName>>,
And<Where<Customer.bAccountID, IsNull, Or<Match<Customer, Current<AccessInfo.userName>>>>>>,
OrderBy<Desc<SOShipment.shipmentNbr>>>))]
[PX.Data.EP.PXFieldDescription]
protected void SOShipment_ShipmentNbr_CacheAttached(PXCache sender)
{
}
protected virtual void SOShipment_ShipmentNbr_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
SOShipment shipment = e.Row as SOShipment;
if (shipment.ShipmentNbr == null)
{
e.NewValue = "<NEW>";
}
}
protected void SOShipment_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting InvokeBaseHandler)
{
SOShipment row = (SOShipment)e.Row;
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
if ((e.Operation & PXDBOperation.Command) != PXDBOperation.Insert)
{
return;
}
var httpContext = HttpContext.Current;
// don't auto number if shipment was created via api
if ( !(httpContext != null && httpContext.Items != null && httpContext.Items.Contains("ApiContextId")) )
{
var num = AutoNumberAttribute.GetNextNumber(cache, row, "SOSHIPMENT", DateTime.Now);
cache.SetValue(e.Row, "ShipmentNbr", num);
}
}
#endregion
}
}
推荐阅读
- javascript - jQuery - 网格返回不均匀的行和列
- ios - 如何在 collectionView 之上使用 UIView,这样当我滚动单元格时,UIView 不应该移动?
- swiftui - 如何使具有多行和光标的文本字段从左上角开始?
- sql - 如何在按联合表分组后选择一行?
- numpy - 将矩阵的每一行与另一个矩阵的每一行相乘
- python - 如何转到下一行而不是打印 \n?
- ios - 为什么 Google 地图会因“尝试设置未知枚举值”错误而崩溃?
- react-native - 可触摸的不透明度不适用于动态更新平面列表的项目
- python - 为什么 pytz.timezone("US/Mountain").localize(datetime.datetime.now()) 给我我的实际日期和时间,而不是美国/山区的?
- postgresql - 如何从postgresql运行java函数