Example #1
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;
        }
        private void OrderItemMain_Load(object sender, EventArgs e)
        {
            //Creating List to hold all customer objects.
            List <OrderItem> allOrderItems = new List <OrderItem>();

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

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

            //Adding the Rows that we are going to display.
            orderItemTable.Columns.Add("Order ID");
            orderItemTable.Columns.Add("Inventory ID");

            //Adding object from the allCustomers list as row in our Data Table.
            foreach (var orderItem in allOrderItems)
            {
                orderItemTable.Rows.Add(orderItem.orderId, orderItem.invId);
            }

            //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.
            dataGridOrderItem.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            //Adding the DataView with our Customers to the DataGrid
            dataGridOrderItem.DataSource = orderItemView;

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

            //Removing the option for users to add directly into the database.
            dataGridOrderItem.AllowUserToAddRows = false;
        }
Example #3
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);
            }
        }
        private void btnOrderItemDeleteGo_Click(object sender, EventArgs e)
        {
            //Creating needed classes
            OrderItem  ordItem = new OrderItem();
            Validation val     = new Validation();

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

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

                //Creating List to hold all customer objects.
                List <OrderItem> allOrderItems = new List <OrderItem>();
                //Get all customers from the database.
                allOrderItems = OrderItemSQL.LoadOrderItems();

                //Loops through database and checks to see if given ID exists
                foreach (OrderItem oi in allOrderItems)
                {
                    if (oi.orderId == ordItem.orderId && oi.invId == ordItem.invId)
                    {
                        idExist = true;
                    }
                }

                //If ID is found, deletes record and displays conformation message
                if (idExist == true)
                {
                    OrderItemSQL.DeleteOrderItem(ordItem);
                    MessageBox.Show("Successfully deleted connection between Order ID " + ordItem.orderId + " and Inventory ID " + ordItem.invId);
                }
                //Else program will cancel the delete, and display error message
                else
                {
                    MessageBox.Show("Delete cancelled; provided IDs could not be found in database.");
                }
            }
            //Else program will cancel the delete, and display error message
            else
            {
                string error = "Delete 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);
            }
        }