如何确保选择了来自PXSelector的特定行 [英] How to make sure specific line from PXSelector is chosen
问题描述
我有一个PXSelector,它可以选择几个字段,第一个是可以重复其值的字段(如下所示):
I've got a PXSelector that selects several fields, the first one being a field whose value may be repeated (as follows):
Field1 Field2 Field3
1234 LL description1
1234 PS description2
1234 CC description3
4321 BB description4
PXSelector代码:
PXSelector code:
[PXSelector(typeof(myTable.field1)
,typeof(myTable.field1)
,typeof(myTable.field2)
,typeof(myTable.field3)
,DescriptionField = typeof(myTable.field3))]
所选表的DAC具有Field1和Field2作为键。
The DAC for the selected table has Field1 and Field2 as keys.
如果我选择上面的第二行或第三行,则每次都会获得第一行的Field3描述。有没有一种方法可以确保仅获取所选行的描述,而不是始终获取第一个出现的行?
If I select row two or three above, I'll get the row one's Field3 description every time. Is there a way to ensure that I only get the description of the row that I've selected, instead of always getting the first occurrence?
推荐答案
您必须使选择器对单个键进行操作,因为所选值是键字段而不是整个DAC记录。
You have to make the selector operate on a single key because the selected value is the key field not the whole DAC record.
一种可能的方法是添加数据库表的唯一记录号列,使选择器对该列进行操作,并为选择器设置一个不同的 TextField属性,以使其不显示记录号。
One possible approach is to add a unique record number column to the database table, make the selector operate on that column and set a different 'TextField' property for the selector so it doesn't show the record number.
这是我在SerialNumber / InventoryItem上创建一个选择器的方法,该选择器不是唯一值(包含重复值)。
Here's how I did it to make a selector on SerialNumber/InventoryItem which is not a unique value (contains duplicate).
数据库脚本随数据库系统的不同而不同。我正在使用用于MSSQL的此脚本将唯一的记录号添加到表中:
Database scripts will vary with database systems. I'm using this script for MSSQL to add the unique record number to the table:
--[mysql: Skip]
--[IfNotExists(Column = SOShipLineSplit.UsrUniqueID)]
BEGIN
alter table SOShipLineSplit add UsrUniqueID int identity(1,1)
END
GO
这是DAC声明。我使用PXDBIdentity来匹配将该列标记为记录编号字段的数据库标识字段类型:
This is the DAC declaration. I use PXDBIdentity to match the DB identity field type that tag the column as a record number field:
[Serializable]
public class SOShipLineSplit_Extension : PXCacheExtension<SOShipLineSplit>
{
#region UsrUniqueID
public abstract class usrUniqueID : IBqlField { }
[PXDBIdentity(IsKey = false)]
[PXUIField(DisplayName = "ID")]
public virtual int? UsrUniqueID { get; set; }
#endregion
}
我在选择器中使用了另一个DAC字段,使用这个唯一的ID密钥,然后将说明设置为要显示在选择器中的实际字段:
I use another DAC field for the selector which uses this unique id key and I set the description to the real field I want to appear in the selector:
#region SerialUniqueID
public abstract class serialUniqueID : IBqlField { }
[PXSelector(typeof(Search5<SOShipLineSplit_Extension.usrUniqueID,
InnerJoin<SOShipment, On<SOShipment.customerID, Equal<Current<customerID>>,
And<SOShipment.shipmentNbr, Equal<SOShipLineSplit.shipmentNbr>>>,
InnerJoin<InventoryItem, On<InventoryItem.inventoryID, Equal<SOShipLineSplit.inventoryID>>>>,
Where<SOShipLineSplit.lotSerialNbr, NotEqual<StringEmpty>>,
Aggregate<GroupBy<SOShipLineSplit.lotSerialNbr,
GroupBy<SOShipLineSplit.inventoryID>>>>),
typeof(SOShipLineSplit.lotSerialNbr),,
typeof(SOShipLineSplit.inventoryID),
typeof(InventoryItem.descr),
CacheGlobal = true,
DescriptionField = typeof(SOShipLineSplit.lotSerialNbr))]
[PXDBInt]
[PXUIField(DisplayName = "Serial Number")]
public virtual int? SerialUniqueID { get; set; }
#endregion
对于此选择器,我想在文本框中显示LotSerialNbr而不是唯一身份。因为选择器默认显示其键,所以我需要使用TextField属性:
For this selector I want to display LotSerialNbr in the textbox instead of the unique id. Because the selector displays it's key by default I need to use the TextField property:
<px:PXSelector ID="edSerialUniqueID"
runat="server"
DataField="SerialUniqueID"
TextField="LotSerialNbr"
AutoGenerateColumns="True">
选择器值将包含选定的唯一ID字段。要获取记录,您可以使用该密钥向数据库发出另一个请求。
The selector value will contain the selected unique id field. To get the record you can issue another request to the database using that key.
这篇关于如何确保选择了来自PXSelector的特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!