/*  Inputs order data into database and resets the form
         *  ***************************************/
        private void submitOrderBtn_Click(object sender, EventArgs e)
        {
            int employeeID = currentUser.getID();     // Get from stored variable when login working

            string findMaxIDQuery = "SELECT MAX(orderID) FROM MaterialOrder LIMIT 1";
            string maxOrderID     = dbconn.getString(findMaxIDQuery);
            int    orderID        = Convert.ToInt32(maxOrderID) + 1;

            foreach (TempOrderInfo item in orderInfo)
            {
                string insertQuery = "INSERT INTO MaterialOrder (orderID, orderDate, itemID, quantity, employeeID, jobCode) " +
                                     "VALUES(" + orderID + ", CURDATE(), " + item.itemNumber + ", " + item.quantity + ", " + employeeID + ", " + item.jobCode + ")";

                bool querySuccess = dbconn.Insert(insertQuery); // Error here - runQuery always returns true but insert is failing

                // Handle query failure
                if (!querySuccess)
                {
                    MessageBox.Show("Failed to place order. Please contact system administrator if problem persists.", "Order Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    break;  // Kick out of for loop if error encountered
                }
            }

            MessageBox.Show("Order placed successfully.", "Order Placed", MessageBoxButtons.OK, MessageBoxIcon.Information);
            resetForm();
        }
        private void btnSubmitOrder_Click(object sender, EventArgs e)
        {
            int employeeID = currentUser.getID();     // Get from stored variable when login working

            string findMaxIDQuery = "SELECT MAX(rentalID) FROM EquipmentRental LIMIT 1";
            string maxOrderID     = db.getString(findMaxIDQuery);
            int    orderID        = Convert.ToInt32(maxOrderID) + 1;

            foreach (TempOrderInfo item in orderInfo)
            {
                int    setAvailable = (Convert.ToInt32(db.getInt("SELECT available FROM Equipment WHERE equipmentID='" + item.itemNumber + "';") - Convert.ToInt32(item.quantity)));
                string insertQuery  = "INSERT INTO EquipmentRental (rentalID, rentalDate, rentalDue, employeeID, equipmentID, quantity, jobCode) " +
                                      "VALUES(" + orderID + ", CURDATE(), NOW()+INTERVAL 7 DAY,'" + employeeID + "'," + item.itemNumber + ", " + item.quantity + ", " + item.jobCode + "); ";
                db.Update("UPDATE Equipment SET available = '" + setAvailable.ToString() + "' WHERE equipmentID= '" + item.itemNumber + "';");

                //If equipment availability is 0 then set to Out of Stock
                if (setAvailable == 0)
                {
                    db.Insert("UPDATE Equipment SET equipmentStatus = 'Out of Stock' WHERE equipmentID = '" + item.itemNumber + "'");
                }

                bool querySuccess = db.Insert(insertQuery); // Error here - runQuery always returns true but insert is failing

                // Handle query failure
                if (!querySuccess)
                {
                    MessageBox.Show("Failed to place order. Please contact system administrator if problem persists.", "Order Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    break;  // Kick out of for loop if error encountered
                }
            }

            MessageBox.Show("Order placed successfully.", "Order Placed", MessageBoxButtons.OK, MessageBoxIcon.Information);
            resetAll();
            //Reduce available to available -quantity on Equipment table


            //If quantity = 0 then equipmentStatus will change to Out of Stock


            /*Create findMaxIDQuery = "SELECT MAX(orderID) FROM MaterialOrder LIMIT 1";
             *
             *  string maxOrderID = dbconn.getString(findMaxIDQuery);
             *
             *  int orderID = Convert.ToInt32(maxOrderID) + 1
             *
             *      INSERT INTO EquipmentRental (rentalID, rentalDate, rentalDue, employeeID, equipmentID, quantity, jobCode) VALUES
             *      (1, NOW(), DATE_ADD(NOW(), INTERVAL 7 DAY), 1, 1, 2, 12345);
             *
             */
        }
Exemple #3
0
 private void EquipReturn_Load(object sender, EventArgs e)
 {
     txtReturnEID.Text         = currentUser.getID().ToString();
     comboStatus.SelectedIndex = 0;
     txtReturnItem.Select();
 }