Ejemplo n.º 1
0
        private void btnOrderSearch_Click(object sender, EventArgs e)
        {
            List <Order> ordersList = new List <Order>();

            if ((cbSearchFields.SelectedItem == null) || (tbx_Search.Text == ""))
            {
                ApplicationObjects.DisplayInvalidInput("Please make sure that you have entered search criteria.");
            }
            else if (cbSearchFields.SelectedItem.ToString() == "Inventory Item Id")
            {
                try
                {
                    // Generate a list of IOrders that match the Inventory Item ID entered by the user
                    ordersList = ApplicationObjects.GetOrderByInventoryItemId(new Guid(tbx_Search.Text));
                }
                catch (Exception)
                {   // Catch if a non-Guid was entered
                    ApplicationObjects.DisplayInvalidInput("Search failed!  You may have entered an invalid ID.  Please check your item ID and try again");
                    return;
                }
            }
            else if (cbSearchFields.SelectedItem.ToString() == "Order Id")
            {
                try
                {
                    // Generate a list of Orders that match the Order ID entered by the user
                    ordersList.Add(ApplicationObjects.GetOrder(new Guid(tbx_Search.Text)));
                }
                catch (Exception)
                {   // Catch if a non-Guid was entered
                    ApplicationObjects.DisplayInvalidInput("Search failed!  You may have entered an invalid ID.  Please check your item ID and try again");
                    return;
                }
            }
            else if (cbSearchFields.SelectedItem.ToString() == "Order Status")
            {
                // Convert user input into enum, before passing to search method
                OrderStatus orderStatus = BusinessLayer.Translators.Order.ConvertStringToOrderStatus(tbx_Search.Text);

                if (orderStatus == OrderStatus.None)
                {
                    ApplicationObjects.DisplayInvalidInput("You may have entered an invalid order status type.  Please try again");
                    return;
                }

                // Generate a list of Orders that match the Order ID entered by the user
                ordersList = ApplicationObjects.GetOrderByOrderStatus(orderStatus);
            }

            orderTable.Rows.Clear();
            if (ordersList.Count > 0)
            {
                foreach (Order order in ordersList)
                {
                    DataRow newRow = orderTable.NewRow();
                    newRow["Order Id"]        = order.OrderId.ToString();
                    newRow["First Name"]      = order.Person.FirstName;
                    newRow["Last Name"]       = order.Person.LastName;
                    newRow["Entry Date"]      = order.OrderEntryDate.ToString();
                    newRow["Fulfilled Date"]  = (order.OrderFulfillDate != null) ? order.OrderFulfillDate.ToString() : "not filled";
                    newRow["Number of Items"] = order.NumberOrderItems.ToString();
                    newRow["Order Status"]    = order.OrderStatus;
                    orderTable.Rows.Add(newRow);
                }

                dgvOrders.AutoResizeColumns();
            }
            else
            {
                MessageBox.Show("Your search turned up no results.  Please try again.", "No Results Found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }