Example #1
0
        // logic for pushing any changes through to the inventory list
        private void Submit_button(object sender, RoutedEventArgs e)
        {
            /*
             *   Data Validation on the text boxes
             *
             *       true => modify file
             *       false => invalidEntry window
             */

            // checks all the fields in the textboxes using validation inside of the global class
            if (Global.IsValid(EditItemNameBox.Text, EditItemCurrentStockBox.Text, EditItemIdealStockBox.Text))
            {
                // replaces the row with in the inventory list with the modified inventory item using the global itemIndex
                inventoryList[itemIndex] = tempInventoryItem;
                // calclulates the percentage by sending the inventorylist and index of the row
                InventoryList.PercentageFillerSingle(inventoryList, itemIndex);

                using (SQLiteConnection conn = new SQLiteConnection(App.databasePath))
                {
                    conn.CreateTable <Inventory>();

                    Inventory m = (from p in conn.Table <Inventory>()
                                   where p.Product == EditItemNameBox.Text
                                   select p).FirstOrDefault();
                    if (m != null)
                    {
                        m.Product = EditItemNameBox.Text;
                        m.Actual  = Convert.ToInt32(EditItemCurrentStockBox.Text);
                        m.Ideal   = Convert.ToInt32(EditItemIdealStockBox.Text);
                        conn.Update(m);
                    }
                }

                // sorts the newly edited inventory list to ensure items are in descending alphabetical order
                InventoryList.SortByItemName(inventoryList);
                // creates a new instance of the main window
                Window mainWindow = new MainWindow();
                // shows the new instance of the main window
                mainWindow.Show();
                // closes the instance of the edit item window
                this.Close();
            }
            else
            {
                // create an instance of the invalid entry window
                Window invalidEntry = new InvalidEntry();
                // show it, however the edit item window is not closed
                invalidEntry.Show();
            }
        }
        private void Submit_Add_Button(object sender, RoutedEventArgs e)
        {
            /*
             *   Data Validation on the text boxes
             *
             *       true => add item
             *       false => invalidEntry window
             */

            if (Global.IsValid(AddItemNameBox.Text, AddItemCurrentStockBox.Text, AddItemIdealStockBox.Text))
            {
                // Uses add method from inventoryList class to add the data in textboxes to inventory list
                inventoryList.Add(tempInventoryItem);
                // Calculates the percentage for the new item added to the inventory
                InventoryList.PercentageFillerSingle(inventoryList, inventoryList.Count - 1);

                using (SQLiteConnection conn = new SQLiteConnection(App.databasePath))
                {
                    Inventory inventory = new Inventory()
                    {
                        Product = AddItemNameBox.Text,
                        Actual  = Convert.ToInt32(AddItemCurrentStockBox.Text),
                        Ideal   = Convert.ToInt32(AddItemIdealStockBox.Text)
                    };

                    conn.CreateTable <Inventory>();
                    conn.Insert(inventory);
                }

                // sorts the inventorylist again
                InventoryList.SortByItemName(inventoryList);
                // Creates a new instance of the main window
                Window mainWindow = new MainWindow();
                // Shows the new instance of the main window
                mainWindow.Show();
                // Closes the instance of the add item window
                this.Close();
            }
            else
            {
                // create an instance of the invalid entry window
                Window invalidEntry = new InvalidEntry();
                // show it, however the edit item window is not closed
                invalidEntry.Show();
            }
        }