I am having trouble getting the individual select check to work on my processing screen. The DAC is unbound composed of data from several tables. Process All works correctly, but I cannot check individual rows. I get an error stating "Error: The argument is out of range. Parameter name: table.
I have tried a variety of combinations of attributes and have had no luck. My code is below. Any help would be appreciated.
using System;
using System.Collections;
using System.Collections.Generic;
using PX.SM;
using PX.Data;
using PX.Objects.AR;
using PX.Objects.CS;
using PX.Objects.SO;
using PX.Objects.CR;
using PX.Objects.IN;
using PX.Objects.SM;
using CRLocation = PX.Objects.CR.Standalone.Location;
using PX.Data.ReferentialIntegrity.Attributes;
using LingoInterface;
using System.Text.RegularExpressions;
namespace EDIASNs
{
public class EDInventoryProcess : PXGraph<EDInventoryProcess>
{
public PXCancel<EDInventoryFilter> Cancel;
public PXFilter<EDInventoryFilter> Filter;
[PXFilterable]
public PXFilteredProcessingOrderBy<EDInventory, EDInventoryFilter,
OrderBy<Asc<EDInventory.partnerID, Asc<EDInventory.inventoryCD>>>> EDItem;
protected virtual IEnumerable eDItem()
{
int ii = 0;
foreach (var row in EDItem.Cache.Cached)
{
ii++;
yield return row;
}
Int32 rowCntr = 0;
if (ii == 0)
{
var cmd = new PXSelectJoin<InventoryItem,
InnerJoin<INItemXRef, On<InventoryItem.inventoryID, Equal<INItemXRef.inventoryID>>,
InnerJoin<EDPartnerInfo, On<INItemXRef.bAccountID, Equal<EDPartnerInfo.customerID>>>>,
Where<INItemXRef.alternateType, Equal<INAlternateType.cPN>,
And<InventoryItem.itemStatus, Equal<InventoryItemStatus.active>>>>(this);
if (this.Filter.Current.TradingPartner != null)
{
cmd.WhereAnd<Where<EDPartnerInfo.partnerID, Equal<Current<EDInventoryFilter.tradingPartner>>>>();
}
cmd.View.Clear();
var ret = cmd.Select();
if (ret != null)
{
EDInventoryFilter filt = (EDInventoryFilter)Filter.Cache.Current;
EDInventory edInv = new EDInventory();
foreach (PXResult<InventoryItem, INItemXRef, EDPartnerInfo> record in ret)
{
edInv = new EDInventory();
InventoryItem item = (InventoryItem)record;
INItemXRef xref = (INItemXRef)record;
EDPartnerInfo partner = (EDPartnerInfo)record;
edInv.InvID = Guid.NewGuid();
rowCntr++;
edInv.IntID = rowCntr;
edInv.PartnerID = partner.PartnerID;
edInv.InventoryID = item.InventoryID;
edInv.InventoryCD = item.InventoryCD;
edInv.ItemDescr = item.Descr;
edInv.ItemStatus = item.ItemStatus;
edInv.BaseUnit = item.BaseUnit;
edInv.SalesUnit = item.SalesUnit;
edInv.PurchaseUnit = item.PurchaseUnit;
edInv.BasePrice = Convert.ToDecimal(item.BasePrice);
edInv.BaseWeight = item.BaseWeight;
edInv.BaseVolume = item.BaseVolume;
edInv.BaseItemWeight = item.BaseItemWeight;
edInv.BaseItemVolume = item.BaseItemVolume;
edInv.WeightUOM = item.WeightUOM;
edInv.VolumeUOM = item.VolumeUOM;
//edInv.NoteID = item.NoteID;
edInv.PartnerCustomerID = partner.CustomerID;
edInv.CustomerItem = xref.AlternateID;
edInv.CustomerItemDescr = xref.Descr;
var cmdAttrib = new PXSelect<CSAnswers,
Where<CSAnswers.refNoteID, Equal<Required<CSAnswers.refNoteID>>>>(this);
cmdAttrib.View.Clear();
var retAttrib = cmdAttrib.Select(item.NoteID);
if (retAttrib != null)
{
foreach (PXResult<CSAnswers> recAttrib in retAttrib)
{
CSAnswers ans = (CSAnswers)recAttrib;
switch (ans.AttributeID)
{
case "CASEQTY":
edInv.CaseQty = Convert.ToInt32(ans.Value);
break;
case "CASEL":
edInv.CaseL = Convert.ToDecimal(ans.Value);
break;
case "CASEW":
edInv.CaseW = Convert.ToDecimal(ans.Value);
break;
case "CASEH":
edInv.CaseH = Convert.ToDecimal(ans.Value);
break;
case "UPC":
edInv.UPC = ans.Value;
break;
}
}
}
var cmdPrice = new PXSelect<ARSalesPrice,
Where<ARSalesPrice.priceType, Equal<PriceTypes.customer>,
And<ARSalesPrice.customerID, Equal<Required<ARSalesPrice.customerID>>,
And<ARSalesPrice.inventoryID, Equal<Required<ARSalesPrice.inventoryID>>,
And<ARSalesPrice.expirationDate, GreaterEqual<Required<ARSalesPrice.expirationDate>>>>>>>(this);
cmdPrice.View.Clear();
var retPrice = cmdPrice.Select(partner.CustomerID, item.InventoryID, this.Accessinfo.BusinessDate);
if (retPrice != null)
{
foreach (PXResult<ARSalesPrice> recPrice in retPrice)
{
ARSalesPrice price = (ARSalesPrice)recPrice;
edInv.CustomerPrice = price.SalesPrice;
}
}
int intOnHand = 0;
int intCommitted = 0;
int intOnOrder = 0;
var cmdStock = new PXSelectJoin<INSiteStatus,
InnerJoin<INSite, On<INSiteStatus.siteID, Equal<INSite.siteID>>>,
Where<INSite.active, Equal<True>,
And<INSiteStatus.inventoryID, Equal<Required<INSiteStatus.inventoryID>>>>>(this);
cmdStock.View.Clear();
var retStock = cmdStock.Select(item.InventoryID);
if (retStock != null)
{
foreach (PXResult<INSiteStatus> recStock in retStock)
{
INSiteStatus stock = (INSiteStatus)recStock;
intOnHand += Convert.ToInt32(stock.QtyOnHand);
intCommitted += Convert.ToInt32(stock.QtySOShipped + stock.QtySOShipping);
intOnOrder += Convert.ToInt32(stock.QtyPOPrepared + stock.QtyPOReceipts);
}
edInv.OnHand = intOnHand;
edInv.Committed = intCommitted;
edInv.OnOrder = intOnOrder;
}
edInv = EDItem.Insert(edInv);
EDItem.Cache.SetStatus(edInv, PXEntryStatus.Held);
yield return edInv;
}
}
EDItem.Cache.IsDirty = false;
}
}
public void EDInventoryFilter_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
EDInventoryFilter filterOld = (EDInventoryFilter)e.OldRow;
EDInventoryFilter filterNew = (EDInventoryFilter)e.Row;
if (filterOld.Action == filterNew.Action) //Don't clear cache if only action changes
EDItem.Cache.Clear();
}
public void EDInventoryFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
//Get list of partners to set filter
List<string> strPartnerList = new List<string>();
strPartnerList.Clear();
var filter = (EDInventoryFilter)e.Row;
foreach (EDPartnerInfo partner in PXSelect<EDPartnerInfo>.Select(this))
{
strPartnerList.Add(partner.PartnerID);
}
if (strPartnerList.Count > 0)
PXStringListAttribute.SetList<EDInventoryFilter.tradingPartner>
(sender, filter, strPartnerList.ToArray(), strPartnerList.ToArray());
else
{
throw new PXException("No active partners found");
}
EDItem.SetProcessDelegate
(
delegate (List<EDInventory> list)
{
var graph = PXGraph.CreateInstance<EDInventoryProcess>();
graph.InventorySync(filter, list);
}
);
//Action must be selected for Process buttons to be available
if (filter.Action == null || filter.Action == "")
{
EDItem.SetProcessVisible(false);
EDItem.SetProcessAllVisible(false);
}
}
public void EDInventory_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
var row = (EDInventory)e.Row;
}
public void InventorySync(EDInventoryFilter filter, List<EDInventory> list)
{
//Create Lingo API object and login
bool ediDemo = false;
bool bolAtLeastOneError = false;
Int32 cntr = 0;
EDCompanyData edCompanyData = new EDCompanyData();
foreach (EDCompanyData data in PXSelect<EDCompanyData,
Where<EDCompanyData.active, Equal<Required<EDCompanyData.active>>>>.Select(this, true))
{
cntr++;
if (data.Service == "DEMO")
ediDemo = true;
edCompanyData = data;
}
if (cntr == 0)
throw new PXException("No active Service Data entries!");
if (cntr > 1)
throw new PXException("More than one active Service Data entry!");
var lingo = new LingoApi();
//Set url for service
lingo.Url = edCompanyData.Url;
if (!ediDemo)
{
if (!lingo.Login(edCompanyData.EDIAccount, edCompanyData.EDILoginName, edCompanyData.EDIPassword, edCompanyData.EDIApiKey))
throw new PXException("Login to EDI system failed.");
}
//Initialize variables
EdiItem updateItem = new EdiItem();
bool bolNewItem = false;
Regex rxNonDigits = new Regex(@"[^\d]+");
foreach (EDInventory acItem in list)
{
//Check for existing item in EDI
if (lingo.Login() || ediDemo) //Refresh the login session
{
if (!ediDemo)
{
LingoRetItem itemRet = lingo.RetrieveItem(acItem.PartnerID, acItem.InventoryCD);
if (itemRet && itemRet.Count != 0) //Found Item
{
if (itemRet.Count > 1)
{
PXProcessing<EDInventory>.SetError(list.IndexOf(acItem), String.Format("More than 1 occurrence found: {0}", itemRet.Message));
bolAtLeastOneError = true;
}
else
{
updateItem = itemRet.DataItem; //Load existing item data and set flag
bolNewItem = false;
}
}
else
{
updateItem = new EdiItem(); //Clear item object for new item and set flag
bolNewItem = true;
}
}
updateItem.account = edCompanyData.EDIAccount;
updateItem.partner = acItem.PartnerID;
if (bolNewItem)
updateItem.createDate = DateTime.Today.ToString("yyyyMMdd");
updateItem.upcCode = rxNonDigits.Replace(acItem.UPC, ""); //Remove non-numeric characters
updateItem.upcCodeType = "UPC";
updateItem.vendorItem = acItem.InventoryCD;
updateItem.vendorItemType = "VNDR";
updateItem.customerItem = acItem.CustomerItem;
if (string.IsNullOrEmpty(acItem.CustomerItemDescr))
updateItem.itemDesc = acItem.ItemDescr;
else
updateItem.itemDesc = acItem.CustomerItemDescr;
if (acItem.BaseItemWeight > 0)
updateItem.itemWeight = acItem.BaseItemWeight.ToString();
else
updateItem.itemWeight = acItem.BaseWeight.ToString();
//Inventory Information
updateItem.qtyOnHand = acItem.OnHand.ToString();
updateItem.qtyCommitted = acItem.Committed.ToString();
updateItem.qtyOnOrder = acItem.OnOrder.ToString();
//Item Pricing Information
if (acItem.CustomerPrice > 0)
updateItem.unitPrice = acItem.CustomerPrice.ToString();
else
updateItem.unitPrice = acItem.BasePrice.ToString();
updateItem.priceBasis = acItem.SalesUnit;
//Item Packing and Carton Information
updateItem.unitMeasure = acItem.BaseUnit;
updateItem.packSize = acItem.CaseQty.ToString();
updateItem.cartonLength = acItem.CaseL.ToString();
updateItem.cartonWidth = acItem.CaseW.ToString();
updateItem.cartonHeight = acItem.CaseH.ToString();
LingoRet itemMaintResult = new LingoRet();
if (!ediDemo)
itemMaintResult = lingo.MaintainItem(updateItem, bolNewItem);
else
{
itemMaintResult.Code = "OK";
itemMaintResult.Message = "Success";
}
//Check result
if (itemMaintResult.Code == "OK" || ediDemo)
{
PXProcessing<EDInventory>.SetInfo(list.IndexOf(acItem),
String.Format(" Item {0} EDI: {1}", bolNewItem ? "added to" : "updated in",itemMaintResult.Message));
}
else
{
PXProcessing<EDInventory>.SetError(list.IndexOf(acItem), String.Format(" Item maintenance failed: {0}", itemMaintResult.Message));
bolAtLeastOneError = true;
}
}
else
{
PXProcessing<EDInventory>.SetError(list.IndexOf(acItem), String.Format(" Lingo login failed: {0}", lingo.ResMessage));
bolAtLeastOneError = true;
}
}
if (bolAtLeastOneError)
throw new PXException("At least one item had exceptions");
}
[Serializable]
public partial class EDInventoryFilter : IBqlTable
{
#region TradingPartner
public abstract class tradingPartner : PX.Data.IBqlField
{
}
protected string _TradingPartner;
[PXString(15)]
[PXUIField(DisplayName = "Trading Partner")]
[PXStringList(new string[] { }, new string[] { })]
public virtual String TradingPartner { get; set; }
#endregion
#region Action
public abstract class action : PX.Data.IBqlField { }
protected string _Action;
[PXDefault("P")]
[PXString(15)]
[PXUIField(DisplayName = "Action")]
[PXStringList(new string[] { "P" }, new string[] { "Push to EDI" })]
public virtual String Action { get; set; }
#endregion
}
[Serializable]
public partial class EDInventory : IBqlTable
{
#region Selected
public abstract class selected : IBqlField { }
protected bool? _Selected = false;
[PXBool]
[PXDefault(false)]
[PXUIField(DisplayName = "Selected")]
public virtual bool? Selected { get; set; }
#endregion
#region InvID
public abstract class invID : PX.Data.IBqlField { }
protected Guid? _InvID;
[PXGuid]
[PXUIField(DisplayName = "ID")]
public virtual Guid? InvID { get; set; }
#endregion
#region intID
public abstract class intID : PX.Data.IBqlField { }
protected int? _IntID;
[PXInt(IsKey = true)]
[PXUIField(DisplayName = "intID")]
public virtual int? IntID { get; set; }
#endregion
#region PartnerID
public abstract class partnerID : IBqlField { }
[PXDBString(30, IsUnicode = true, IsKey = true)]
[PXDefault("")]
[PXUIField(DisplayName = "Partner")]
public virtual string PartnerID { get; set; }
#endregion
#region InventoryID
public abstract class inventoryID : PX.Data.IBqlField { }
protected Int32? _InventoryID;
[PXDBInt(IsKey = true)]
[PXUIField(DisplayName = "Inventory ID", Visibility = PXUIVisibility.Visible, Visible = false)]
public virtual Int32? InventoryID { get; set; }
#endregion
#region InventoryCD
public abstract class inventoryCD : PX.Data.IBqlField { }
protected String _InventoryCD;
[PXDefault()]
[InventoryRaw(IsKey = true, DisplayName = "Inventory ID")]
public virtual String InventoryCD { get; set; }
#endregion
#region ItemDescr
public abstract class itemDescr : PX.Data.IBqlField { }
protected String _ItemDescr;
[PXDBString(255, IsUnicode = true)]
[PXUIField(DisplayName = "Item Description")]
public virtual String ItemDescr { get; set; }
#endregion
#region ItemStatus
public abstract class itemStatus : PX.Data.IBqlField { }
protected String _ItemStatus;
[PXDBString(2, IsFixed = true)]
[PXDefault("AC")]
[PXUIField(DisplayName = "Item Status", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String ItemStatus { get; set; }
#endregion
#region BaseUnit
public abstract class baseUnit : PX.Data.IBqlField { }
protected String _BaseUnit;
[PXDBString]
[PXDefault("")]
[PXUIField(DisplayName = "Base Unit", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String BaseUnit { get; set; }
#endregion
#region SalesUnit
public abstract class salesUnit : PX.Data.IBqlField { }
protected String _SalesUnit;
[PXDBString(6)]
[PXDefault("")]
[PXUIField(DisplayName = "Sales Unit", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String SalesUnit { get; set; }
#endregion
#region PurchaseUnit
public abstract class purchaseUnit : PX.Data.IBqlField { }
protected String _PurchaseUnit;
[PXDBString(6)]
[PXDefault("")]
[PXUIField(DisplayName = "Purchase Unit", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String PurchaseUnit { get; set; }
#endregion
#region BasePrice
public abstract class basePrice : PX.Data.IBqlField { }
protected Decimal? _BasePrice;
[PXPriceCost()]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Default Price", Visibility = PXUIVisibility.SelectorVisible)]
public virtual Decimal? BasePrice { get; set; }
#endregion
#region BaseWeight
public abstract class baseWeight : PX.Data.IBqlField { }
protected Decimal? _BaseWeight;
[PXDBDecimal(6)]
[PXUIField(DisplayName = "Base Weight")]
[PXDefault(TypeCode.Decimal, "0.0")]
public virtual Decimal? BaseWeight { get; set; }
#endregion
#region BaseVolume
public abstract class baseVolume : PX.Data.IBqlField { }
protected Decimal? _BaseVolume;
[PXDBDecimal(6)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Base Volume")]
public virtual Decimal? BaseVolume { get; set; }
#endregion
#region BaseItemWeight
public abstract class baseItemWeight : PX.Data.IBqlField { }
protected Decimal? _BaseItemWeight;
[PXDBDecimal(6)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Weight")]
public virtual Decimal? BaseItemWeight { get; set; }
#endregion
#region BaseItemVolume
public abstract class baseItemVolume : PX.Data.IBqlField { }
protected Decimal? _BaseItemVolume;
[PXDBDecimal(6)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Volume")]
public virtual Decimal? BaseItemVolume { get; set; }
#endregion
#region WeightUOM
public abstract class weightUOM : PX.Data.IBqlField { }
protected String _WeightUOM;
[PXDBString(6)]
[PXUIField(DisplayName = "Weight UOM")]
[PXDefault("")]
public virtual String WeightUOM { get; set; }
#endregion
#region VolumeUOM
public abstract class volumeUOM : PX.Data.IBqlField { }
protected String _VolumeUOM;
[PXDBString(6)]
[PXUIField(DisplayName = "Volume UOM")]
[PXDefault("")]
public virtual String VolumeUOM { get; set; }
#endregion
/*
#region NoteID
public abstract class noteID : PX.Data.IBqlField { }
[PXGuid(IsKey = true)]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
[PXNote]
public virtual Guid? NoteID { get; set; }
#endregion
*/
#region PartnerCustomerID
public abstract class partnerCustomerID : PX.Data.IBqlField { }
[PXDBInt]
[PXUIField(DisplayName = "Customer")]
[Customer(DescriptionField = typeof(Customer.acctName))]
public virtual Int32? PartnerCustomerID { get; set; }
#endregion
#region CustomerItem
public abstract class customerItem : PX.Data.IBqlField { }
protected string _CustomerItem;
[PXDBString(50)]
[PXDefault("")]
[PXUIField(DisplayName = "Customer Item")]
public virtual String CustomerItem { get; set; }
#endregion
#region CustomerItemDescr
public abstract class customerItemDescr : PX.Data.IBqlField { }
[PXDBString(60, IsUnicode = true)]
[PXDefault("")]
[PXUIField(DisplayName = "Customer Item Description")]
public virtual String CustomerItemDescr { get; set; }
#endregion
#region CaseQty
public abstract class caseQty : PX.Data.IBqlField { }
protected int? _CaseQty;
[PXDBInt]
[PXDefault(0)]
[PXUIField(DisplayName = "Case Qty")]
public virtual Int32? CaseQty { get; set; }
#endregion
#region CaseL
public abstract class caseL : PX.Data.IBqlField { }
protected decimal? _CaseL;
[PXDBDecimal(6)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Case Length")]
public virtual Decimal? CaseL { get; set; }
#endregion
#region CaseW
public abstract class caseW : PX.Data.IBqlField { }
protected decimal? _CaseW;
[PXDBDecimal(6)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Case Width")]
public virtual Decimal? CaseW { get; set; }
#endregion
#region CaseH
public abstract class caseH : PX.Data.IBqlField { }
protected decimal? _CaseH;
[PXDBDecimal(6)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Case Height")]
public virtual Decimal? CaseH { get; set; }
#endregion
#region CaseL
public abstract class customerPrice : PX.Data.IBqlField { }
protected int? _CustomerPrice;
[PXDBDecimal(6)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Customer Price")]
public virtual Decimal? CustomerPrice { get; set; }
#endregion
#region UPC
public abstract class uPC : PX.Data.IBqlField { }
protected string _UPC;
[PXDBString(20)]
[PXDefault("")]
[PXUIField(DisplayName = "UPC Code")]
public virtual String UPC { get; set; }
#endregion
#region OnHand
public abstract class onHand : PX.Data.IBqlField { }
protected int? _OnHand;
[PXDBInt]
[PXDefault(0)]
[PXUIField(DisplayName = "On Hand")]
public virtual Int32? OnHand { get; set; }
#endregion
#region Committed
public abstract class committed : PX.Data.IBqlField { }
protected int? _Committed;
[PXDBInt]
[PXDefault(0)]
[PXUIField(DisplayName = "Committed")]
public virtual Int32? Committed { get; set; }
#endregion
#region OnOrder
public abstract class onOrder : PX.Data.IBqlField { }
protected int? _OnOrder;
[PXDBInt]
[PXDefault(0)]
[PXUIField(DisplayName = "On Order")]
public virtual Int32? OnOrder { get; set; }
#endregion
}
}
}