Example #1
0
 public static List <InventoryItem> GetInventoryItemByCatalogItemIdAndInventoryItemStatusId(CatalogItem catalogItem, int inventoryItemStatus)
 {
     if (catalogItem != null)
     {
         BusinessObjects _businessObjects = new BusinessObjects();
         return((catalogItem.CatalogItemId != null && catalogItem.CatalogItemId != Guid.Empty)
             ? _businessObjects.GetInventoryItemByCatalogItemIdAndInventoryItemStatusId(catalogItem.CatalogItemId, inventoryItemStatus)
             : null);
     }
     else
     {
         return(null);
     }
 }
        // INVENTORY SEARCH submit button click event
        private void btn_SearchSubmit_Click(object sender, EventArgs e)
        {
            BusinessObjects _businessObjects = new BusinessObjects();

            // Element reset to be performed each time, before a search is ran
            lbl_ResultsFound.Text = null;           // Clear contents of search result label
            cbx_ResultsList.Items.Clear();          // Clear old search results from results combo box
            cbx_ResultsList.Text = "";              // Clear text from visible combobox area
            rbox_clerkSearchDisplay.Clear();        // Clear search results each time a new search is submitted
            inventoryItems = null;

            // Verify that a query type was selected by the user
            if ((cbx_QueryType.SelectedItem == null) || (cbx_InventoryStatus.SelectedItem == null) || (tbx_QueryInput.Text == ""))
            {
                MessageBox.Show("Please make sure all search criteria is filled out and try again", "Invalid Query Input",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // SEARCH BY MANUFACTURER NAME - Chech to see if user entered a Manufacturer Name
            else if (cbx_QueryType.SelectedItem.ToString() == "Manufacturer")
            {
                // Generate a list of Inventory Items that match the Manufacturer Name entered by the user
                inventoryItems = _businessObjects.GetInventoryItemByItemManufacturer(tbx_QueryInput.Text, cbx_InventoryStatus.SelectedIndex);
            }

            // SEARCH BY ITEM NAME - Check to see if user entered an Item Name
            else if (cbx_QueryType.SelectedItem.ToString() == "Item Name")
            {
                // Generate a list of Inventory Items that match the Item Name entered by the user
                inventoryItems = _businessObjects.GetInventoryItemByItemName(tbx_QueryInput.Text, cbx_InventoryStatus.SelectedIndex);
            }

            // SEARCH BY ITEM GUID - Check to see if user entered an ID Number
            else if (cbx_QueryType.SelectedItem.ToString() == "Inventory ID")
            {
                try
                {
                    // Generate a list of Inventory Items that match the Item ID entered by the user
                    inventoryItems = ApplicationObjects.GetInventoryItemByInventoryItemIdAndInventoryItemStatusId(new Guid(tbx_QueryInput.Text), cbx_InventoryStatus.SelectedIndex);
                }
                catch (Exception)
                {   // Catch if a non-Guid was entered
                    MessageBox.Show("Search failed!  You may have entered an invalid ID.  Please check your item ID and try again", "Search Failure",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    rbox_clerkSearchDisplay.AppendText("Input error - please try again");
                    return;
                }
            }

            // SEARCH BY CATALOG NUMBER - Check to see if user entered an Item Name
            else if (cbx_QueryType.SelectedItem.ToString() == "Catalog Number")
            {
                try
                {
                    // Generate a list of Inventory Items that match the Item Name entered by the user
                    inventoryItems = _businessObjects.GetInventoryItemByCatalogItemIdAndInventoryItemStatusId(new Guid(tbx_QueryInput.Text), cbx_InventoryStatus.SelectedIndex);
                }

                catch (Exception)
                {   // Catch if a non-integer was entered
                    MessageBox.Show("Search failed!  You may have entered an invalid ID.  Please check your catalog ID and try again", "Search Failure",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    rbox_clerkSearchDisplay.AppendText("Input error - please try again");
                    return;
                }
            }

            // If nothing is populated into the searchDisplay box, we can assume that there were no search results
            else
            {
                lbl_ResultsFound.Text = "No matches found - please try again";
            }

            // Populate label that displays how many results were found
            lbl_ResultsFound.Text = (inventoryItems.Count.ToString() + " result(s) found!");


            // This string list holds the results of an InventoryItem's ToItemDescription method, which actually
            // returns a list of individual line items, which each hold the item's attributes that will be
            // displayed on seperate lines of the text box
            try
            {
                List <string> itemDescriptions = inventoryItems.FirstOrDefault().ToItemDescription();
                foreach (string lineItem in itemDescriptions)
                {   // Add each description line item to the text box
                    rbox_clerkSearchDisplay.AppendText(lineItem + Environment.NewLine);
                }

                // Populate the search result combobox with the catalog numbers of the search results
                foreach (InventoryItem inventoryItem in inventoryItems)
                {
                    cbx_ResultsList.Items.Add(inventoryItem.InventoryItemId.ToString());
                }
                // Set the combobox to show the catalog number of the first search record
                cbx_ResultsList.SelectedIndex = 0;
            }
            catch (Exception)
            {
                rbox_clerkSearchDisplay.AppendText("No matches found - please try again");
                return;
            }
        }