public void ModifierLocation(LocationModel location) { try { ContextDb.Connecter(); var rowsAffected = ContextDb.GetInstanceDb.MiseAJour_Location(location.Id, location.DateLocation, location.DatePaiement, location.MontantMensuel, location.NombrePaiment, location.IDVehicule, location.IDClient, location.IDTerme, location.KmInitial, location.KmFinal); ContextDb.SaveChanges(); message = rowsAffected > 0 ? "Location mise à jour!" : "Erreur pendant le mise à jour!"; } catch (Exception e) { message = "Erreur de connexion à la base de données :" + e.Message; } finally { ContextDb.Deconnecter(); } }
public LocationModel GetLocation(int idLocation) { LocationModel location = new LocationModel(); try { ContextDb.Connecter(); var result = ContextDb.GetInstanceDb.Selection_Location(idLocation).FirstOrDefault(); if (result != null) { location.Id = result.ID; location.DateLocation = result.Date_Location; location.DatePaiement = result.Date_Paiement; location.MontantMensuel = result.Montant_Mensuel.GetValueOrDefault(); location.NombrePaiment = result.Nombre_Paiment; location.IDVehicule = result.ID_Vehicule; location.IDClient = result.ID_Client; location.IDTerme = result.ID_Terme; location.KmInitial = result.Km_Initial; location.KmFinal = result.Km_Final; } else { message = $"La location {idLocation} n'existe pas."; } } catch (Exception e) { this.message = "Erreur de connexion à la base de données :" + e.Message; } finally { ContextDb.Deconnecter(); } return(location); }
private void buttonSauvergarder_Click(object sender, EventArgs e) { LocationModel location = new LocationModel(); location.DateLocation = !string.IsNullOrWhiteSpace(textBoxDateLocation.Text) ? Convert.ToDateTime(textBoxDateLocation.Text): DateTime.Now; location.DatePaiement = !string.IsNullOrWhiteSpace(textBoxDatePaiement.Text) ? Convert.ToDateTime(textBoxDatePaiement.Text) : DateTime.MinValue; location.MontantMensuel = !string.IsNullOrWhiteSpace(textBoxMontantMensuel.Text) ? Convert.ToDecimal(textBoxMontantMensuel.Text): 0; location.NombrePaiment = !string.IsNullOrWhiteSpace(textBoxNombrePaiement.Text) ? Convert.ToInt32(textBoxNombrePaiement.Text) : 0; location.IDVehicule = !string.IsNullOrWhiteSpace(textBoxIDVehicule.Text) ? Convert.ToInt32(textBoxIDVehicule.Text) : 0; location.IDClient = !string.IsNullOrWhiteSpace(textBoxIDClient.Text) ? Convert.ToInt32(textBoxIDClient.Text) : 0; location.IDTerme = !string.IsNullOrWhiteSpace(textBoxIDTerme.Text) ? Convert.ToInt32(textBoxIDTerme.Text) : 0; location.KmInitial = !string.IsNullOrWhiteSpace(textBoxkmInitial.Text) ? Convert.ToDecimal(textBoxkmInitial.Text) : 0; location.KmFinal = !string.IsNullOrWhiteSpace(textBoxKmFinal.Text) ? Convert.ToDecimal(textBoxKmFinal.Text) : 0; MultiLocationsDAL dal = new MultiLocationsDAL(); dal.AjouterLocation(location); if (!string.IsNullOrEmpty(dal.message)) { MessageBox.Show(dal.message); } }