首页 文章

Acumatica - 在销售订单行中添加图像

提问于
浏览
2

当选择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

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

Update 1: FIXED 我重做了上面的所有代码,回答了1,并在上面的帖子中添加了Ruslan回答中的代码 . 屏幕截图仍然是相同的 .

Update 2: 我似乎有一切正常工作 . 我现在有时只收到这个错误,我不确定原因是什么 . 忽略CustomerID错误,因为他们的信用余额已逾期 .
enter image description here

1 回答

  • 2

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

    UPDATE 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 的实例,具体取决于项目类型(Stock / NonStock) .

    结果你应该得到这个:

    enter image description here

相关问题