Adding order number search to all Admin pages

From AbleCommerce Wiki
Revision as of 03:57, 4 September 2008 by Sohaib (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Introduction

This topic is about how to modify the Admin header navigation control to include an order number field. That way every single page on the Admin side has a box where you can type in any order number and jump straight to the order details page.

Code Changes

Edit the ~/Admin/UserControls/HeaderNavigation.ascx file and replace the entire contents with this code:

    <%@ Control Language="C#" ClassName="HeaderNavigation" EnableViewState="false" %>
    <script runat="server">
    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (Token.Instance.User == null || Token.Instance.User.IsAdmin == false)
        {
            AdminNavigationHeaderPanel.Visible = false;
        }
        else
        {
            OrdersLink.Visible = (Token.Instance.User.IsInRole(Role.OrderAdminRoles));
            CatalogLink.Visible = (Token.Instance.User.IsInRole(Role.CatalogAdminRoles));
            OrderId.Visible = (Token.Instance.User.IsInRole(Role.OrderAdminRoles));
            ViewOrderButton.Visible = (Token.Instance.User.IsInRole(Role.OrderAdminRoles));
        }
    }
    protected void ViewOrderButton_Click(object sender, EventArgs e)
    {
        int tempOrderId = AlwaysConvert.ToInt(OrderId.Text);
        Order order = OrderDataSource.Load(tempOrderId);
        if (order != null)
        {
            Response.Redirect("~/Admin/Orders/ViewOrder.aspx?OrderId=" + tempOrderId.ToString());
        }
        else
        {
            CustomValidator invalidOrderId = new CustomValidator();
            invalidOrderId.ControlToValidate = "OrderId";
            invalidOrderId.ErrorMessage = "*";
            invalidOrderId.Text = "Order number is not valid";
            invalidOrderId.IsValid = false;
            AdminNavigationHeaderPanel.Controls.Add(invalidOrderId);
        }
    }
    </script>
    <asp:Panel ID="AdminNavigationHeaderPanel" runat="server" >
    <table>
    <tr>
    <td>
    <asp:HyperLink ID="DashboardLink" runat="server" NavigateUrl="~/Admin/Default.aspx" 
    CssClass="dashboard" Text="Dashboard"></asp:HyperLink>
    <asp:HyperLink ID="OrdersLink" runat="server" 
    NavigateUrl="~/Admin/Orders/Default.aspx" CssClass="orders" text="Orders"></asp:HyperLink>
    <asp:HyperLink ID="CatalogLink" runat="server" NavigateUrl="~/Admin/Catalog/Browse.aspx" 
    CssClass="catalog" Text="Catalog"></asp:HyperLink><asp:HyperLink ID="StoreLink" runat="server" 
    NavigateUrl="~/Default.aspx" CssClass="stores" Text="Store"></asp:HyperLink><asp:HyperLink 
    ID="LogoutLink" runat="server" NavigateUrl="~/Logout.aspx" CssClass="logout" Text="Logout">
    </asp:HyperLink></td><td class="header" align="left" valign="bottom"><asp:Localize 
    ID="ViewOrderNumberCaption" runat="server" Text="View Order:"></asp:Localize><br />
    <asp:TextBox ID="OrderId" runat="server" Width="40px" ValidationGroup="OrderSummary">
    </asp:TextBox>
    <asp:Button ID="ViewOrderButton" runat="server" ValidationGroup="OrderSummary" 
    OnClick="ViewOrderButton_Click" Text="Go" />
    </td>
    </tr>
    </table>
    </asp:Panel>

Reference

Originally posted in forums by Joe Payne http://forums.ablecommerce.com/viewtopic.php?f=47&t=7727