【问题标题】:Acumatica - Adding Image in Sales Order LineAcumatica - 在销售订单行中添加图像
【发布时间】:2019-04-04 18:37:31
【问题描述】:

我正在努力在选择InventoryID时在销售订单行上为文档详细信息制作缩略图图像。但是,只要我在行中选择 InventoryID,图像就不会填充到网格中。这是我目前所拥有的:

DAC 扩展:

namespace PX.Objects.IN
{
  public class InventoryItemExt : PXCacheExtension<InventoryItem>
  {
      #region ThumbnailURL
      public abstract class thumbnailURL : IBqlField
    { }
    [PXString]
    public string ThumbnailURL { get; set; }
      #endregion
  }
}

代码扩展:

using PX.Data;
using PX.Objects.SO;
using System;
using PX.Objects.IN;
using PX.Web.UI;

namespace Combined
{
  public class SOLineExt : PXCacheExtension<SOLine>
    {
        #region ThumbnailURL
        public abstract class thumbnailURL : IBqlField
        { }
        [PXString]
        public string ThumbnailURL { get; set; }
        #endregion
    }
    public class SOOrderEntryExt: PXGraphExtension<SOOrderEntry>
    {
        public void SOLine_RowSelecting(PXCache sender, PXRowSelectingEventArgs e,PXRowSelecting baseMethod)
        {
            baseMethod.Invoke(sender, e);
            if(e.Row!=null)
            {
                var row = e.Row as SOLine;
                if (row.InventoryID != null)
                {

                    InventoryItem currentLineItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(this.Base, row.InventoryID);
                    if (row != null && !string.IsNullOrEmpty(currentLineItem.ImageUrl))
                    {
                        if(currentLineItem.StkItem==true)
                        {
                            InventoryItemMaint inventoryItemMaint = PXGraph.CreateInstance<InventoryItemMaint>();
                            Guid[] files = PXNoteAttribute.GetFileNotes(inventoryItemMaint.Item.Cache, currentLineItem);
                            var fm = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
                            foreach (Guid fileID in files)
                            {
                                PX.SM.FileInfo fi = fm.GetFileWithNoData(fileID);
                                if (fi.FullName == currentLineItem.ImageUrl || fi.Name == currentLineItem.ImageUrl)
                                {
                                    row.GetExtension<SOLineExt>().ThumbnailURL = ControlHelper.GetAttachedFileUrl(null, fileID.ToString());
                                    break;
                                }
                            }
                        }
                        else
                        {
                            NonStockItemMaint inventoryItemMaint = PXGraph.CreateInstance<NonStockItemMaint>();
                            Guid[] files = PXNoteAttribute.GetFileNotes(inventoryItemMaint.Item.Cache, currentLineItem);
                            var fm = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
                            foreach (Guid fileID in files)
                            {
                                PX.SM.FileInfo fi = fm.GetFileWithNoData(fileID);
                                if (fi.FullName == currentLineItem.ImageUrl || fi.Name == currentLineItem.ImageUrl)
                                {
                                    row.GetExtension<SOLineExt>().ThumbnailURL = ControlHelper.GetAttachedFileUrl(null, fileID.ToString());
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

ASPX 代码:

网格中的代码:

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

InventoryID SegmentMask 上的代码:

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

我确实找到了一篇关于将图像添加到 InventoryID 选择器的帖子,它有一种将图像添加到该网格的不同方法,这里同样适用吗?这是另一个帖子:How to show images inside selector lookup?

我已更改上面的代码以匹配其他帖子,但现在我收到此错误:

\App_RuntimeCode\SOOrderEntry.cs(61): error CS0103: The name 'ControlHelper' does not exist in the current context
\App_RuntimeCode\SOOrderEntry.cs(61): error CS0103: The name 'ControlHelper' does not exist in the current context

从下面的第一个答案添加代码,但现在网格列显示为空白:

更新 1: 已修复 我已经重做了上面的所有代码来回答 1,并在上面的帖子中添加了 Ruslan 的回答帖子中的代码。屏幕截图还是一样。

更新 2: 我已经让一切正常工作了,或者看起来如此。我现在只是有时会收到此错误,我不确定原因是什么。忽略 CustomerID 错误,因为他们的信用余额已过期。

【问题讨论】:

  • 应该正确应用相同的步骤。您可以跳过有关修改选择器的部分,因为您的图像应该直接应用于 SOLine
  • 我已经尝试过另一篇文章中的代码,但我将其视为编译器错误:当前上下文中不存在名称“ControlHelper”
  • 更新了上面的代码。

标签: acumatica


【解决方案1】:

如果您在自定义的代码编辑器中编写代码,请从 Acumatica 的 Bin 文件夹中添加对 PX.Web.UI.dll 的引用,或者添加对 using PX.Web.UI; 的引用。 ControlHelper 是一个静态帮助类,用于更轻松地使用 Acumatica 的 Web 控件。

更新 1

在您提到的答案中,图像的添加是在库存项目选择器的查找中完成的,并将 SOLineExt 的字段添加到网格中。在您的情况下,您将其添加到 SOLine。这是这样做的代码:

using PX.Data;
using PX.Objects.SO;
using System;
using PX.Objects.IN;
using PX.Web.UI;

namespace ClassLibrary1
{

    public class SOLineExt : PXCacheExtension<SOLine>
    {
        #region ThumbnailURL
        public abstract class thumbnailURL : IBqlField
        { }
        [PXString]
        public string ThumbnailURL { get; set; }
        #endregion
    }
    public class SOOrderEntryExt: PXGraphExtension<SOOrderEntry>
    {
        public void SOLine_RowSelecting(PXCache sender, PXRowSelectingEventArgs e,PXRowSelecting baseMethod)
        {
            baseMethod?.Invoke(sender, e);
            if(e.Row!=null)
            {
                var row = e.Row as SOLine;
                if (row.InventoryID != null)
                {

                    InventoryItem currentLineItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(this.Base, row.InventoryID);
                    if (row != null && !string.IsNullOrEmpty(currentLineItem.ImageUrl))
                    {
                        if(currentLineItem.StkItem==true)
                        {
                            InventoryItemMaint inventoryItemMaint = PXGraph.CreateInstance<InventoryItemMaint>();
                            Guid[] files = PXNoteAttribute.GetFileNotes(inventoryItemMaint.Item.Cache, currentLineItem);
                            var fm = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
                            foreach (Guid fileID in files)
                            {
                                PX.SM.FileInfo fi = fm.GetFileWithNoData(fileID);
                                if (fi.FullName == currentLineItem.ImageUrl || fi.Name == currentLineItem.ImageUrl)
                                {
                                    row.GetExtension<SOLineExt>().ThumbnailURL = ControlHelper.GetAttachedFileUrl(null, fileID.ToString());
                                    break;
                                }
                            }
                        }
                        else
                        {
                            NonStockItemMaint inventoryItemMaint = PXGraph.CreateInstance<NonStockItemMaint>();
                            Guid[] files = PXNoteAttribute.GetFileNotes(inventoryItemMaint.Item.Cache, currentLineItem);
                            var fm = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
                            foreach (Guid fileID in files)
                            {
                                PX.SM.FileInfo fi = fm.GetFileWithNoData(fileID);
                                if (fi.FullName == currentLineItem.ImageUrl || fi.Name == currentLineItem.ImageUrl)
                                {
                                    row.GetExtension<SOLineExt>().ThumbnailURL = ControlHelper.GetAttachedFileUrl(null, fileID.ToString());
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

如您所见,我已将ThumbnailURL 直接添加到SOLine。 现在还需要根据项目类型(库存/非库存)创建 InventoryItemMaintNonStockItemMaint 的实例。

因此你应该得到这个:

【讨论】:

  • 我已添加该参考,但该列仍显示为空白。没有列标题,因为它只是空白,我确定这只是添加 PXUIField 属性,但图片没有显示。网格上的aspx代码还是和上面一样。
  • @Dane 您能否取消发布/发布自定义并将显示空白列的网格屏幕截图发送给我
  • 添加到上面的原始帖子中。
  • 哦,不,我还没有将图像添加到 InventoryID 选择器中。我只希望它在 SOLine 而不是 InventoryID 选择器上。我应该只删除 InventoryItemExt 中的 ThumbnailURL 吗?这会影响你的代码吗?
  • @Dane 不,你不应该。我的代码没有将它添加到选择器中。它将图像添加到销售订单行。您已使用 RuslanDev 将图像添加到选择器的答案中的代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-15
  • 2021-12-11
  • 1970-01-01
  • 2019-08-07
  • 1970-01-01
  • 2019-04-01
  • 2016-10-14
相关资源
最近更新 更多