//overloaded constructor. in this case the admin add a services public AdminServiceEdit(string Email, string PassHash, string CarPlate) { InitializeComponent(); this.Email = Email; this.PassHash = PassHash; this.ServicedCar = new Service.Car(); this.newService = true; TotalUpDown.Value = 0; KilometersUpDown.Value = 0; DeleteButton.Visible = false; try { CarManagerClient carManager = new CarManagerClient(); Car.Car FetchedCar = carManager.GetCarByPlate(CarPlate, this.Email, this.PassHash); ServicedCar.PlateNumber = FetchedCar.PlateNumber; ServicedCar.Make = FetchedCar.Make; ServicedCar.Model = FetchedCar.Model; ServicedCar.Year = FetchedCar.Year; ServicedCar.Kilometers = FetchedCar.Kilometers; ServicedCar.BurnedLiters = FetchedCar.BurnedLiters; this.serviceManager = new ServiceManagerClient(); } catch (Exception exc) { MessageBox.Show("Errore nella connessione al server.", "Proprio non riesco.", MessageBoxButtons.OK); } }
//constructor public AdminCarEdit(Car.Car EditingCar, string Email, string PassHash) { InitializeComponent(); this.EditingCar = EditingCar; this.Email = Email; this.PassHash = PassHash; this.newCar = false; MakerTextBox.Text = EditingCar.Make; ModelTextBox.Text = EditingCar.Model; PlateNumberTextBox.Text = EditingCar.PlateNumber; PlateNumberTextBox.ReadOnly = true; for (int i = 1980; i <= DateTime.Now.Year; i++) { YearComboBox.Items.Add(i); } if (EditingCar.Year != 0) { YearComboBox.SelectedIndex = EditingCar.Year - 1980; } LitersUpDown.Value = EditingCar.BurnedLiters; KilometersUpDown.Value = EditingCar.Kilometers; try { this.carManager = new CarManagerClient(); }catch (Exception exc) { MessageBox.Show("Errore nella connessione al server.", "Proprio non riesco.", MessageBoxButtons.OK); } }
//This function add the report private void CreateCar(object sender, EventArgs e) { if ("" != MakerTextBox.Text && "" != ModelTextBox.Text && 0 != Convert.ToInt32(YearComboBox.SelectedIndex + 1980) && "" != PlateNumberTextBox.Text) { Car.Car UpdatingCar = new Car.Car(); UpdatingCar.PlateNumber = PlateNumberTextBox.Text; UpdatingCar.Model = ModelTextBox.Text; UpdatingCar.Make = MakerTextBox.Text; UpdatingCar.Kilometers = Convert.ToInt32(KilometersUpDown.Value); UpdatingCar.BurnedLiters = Convert.ToInt32(LitersUpDown.Value); UpdatingCar.Year = Convert.ToInt32(YearComboBox.SelectedIndex + 1980); try { this.carManager.AddCar(UpdatingCar, this.Email, this.PassHash); this.stopEditing(sender, e); }catch (Exception exc) { MessageBox.Show("Errore nella connessione al server.", "Proprio non riesco a creare la macchina.", MessageBoxButtons.OK); } } else { MessageBox.Show("Hai inserito tutti i dati?", "Controlla, per favore.", MessageBoxButtons.OK); } }
//this function control if there are some changes and update the car private void UpdateCar(object sender, EventArgs e) { if (EditingCar.Make != MakerTextBox.Text || EditingCar.Model != ModelTextBox.Text || EditingCar.Year != Convert.ToInt32(YearComboBox.SelectedIndex + 1980) || EditingCar.Kilometers != KilometersUpDown.Value || EditingCar.BurnedLiters != LitersUpDown.Value) { Car.Car UpdatingCar = new Car.Car(); UpdatingCar.PlateNumber = PlateNumberTextBox.Text; UpdatingCar.Model = ModelTextBox.Text; UpdatingCar.Make = MakerTextBox.Text; UpdatingCar.Kilometers = Convert.ToInt32(KilometersUpDown.Value); UpdatingCar.BurnedLiters = Convert.ToInt32(LitersUpDown.Value); UpdatingCar.Year = Convert.ToInt32(YearComboBox.SelectedIndex + 1980); try { carManager.UpdateCar(UpdatingCar, this.Email, this.PassHash); this.stopEditing(sender, e); } catch (Exception exc) { MessageBox.Show("Errore nella connessione al server.", "Proprio non riesco ad aggiornare la macchina.", MessageBoxButtons.OK); } } }