gpt4 book ai didi

c# - 选择器内图像的数据读取器问题

转载 作者:太空宇宙 更新时间:2023-11-03 22:41:17 24 4
gpt4 key购买 nike

我引用了下面的 Ruslan 帖子并实现了相同的操作并按预期工作但有时,我面临一个问题,如“在处理字段 ItemRequiresTerms 期间发生错误:已经有一个与此命令关联的打开的 DataReader,它必须是先关门。”

How to show images inside selector lookup?

一个 Stock Item 可能有多个图像,我们只需要图标图像。下面是代码。

public void InventoryItemRowSelecting(PXCache sender, PXRowSelectingEventArgs e)
{
var row = e.Row as InventoryItem;
if (row != null)
{
if (!string.IsNullOrEmpty(row.ImageUrl))
{
foreach (NoteDoc noteDoc in PXSelectReadonly<NoteDoc, Where<NoteDoc.noteID, Equal<Required<NoteDoc.noteID>>>>.Select(Base, row.NoteID)) // here i got error
{
foreach (UploadFile uploadFile in PXSelectReadonly<UploadFile, Where<UploadFile.fileID, Equal<Required<UploadFile.fileID>>>>.Select(Base, noteDoc.FileID))
{
if (uploadFile.Name.Contains("icon"))
{
row.ImageUrl =
ControlHelper.GetAttachedFileUrl(null, uploadFile.FileID.ToString());
break;
}
}
}
}
}
}

最佳答案

您需要使用单独的连接范围在 RowSelecting 事件处理程序中执行额外的 BQL 语句。

可以找到更多详细信息here .

您可以通过使用适当的 Join 来避免嵌套 for 循环,

public void InventoryItemRowSelecting(PXCache sender, PXRowSelectingEventArgs e)
{
var row = e.Row as InventoryItem;
if (row != null)
{
if (!string.IsNullOrEmpty(row.ImageUrl))
{
using (new PXConnectionScope())
{
UploadFile uploadFile = PXSelectReadonly2<UploadFile, InnerJoin<NoteDoc, On<NoteDoc.fileID, Equal<UploadFile.fileID>>>,
Where<NoteDoc.noteID, Equal<Required<NoteDoc.noteID>>,
And<UploadFile.name, Like<Required<UploadFile.name>>>>>.
Select(Base, row.NoteID, "%icon%");
row.ImageUrl = (uploadFile != null) ? ControlHelper.GetAttachedFileUrl(null, uploadFile.FileID.ToString())
: null;
}
}
}
}

关于c# - 选择器内图像的数据读取器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52099095/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com