コード例 #1
0
        /// <summary>
        /// This method takes the UPC and searches to see if it is avaliable.
        /// </summary>
        private void UpCButton_Click(object sender, RoutedEventArgs e)
        {
            string  upC   = UpC.Text;
            ItemDTO itm   = cartController.GetItem(upC);
            var     items = itemDTOs.Cast <ItemDTO>().Where(x => x.UPC.Equals(upC));

            if (items.Count() > 0)
            {
                Category.SelectedIndex = -1;
                FillItemList(items);
                UpC.Text = "";
            }
            else
            {
                MessageBox.Show("Item with the entered UPC not found.");
            }
        }
コード例 #2
0
        /// <summary>
        /// This method updates the passed items category to the category specified in 'category' variable
        /// </summary>
        /// <param name="item">item thats category is being updated</param>
        /// <param name="category">is the category that is being updated to</param>
        /// <returns></returns>
        public bool UpdateItemCategory(ItemDTO item, CategoryDTO category)
        {
            int    result        = -1;
            string commandString = $@"UPDATE {ItemTableName}
                                   SET {CategoryColumn} = @CategoryID
                                   WHERE {UPCColumn} = @UPC";

            using (MySqlConnection conn = new MySqlConnection(connectionStringToDB))
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand(commandString, conn);
                cmd.Parameters.AddWithValue("@CategoryId", category.CategoryID);
                cmd.Parameters.AddWithValue("@UPC", item.UPC);
                result = int.Parse(cmd.ExecuteNonQuery().ToString());
                cmd.Dispose();
            }
            return(result > 0);
        }
コード例 #3
0
        /// <summary>
        /// Removes one of the given item from the cart
        /// </summary>
        /// <param name="item">The item to be removed</param>
        /// <returns>True if an item was remvoed otherwise false</returns>
        public bool RemoveSingleItem(ItemDTO item)
        {
            bool itemRemoved = false;

            DTOs.SalesItemDTO salesItem;
            if ((salesItem = Items.Find(x => x.Item.Equals(item))) != null)
            {
                itemRemoved = true;
                if (salesItem.Quantity > 1)
                {
                    salesItem.Quantity--;
                }
                else
                {
                    Items.Remove(salesItem);
                }
            }
            return(itemRemoved);
        }
コード例 #4
0
        /// <summary>
        /// This method takes the selected item and adds it to the cart list
        /// </summary>
        private void Inventory_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ItemDTO itm = (ItemDTO)Inventory.SelectedItem;

            if (itm != null)
            {
                try
                {
                    cartController.AddItem(itm);
                    UpdateTransactionView();
                    UpdateTotal();
                    Inventory.SelectedItem = null;
                }
                catch (Exception)
                {
                    MessageBox.Show("Error. Please try again");
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// Change the quantity of the item selected by entering an amount via touch controls.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ChangeQuantity_TouchUp(object sender, TouchEventArgs e)
 {
     if (Transaction.SelectedItem != null)
     {
         GUI.OnScreenKeyboard.OnScreenNumPad dialog = new GUI.OnScreenKeyboard.OnScreenNumPad("");
         bool?result = dialog.ShowDialog();
         if (result != null && (bool)result && !dialog.GetResult().Equals(""))
         {
             ItemDTO item     = ((DTOs.SalesItemDTO)Transaction.SelectedItem).Item;
             int     quantity = ((DTOs.SalesItemDTO)Transaction.SelectedItem).Quantity;
             cartController.ChangeQuantity(int.Parse(dialog.GetResult()), item);
             UpdateTransactionView();
             UpdateTotal();
         }
     }
     else
     {
         MessageBox.Show("Select an Item from the transaction to change the quantity");
     }
 }
コード例 #6
0
 /// <summary>
 /// Change the quantity of the item selected by entering an amount via mouse controls.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ChangeQuantity_Click(object sender, RoutedEventArgs e)
 {
     if (Transaction.SelectedItem != null)
     {
         GUI.ChangeQuantityOnClickDialog dialog = new GUI.ChangeQuantityOnClickDialog();
         bool?result = dialog.ShowDialog();
         if (result != null && (bool)result)
         {
             ItemDTO item     = ((DTOs.SalesItemDTO)Transaction.SelectedItem).Item;
             int     quantity = ((DTOs.SalesItemDTO)Transaction.SelectedItem).Quantity;
             cartController.ChangeQuantity(int.Parse(dialog.Result), item);
             UpdateTransactionView();
             UpdateTotal();
         }
     }
     else
     {
         MessageBox.Show("Select an Item from the transaction to change the quantity");
     }
 }
コード例 #7
0
        /// <summary>
        /// Get Item corresponding with passed in UPC
        /// </summary>
        /// <param name="uPC">Item UPC</param>
        /// <returns>Item associated with UPC</returns>
        public ItemDTO GetItem(string uPC)
        {
            ItemDTO item          = null;
            string  commandString = $@"SELECT * FROM {ItemTableName}
                                      WHERE {UPCColumn} = @UPC
                                      LIMIT 1";

            using (MySqlConnection conn = new MySqlConnection(connectionStringToDB))
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand(commandString, conn);
                cmd.Parameters.AddWithValue("@UPC", uPC);
                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    item = ReadInItem(reader);
                }
                cmd.Dispose();
            }
            return(item);
        }
コード例 #8
0
 /// <summary>
 /// Check for barcode reader key combinations when keys are pressed is entered
 /// </summary>
 /// <param name="sender">Object that triggered the event</param>
 /// <param name="e">Event details</param>
 private void HandleBarcodeScan(object sender, KeyEventArgs e)
 {
     // leftCtrl + B focus upcText and set reading to true
     if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.B))
     {
         PageReturns.Focus();
         scannerUPCString = "";
         reading          = true;
     }
     // leftCtrl + J take the UPC from UPCText and find the item if it exists
     // otherwise clear fields and prepare for new item entry
     else if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.J))
     {
         if (reading)
         {
             // find the item associated with the upc entered
             ItemDTO item = itemDTOs
                            .Cast <ItemDTO>()
                            .Where(x => x.UPC.Equals(scannerUPCString)).FirstOrDefault();
             if (item != null)
             {
                 cartController.AddItem(item);
                 UpdateTransactionView();
                 UpdateTotal();
             }
             else
             {
                 MessageBox.Show("Item Not Found!!!");
             }
         }
         reading = false;
     }
     else if (reading && !Keyboard.IsKeyDown(Key.LeftCtrl))
     {
         // get the character from the event item and add it to the current upc
         scannerUPCString += e.Key.ToString()[1];
     }
 }
コード例 #9
0
 public bool ChangeQuantity(int quantity, ItemDTO item)
 {
     if (quantity == 0)
     {
         RemoveAllItems(item);
     }
     else
     {
         DTOs.SalesItemDTO salesItem;
         if ((salesItem = Items.Find(x => x.Item.Equals(item))) != null)
         {
             salesItem.Quantity = quantity;
         }
         else
         {
             Items.Add(new DTOs.SalesItemDTO
             {
                 Item     = item,
                 Quantity = quantity
             });
         }
     }
     return(true);
 }
コード例 #10
0
        /// <summary>
        /// Add a new Item to the database if it doesn't already exist
        /// </summary>
        /// <param name="item">Item to be added</param>
        /// <returns>True if Item added successfully</returns>
        public bool CreateItem(ItemDTO item)
        {
            int result = -1;

            if (!DoesUPCExist(item.UPC))
            {
                string commandString = $@"INSERT INTO {ItemTableName} ({CategoryColumn}, {NameColumn}, {PriceColumn}, {QuantityColumn}, {UPCColumn})
                                       VALUES(@CategoryID, @Name, @Price, @Quantity, @UPC)";

                using (MySqlConnection conn = new MySqlConnection(connectionStringToDB))
                {
                    conn.Open();
                    MySqlCommand cmd = new MySqlCommand(commandString, conn);
                    cmd.Parameters.AddWithValue("@CategoryId", item.Category.CategoryID);
                    cmd.Parameters.AddWithValue("@Name", item.Name);
                    cmd.Parameters.AddWithValue("@Price", item.Price);
                    cmd.Parameters.AddWithValue("@Quantity", item.Quantity);
                    cmd.Parameters.AddWithValue("@UPC", item.UPC);
                    result = int.Parse(cmd.ExecuteNonQuery().ToString());
                    cmd.Dispose();
                }
            }
            return(result > 0);
        }
コード例 #11
0
 /// <summary>
 /// Removes all of a given item from the cart
 /// </summary>
 /// <param name="item">The item to remove all of</param>
 /// <returns>True if items were removed, otherwise false</returns>
 public bool RemoveAllItems(ItemDTO item)
 {
     return(Items.Remove(Items.Find(x => x.Item.Equals(item))));
 }
コード例 #12
0
 /**
  * This method checks to see if a pLU and item are valid input for update into iDA. If so,
  * the item is updated into iDA via a call to UpdateItem();
  * @param UPC of item to be updated
  * @param item object being updated
  * @return boolean detailing if operation was carried out
  */
 public bool UpdateItem(string uPC, ItemDTO itemDTO)
 {
     return(iDA.UpdateItem(uPC, itemDTO));
 }
コード例 #13
0
 /// <summary>
 /// This method updates a specificed item with a new category
 /// </summary>
 /// <param name="item">itemDTO of the item we are trying to update</param>
 /// <param name="category">is the category to update the item to</param>
 /// <returns></returns>
 public bool UpdateItemCategory(ItemDTO item, CategoryDTO category)
 {
     return(iDA.UpdateItemCategory(item, category));
 }