无法在表单视图中显示图像

时间:2018-07-11 14:06:57

标签: acumatica

我有未绑定的字段并为其分配文件ID,我什至也尝试分配URL,但这不起作用,请查看下面的设计和代码,请让我知道在哪里做错了。

<px:PXFormView runat="server" ID="frmImage2" DataSourceID="ds" DataMember="IconImage" SkinID="Preview">
                <Template>
                    <px:PXLayoutRule ID="PXLayoutRule18" runat="server" StartColumn="true" />
                    <px:PXImageUploader runat="server" DataField="UsrKWJMThumbnailURL" AllowUpload="false" DataMember="IconImage" SuppressLabel="True" ID="imgViewImage12" Height="150px" Width="150px" />
                </Template>
    </px:PXFormView>

     public PXSelect<AMProdItem> IconImage;

        public virtual void iconImage()
        {
            foreach (AMProdItem item in Base.ProdItemRecords.Select())
            {
                AMProdItemExt extItems = item.GetExtension<AMProdItemExt>();

                if (extItems != null)
                {
                    if (extItems.UsrKWJMSerialNbr != null)
                    {
                        InfoSmartSearch.InfoINItemLotSerialImage infoItemLotSerialImg = PXSelectReadonly<InfoSmartSearch.InfoINItemLotSerialImage, Where<InfoSmartSearch.InfoINItemLotSerialImage.lotSerialNbr, Equal<Required<InfoSmartSearch.InfoINItemLotSerialImage.lotSerialNbr>>>>.Select(Base, extItems.UsrKWJMSerialNbr);

                        if (infoItemLotSerialImg != null)
                        {
                            if (!string.IsNullOrEmpty(infoItemLotSerialImg.UsrIconImageUrl))
                            {
                                NoteDoc noteDoc = PXSelectReadonly<NoteDoc, Where<NoteDoc.noteID, Equal<Required<NoteDoc.noteID>>>>.Select(Base, infoItemLotSerialImg.NoteID);

                                if (noteDoc != null)
                                {
                                    UploadFile uploadFile = PXSelectReadonly<UploadFile, Where<UploadFile.fileID, Equal<Required<UploadFile.fileID>>>>.Select(Base, noteDoc.FileID);

                                    if (uploadFile != null)
                                    {
                                        extItems.UsrKWJMThumbnailURL =
                                           ControlHelper.GetAttachedFileUrl(null, uploadFile.FileID.ToString());
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        InventoryItem invItems = PXSelectReadonly<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(Base, item.InventoryID);

                        if (invItems != null)
                        {
                            if (!string.IsNullOrEmpty(invItems.ImageUrl))
                            {
                                NoteDoc noteDoc = PXSelectReadonly<NoteDoc, Where<NoteDoc.noteID, Equal<Required<NoteDoc.noteID>>>>.Select(Base, invItems.NoteID);

                                if (noteDoc != null)
                                {
                                    UploadFile uploadFile = PXSelectReadonly<UploadFile, Where<UploadFile.fileID, Equal<Required<UploadFile.fileID>>>>.Select(Base, noteDoc.FileID);

                                    if (uploadFile != null)
                                    {
                                        extItems.UsrKWJMThumbnailURL =
                                          ControlHelper.GetAttachedFileUrl(null, uploadFile.FileID.ToString());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

1 个答案:

答案 0 :(得分:1)

我建议您使用PXImageView控件而不是PXImageUploader。

<px:PXImageView runat="server" ID="edImage" DataField="UsrKWJMThumbnailURL" />

首先使用绝对URL进行测试,如下所示: https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png

我测试了此方法,可以为其提供担保: enter image description here

这是我的测试项目的完整代码:

using System;
using PX.Data;

namespace PXImageTest
{
  public class TestImage : PXGraph<TestImage>
  {
    public PXFilter<MasterTable> MasterView;

    public void MasterTable_ImageUrl_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
    {
        e.ReturnValue = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png";
    }

    [Serializable]
    public class MasterTable : IBqlTable
    {
      public abstract class imageUrl : IBqlField { }

      [PXUIField(DisplayName = "Image")]
      [PXDBString(255, IsUnicode = true)]  
      public virtual String ImageUrl { get; set; }
    }
  }
}

ASPX:

<%@ Page Language="C#" MasterPageFile="~/MasterPages/FormView.master" AutoEventWireup="true" ValidateRequest="false" CodeFile="ZZ999999.aspx.cs" Inherits="Page_ZZ999999" Title="Untitled Page" %>
<%@ MasterType VirtualPath="~/MasterPages/FormView.master" %>

<asp:Content ID="cont1" ContentPlaceHolderID="phDS" Runat="Server">
    <px:PXDataSource ID="ds" runat="server" Visible="True" Width="100%"
        TypeName="PXImageTest.TestImage"
        PrimaryView="MasterView">
        <CallbackCommands>
        </CallbackCommands>
    </px:PXDataSource>
</asp:Content>
<asp:Content ID="cont2" ContentPlaceHolderID="phF" Runat="Server">
    <px:PXFormView ID="form" runat="server" DataSourceID="ds" DataMember="MasterView" Width="100%" AllowAutoHide="false">
        <Template>
            <px:PXLayoutRule runat="server" StartRow="True" ID="PXLayoutRule1" />
            <px:PXImageView runat="server" DataField="ImageUrl" ID="edImage" Style='left:9px;top:9px;Position:absolute;' />
        </Template>
        <AutoSize Container="Window" Enabled="True" MinHeight="200" ></AutoSize>
    </px:PXFormView>
</asp:Content>