c# - 从 Ax 2012 Listpage (EP) 多选到 downloadDocument.aspx

标签 c# asp.net axapta dynamics-ax-2012 enterprise-portal

我已经为此苦苦挣扎了一段时间,似乎无法找到解决我问题的方法。如果可能的话,我真的很想在这里得到一些帮助,这对我来说意义重大。

我目前正在企业门户网站上运行来自 ax 2012 的列表页,允许用户选择发票,然后单击开始下载生成的 PDF 发票的按钮。 它看起来像这样: enter image description here

EpDocuGetMenuitem 按钮(输出菜单项)引用启动静态文件 downloadDocument.aspx 的 URL webMenuItem。

downloadDocument.aspx 获取 Websession 和 axaptasession 并提取在 Ax ListPage 中选择的单个记录。 downloadDocument.aspx 具有以下代码:

<%@ Page Language="C#" Trace="false" %>
<%@ Assembly Name="Microsoft.Dynamics.Framework.Portal, Version=6.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null" %>
<%@ Assembly Name="Microsoft.Dynamics.Framework.Data.Ax, Version=6.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null" %>
<%@ Assembly Name="Microsoft.Dynamics.Framework.BusinessConnector, Version=6.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null" %>
<%@ Assembly Name="Microsoft.Dynamics.Framework.BusinessConnector.Proxy, Version=6.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null" %>
<%@ Assembly Name="Microsoft.Dynamics.Framework.Metadata.AX, Version=6.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null" %>
<%@ Import Namespace="Microsoft.Dynamics.Framework.Portal" %>
<%@ Import Namespace="Microsoft.Dynamics.Framework.Portal.UI" %>
<%@ Import Namespace="Microsoft.Dynamics.AX.Framework.Portal.Data" %>
<%@ Import Namespace="Microsoft.Dynamics.Framework.BusinessConnector.Proxy" %>
<%@ Import Namespace="Microsoft.Dynamics.Framework.BusinessConnector.Session" %>
<%@ Import Namespace="Microsoft.Dynamics.Framework.BusinessConnector.Adapter" %>
<%@ Import Namespace="Microsoft.Dynamics.AX.Framework.Services.Client" %>
<%@ Register TagPrefix="dynamics" TagName="EPSecurityControl" src="EPSecurityControl.ascx" %>
<dynamics:EPSecurityControl ID="AxEPSecurity" runat="server" /> 
<script runat="server">
    void Page_Load(object sender, EventArgs e)
    {
        AxSharepointWebSession session = null;
        try
        {
            session = SessionHelper.Instance.GetSharepointSession();

            if (session != null)
            {
                using (EPDocuGet doc = new EPDocuGet(session.AxaptaAdapter))
                {
                    // EPDocuGet writes directly to the output stream
                    AxQueryString query = new AxQueryString(this.Request);
                    if (query.RecordContext != null)
                    {
                        AxTableContext tableContext = AxTableContext.Create(session, query);
                        if(tableContext != null && tableContext.DataKey != null)
                        {
                            using (IAxaptaRecordAdapter record = tableContext.DataKey.GetRecords(session))
                            {
                                if (tableContext.TableId == TableMetadata.TableNum("DocuRef"))
                                {
                                    doc.runDownload(record);

                                }
                                else
                                {
                                    // Run a report using the Client SDK UserImpersonationContext to revert the credentials from EP application pool to the authenticated user
                                    using (new UserImpersonationContext())
                                    {
                                        doc.runDownload(record);
                                    }
                                }
                            }
                        }
                    }
                }

                Response.Flush();
            }
        }
        catch (System.Exception)
        {
            // Current design is to not display errors to the user

            // Errors are stored in the event log for review by the site operator
        }
        finally
        {
            if (session != null)
            {
                SessionHelper.Instance.ReleaseSharepointSession(session);
            }
        }
    }
</script>

文件中有趣的部分是这段代码:

using (EPDocuGet doc = new EPDocuGet(session.AxaptaAdapter))
{
    // EPDocuGet writes directly to the output stream
    AxQueryString query = new AxQueryString(this.Request);
    if (query.RecordContext != null)
    {
        AxTableContext tableContext = AxTableContext.Create(session, query);
        if (tableContext != null && tableContext.DataKey != null)
        {
             using (IAxaptaRecordAdapter record = tableContext.DataKey.GetRecord(session))
             {
                 if (tableContext.TableId == TableMetadata.TableNum("DocuRef"))
                 {
                       doc.runDownload(record);
                 }
                 else
                 {
                      // Run a report using the Client SDK UserImpersonationContext to revert the credentials from EP application pool to the authenticated user
                      using (new UserImpersonationContext())
                      {
                           doc.runDownload(record);
                      }
                 }
             }
        }
    }
}

这里的目标是让所有选定的记录都可以在 downloadDocument.aspx 中访问。我在 Ax 中启用了多选,所以我想应该可以以某种方式获取所有记录。 我认为这段代码应该有所不同

IAxaptaRecordAdapter record = tableContext.DataKey.GetRecord(session)

但是我想不通。

如果我可以获取 downloadDocument.aspx 文件中的所有记录,我可以将一个字符串发送回 ax 以创建必要的文档并将它们发送给用户。

关于如何做到这一点有什么建议吗??

最佳答案

我前段时间有过类似的需求。尝试使用此代码段。 请注意,这会为每个标记的行调用 ax 方法。可能有更有效的方法将数据集作为一个整体发送。

 IReadOnlySet<DataSetViewRow> rows     = this.ds_yourDSName.GetDataSourceView("YourDSName").DataSetView.GetMarkedRowsSet();
 IEnumerator<DataSetViewRow> enumRows  = rows.GetEnumerator(); 


        while (enumRows.MoveNext())
        {
            //code to get fields needed
            //call to a static ax method to send the fields as parms
            this.AxSession.AxaptaAdapter.CallStaticClassMethod("ClasName","MethodName", parm1, parm2);
        }

        DialogHelper.Close(CloseDialogBehavior.RefreshDataSource);

关于c# - 从 Ax 2012 Listpage (EP) 多选到 downloadDocument.aspx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39533080/

相关文章:

c# - 在 Azure 队列存储中传递对象消息

c# - 仅返回 base.method 时隐藏带有 new 关键字的方法的原因是什么?

c# - 如何通过自定义打印窗口打印完整的 gridview 区域?

asp.net - 我将如何使用 CSS 复制此 GridView 样式?

c# - 如何确定 Request.Form 对象有多大?

c# - 如何在 ApiController 中为单个方法返回 JSON?

c# - 如何使用C#模拟Windows简单 "Button"的点击功能

axapta - 如何使用 IN 创建查询?

c++ - Axapta 商务连接器

axapta - 试图更改 LedgerTrans 中的文本 "Purchase Invoice"