/** * @desc This method will save or update an equipment booking in the EQUIPMENT_BOOKINGS table * @params [none] No input parameter. * @return [bool] Returns true in case of success, false if there was problem saving/updating the equipment */ public bool SaveEquipmentBooking() { string query; // Create mysql connection mySqlConn conn = new mySqlConn(); conn.connect(); // Check whether there is a new id_eq_booking assigned to this booking, // if not then this a new equipment booking to save if (this.Id_eq_booking == -1) { // Create the save query query = "insert into `gym`.`equipment_bookings` (`id_eq_booking`, `id_staff`, `id_member`, `id_class_instance`, `date_start`, `date_due`, `id_equipment`, `borrowedamount`,`isreturned`) values " + "(NULL, " + this.Id_staff + ", " + this.Id_member + ", " + this.Id_class_instance + ", '" + this.DateStart + "', '" + this.DateDue + "', " + this.Id_equipment + ", " + this.BorrowedAmount + ", NULL)"; // Launch save query int id_eq_booking = conn.InsertToDB(query); // Check saving result if (id_eq_booking != -1) { this.Id_eq_booking = id_eq_booking; MessageBox.Show("The new equipment booking has been added to the databse succesfully!"); return true; } else { MessageBox.Show("There was a problem adding the new equipment booking, please check your data!"); return false; } } // If an id_eq_booking already exists for this booking, then this is an existing booking to update else { // Create update query query = "UPDATE `gym`.`equipment_bookings` SET `borrowedamount` = " + this.BorrowedAmount + ", `isreturned`= " + this.IsReturned + " WHERE id_eq_booking = '" + this.Id_eq_booking + "'"; // Launch update query int result = conn.DeleteOrUpdate(query); // Check update result if (result > 0) { MessageBox.Show("The equipment booking data has been updated succesfully!"); return true; } else { MessageBox.Show("There was a problem updating the equipment booking information, please check your data!"); return false; } } //return true; }
/** * @desc This method will save or update a user in the USERS table * @params [none] No input parameter. * @return [bool] Returns true in case of success, false if there was problem saving/updating the user */ public bool SaveUser() { // Create mysql connection mySqlConn conn = new mySqlConn(); conn.connect(); // If this is a new user if (this.Id_user == -1) { // Create insert query string query = "insert into users (id_user, login, password, profile, active) " + "values (NULL, '" + this.Login + "', MD5('" + this.Password + "'), '" + this.Profile + "', '" + ((this.isActive) ? "1" : "0") + "')"; // Launch insert query this.id_user = conn.InsertToDB(query); // Check result if (this.id_user > 0) return true; } // This is an existing user else { // Create update query string query = "UPDATE users SET login = '******', active = '" + ((this.isActive) ? "1" : "0") + "' "+ "WHERE id_user = '******'"; // Launch update query int result = conn.DeleteOrUpdate(query); // Check update result if (result > 0) return true; } return false; }
/** * @desc This method will save or update a class in the CLASS table * @params [none] No input parameter. * @return [bool] Returns true in case of success, false if there was problem saving/updating the class */ public bool SaveClass() { string query; // Checking user input if (this.Name == "") { MessageBox.Show("Please Insert a name."); } else { // Create mysql connection mySqlConn conn = new mySqlConn(); conn.connect(); // Check whether there is a new id_class assigned to this class, // if not then this a new class to save if (this.Id_class == -1) { // Create the save query query = "insert into `gym`.`classes` (`id_class`, `name`, `type`, `description`) values " + "(NULL, '" + this.Name + "', '" + this.Type + "', '" + this.Description + "')"; // Launch save query int id_class = conn.InsertToDB(query); // Check saving result if (id_class != -1) { this.Id_class = id_class; MessageBox.Show("The new class has been added to the databse succesfully!"); return true; } else { MessageBox.Show("There was a problem adding the new class, please check your data!"); return false; } } // If an id_class already exists for this class instance, then this is an existing class to update else { // Create update query query = "UPDATE classes SET name = '" + this.Name + "', description = '" + this.Description + "' " + " WHERE id_class = '" + this.Id_class + "'"; // Launch update query int result = conn.DeleteOrUpdate(query); // Check update result if (result > 0) { MessageBox.Show("The class data has been updated succesfully!"); return true; } else { MessageBox.Show("There was a problem updating the class information, please check your data!"); return false; } } } return false; }
/** * @desc This method will save or update an equipment in the EQUIPMENT table * @params [none] No input parameter. * @return [bool] Returns true in case of success, false if there was problem saving/updating the equipment */ public bool SaveEquipment() { string saveEquipmentQuery; // Checking user input if (this.Name == "") { MessageBox.Show("Please Insert a name."); } else { // Create mysql connection mySqlConn conn = new mySqlConn(); conn.connect(); // Check whether there is a new id_equipment assigned to this equipment, // if not then this a new equipment to save if (this.Id_equipment == -1) { // Create the save query saveEquipmentQuery = "insert into `gym`.`equipment` (`id_equipment`, `type`, `id_vehicle`, `name`, `description`, `iteminset1`, `iteminset2`, `iteminset3`, `iteminset4`, `iteminset5`, `amountinset1`, `amountinset2`, `amountinset3`, `amountinset4`, `amountinset5`) values " + "(NULL, '" + this.Type + "', '" + this.Id_vehicle + "', '" + this.Name + "', '" + this.Description + "', '" + this.ItemInSet1 + "', '" + this.ItemInSet2 + "', '" + this.ItemInSet3 + "', '" + this.ItemInSet4 + "', '" + this.ItemInSet5 + "', '" + this.AmountInSet1 + "', '" + this.AmountInSet2 + "', '" + this.AmountInSet3 + "', '" + this.AmountInSet4 + "', '" + this.AmountInSet5 + "')"; // Launch save query int id_equipment = conn.InsertToDB(saveEquipmentQuery); // Check saving result if (id_equipment != -1) { this.Id_equipment = id_equipment; MessageBox.Show("The new equipment has been added to the databse succesfully!"); return true; } else { MessageBox.Show("There was a problem adding the new equipment, please check your data!"); return false; } } // If an id_equipment already exists for this equipment, then this is an existing equipment to update else { // Create update query string updateEquimentQuery = "UPDATE equipment SET type = '" + this.Type + "', id_vehicle = '" + this.Id_vehicle + "', name = '" + this.Name + "', description = '" + this.Description + "', iteminset1 = '" + this.ItemInSet1 + "', iteminset2 = '" + this.ItemInSet2 + "', iteminset3 = '" + this.ItemInSet3 + "', iteminset4 = '" + this.ItemInSet4 + "', iteminset5 = '" + this.ItemInSet5 + "', amountinset1 = '" + this.AmountInSet1 + "', amountinset2 = '" + this.AmountInSet2 + "', amountinset3 = '" + this.AmountInSet3 + "', amountinset4 = '" + this.AmountInSet4 + "', amountinset5 = '" + this.AmountInSet5 + "' " + " WHERE id_equipment = '" + this.Id_equipment + "'"; // Launch update query int result = conn.DeleteOrUpdate(updateEquimentQuery); // Check update result if (result > 0) { MessageBox.Show("The equipment data has been updated succesfully!"); return true; } else { MessageBox.Show("There was a problem updating the equipment information, please check your data!"); return false; } } } return false; }
/** * @desc This method will save the object into the database * @return [bool] Returns true in case of success, false if there was a problem */ public bool SaveMember() { // Convert date into mysql format string mysqlDate = Utils.sGetMysqlDate(this.Birthdate); string query; // Check Birthdate format if (mysqlDate == "0000-00-00") { MessageBox.Show("The Date of Birth is in incorrect format!"); } // Check e-mail format else if (Utils.bValidateEmail(this.Email) == false) { MessageBox.Show("The E-Mail address is incorrect!"); } else { // First the user object is filled clUser.IsActive = (this.IsActive) ? true : false; clUser.Login = this.Email; clUser.Password = mysqlDate; clUser.Profile = "member"; // Create mysql connection mySqlConn conn = new mySqlConn(); conn.connect(); // If the User details were correctly saved if (clUser.SaveUser()) { // Check if there is a new picture to save if ((this.FilePath != null) && (this.FilePath.Length > 1)) { this.Id_file = conn.uploadFileToDB(this.FilePath, this.FileName); } // The insert query is launched in case of existing members only, not new members if (this.Id_member == -1) { // Create insert query query = "insert into `gym`.`members` (`id_member`, `firstName`, `lastName`, `birthdate`, `address_1`, `city`, `county`, `postalcode`, `type`, `id_user`, `is_active`, `address_2`, `emerg_contact_name`, `emerg_contact_relation`, `emerg_contact_phone`, `emerg_contact_mobile`, `medical_allergies`, `medical_notes`, `id_file`, `medical_doctor_name`, `medical_phone`, `email`, `member_number`, `phone`,`mobile`,`gender`) values " + "(NULL, '" + this.FirstName + "', '" + this.LastName + "', '" + mysqlDate + "', '" + this.Address_1 + "', '" + this.City + "', '" + this.County + "', '" + this.PostalCode + "', '" + this.Type + "', '" + clUser.Id_user + "', '" + ((this.IsActive) ? "1" : "0") + "', '" + this.Address_2 + "', '" + this.EmergContactName + "', '" + this.EmergContactRelation + "', '" + this.EmergContactPhone + "', '" + this.EmergContactMobile + "', '" + this.MedicalAllergies + "', '" + this.MedicalNotes + "', '" + this.Id_file + "', '" + this.MedicalDoctorName + "', '" + this.MedicalPhone + "', '" + this.Email + "', '" + this.MemberNumber + "','" + this.Phone + "','" + this.Mobile + "','" + this.Gender + "')"; // Launch insert query int id_member = conn.InsertToDB(query); // Check if the insert was successful if (id_member != -1) { this.Id_member = id_member; MessageBox.Show("The new member has been added to the databse succesfully!"); return true; } else { MessageBox.Show("There was a problem adding the new user, please check your data!"); clUser.DeleteUser(); return false; } } // This is a member update else { // Create update query query = "UPDATE members SET firstName = '" + this.FirstName + "', lastName = '" + this.LastName + "', birthdate = '" + mysqlDate + "', address_1 = '" + this.Address_1 + "', city = '" + this.City + "', county = '" + this.County + "', postalcode = '" + this.PostalCode + "', type = '" + this.Type + "', is_active = " + ((this.IsActive) ? "1" : "0") + ", address_2 = '" + this.Address_2 + "', emerg_contact_name = '" + this.EmergContactName + "', emerg_contact_relation = '" + this.EmergContactRelation + "', emerg_contact_phone = '" + this.EmergContactPhone + "', emerg_contact_mobile = '" + this.EmergContactMobile + "', medical_allergies = '" + this.MedicalAllergies + "', medical_notes = '" + this.MedicalNotes + "', id_file = '" + this.Id_file + "', medical_doctor_name = '" + this.MedicalDoctorName + "', medical_phone = '" + this.MedicalPhone + "', email = '" + this.Email + "', phone = '" + this.Phone + "', mobile = '" + this.Mobile + "', gender = '" + this.Gender + "' " + " WHERE id_member = '"+this.Id_member+"'"; // Launch update query int result = conn.DeleteOrUpdate(query); // Check if the update was successful if (result > 0) { MessageBox.Show("The member data has been updated succesfully!"); return true; } else { MessageBox.Show("There was a problem updating the user information, please check your data!"); clUser.DeleteUser(); return false; } } } // If the user saving was false, then it was becuase of duplicate e-mail at this point else { MessageBox.Show("The e-mail already exists in the database! Please choose another one."); return false; } } return false; }
/** * @desc This method will save or update a room in the ROOMS table * @params [none] No input parameter. * @return [bool] Returns true in case of success, false if there was problem saving/updating the class */ public bool SaveRoom() { string query; // Checking user input if (this.Name == "") { MessageBox.Show("Please Insert a name."); } else { // Create mysql connection mySqlConn conn = new mySqlConn(); conn.connect(); // Check whether there is a new id_room assigned to this room, // if not then this a new room to save if (this.Id_room == -1) { // Create insert query query = "insert into `gym`.`rooms` (`id_room`, `name`, `size`, `description`) values " + "(NULL, '" + this.Name + "', '" + this.Size + "', '" + this.Description + "')"; // Launch insert query int id_room = conn.InsertToDB(query); // Check saving result if (id_room != -1) { this.Id_room = id_room; MessageBox.Show("The new room has been added to the databse succesfully!"); return true; } else { MessageBox.Show("There was a problem adding the new room, please check your data!"); return false; } } // If an id_room already exists for this room instance, then this is an existing room to update else { // Create update query query = "UPDATE rooms SET name = '" + this.Name + "', size = '" + this.Size + "', description = '" + this.Description + "' " + " WHERE id_room = '" + this.Id_room + "'"; // Launch update query int result = conn.DeleteOrUpdate(query); // Check update reults if (result > -1) { MessageBox.Show("The room data has been updated succesfully!"); return true; } else { MessageBox.Show("There was a problem updating the room information, please check your data!"); return false; } } } return false; }
/** * @desc This method will save the object into the database * @return [bool] Returns true in case of success, false if there was a problem */ public bool SavePayment() { // If this is an existing member's payment if (this.ClMember.Id_member != -1) { // Create insert query string query = "insert into `gym`.`payments` (`id_payment`, `id_member`, `date`, `amount`, `details`,`receiptnumber`,`paymentmethod`,`receivedby`) values (NULL, '" + this.ClMember.Id_member + "', '" + this.Date + "', '" + this.Amount + "', '" + this.Details + "', '" + this.ReceiptNumber + "', '" + this.PaymentMethod + "', '" + this.ReceivedBy + "');"; // Create mysql connection mySqlConn conn = new mySqlConn(); conn.connect(); // Launch insert query int payment = conn.InsertToDB(query); // Check if the insert was succesful if (payment != -1) return true; } return false; }
/** * @desc This method will save or update a class instance in the CLASS_INSTANCE table * @params [none] No input parameter. * @return [bool] Returns true in case of success, false if there was problem saving/updating the class */ public bool SaveClassInstance() { // Create mysql connection mySqlConn conn = new mySqlConn(); conn.connect(); // SAVING THE CLASS INSTANCE INTO CLASS_INSTANCE // Check whether there is a new id_class_instance assigned to this class instance, // if not then this a new class to save if (this.Id_class_instance == -1) { // Create the save query string saveClInstanceQuery = "insert into `gym`.`class_instance` (`id_class_instance`, `id_class`, `id_staff`, `date`, `start_time`, `end_time`, `frequency`, `id_room`) values " + "(NULL, '" + this.ClClass.Id_class + "', '" + this.Id_staff + "', '" + Utils.sGetMysqlDate(this.DateStart) + "', '" + this.StartTime + "', '" + this.EndTime + "', '" + this.Frequency + "', '" + this.ClRoom.Id_room + "');"; // Launch save query int id_class_instance = conn.InsertToDB(saveClInstanceQuery); // Check saving result if (id_class_instance != -1) { this.Id_class_instance = id_class_instance; MessageBox.Show("The class has been saved!"); return true; } else { MessageBox.Show("There has been an error creating the class instance! Contact with your administrator."); } } // If an id_class_instance already exists for this class instance, then this is an existing class instance to update else { string updateClInstanceQuery = "UPDATE class_instance SET id_staff= '" + this.Id_staff + "', date = '" + Utils.sGetMysqlDate(this.DateStart) + "', start_time = '" + this.StartTime + "', end_time = '" + this.EndTime + "', frequency = '" + this.Frequency + "', id_room = '" + this.ClRoom.Id_room + "' " + "WHERE id_class_instance = '" + this.Id_class_instance + "'"; // Launch update query int result = conn.DeleteOrUpdate(updateClInstanceQuery); // Check update result if (result > 0) { MessageBox.Show("The class booking data has been updated succesfully!"); } else { MessageBox.Show("There was a problem updating the class booking information, please check your data!"); return false; } } // SAVING THE ATTENDANTS INTO CLASS_BOOKINGS // If there are any attendants save them into the CLASS_BOOKINGS table if (this.lclAttendants.Count > 0) { StringBuilder sbQueryClassBooking = new StringBuilder(); // Create the first half of the insert query containing so far only the fields sbQueryClassBooking.Append("insert into `gym`.`class_bookings` (`id_class_booking`, `id_member`, `id_class_instance`, `booking_date`) values "); int i = 0; // Create a string array storing each second half of the queries, that is the values of each booking string[] aQueryClassBookingValues = new string[this.lclAttendants.Count]; // Copy all values of each booking into each string in the array foreach (Member clMember in this.lclAttendants) { aQueryClassBookingValues[i] = "(NULL, '" + clMember.Id_member + "', '" + this.Id_class_instance + "', NOW())"; i++; } // It is possible to add more than one class booking into the CLASS_BOOKINGS table in the same query at the same time // so append each set of booking values one after the other at the end of the query, separated by comma sbQueryClassBooking.Append(string.Join(", ", aQueryClassBookingValues)); sbQueryClassBooking.Append(" ON DUPLICATE KEY UPDATE booking_date = booking_date"); int lastMemberId = conn.InsertToDB(sbQueryClassBooking.ToString()); if (lastMemberId != -1) { MessageBox.Show("The attendant has been enrolled!"); } } return true; }