如何解决为什么我的操作比当前过滤的记录影响更多?
我用我自己的一个覆盖了 Records
上的 ARSalesPriceMaint
数据视图,以便也覆盖数据视图委托 records
。这是必要的,因为我已经自定义了页面过滤器。 效果很好。
我添加了一个操作,该操作应获取结果记录(过滤后)并更新 DAC 扩展中的自定义字段。这确实会更新记录,但它不尊重记录上的过滤器,尤其是网格过滤器。例如,过滤 UOM
列会影响视图,但我的操作会更新所有 UOM。
所以这是问题:为什么我的操作的 foreach
语句被赋予的记录多于网格中的记录?
我相信这是问题区域,但整个代码也在下面:
(这是来自 UpdateDifs
操作,而不是数据视图委托)
foreach (PXResult<ARSalesPrice> result in Records.View.Select(null,null,PXView.Searches,Base.Records.View.GetExternalSorts(),Base.Records.View.GetExternalDescendings(),Base.Records.View.GetExternalFilters() ?? new PXFilterRow[0],ref startRow,ref totalRows))
{
// more code
}
完整代码:
public class ARSalesPriceMaint_Extension : PXGraphExtension<ARSalesPriceMaint>
{
public PXFilter<ARSalesPricesExtDialog> UpdatePriceFactorsDialog;
[PXFilterable]
public SelectFrom<ARSalesPrice>.View Records;
#region Data View Delegates
protected IEnumerable records()
{
int startRow = 0;
int totalRows = 0;
if (PXView.MaximumRows == 1
&& PXView.sortColumns?.Length > 0 && PXView.sortColumns[0].Equals(nameof(ARSalesPrice.RecordID),StringComparison.OrdinalIgnoreCase)
&& PXView.Searches?.Length > 0 && PXView.Searches[0] != null)
{
var cached = Records.Cache.Locate(new ARSalesPrice { RecordID = Convert.ToInt32(PXView.Searches[0]) });
if (cached != null)
return new[] { cached };
}
ARSalesPriceFilter filter = Base.Filter.Current;
ARSalesPriceFilterExt filterExt = PXCache<ARSalesPriceFilter>.GetExtension<ARSalesPriceFilterExt>(filter);
var priceCode = ParsePriceCode(Base,filter.PriceType,filter.PriceCode);
var list = new ArrayList();
// Set filters
var filterParams = new object[]
{
filter.PriceType,filter.PriceType == PriceTypes.Customer ? priceCode : null,filter.PriceType == PriceTypes.CustomerPriceClass ? priceCode : null,priceCode,filter.InventoryID,filter.SiteID,filter.EffectiveAsOfDate,filter.ItemClassCD,filter.ItemClassCDWildcard,filter.InventoryPriceClassID,filter.OwnerID,filter.MyWorkGroup,filter.WorkGroupID,filter.WorkGroupID
};
var records = Base.Records.View.Select(null,filterParams,ref totalRows);
if (filterExt.UsrComponentID != null)
{
foreach (PXResult<ARSalesPrice,INItemClass,BAccount> result in records)
{
ARSalesPrice salesPrice = result;
InventoryItem inItem = ARSalesPrice.FK.InventoryItem.FindParent(Base,salesPrice);
if ((inItem.KitItem ?? false) == false) continue;
// Get kits containing the selected component
var kitsContainingComps = SelectFrom<INKitSpecstkDet>.
InnerJoin<INKitSpecHdr>.
On<INKitSpecHdr.kitInventoryID.IsEqual<INKitSpecstkDet.kitInventoryID>.
And<INKitSpecHdr.revisionID.IsEqual<INKitSpecstkDet.revisionID>>>.
Where<INKitSpecstkDet.kitInventoryID.IsEqual<@P.AsInt>.
And<INKitSpecstkDet.compInventoryID.IsEqual<@P.AsInt>>.
And<INKitSpecHdr.isActive.IsEqual<boolTrue>>>.View.Select(new PXGraph(),salesPrice.InventoryID,filterExt.UsrComponentID);
// If kits exist with that component,add the item to the list
if (kitsContainingComps != null && kitsContainingComps.Count > 0)
list.Add(salesPrice);
}
return list;
}
else
return records;
}
#endregion
#region Event Handlers
protected virtual void _(Events.FieldUpdated<ARSalesPriceFilterExt.usrComponentID> e)
{
Records.View.RequestRefresh();
}
#endregion
#region Actions
/// <summary>
/// Mass updates pricing factors
/// </summary>
public PXAction<ARSalesPriceFilter> updateDifs;
[PXButton(CommitChanges = true)]
[PXUIField(displayName = "Update Difs")]
protected virtual void UpdateDifs()
{
int startRow = 0;
int totalRows = 0;
// Check for filter
if (Base.Records.View.GetExternalFilters() == null && Base.Filter.Current.GetExtension<ARSalesPriceFilterExt>().UsrComponentID == null)
{
if (Base.Filter.Ask("No Filter Set","A filter has not been set. Make sure you have filtered to the items you wish to update. Continue?",MessageButtons.YesNo,MessageIcon.Question) != WebDialogResult.Yes)
throw new PXException();
}
// Show dialog
UpdatePriceFactorsDialog.View.Clear();
if (UpdatePriceFactorsDialog.AskExt((graph,view) =>
{
UpdatePriceFactorsDialog.Cache.Clear();
UpdatePriceFactorsDialog.Current = new ARSalesPricesExtDialog();
},true) != WebDialogResult.OK) return;
foreach (PXResult<ARSalesPrice> result in Records.View.Select(null,ref totalRows))
{
ARSalesPrice salesPrice = result;
ARSalesPriceExt salesPriceExt = salesPrice.GetExtension<ARSalesPriceExt>();
if (UpdatePriceFactorsDialog.Current.Calculation != null && UpdatePriceFactorsDialog.Current.Calculation != "UC")
Base.Records.SetValueExt<ARSalesPriceExt.usrCalculation>(result,UpdatePriceFactorsDialog.Current.Calculation);
if (UpdatePriceFactorsDialog.Current.DifPctSelected ?? false)
{
switch (UpdatePriceFactorsDialog.Current.DifPctAction)
{
case "EQ":
Base.Records.SetValueExt<ARSalesPriceExt.usrDifPct>(result,UpdatePriceFactorsDialog.Current.DifPct);
break;
case "PL":
Base.Records.SetValueExt<ARSalesPriceExt.usrDifPct>(result,decimal.Add(salesPriceExt.UsrDifPct ?? 0,UpdatePriceFactorsDialog.Current.DifPct ?? 0));
break;
case "MI":
Base.Records.SetValueExt<ARSalesPriceExt.usrDifPct>(result,decimal.Subtract(salesPriceExt.UsrDifPct ?? 0,UpdatePriceFactorsDialog.Current.DifPct ?? 0));
break;
}
}
if (UpdatePriceFactorsDialog.Current.DifAmtSelected ?? false)
{
switch (UpdatePriceFactorsDialog.Current.DifAmtAction)
{
case "EQ":
Base.Records.SetValueExt<ARSalesPriceExt.usrDifAmt>(result,UpdatePriceFactorsDialog.Current.DifAmt);
break;
case "PL":
Base.Records.SetValueExt<ARSalesPriceExt.usrDifAmt>(result,decimal.Add(salesPriceExt.UsrDifAmt ?? 0,UpdatePriceFactorsDialog.Current.DifAmt ?? 0));
break;
case "MI":
Base.Records.SetValueExt<ARSalesPriceExt.usrDifAmt>(result,decimal.Subtract(salesPriceExt.UsrDifAmt ?? 0,UpdatePriceFactorsDialog.Current.DifAmt ?? 0));
break;
}
}
Base.Records.Update(result);
};
Base.Actions.PressSave();
}
#endregion
#region Methods
private static string ParsePriceCode(PXGraph graph,string priceType,string priceCode)
{
if (priceCode != null)
{
if (priceType == PriceTypes.Customer)
{
var customerRepository = new CustomerRepository(graph);
Customer customer = customerRepository.FindByCD(priceCode);
if (customer != null)
{
return customer.BAccountID.ToString();
}
}
return priceType == PriceTypes.CustomerPriceClass ? priceCode : null;
}
else
return null;
}
#endregion
}
解决方法
事实证明这不是代码错误的操作。
对数据视图委托的以下更改已解决该问题:
var records = Base.Records.View.Select(PXView.Currents,filterParams,PXView.Searches,PXView.SortColumns,PXView.Descendings,Records.View.GetExternalFilters(),ref startRow,ref totalRows);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。