Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 选择器内有图像的数据读取器问题_C#_Acumatica - Fatal编程技术网

C# 选择器内有图像的数据读取器问题

C# 选择器内有图像的数据读取器问题,c#,acumatica,C#,Acumatica,我从下面的Ruslan post中获取了参考,实现了相同的功能,并按预期工作,但有时会遇到这样的问题:“在处理字段ItemRequiresTerms时发生错误:已经有一个与此命令关联的打开的DataReader,必须先关闭它。” 一个库存项目可能有多个图像,我们只需要图标图像。 下面是代码 public void InventoryItemRowSelecting(PXCache sender, PXRowSelectingEventArgs e) { var row

我从下面的Ruslan post中获取了参考,实现了相同的功能,并按预期工作,但有时会遇到这样的问题:“在处理字段ItemRequiresTerms时发生错误:已经有一个与此命令关联的打开的DataReader,必须先关闭它。”

一个库存项目可能有多个图像,我们只需要图标图像。 下面是代码

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;
                        }
                    }
                }
            }
        }
    }
public void InventoryItemRowSelecting(PXCache发送方,PXRowSelectingEventArgs e)
{
var行=e.作为库存项目的行;
如果(行!=null)
{
如果(!string.IsNullOrEmpty(row.ImageUrl))
{
foreach(PXSelectReadonly.Select中的NoteDoc NoteDoc(Base,row.NoteID))//这里有一个错误
{
foreach(上传文件PXSelectReadonly.Select中的上传文件(Base,noteDoc.FileID))
{
if(uploadFile.Name.Contains(“图标”))
{
row.ImageUrl=
GetAttachedFileUrl(null,uploadFile.FileID.ToString());
打破
}
}
}
}
}
}

您需要使用单独的连接作用域在
行选择
事件处理程序中执行额外的
BQL
语句

可以找到更多细节

通过使用适当的联接,可以避免嵌套for循环

public void InventoryItemRowSelecting(PXCache发送方,PXRowSelectingEventArgs e)
{
var行=e.作为库存项目的行;
如果(行!=null)
{
如果(!string.IsNullOrEmpty(row.ImageUrl))
{
使用(新的PXConnectionScope())
{
UploadFile UploadFile=PXSelectReadonly2。
选择(Base,row.NoteID,“%icon%”);
row.ImageUrl=(uploadFile!=null)?ControlHelper.GetAttachedFileUrl(null,uploadFile.FileID.ToString())
:null;
}
}
}
}

这里已经有了一个公认的答案,但我想向您展示一种替代您在示例代码中使用的深度缩进结构的方法

public void InventoryItemRowSelecting(PXCache sender, PXRowSelectingEventArgs e)
{
    var row = e.Row as InventoryItem;
    if (row == null)
        return;  // Don't proceed when row doesn't exist

    if (string.IsNullOrEmpty(row.ImageUrl))
        return; // Don't proceed when ImageUrl doesn't exist

    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"))
                continue;  // Skip non-icon files

            row.ImageUrl = ControlHelper.GetAttachedFileUrl(null, uploadFile.FileID.ToString());
        }
    }
}
public void InventoryItemRowSelecting(PXCache发送方,PXRowSelectingEventArgs e)
{
var行=e.作为库存项目的行;
if(行==null)
return;//行不存在时不继续
if(string.IsNullOrEmpty(row.ImageUrl))
return;//当ImageUrl不存在时不继续
foreach(PXSelectReadonly.Select中的NoteDoc NoteDoc(Base,row.NoteID))//这里有一个错误
{
foreach(上传文件PXSelectReadonly.Select中的上传文件(Base,noteDoc.FileID))
{
如果(!uploadFile.Name.Contains(“图标”))
继续;//跳过非图标文件
row.ImageUrl=ControlHelper.GetAttachedFileUrl(null,uploadFile.FileID.ToString());
}
}
}
请注意如何在代码页中使用更多的内容,而不是将所有内容都推到右边。这是你最初的例子,所以它没有从被接受的答案中得到修复,我只是想给你展示一个未来可能考虑的替代模式。

当您将此应用于已接受的解决方案时,这也是一个巨大的变化:

public void InventoryItemRowSelecting(PXCache sender, PXRowSelectingEventArgs e)
{
    var row = e.Row as InventoryItem;
    if (row == null)
        return;  // Don't proceed when row doesn't exist

    if (string.IsNullOrEmpty(row.ImageUrl))
        return; // Don't proceed when ImageUrl doesn't exist

    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%");
        if (uploadFile == null)
            continue; // Skip non-icon files         

        row.ImageUrl = ControlHelper.GetAttachedFileUrl(null, uploadFile.FileID.ToString()); 
    }
}
public void InventoryItemRowSelecting(PXCache发送方,PXRowSelectingEventArgs e)
{
var行=e.作为库存项目的行;
if(行==null)
return;//行不存在时不继续
if(string.IsNullOrEmpty(row.ImageUrl))
return;//当ImageUrl不存在时不继续
使用(新的PXConnectionScope())
{
UploadFile UploadFile=PXSelectReadonly2。
选择(Base,row.NoteID,“%icon%”);
if(uploadFile==null)
继续;//跳过非图标文件
row.ImageUrl=ControlHelper.GetAttachedFileUrl(null,uploadFile.FileID.ToString());
}
}

非常感谢,DChhapgar。