/// <summary>
        /// Validates all user inputs, then deletes given record
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnInventoryDeleteGo_Click(object sender, EventArgs e)
        {
            // Create a temporary inventory object.
            Inventory  inv = new Inventory();
            Validation val = new Validation();

            //Running validation and saving validated input to object class
            inv.InvID = val.numValidate(txtIDInventoryDelete.Text);

            //If input is valid...
            if (inv.InvID != -1)
            {
                //Bool to check whether given ID exists in database
                bool idExist = false;

                //Creating List to hold all inventory objects.
                List <Inventory> allInventory = new List <Inventory>();

                //Get all items from the inventory table.
                allInventory = InventorySQL.LoadInventory();

                //Loops through database and checks to see if given ID exists
                foreach (Inventory i in allInventory)
                {
                    if (i.InvID == inv.InvID)
                    {
                        idExist = true;

                        //Fills out item name of inventory if ID is found
                        inv.ItemName = i.ItemName;
                    }
                }

                //If ID is found, deletes record and displays conformation message
                if (idExist == true)
                {
                    InventorySQL.DeleteInventory(inv);
                    MessageBox.Show("Successfully deleted " + inv.ItemName);
                }
                //Else program will cancel the delete, and display error message
                else
                {
                    MessageBox.Show("Delete cancelled; provided ID could not be found in database.");
                }
            }
            //Else program will cancel the delete, and display error message
            else
            {
                MessageBox.Show("Delete cancelled due to error in Inventory ID field." +
                                "\n\nPlease ensure field is not empty and has proper input.");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// On form load, loads all records from database and displays them in data grid. (Also called by Refresh button)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InventoryMain_Load(object sender, EventArgs e)
        {
            //Resetting search box for Refresh button
            txtBoxSearchInventoryItemName.Text = "";
            txtBoxSearchInventoryID.Text       = "";
            txtBoxSearchInventoryPrice.Text    = "";

            //Creating List to hold all inventory objects.
            List <Inventory> allInventory = new List <Inventory>();

            //Get all items from the inventory table.
            allInventory = InventorySQL.LoadInventory();

            //Creating DataTable object to present the Inventory Table from the database.
            DataTable inventoryTable = new DataTable();

            //Adding the Rows that we are going to display.
            inventoryTable.Columns.Add("InvID");
            inventoryTable.Columns.Add("ItemName");
            inventoryTable.Columns.Add("Price");

            //Adding object from the allInventory list as row in our Data Table.
            foreach (var item in allInventory)
            {
                inventoryTable.Rows.Add(item.InvID, item.ItemName, item.Price);
            }
            //Filling our Data Table in a DataView so we can give it to our DataGrid.
            inventoryView = new DataView(inventoryTable);

            //Dynamically adjust the width of the DataGrid depending on how many columns we have.
            dataGridInventory.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            //Adding the DataView with our Inventory to the DataGrid
            dataGridInventory.DataSource = inventoryView;

            //Making the DataGrid read only.
            dataGridInventory.ReadOnly = true;

            //Removing the option for users to add directly into the database.
            dataGridInventory.AllowUserToAddRows = false;
        }
Exemplo n.º 3
0
        private void OrderItemSearch_Load(object sender, EventArgs e)
        {
            //Get all items from the inventory table.
            allInventory = InventorySQL.LoadInventory();

            //Get all customers from the database.
            allOrderItems = OrderItemSQL.LoadOrderItems();

            //Creating DataTable object to present the OrderItem Table from the database.
            DataTable orderItemTable = new DataTable();

            //Adding the Rows that we are going to display.
            orderItemTable.Columns.Add("InvID");
            orderItemTable.Columns.Add("ItemName");
            orderItemTable.Columns.Add("Price");

            //Adding object from the allInventory list as row in our Data Table.
            foreach (var item in allInventory)
            {
                orderItemTable.Rows.Add(item.InvID, item.ItemName, item.Price);
            }

            //Filling our Data Table in a DataView so we can give it to our DataGrid.
            orderItemView = new DataView(orderItemTable);

            //Dynamically adjust the width of the DataGrid depending on how many columns we have.
            dataGridOrderItemSearch.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            //Adding the DataView with our Inventory to the DataGrid
            dataGridOrderItemSearch.DataSource = orderItemView;

            //Making the DataGrid read only.
            dataGridOrderItemSearch.ReadOnly = true;

            //Removing the option for users to add directly into the database.
            dataGridOrderItemSearch.AllowUserToAddRows = false;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Validates all user inputs, then saves new item to inventory table
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnInventoryAddGo_Click(object sender, EventArgs e)
        {
            //Creating needed classes
            Inventory  inv = new Inventory();
            Validation val = new Validation();

            //Running validation and saving validated input to object class
            inv.ItemName = txtNameInventoryAdd.Text;
            inv.Price    = val.moneyValidate(txtPriceInventoryAdd.Text);

            //If all input is valid (returns something other than "" or -1) saves results and displays conformation message
            if (inv.ItemName != "" && inv.Price != -1)
            {
                InventorySQL.SaveInventory(inv);
                MessageBox.Show("Successfully saved item " + inv.ItemName +
                                "\nwith price of " + inv.Price);
            }
            //Else program will cancel the save, and display text fields that caused the error
            else
            {
                string error = "Add canceled due to error in the following fields:";

                if (inv.ItemName == "")
                {
                    error += " \n   Item Name";
                }

                if (inv.Price == -1)
                {
                    error += " \n   Price";
                }

                error += " \n \nPlease ensure all fields are not empty and have proper input.";

                MessageBox.Show(error);
            }
        }
Exemplo n.º 5
0
        private void btnOrderItemAddGo_Click(object sender, EventArgs e)
        {
            bool ordCheck = false;
            bool invCheck = false;

            //Creating needed classes
            OrderItem  ordItem = new OrderItem();
            Validation val     = new Validation();

            //Running validation and saving validated input to object class
            ordItem.invId   = val.numValidate(txtInvIDOrderItemAdd.Text);
            ordItem.orderId = val.numValidate(txtOrderIDOrderItemAdd.Text);

            //Creating List to hold all inventory objects.
            List <Inventory> allInventory = new List <Inventory>();

            //Get all items from the inventory table.
            allInventory = InventorySQL.LoadInventory();

            foreach (Inventory i in allInventory)
            {
                if (i.InvID == ordItem.invId)
                {
                    invCheck = true;
                }
            }

            //Creating List to hold all order objects.
            List <Orders> allOrders = new List <Orders>();

            //Get all orders from the database.
            allOrders = OrdersSQL.LoadOrders();

            foreach (Orders o in allOrders)
            {
                if (o.OrderID == ordItem.orderId)
                {
                    ordCheck = true;
                }
            }

            //If all input is valid (returns something other than -1) saves results and displays conformation message
            if (ordItem.invId != -1 && ordItem.orderId != -1 && invCheck == true && ordCheck == true)
            {
                bool idCheck = false;

                //Creating List to hold all customer objects.
                List <OrderItem> allOrderItems = new List <OrderItem>();

                //Get all customers from the database.
                allOrderItems = OrderItemSQL.LoadOrderItems();

                foreach (OrderItem oi in allOrderItems)
                {
                    if (oi.orderId == ordItem.orderId && oi.invId == ordItem.invId)
                    {
                        idCheck = true;
                    }
                }

                if (idCheck == false)
                {
                    OrderItemSQL.SaveOrderItem(ordItem);
                    MessageBox.Show("Successfully added connection between Inventory ID " + ordItem.invId + " and Order ID " + ordItem.orderId);
                }
                else
                {
                    MessageBox.Show("Add cancelled; provided IDs already exist in database.");
                }
            }
            else if (ordItem.invId == -1 || ordItem.orderId == -1)
            {
                string error = "Add canceled due to error in the following fields:";

                if (ordItem.invId == -1)
                {
                    error += " \n   Inventory ID";
                }

                if (ordItem.orderId == -1)
                {
                    error += " \n   Order ID";
                }

                error += " \n \nPlease ensure all fields are not empty and have proper input.";

                MessageBox.Show(error);
            }
            else
            {
                string error = "Add canceled; the IDs input for the following text fields were not found:";

                if (ordCheck == false)
                {
                    error += "\n   Order ID";
                }

                if (invCheck == false)
                {
                    error += "\n   Inventory ID";
                }

                error += "\n\nPlease ensure that all fields have existing IDs.";

                MessageBox.Show(error);
            }
        }