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);
             *
             */
        }
        /*  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 btnAddNewUser_Click(object sender, EventArgs e)
        {
            //set variables
            string first, last, status, rank, username, password;

            first    = txtAddFName.Text;
            last     = txtAddLName.Text;
            rank     = cbAddRank.Text;
            status   = cbNewStatus.Text;
            username = txtAddUsername.Text;
            password = txtAddPassword.Text;

            //encrypt password
            password = db.encrypt(password);


            //Attempt to insert into database
            string query = "INSERT INTO Employees(firstName, lastName, username, userPass, rank, employeeStatus) " +
                           " VALUES ('" + first + "', '" + last + "', '" + username + "', '" + password + "', " + rank + ", '" + status + "')";

            if (db.Insert(query))
            {
                MessageBox.Show("Employee was successfully added.");
            }
            else
            {
                MessageBox.Show("An error has occured while connecting to the database. Please contact Technicial Support.");
            }
        }
示例#4
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //Testing insert
            bool isInserted;

            isInserted = db.Insert(txtItemNumber.Text);
            MessageBox.Show("Result of insert is: " + isInserted);
        }