/// <summary> /// Récupére tout les animaux par clients, archivé ou non /// </summary> /// <param name="?"></param> /// <param name="archived"></param> /// <returns></returns> public static List <BO.Animaux> GetAllByClient(BO.Clients cli, bool archived) { try { SqlConnection cnx = DAL.SqlConnexion.OpenConnexion(); String query = @"SELECT * FROM Animaux a LEFT JOIN Clients c ON a.CodeClient = c.CodeClient WHERE a.CodeClient = @codeClient AND a.Archive = @archive ORDER BY a.CodeAnimal"; List <BO.Animaux> results = cnx.Query <BO.Animaux, BO.Clients, BO.Animaux>(query, (animaux, client) => { animaux.Client = client; return(animaux); }, param: new { archive = archived, codeClient = cli.CodeClient }, splitOn: "CodeClient") .ToList <BO.Animaux>(); SqlConnexion.CloseConnexion(cnx); return(results); } catch (Exception e) { throw e; } }
/// <summary> /// Creer l'animal passé en params /// Et le retourne avec son GUID /// </summary> /// <param name="animal"></param> public static BO.Animaux Create(BO.Animaux animal) { try { BO.Clients cli = DAL.Clients.Get(animal.CodeClient); SqlConnection cnx = DAL.SqlConnexion.OpenConnexion(); Guid temp = cnx.ExecuteScalar <Guid>("EXEC ajout_animal @nomclient, @prenomclient, @nomani, @sexe, @couleur, @espece, @race, @archive", new { nomclient = cli.NomClient, prenomclient = cli.PrenomClient, nomani = animal.NomAnimal, sexe = animal.Sexe, couleur = animal.Couleur, espece = animal.Espece, race = animal.Race, archive = false }); animal.CodeAnimal = temp; SqlConnexion.CloseConnexion(cnx); return(animal); } catch (Exception e) { throw e; } }
// Chargement d'un client private void LoadClient() { //Liste vide if (index == -1) { // Vide le tableau des animaux this.dataGridViewAnimals.DataSource = null; this.dataGridViewAnimals.Enabled = false; // Vide les textbox this.textBoxAdresse.Text = ""; this.textBoxAdresse2.Text = ""; this.textBoxCity.Text = ""; this.textBoxCode.Text = ""; this.textBoxFirstName.Text = ""; this.textBoxLastName.Text = ""; this.textBoxPostalCode.Text = ""; // Déactive les textbox this.textBoxAdresse.Enabled = false; this.textBoxAdresse2.Enabled = false; this.textBoxCity.Enabled = false; this.textBoxCode.Enabled = false; this.textBoxFirstName.Enabled = false; this.textBoxLastName.Enabled = false; this.textBoxPostalCode.Enabled = false; this.buttonAddAni.Enabled = false; this.buttonEditAni.Enabled = false; this.buttonDeleteAni.Enabled = false; } // Liste non vide else if (index < clientsList.Count) { currentClient = clientsList[index]; this.Text = GUI.Lang.SUBFORM_FOLDERCUSTANI_TITLE + " - " + currentClient.NomClient + " " + currentClient.PrenomClient; //Remplis les textbox this.textBoxAdresse.Text = currentClient.Adresse1; this.textBoxAdresse2.Text = currentClient.Adresse2; this.textBoxCity.Text = currentClient.Ville; this.textBoxCode.Text = currentClient.CodeClient.ToString(); this.textBoxFirstName.Text = currentClient.NomClient; this.textBoxLastName.Text = currentClient.PrenomClient; this.textBoxPostalCode.Text = currentClient.CodePostal; //Active les texbox this.textBoxAdresse.Enabled = true; this.textBoxAdresse2.Enabled = true; this.textBoxCity.Enabled = true; this.textBoxFirstName.Enabled = true; this.textBoxLastName.Enabled = true; this.textBoxPostalCode.Enabled = true; this.checkBoxSearch.Text = GUI.Lang.SUBFORM_FOLDERCUSTANI_SEARCH; LoadAnimaux(); //charge les animaux } }
/// <summary> /// Archive tout les animaux du client /// </summary> /// <param name="cli"></param> /// <returns></returns> public static bool ArchiveAllByClient(BO.Clients cli) { try { List <BO.Animaux> animaux = DAL.Animaux.GetAllByClient(cli); SqlConnection cnx = DAL.SqlConnexion.OpenConnexion(); var query = @"UPDATE Animaux SET Archive=1 WHERE CodeAnimal = @codeAnimal"; int rowNb = 0; foreach (BO.Animaux animal in animaux) { rowNb += cnx.Execute(query, new { codeAnimal = animal.CodeAnimal }); } SqlConnexion.CloseConnexion(cnx); return(rowNb > 0); } catch (Exception e) { throw e; } }