private void btnUpdate_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to commit these changes?", "Confirmation", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                //Update database with correseponding information
                int    rank     = Convert.ToInt32(cbRank.Text);
                string fname    = txtFirst.Text;
                string lname    = txtLast.Text;
                string username = txtUsername.Text;
                string status   = cboStatus.Text;
                int    id       = selectedID;

                string query = "UPDATE Employees SET firstName = '" + fname + "', lastName ='" + lname + "', username = '******', rank =" + rank + ", employeeStatus = '" + status + "' WHERE employeeID =" + id + ";";
                if (db.Update(query))
                {
                    MessageBox.Show("Successfully updated user.");
                    resetFields();
                }
                else
                {
                    MessageBox.Show("An error occurred while updating this employees data. Contact Technicial Support. ID # ID10T");
                }
            }
        }
Esempio n. 2
0
        private void btnReturnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                //Pulls values from right side jobCode and rentalID for insert query
                string insert1 = lblChkBox1.Text;
                string insert2 = lblChkBox2.Text;
                string insert3 = lblChkBox3.Text;
                string insert4 = lblRentalID.Text = "...";
                string insert5 = lblJobCode.Text = "...";


                /*
                 * string isReturnedChk = "SELECT returnDate FROM EquipmentRental WHERE equipmentID LIKE '%" + insert2 + "%' AND employeeID LIKE '%" + insert3 + "%' AND jobCode LIKE '%" + insert4 + "%' AND rentalID LIKE '%" + insert5 + "%'";
                 * string checkReturn = mydb.getString(isReturnedChk);
                 *
                 * if (checkReturn != null)
                 * {
                 */
                string query3 = "UPDATE CEIS400.EquipmentRental SET returnDate=NOW() WHERE equipmentID='" + insert2 + "' AND employeeID='" + insert3 + "' AND jobCode='" + insert4 + "' AND rentalID='" + insert5 + "'";
                mydb.Update(query3);
                string query4 = "UPDATE CEIS400.Equipment SET available=available+1 WHERE equipmentStatus='" + insert1 + "' AND equipmentID= '" + insert2 + "'";
                mydb.Update(query4);

                /*
                 * }
                 * else
                 * {
                 *  MessageBox.Show("This item has already been returned.");
                 * }
                 */
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //Empties field so it is ready for another return
            lblChkBox1.Text = "";
            lblChkBox2.Text = "";
            lblChkBox3.Text = "";
            MessageBox.Show("Return complete");
        }
        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);
             *
             */
        }