public static void PercentageFillerAll(InventoryList inList)
 {
     for (int i = 0; i < inList.Count; i++)
     {
         PercentageFillerSingle(inList, i);
     }
 }
        private void Update_Home(object sender, RoutedEventArgs e)
        {
            // Update the inventory list with the new stock
            inventoryList[itemIndex] = tempInventoryItem;
            // Calculate the new percentage based on the new stock
            InventoryList.PercentageFillerSingle(inventoryList, itemIndex);
            // reset the global item index
            Global.SetIndex(-1);

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

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

            // create a new instance of the main window
            Window mainWindow = new MainWindow();

            // Show the new instance of the main window
            mainWindow.Show();
            // Close the instance of the iterative update window
            this.Close();
        }
Exemple #3
0
        //returns the index of the match if match is found, otherwise returns -1
        //if -1 returned, then ensure invalid entry window is opened.
        internal static int InventoryListSearch(String itemName)
        {
            //gets the inventorylist to be used for checking for item name match
            InventoryList inventoryList = ((App)Application.Current).GetInventoryList();

            //sets the index to an out of range value
            index = -1;

            for (int i = 0; i < inventoryList.Count; i++)
            {
                if (string.Compare(inventoryList[i].ItemName, itemName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    //sets the index to match the index of the match
                    index = i;
                }
            }

            //if there is no matches, set the errorIndex so that message in invalid entry window
            //reflects no matches
            if (index == -1)
            {
                errorIndex = 5;
            }

            //returns index
            return(index);
        }
 // Method to run the percentage fill single method on all the inventorylist rows
 public static void PercentageFillerAll(InventoryList inList)
 {
     // goes through every row in the inventory list
     for (int i = 0; i < inList.Count; i++)
     {
         // calclulates the perfect
         PercentageFillerSingle(inList, i);
     }
 }
Exemple #5
0
        private void Submit_button(object sender, RoutedEventArgs e)
        {
            inventoryList[itemIndex] = tempInventoryItem;
            InventoryList.PercentageFillerSingle(inventoryList, itemIndex);
            Window mainWindow = new MainWindow();

            mainWindow.Show();
            this.Close();
        }
        private void Submit_Add_Button(object sender, RoutedEventArgs e)
        {
            inventoryList.Add(tempInventoryItem);
            InventoryList.PercentageFillerSingle(inventoryList, inventoryList.Count - 1);
            Window mainWindow = new MainWindow();

            mainWindow.Show();
            this.Close();
        }
        /*
         * public static InventoryList FillInventoryListFromExcel()
         * {
         *  InventoryList inList = new InventoryList();
         *  Excel.Application xlapplication = new Excel.Application();
         *  xlapplication.Visible = false;
         *  System.IO.DirectoryInfo myDirectory = new DirectoryInfo(Environment.CurrentDirectory);
         *  string gparent = myDirectory.Parent.Parent.FullName;
         *  gparent += "\\InventoryDatabase.xlsx";
         *  Excel.Workbook xlworkbook = xlapplication.Workbooks.Open(@gparent);
         *  Excel.Worksheet xlworksheet = (Excel.Worksheet)xlworkbook.Sheets[1];
         *  Excel.Range xlrange = xlworksheet.UsedRange;
         *
         *  int rowCount = xlrange.Rows.Count;
         *  int colCount = xlrange.Columns.Count;
         *
         *  //excel not zero based; skip first row of excel worksheet
         *  for (int row = 2; row <= rowCount; row++)
         *  {
         *      inList.Add(new InventoryItem((String)xlrange.Cells[row, 1].Value2, (int)xlrange.Cells[row, 2].Value2, (int)xlrange.Cells[row, 3].Value2));
         *  }
         *
         *  //garbage collection
         *  GC.Collect();
         *  GC.WaitForPendingFinalizers();
         *
         *  xlworkbook.Save();
         *
         *  //release com objects to fully kill excel process from running in the background
         *  Marshal.ReleaseComObject(xlrange);
         *  Marshal.ReleaseComObject(xlworksheet);
         *
         *  //close and release
         *  xlworkbook.Close();
         *  Marshal.ReleaseComObject(xlworkbook);
         *
         *  //quit and release
         *  xlapplication.Quit();
         *  Marshal.ReleaseComObject(xlapplication);
         *
         *  //fills in the percentages
         *  PercentageFillerAll(inList);
         *
         *  return inList;
         * }
         */

        public static void PrintInventoryList(InventoryList inList)
        {
            Console.WriteLine("Capacity: {0}", inList.Capacity);
            Console.WriteLine("Count: {0}", inList.Count);

            for (int i = 0; i < inList.Count; i++)
            {
                Console.WriteLine("Item Name: " + inList[i].ItemName + " Current Stock: " + inList[i].CurrentStock + " Ideal Stock: " + inList[i].IdealStock);
            }
        }
Exemple #8
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();
            }
        }
        public static void WriteFullInventoryListToCSV(InventoryList inList)
        {
            System.IO.DirectoryInfo myDirectory = new DirectoryInfo(Environment.CurrentDirectory);
            string gparent = myDirectory.Parent.Parent.FullName;

            gparent += "\\InventoryDatabase.csv";
            var writer = new StreamWriter(@gparent);

            for (int i = 0; i < inList.Count; i++)
            {
                writer.WriteLine(string.Format("{0},{1},{2}", inList[i].ItemName, inList[i].CurrentStock, inList[i].IdealStock));
                writer.Flush();
            }
            writer.Close();
        }
        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();
            }
        }
        public static InventoryList FillInventoryListFromCSV()
        {
            InventoryList inList = new InventoryList();

            System.IO.DirectoryInfo myDirectory = new DirectoryInfo(Environment.CurrentDirectory);
            string gparent = myDirectory.Parent.Parent.FullName;

            gparent += "\\InventoryDatabase.csv";
            var reader = new StreamReader(@gparent);

            while (!reader.EndOfStream)
            {
                string   line = reader.ReadLine();
                string[] data = line.Split(',');

                inList.Add(new InventoryItem(data[0], Int32.Parse(data[1]), Int32.Parse(data[2])));
            }
            reader.Close();
            PercentageFillerAll(inList);

            return(inList);
        }
        public static InventoryList FillInventoryListFromSQL()
        {
            // creates an inventory list object
            InventoryList inList = new InventoryList();

            // sql reader object to get all the rows from the query
            using (SQLiteConnection conn = new SQLiteConnection(App.databasePath))
            {
                conn.CreateTable <Inventory>();

                foreach (Inventory item in conn.Table <Inventory>().ToList())
                {
                    inList.Add(new InventoryItem(item.Product, item.Actual, item.Ideal));
                }
            }

            // calculate the stock percentages for all the items in the inventory list
            PercentageFillerAll(inList);

            // Sorts by the item name!
            SortByItemName(inList);

            return(inList);
        }
Exemple #13
0
 // behaviour when the program is started
 protected override void OnStartup(StartupEventArgs e)
 {
     base.OnStartup(e);
     // populate the instance of the inventory item list on start up
     inventoryList = InventoryList.FillInventoryListFromSQL();
 }
 //this sorts the inventorylist in descending item name
 public static void SortByItemName(InventoryList inList)
 {
     inList.InnerList.Sort(new myComparer());
 }
Exemple #15
0
        internal static bool IsValid(String Name, String CurrentStock, String IdealStock)
        {
            //gets the inventorylist to be used for checking for duplications
            InventoryList inventoryList = ((App)Application.Current).GetInventoryList();


            // *********data validation*******************//
            bool valid = true;
            bool isNumeric;


            // If length of the item length is greater than 40 or less than 1 its not valid
            if (Name.Length > 40 || Name.Length < 1)
            {
                valid      = false;
                errorIndex = 0;
            }

            // not valid if not a number
            // if invalid already, skip
            if (valid)
            {
                isNumeric = int.TryParse(CurrentStock, out _);
                if (!isNumeric)
                {
                    valid      = false;
                    errorIndex = 1;
                }
            }

            // if invalid already, skip
            if (valid)
            {
                isNumeric = int.TryParse(IdealStock, out _);
                if (!isNumeric)
                {
                    valid      = false;
                    errorIndex = 2;
                }
            }

            //not valid if idealstock is 0
            // if invalid already, skip
            if (valid)
            {
                if (Int32.Parse(IdealStock) == 0)
                {
                    valid      = false;
                    errorIndex = 3;
                }
            }

            // checking if item will be a duplicate
            // if invalid already, skip
            if (valid)
            {
                for (int i = 0; i < inventoryList.Count; i++)
                {
                    //if (Name.Equals(inventoryList[i].ItemName)){ //exact matching
                    //case insensitive check for duplicates
                    if (i != index)
                    {
                        if (string.Compare(inventoryList[i].ItemName, Name, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            valid      = false;
                            errorIndex = 4;
                        }
                    }
                }
            }

            // if not valid then InvalidEntry popup window
            if (!valid)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemple #16
0
 protected override void OnStartup(StartupEventArgs e)
 {
     base.OnStartup(e);
     //inventoryList = InventoryList.FillInventoryListFromExcel();
     inventoryList = InventoryList.FillInventoryListFromCSV();
 }
        private void Update_Next(object sender, RoutedEventArgs e)
        {
            // Stores the inventory
            inventoryList[itemIndex] = tempInventoryItem;
            InventoryList.PercentageFillerSingle(inventoryList, itemIndex);
            // Increments to the next item in the inventory list
            itemIndex++;

            // If we're at the end of the inventory list
            if (itemIndex > inventoryList.Count - 1) // greater than total number of items in list, then at end of list
            {
                // reset the global item index
                Global.SetIndex(-1);

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

                    Inventory m = (from p in conn.Table <Inventory>()
                                   where p.Product == ProductNameTextBlock.Text
                                   select p).FirstOrDefault();
                    if (m != null)
                    {
                        m.Actual = Convert.ToInt32(UpdateIdealTextBox.Text);
                        conn.Update(m);
                        //Console.WriteLine("This ran");
                    }
                }

                // create a new instance of the main window
                Window mainWindow = new MainWindow();
                // show the instance of the main window
                mainWindow.Show();
                // close the full iterative update window
                this.Close();
            }
            // if we're not at the end yet
            else
            {
                // set the global item index to the incremented index
                Global.SetIndex(itemIndex);

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

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

                // create a new instance of the iterative update window
                Window iterativeUpdateWindow = new Iterative_Update_Window();
                // show the instance of the iterative update window
                iterativeUpdateWindow.Show();
                // close the previous instance of the iterative update window
                this.Close();
            }
        }
 public static void FillAdditionalSampleItems(InventoryList inList)
 {
     inList.Add(new InventoryItem("Computer", 3, 5));
     inList.Add(new InventoryItem("Monitor", 2, 3));
     inList.Add(new InventoryItem("Keyboard", 3, 4));
 }
 public static void PercentageFillerSingle(InventoryList inList, int i)
 {
     inList[i].Percentage = 100 * inList[i].CurrentStock / inList[i].IdealStock;
 }