public static List <PoleEmbauche> GetAllPoleEmbauches() { List <PoleEmbauche> PoleEmbauches = new List <PoleEmbauche>(); // création connection using (SqlConnection sqlConnect = Connection.GetConnection()) { using (SqlCommand sqlCde = new SqlCommand()) { //initialiser la connection de la commande sqlCde.Connection = sqlConnect; // chargement des collaborateurs + leur qualif String strSql = "select idPole, libellePole from dbo.PoleEmbauche "; sqlCde.CommandText = strSql; // Exécution de la commande try { SqlDataReader sqlRdr = sqlCde.ExecuteReader(); while (sqlRdr.Read()) { PoleEmbauche oPoleEmbauche = new PoleEmbauche() { IdPole = Convert.ToInt32(sqlRdr[0]), LibellePole = sqlRdr.GetString(1) }; PoleEmbauches.Add(oPoleEmbauche); } sqlRdr.Close(); return(PoleEmbauches); } catch (SqlException se) { throw new DaoExceptionFinAppli("Lecture base impossible" + se.Message, se); } } } }
public static Candidat GetAllCandidats() { // création connection using (SqlConnection sqlConnect = Connection.GetConnection()) { using (SqlCommand sqlCde = new SqlCommand()) { //initialiser la connection de la commande sqlCde.Connection = sqlConnect; // chargement des qualifications String strSql = "GetAllCandidat"; sqlCde.CommandText = strSql; sqlCde.CommandType = CommandType.StoredProcedure; // Exécution de la commande try { SqlDataReader sqlRdr = sqlCde.ExecuteReader(); Candidat cd = null; if (sqlRdr.Read()) { // Pole null ? PoleEmbauche oPoleEmbauche = null; if (!sqlRdr.IsDBNull(1)) { oPoleEmbauche = new PoleEmbauche() { IdPole = sqlRdr.GetInt32(1) } } ; // Situation familiale SituationFamiliale oSituFam = new SituationFamiliale() { IdSituF = Convert.ToSByte(sqlRdr[0]) }; // Création objet cd = new Candidat() { IdCandidat = sqlRdr.GetInt32(9), SituationF = oSituFam, PoleRattachement = oPoleEmbauche, Nom = sqlRdr[2].ToString(), Prenom = sqlRdr[3].ToString(), DateNaissance = sqlRdr.GetDateTime(4), Telephone = sqlRdr[5].ToString(), AdresseMail = sqlRdr[6].ToString(), SituationProfess = sqlRdr.GetBoolean(7), Mobilite = sqlRdr.GetBoolean(8) }; } sqlRdr.Close(); return(cd); } catch (SqlException se) { throw new DaoExceptionFinAppli("Lecture Candidat impossible \n" + se.Message, se); } } } }
protected void ButtonValider_Click(object sender, EventArgs e) { if (Page.IsValid) { Entreprise ent = new Entreprise(); ent.RaisonSociale = TextBoxNom.Text; ent.Adresse1Ent = TextBoxAdresse.Text; if (TextBoxComplement.Text == string.Empty) { ent.Adresse2Ent = null; } else { ent.Adresse2Ent = TextBoxComplement.Text; } ent.CpEnt = TextBoxCodePostal.Text; ent.VilleEnt = TextBoxVille.Text; if (DropDownListClient.SelectedIndex == 1) { ent.Cliente = true; } else { ent.Cliente = false; } if (TextBoxContact.Text == string.Empty) { ent.Contact = null; } else { ent.Contact = TextBoxContact.Text; } if (TextBoxTel.Text == string.Empty) { ent.TelContact = null; } else { ent.TelContact = TextBoxTel.Text; } if (TextBoxMail.Text == string.Empty) { ent.MailContact = null; } else { ent.MailContact = TextBoxMail.Text; } Activite act = new Activite(); ent.SecteurActivite = act; if (DropDownListSecteur.SelectedIndex == 0) { act.IdActivite = null; } else { act.IdActivite = Convert.ToSByte(DropDownListSecteur.SelectedIndex); } PoleEmbauche polE = new PoleEmbauche(); ent.PoleRattachement = polE; if (DropDownListPole.SelectedIndex == 0) { polE.IdPole = null; } else { polE.IdPole = Convert.ToSByte(DropDownListPole.SelectedIndex); } ent.DateCreation = DateTime.Now; try { ent.IdEntreprise = DaoEntreprise.AddEntreprise(ent); ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('L'entreprise a bien été ajouté');</script>"); } catch (Exception ex) { ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Impossible d'ajouter l'entreprise');</script>" + ex); } } }
public static Entreprise GetEntrepriseById(int idEnt) { // création connection using (SqlConnection sqlConnect = Connection.GetConnection()) { // using (SqlCommand sqlCde = new SqlCommand()) { //initialiser la connection de la commande sqlCde.Connection = sqlConnect; // chargement des qualifications String strSql = "GetEntrepriseById"; sqlCde.CommandText = strSql; sqlCde.CommandType = CommandType.StoredProcedure; sqlCde.Parameters.Add(new SqlParameter("@idEntreprise", SqlDbType.Int)).Value = idEnt; // Exécution de la commande try { SqlDataReader sqlRdr = sqlCde.ExecuteReader(); Entreprise cd = null; if (sqlRdr.Read()) { // Pole null ? PoleEmbauche oPoleEmbauche = null; if (!sqlRdr.IsDBNull(1)) { oPoleEmbauche = new PoleEmbauche() { IdPole = sqlRdr.GetInt32(1) } } ; // Secteur d'activite Activite oActivite = new Activite() { IdActivite = Convert.ToSByte(sqlRdr[0]) }; // Création objet cd = new Entreprise() { IdEntreprise = idEnt, RaisonSociale = sqlRdr[2].ToString(), Adresse1Ent = sqlRdr[3].ToString(), Adresse2Ent = sqlRdr[4].ToString(), CpEnt = sqlRdr[5].ToString(), VilleEnt = sqlRdr[6].ToString(), Cliente = sqlRdr.GetBoolean(7), Contact = sqlRdr[8].ToString(), TelContact = sqlRdr[9].ToString(), MailContact = sqlRdr[10].ToString(), DateCreation = sqlRdr.GetDateTime(11), SecteurActivite = oActivite, PoleRattachement = oPoleEmbauche }; } sqlRdr.Close(); return(cd); } catch (SqlException se) { throw new DaoExceptionFinAppli("Lecture Entreprise impossible \n" + se.Message, se); } } } }