如何在选择器查找中显示图像?

时间:2016-10-07 21:34:22

标签: acumatica acumatica-kb

在“销售订单”屏幕上的“库存ID选择器查找”中显示图像以及其他列的最佳方法是: enter image description here

1 个答案:

答案 0 :(得分:10)

PXGridColumn属性设置为Type

Icon用于在PXGrid容器中显示图像:

<px:PXGridColumn DataField="ImageUrl" Width="300px" Type="Icon" />

这样的专栏能够显示来自两个来源的图像:

  1. 精灵

    row.ImageUrl = string.IsNullOrEmpty(row.ImageUrl) ? "main@Fail" : "main@Success";
    

    enter image description here

  2. 网址:

    row.ImageUrl = @"http://www.acumatica.asia/acumaticawwwsite-acumaticainc.netdna-ssl.com/wp-content/uploads/2014/09/acumatica-2.png";
    

    enter image description here

  3. 要在Inventory ID选择器查找中添加Icon类型的列,应该:

    1. 为SOLine DAC声明扩展类并扩展Inventory ID选择器的列列表:

      [PXNonInstantiatedExtension]
      public class SO_SOLine_ExistingColumn : PXCacheExtension<PX.Objects.SO.SOLine>
      {
          #region InventoryID 
          [PXMergeAttributes(Method = MergeMethod.Append)]
          [PXCustomizeSelectorColumns(
              typeof(PX.Objects.IN.InventoryItem.inventoryCD),
              typeof(PX.Objects.IN.InventoryItem.descr),
              typeof(PX.Objects.IN.InventoryItem.itemClassID),
              typeof(PX.Objects.IN.InventoryItem.itemStatus),
              typeof(PX.Objects.IN.InventoryItem.itemType),
              typeof(PX.Objects.IN.InventoryItem.baseUnit),
              typeof(PX.Objects.IN.InventoryItem.salesUnit),
              typeof(PX.Objects.IN.InventoryItem.purchaseUnit),
              typeof(PX.Objects.IN.InventoryItem.basePrice),
              typeof(PX.Objects.IN.InventoryItem.imageUrl))]
          public int? InventoryID { get; set; }
          #endregion
      }
      
    2. 对于新列,请将Type属性值设置为Icon

      <px:PXSegmentMask ID="edInventoryID" runat="server" DataField="InventoryID">
          <GridProperties>
              <Columns>
                  <px:PXGridColumn DataField="ImageUrl" Type="Icon" Width="300px" AutoGenerateOption="Add" />
              </Columns>
          </GridProperties>
      </px:PXSegmentMask>
      
    3. 但是,这似乎不足以在选择器查找中显示附加到库存项目的图像。我们接下来的步骤是为InventoryItem DAC定义未绑定的自定义字段,并使用有效的URL填充它以显示附加的图像。

      请注意,下面的示例可能会导致性能显着下降。在现实生活中,您必须使用缩小版本的图片(缩略图)和存储URL,以通过Acumatica数据库中的自定义数据库绑定字段访问它们。

      1. 为InventoryItem DAC实现扩展类,并声明未绑定的ThumbnailURL字段以存储附加图像的URL:

        public class InventoryItemExt : PXCacheExtension<InventoryItem>
        {
            public abstract class thumbnailURL : IBqlField
            { }
            [PXString]
            public string ThumbnailURL { get; set; }
        }
        
      2. 在SOOrderEntry BLC扩展中,订阅RowSelecting处理程序并使用有效URL填充未绑定的ThumbnailURL字段以显示附加图像:

        public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
        {
            public override void Initialize()
            {
                Base.RowSelecting.AddHandler<InventoryItem>(InventoryItemRowSelecting);
            }
        
            public void InventoryItemRowSelecting(PXCache sender, PXRowSelectingEventArgs e)
            {
                var row = e.Row as InventoryItem;
                if (row != null && !string.IsNullOrEmpty(row.ImageUrl))
                {
                    Guid[] files = PXNoteAttribute.GetFileNotes(sender, e.Row);
                    var fm = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
                    foreach (Guid fileID in files)
                    {
                        PX.SM.FileInfo fi = fm.GetFileWithNoData(fileID);
                        if (fi.FullName == row.ImageUrl || fi.Name == row.ImageUrl)
                        {
                            row.GetExtension<InventoryItemExt>().ThumbnailURL = 
                                ControlHelper.GetAttachedFileUrl(null, fileID.ToString());
                            break;
                        }
                    }
                }
            }
        }
        
      3. 将ThumbnailURL列的Type属性设置为Icon

        <px:PXSegmentMask CommitChanges="True" ID="edInventoryID" runat="server" DataField="InventoryID" AllowEdit="True" >
            <GridProperties>
                <Columns>
                    <px:PXGridColumn DataField="ThumbnailURL" Width="300px" AutoGenerateOption="Add" Type="Icon" />
                </Columns>
            </GridProperties>
        </px:PXSegmentMask>
        
      4. enter image description here