既然 GIScreenHelper 已标记为过时,我该如何重定向到仪表板?

How do I redirect to a dashboard now that GIScreenHelper is marked obsolete?

我们有一个仪表板,可通过“库存商品”页面上的“查询”菜单访问。在我们最近对 2019 R2 进行小幅升级之前,以下代码可以毫无问题地编译以允许打开与当前库存 ID 相关的仪表板。它仍然可以编译,但会警告 GIScreenHelper 已过时,将在下次升级时标记为内部。因此我的问题是......如果我不能使用 GIScreenHelper 来初始化 PXRedirectRequiredException 中使用的图形,我该如何重定向到仪表板?

string screenID = "SS0010DB"; //DashboardID 
PXSiteMapNode sm = GIScreenHelper.GetSiteMapNode(screenID);
PXGraph graph = GIScreenHelper.InstantiateGraph(screenID);
if (graph is LayoutMaint)
{
    LayoutMaint copygraph = graph as LayoutMaint;
    Dictionary<string, object> parameters = new Dictionary<string, object>();

    parameters["InventoryID"] = item.InventoryCD;
    copygraph.Filter.Current.Values = parameters;

    throw new PXRedirectRequiredException(sm.Url, copygraph, PXBaseRedirectException.WindowMode.New, string.Empty);
}

我试过直接初始化 LayoutMaint,但我不知道要设置什么来指定使用哪个屏幕 ID 和传递参数。

我猜你有两个选择:

  1. 创建作为仪表板页面图形的 DashboardMaint 图形实例并提供仪表板的名称并调用该图形的 viewDashboard 操作。

  2. 只需获取 DashboardMaint 的 viewDashboard 操作的代码并直接重定向到您的仪表板:

    [PXButton(ConfirmationType = PXConfirmationType.IfDirty, ConfirmationMessage = "Any unsaved changes will be discarded. Do you want to proceed?")]
    [PXUIField(DisplayName = "View")]
    public void viewDashboard()
    {
        throw new PXRedirectToUrlException(PXSiteMap.Provider.FindSiteMapNodeByScreenID(this.Dashboards.Current.ScreenID).Url, PXBaseRedirectException.WindowMode.Same, "View Dashboard");
    }
    

已更新

下面是一个代码示例,说明如何使用过滤器的预定义值打开仪表板。 该示例是为 Customer View 仪表板编写的。

[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "CustomerView")]
protected virtual IEnumerable RedirectToCustomerViewDashboard(PXAdapter adapter)
{
    string screenID = "DB000031"; //DashboardID 
    LayoutMaint graph;
    using (new PXScreenIDScope(screenID))
    {
        graph = PXGraph.CreateInstance<LayoutMaint>(screenID);
    }
    Dictionary<string, object> parameters = new Dictionary<string, object>();
    parameters["CustomerAccountID"] = "ABARTENDE";
    graph.Filter.Current.Values = parameters;
    throw new PXRedirectRequiredException(PXSiteMap.Provider.FindSiteMapNodeByScreenID(screenID).Url, graph, PXBaseRedirectException.WindowMode.New, string.Empty);
}

值的键是仪表板定义中参数的名称