/** * @desc This method executes when "Save" button is clicked and IsBooking is true * It checks to whom the booking will be for, checks user input and then calls for saving the new booking * @params [none] No input parameter. * @return [none] No directly returned data. */ private void save_eq_booking() { // Instantiate new booking this.clEquipmentBooked = new EquipmentBooked(); // Pass the equipment id to borrow clEquipmentBooked.Id_equipment = clEquipment.Id_equipment; // If this is a member booking if ((Id_staff == -1)&&(Id_class_instance == -1)) { // Store the member id only clEquipmentBooked.Id_member = this.Id_member.ToString(); clEquipmentBooked.Id_staff = "NULL"; clEquipmentBooked.Id_class_instance = "NULL"; } // Else If this is a staff booking else if (Id_class_instance == -1) { // Store the staff id only clEquipmentBooked.Id_member = "NULL"; clEquipmentBooked.Id_staff = this.Id_staff.ToString(); clEquipmentBooked.Id_class_instance = "NULL"; } // Else this is a class instance booking else { // Store the class instance id only clEquipmentBooked.Id_member = "NULL"; clEquipmentBooked.Id_staff = "NULL"; clEquipmentBooked.Id_class_instance = this.Id_class_instance.ToString(); } // Set the date start for today by default DateTime today = DateTime.Today; clEquipmentBooked.DateStart = String.Format("{0:yyyy-MM-dd}", today); // Add to the start date the number of days the user selected to ccreate return date if (counter_amounttoborrow.Value > 0) { clEquipmentBooked.DateDue = String.Format("{0:yyyy-MM-dd}", today.AddDays(double.Parse(counter_numberofdays.Value.ToString()))); } else { MessageBox.Show("Please set the number of days to borrow to be more than 0."); return; } // Check that there is at least one item is selected if (counter_amounttoborrow.Value > 0) { clEquipmentBooked.BorrowedAmount = int.Parse(counter_amounttoborrow.Value.ToString()); } else { MessageBox.Show("Please set the borrowed amount of "+clEquipment.Type+" to be more than 0."); return; } // Set the returned state to false clEquipmentBooked.IsReturned = false; // Call for saving the new booking clEquipmentBooked.SaveEquipmentBooking(); // Close the form this.Close(); }
/** * @desc Executes when a grid cell is double clicked on the borrowed equipment list * It loads in the equipment return dialog belonging to the cell * @params [none] No input parameter. * @return [none] No directly returned data. */ private void dg_eqbookings_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { // Retrieve equipment booking details from grid row string equipmentName = dg_eqbookings.Rows[e.RowIndex].Cells[1].Value.ToString(); int borrowedAmount = int.Parse(dg_eqbookings.Rows[e.RowIndex].Cells[2].Value.ToString()); int id_eq_booking = int.Parse(dg_eqbookings.Rows[e.RowIndex].Cells[4].Value.ToString()); // Show return dialog for confirming amount to be returned frm_message_box myMessageBox = new frm_message_box(); string result = myMessageBox.ShowBox(Utils.MB_CUST4, "", "How many " + equipmentName + " would you like to return?", borrowedAmount.ToString()); // Reference how to use TryParse //ref http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/84990ad2-5046-472b-b103-f862bfcd5dbc // Check the result of user input double Num; bool isNum = double.TryParse(result, out Num); if (isNum) { // If there is something to return but not everything if ((int.Parse(result) > 0) && (result != "Cancel")) { // Save the new amount into eq. booking this.clEquipmentBooked = new EquipmentBooked(id_eq_booking); this.clEquipmentBooked.BorrowedAmount = int.Parse(result); this.clEquipmentBooked.IsReturned = false; this.clEquipmentBooked.SaveEquipmentBooking(); } // If all amount of this booking is to be returned else { // Mark the booking as returned this.clEquipmentBooked = new EquipmentBooked(id_eq_booking); this.clEquipmentBooked.BorrowedAmount = 0; this.clEquipmentBooked.IsReturned = true; this.clEquipmentBooked.SaveEquipmentBooking(); } // Refresh eq. booking list this.vLoadBookedList(); } }
/** * @desc Executes when a grid cell is double clicked on the equipment bookings list * It loads in the class belonging to the cell * @params [none] No input parameter. * @return [none] No directly returned data. */ private void dg_eqbookings_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { // Retrieve equipment booking details from grid row int id_eq_booking = int.Parse(dg_eqbookings.Rows[e.RowIndex].Cells[0].Value.ToString()); string equipmentName = dg_eqbookings.Rows[e.RowIndex].Cells[2].Value.ToString(); int borrowedAmount = int.Parse(dg_eqbookings.Rows[e.RowIndex].Cells[3].Value.ToString()); // Show return dialog for confirming amount to be returned frm_message_box myMessageBox = new frm_message_box(); string result = myMessageBox.ShowBox(Utils.MB_CUST4, "", "How many "+equipmentName+" would you like to return?",borrowedAmount.ToString()); // Reference how to use TryParse //ref in Bibliography at (Alani, S., 2006) // Check the result of user input double Num; bool isNum = double.TryParse(result, out Num); if (isNum) { // If there is something to return but not everything if ((int.Parse(result) > 0) && (result != "Cancel")) { // Save the new amount into eq. booking this.clEquipmentBooked = new EquipmentBooked(id_eq_booking); this.clEquipmentBooked.BorrowedAmount = int.Parse(result); this.clEquipmentBooked.IsReturned = false; this.clEquipmentBooked.SaveEquipmentBooking(); } // If all amount of this booking is to be returned else if (result != "Cancel") { // Mark the booking as returned this.clEquipmentBooked = new EquipmentBooked(id_eq_booking); this.clEquipmentBooked.BorrowedAmount = 0; this.clEquipmentBooked.IsReturned = true; this.clEquipmentBooked.SaveEquipmentBooking(); } // Refresh eq. booking list this.vLoadBookedList(); } }