Add Order Number search to all Admin pages

by Joe Payne 22. July 2008 00:44
Introduction

This is a quick and dirty one, but oh will it make your day. I don't know about you, but I find myself jumping from order to order and it's always by order number. Well, there really isn't a way to get straight from one order to another by order number. You have to always go back to the main Dashboard and enter the order number there.

So I modified 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

Normally I just post the changes to a file. In this case, the file is small so I'm going to post the entire file. That, and I have a dental appointment in 45 minutes :)

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

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>


Save it.

Conclusion

You might notice the text color isn't right. Well, I hate CSS styles and CSS styles hate me. It's mutual and I'm ok with that. If you know how to make two stupid little words show the proper style color from the style sheet, please post it here. Others will be grateful and the score will become CSS 220, Joe 0 :wink:

Tags: , , ,

AC7 Articles

How to FTP files in AC7 code

by Joe Payne 2. July 2008 00:45
Introduction

Did you know that you can send and receive files via FTP right in your own web pages?

Did you know you can do it with 4 lines of code AND know if it worked? Aha, now I have your attention :)

AbleCommerce 7 includes a nifty little FTP component that makes uploading and downloading files via FTP a snap. This brief tutorial will explain how to do a simple FTP upload to a remote site. Remember, since .Net programming is all server-side, this is from the perspective of your web server and not your web browser. In other words, this is how you make your web server upload a file to a remote FTP site. For drop-ship distributors like me, this is invaluable when automating the distributor order process.

The Magic

Here's a code snippet that makes an FTP connection and uploads a file:

Code:
                Dim _FTPCon As New FTPConnection
                Try
                    _FTPCon.ServerAddress = "ftp.yourftpsite.com"
                    _FTPCon.ServerPort = 21
                    _FTPCon.UserName = "ftp_user"
                    _FTPCon.Password = "ftp_password"
                    _FTPCon.Connect()
                    _FTPCon.UploadFile(_LocalName, _RemoteName)
                    ' File uploaded successfully

                Catch ex As Exception
                    ' Upload or connect failed

                End Try


Notice how using the TRY/CATCH command allows you to catch if the upload failed. The FTP component is designed to throw an exception if either the upload or the connect command fails. Also note that you do not have to specify the FTP:// in the host URL.

More Documentation
You can find the documentation for this nifty FTP component at http://www.enterprisedt.com/products/edtftpnetpro/documentation.html. The links in the online documentation do not fully work because their online docs assume you've installed the component from their CD. But there's enough there to get your started - the rest can be exposed through the Visual Studio Object Browser or simply by using the Intellisense feature in VS.

Conclusion
Automation is one of many keys to getting those profit margins you seek. Always try to spend more time running your business and less time doing data entry. Your bank account (and your significant other) will thank you 8)

Tags: , ,

AC7 Articles

Month List