//overloaded constructor. in this case the admin add a report public AdminReportEdit(string Email, string PassHash, int BookingID) { InitializeComponent(); this.Email = Email; this.PassHash = PassHash; this.ReportedBooking = new Report.Booking(); this.newReport = true; subjectTextbox.Text = ""; messageTextBox.Text = ""; DeleteButton.Visible = false; try { BookingManagerClient bookingManager = new BookingManagerClient(); this.reportManager = new ReportManagerClient(); Booking.Booking FetchedBooking = bookingManager.GetBookingByID(BookingID, this.Email, this.PassHash); ReportedBooking.ID = FetchedBooking.ID; ReportedBooking.BookedCar = new Report.Car(); ReportedBooking.BookedCar.PlateNumber = FetchedBooking.BookedCar.PlateNumber; ReportedBooking.Booker = new Report.User(); ReportedBooking.Booker.Email = FetchedBooking.Booker.Email; ReportedBooking.End = FetchedBooking.End; ReportedBooking.Start = FetchedBooking.Start; }catch (Exception exc) { MessageBox.Show("Errore nella connessione al server.", "Proprio non riesco.", MessageBoxButtons.OK); } }
//on Click function. this function control the data insert by the user and, if the data are correct, send all to the server private void InviaButton_Click(object sender, EventArgs e) { if (SubjectTextBox.Text == ("") || MessageTextBox.Text == ("")) { MessageBox.Show("Riempi tutti i campi", "Controlla bene!", MessageBoxButtons.OK); } else if (BookingListComboBox.SelectedIndex == -1) { MessageBox.Show("Selezionare una prenotazione", "Controlla bene!", MessageBoxButtons.OK); //la combobox restituisce -1 se non è stato selezionato nessun elemento } else { Booking.Booking Booked = bookings[BookingListComboBox.SelectedIndex]; Report.Booking selectedBooking = new Report.Booking(); selectedBooking.ID = Booked.ID; selectedBooking.Start = Booked.Start; selectedBooking.End = Booked.End; selectedBooking.Returned = Booked.Returned; //adding user data Report.User UserReported = new Report.User(); UserReported.Email = Booked.Booker.Email; UserReported.PasswordHash = Booked.Booker.PasswordHash; UserReported.Name = Booked.Booker.Name; UserReported.License = Booked.Booker.License; UserReported.LicensePoints = Booked.Booker.LicensePoints; UserReported.LicenseExpiration = Booked.Booker.LicenseExpiration; selectedBooking.Booker = UserReported; //addign booked car data Report.Car CarReported = new Report.Car(); CarReported.PlateNumber = Booked.BookedCar.PlateNumber; CarReported.Make = Booked.BookedCar.Make; CarReported.Model = Booked.BookedCar.Model; CarReported.Year = Booked.BookedCar.Year; CarReported.Kilometers = Booked.BookedCar.Kilometers; CarReported.BurnedLiters = Booked.BookedCar.BurnedLiters; selectedBooking.BookedCar = CarReported; try { ReportManagerClient reportManager = new ReportManagerClient(); if (reportManager.AddReport(SubjectTextBox.Text, MessageTextBox.Text, selectedBooking, Email, PasswordHash)) { MessageBox.Show("Report inviato", "Grazie per la sua disponibilita"); this.cancelReport(); } else { MessageBox.Show("oh-ho c'è stato un problema non previsto. La preghiamo di riprovare più tardi"); } } catch (Exception exp) { MessageBox.Show("Errore nella connessione al server.", "Proprio non riesco.", MessageBoxButtons.OK); } } }