Difference between revisions of "Adding order number search to all Admin pages"

From AbleCommerce Wiki
Jump to: navigation, search
Line 58: Line 58:
 
       <asp:HyperLink ID="LogoutLink" runat="server" NavigateUrl="~/Logout.aspx" CssClass="logout"  
 
       <asp:HyperLink ID="LogoutLink" runat="server" NavigateUrl="~/Logout.aspx" CssClass="logout"  
 
       Text="Logout"></asp:HyperLink>
 
       Text="Logout"></asp:HyperLink>
       </td><td class="header" align="left" valign="bottom"><asp:LocalizeID="ViewOrderNumberCaption"  
+
       </td><td class="header" align="left" valign="bottom"><asp:LocalizeID="ViewOrderNumberCaption" runat="server" Text="View Order:"></asp:Localize><br />
      runat="server" Text="View Order:"></asp:Localize><br />
+
 
       <asp:TextBox ID="OrderId" runat="server" Width="40px" ValidationGroup="OrderSummary">
 
       <asp:TextBox ID="OrderId" runat="server" Width="40px" ValidationGroup="OrderSummary">
 
       </asp:TextBox><asp:Button ID="ViewOrderButton" runat="server" ValidationGroup="OrderSummary"  
 
       </asp:TextBox><asp:Button ID="ViewOrderButton" runat="server" ValidationGroup="OrderSummary"  

Revision as of 13:39, 15 August 2008

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" >
      <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>
<asp:LocalizeID="ViewOrderNumberCaption" runat="server" Text="View Order:"></asp:Localize>
      <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" />
   </asp:Panel></code>