public override int CreateBagage(BagageDefinition bagage) { using (SqlConnection cnx = new SqlConnection(strCnx)) { SqlCommand cmd = new SqlCommand(this.commandInsertBagage, cnx); SqlCommand cmd2 = new SqlCommand(this.commandInsertBagage2, cnx); cmd.Parameters.AddWithValue("@codeIata", bagage.CodeIata); cmd.Parameters.AddWithValue("@prioritaire", bagage.Prioritaire); cmd.Parameters.AddWithValue("@itineraire", bagage.Itineraire); cmd.Parameters.AddWithValue("@dateCreation", (System.Data.SqlTypes.SqlDateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")))); cmd.Parameters.AddWithValue("@compagnie", bagage.Compagnie); cmd.Parameters.AddWithValue("@ligne", bagage.Ligne); cmd.Parameters.AddWithValue("@continuation", bagage.EnContinuation); cnx.Open(); int res = Convert.ToInt32(cmd.ExecuteScalar()); if (bagage.Rush == true) { cmd2.Parameters.AddWithValue("@idBagage", res); cmd2.Parameters.AddWithValue("@particularite", 10); cmd2.ExecuteScalar(); } return(res); } }
public override List <BagageDefinition> GetBagage(string codeIataBagage) { List <BagageDefinition> bagsRes = new List <BagageDefinition>(); using (SqlConnection cnx = new SqlConnection(strCnx)) { SqlCommand cmd = new SqlCommand(commandGetBagageIata, cnx); cmd.Parameters.AddWithValue("@code_iata", codeIataBagage); cnx.Open(); SqlDataReader sdr = cmd.ExecuteReader(); //Implémenter ici le code de récupération et de convertion while (sdr.Read()) //return 1 ou 0 à chaque ligne si ca a marché { BagageDefinition bagRes = new BagageDefinition() { IdBagage = sdr.GetInt32(sdr.GetOrdinal("ID_BAGAGE")), CodeIata = sdr.GetString(sdr.GetOrdinal("CODE_IATA")), EnContinuation = (sdr.GetString(sdr.GetOrdinal("CONTINUATION")) == "Y"), Compagnie = sdr.GetString(sdr.GetOrdinal("COMPAGNIE")), Ligne = sdr.GetString(sdr.GetOrdinal("LIGNE")), DateVol = sdr.GetDateTime(sdr.GetOrdinal("DATE_CREATION")), Itineraire = sdr.GetString(sdr.GetOrdinal("ESCALE")), //Prioritaire = sdr.GetBoolean(sdr.GetOrdinal("")), Rush = sdr.GetBoolean(sdr.GetOrdinal("RUSH")) }; bagsRes.Add(bagRes); } } return(bagsRes); }
/// <summary> /// Insert a bagage in BAGAGE table /// </summary> /// <param name="bagage"></param> /// <returns>the new bagage id</returns> public override int InsertBagage(BagageDefinition bagage) { int id = 0; using (SqlConnection cnx = new SqlConnection(strCnx)) { if (CheckCompanyExist(bagage.Compagnie)) { // if the company iata code exist, insert in the database SqlCommand cmd = new SqlCommand(INSERT_BAGAGE + GET_INSERT, cnx); cmd.Parameters.AddWithValue("@CODE_IATA", bagage.CodeIata); cmd.Parameters.AddWithValue("@EN_CONTINUATION", bagage.EnContinuation); cmd.Parameters.AddWithValue("@COMPAGNIE", bagage.Compagnie); cmd.Parameters.AddWithValue("@LIGNE", bagage.Ligne); cmd.Parameters.AddWithValue("@DESTINATION", bagage.Itineraire); cmd.Parameters.AddWithValue("@PRIORITAIRE", bagage.Prioritaire); cnx.Open(); id = Convert.ToInt32(cmd.ExecuteScalar()); if (bagage.Rush == true) { // if the bagage is rush insert in the table BAGAGE_A_POUR_PARTICULARITE SqlCommand cmd2 = new SqlCommand(INSERT_PARTICULARITE, cnx); cmd2.Parameters.AddWithValue("@ID_BAGAGE", id); cmd2.ExecuteScalar(); } } } return(id); }
private BagageDefinition ReaderToBagage(SqlDataReader reader) { var bagRes = new BagageDefinition { IdBagage = reader.GetInt32(reader.GetOrdinal("ID_BAGAGE")), CodeIata = reader.GetString(reader.GetOrdinal("CODE_IATA")), Ligne = reader.GetString(reader.GetOrdinal("LIGNE")), DateVol = reader.GetDateTime(reader.GetOrdinal("DATE_CREATION")), Rush = reader.GetBoolean(reader.GetOrdinal("RUSH")), EnContinuation = reader.GetBoolean(reader.GetOrdinal("EN_CONTINUATION")), Compagnie = reader.GetString(reader.GetOrdinal("COMPAGNIE")) }; int index = reader.GetOrdinal("ESCALE"); if (!reader.IsDBNull(index)) { bagRes.Itineraire = reader.GetString(index); } index = reader.GetOrdinal("PRIORITAIRE"); if (!reader.IsDBNull(index)) { bagRes.Prioritaire = reader.GetBoolean(index); } return(bagRes); }
public override BagageDefinition GetBagage(int idBagage) { BagageDefinition bagRes = null; using (SqlConnection cnx = new SqlConnection(strCnx)) { SqlCommand cmd = new SqlCommand(commandGetBagageId, cnx); cmd.Parameters.AddWithValue("@id_bagage", idBagage); cnx.Open(); SqlDataReader sdr = cmd.ExecuteReader(); if (sdr.Read()) { bagRes = new BagageDefinition() { CodeIata = sdr.GetString(sdr.GetOrdinal("CODE_IATA")), EnContinuation = sdr.GetString(sdr.GetOrdinal("CONTINUATION")).Equals("Y"), Ligne = sdr.GetString(sdr.GetOrdinal("LIGNE")), NomCompagnie = sdr.GetString(sdr.GetOrdinal("NOM")), Compagnie = sdr.GetString(sdr.GetOrdinal("COMPAGNIE")), DateVol = sdr.GetDateTime(sdr.GetOrdinal("DATE_CREATION")), ClasseBagage = sdr["CLASSE"] is DBNull ? "Y" : Convert.ToString(sdr["CLASSE"]), Prioritaire = sdr.GetBoolean(sdr.GetOrdinal("PRIORITAIRE")), Itineraire = sdr.GetString(sdr.GetOrdinal("ESCALE")), Rush = sdr.GetBoolean(sdr.GetOrdinal("RUSH")) }; } } Console.WriteLine(bagRes.ToString()); return(bagRes); }
/// <summary> /// Update a bagage, company and creation date cannot be modified /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void saveButton_Click(object sender, EventArgs e) { BagageDefinition bagage = new BagageDefinition(); bagage.IdBagage = selectedBagage.IdBagage; bagage.CodeIata = selectedBagage.CodeIata; bagage.EnContinuation = continuationCheckBox.Checked; bagage.Itineraire = destinationTextBox.Text; bagage.Ligne = lineTextBox.Text; bagage.Prioritaire = !(classTextBox.Text.Equals("") || classTextBox.Text.Equals("Non prioritaire")); bagage.Rush = rushCheckBox.Checked; // update in the database and display a message whether it is updated try { selectedBagage = proxy.UpdateBagage(bagage); State = PimState.DisplayBagage; MessageBox.Show("Bagage saved ! id=" + bagage.IdBagage); } catch (FaultException excp) { this.label12.Text += excp.Message; this.label12.Visible = true; } catch (AggregateException) { this.label12.Text += "Une erreur de communication s'est produite dans le traitement de votre demande"; this.label12.Visible = true; } catch (Exception) { this.label12.Text += "Une erreur s'est produite dans le traitement de votre demande"; this.label12.Visible = true; } }
public override BagageDefinition GetBagage(string codeIata) { using (SqlConnection cnx = new SqlConnection(strcnx)) { SqlDataReader sdr; BagageDefinition bag = null; SqlCommand cmd = new SqlCommand(commandGetBagage, cnx); cmd.Parameters.AddWithValue("@code", codeIata); cnx.Open(); sdr = cmd.ExecuteReader(); if (sdr.Read()) #region cache { bag = new BagageDefinition(); bag.IdBagage = Convert.ToInt32(sdr["id_bagage"]); bag.Compagnie = sdr["compagnie"].ToString(); bag.Ligne = Convert.ToInt32(sdr["ligne"]); bag.DateCreation = sdr.GetDateTime(sdr.GetOrdinal("date_creation")); bag.Itineraire = sdr.GetString(sdr.GetOrdinal("escale")); bag.ClasseBagage = sdr["classe"] is DBNull ? 'Y' : Convert.ToChar(sdr["classe"]); bag.CodeIata = sdr.GetString(sdr.GetOrdinal("code_iata")); bag.Continuation = sdr[sdr.GetOrdinal("continuation")].ToString() == "Y" ? true : false; bag.Rush = sdr.GetFieldValue <bool>(sdr.GetOrdinal("rush")); } if (sdr.Read()) { throw new ApplicationException("Trop de résultats retournés"); } #endregion return(bag); } }
/// <summary> /// Execute a select query and convert the result into a list of BagageDefinition /// </summary> /// <param name="cmd"></param> /// <returns>a list of BagageDefinition</returns> private List <BagageDefinition> executeQuery(SqlCommand cmd) { List <BagageDefinition> bagList = new List <BagageDefinition>(); using (SqlDataReader dataReader = cmd.ExecuteReader()) { if (dataReader.HasRows) { while (dataReader.Read()) { BagageDefinition bag = new BagageDefinition(); bag.IdBagage = dataReader.GetInt32(dataReader.GetOrdinal("ID_BAGAGE")); bag.CodeIata = dataReader.GetString(dataReader.GetOrdinal("CODE_IATA")); bag.Compagnie = dataReader.GetString(dataReader.GetOrdinal("COMPAGNIE")); bag.Ligne = dataReader.GetString(dataReader.GetOrdinal("LIGNE")); bag.DateVol = dataReader.GetDateTime(dataReader.GetOrdinal("DATE_CREATION")); bag.Itineraire = dataReader.GetString(dataReader.GetOrdinal("DESTINATION")); bag.Prioritaire = dataReader.GetBoolean(dataReader.GetOrdinal("PRIORITAIRE")); bag.EnContinuation = dataReader.GetBoolean(dataReader.GetOrdinal("EN_CONTINUATION")); bag.Rush = dataReader.GetBoolean(dataReader.GetOrdinal("RUSH")); bagList.Add(bag); } } } return(bagList); }
/// <summary> /// Update a bagage in bagage table /// </summary> /// <param name="bagage"></param> /// <returns>the bagage updated</returns> public override BagageDefinition UpdateBagage(BagageDefinition bagage) { using (SqlConnection cnx = new SqlConnection(strCnx)) { // update the bagage in BAGAGE table SqlCommand cmd = new SqlCommand(UPDATE_BAGAGE + EXACT_ID, cnx); cmd.Parameters.AddWithValue("@ID_BAGAGE", bagage.IdBagage); cmd.Parameters.AddWithValue("@EN_CONTINUATION", bagage.EnContinuation); cmd.Parameters.AddWithValue("@LIGNE", bagage.Ligne); cmd.Parameters.AddWithValue("@DESTINATION", bagage.Itineraire); cmd.Parameters.AddWithValue("@PRIORITAIRE", bagage.Prioritaire); cnx.Open(); List <BagageDefinition> bagList = executeQuery(cmd); if (bagage.Rush == true) { // if the bagage is rush, insert a line BAGAGE_A_POUR_PARTICULARITE corresponding to bagage id if there is none SqlCommand cmd2 = new SqlCommand(INSERT_PARTICULARITE, cnx); cmd2.Parameters.AddWithValue("@ID_BAGAGE", bagage.IdBagage); cmd2.ExecuteScalar(); } else { // if the bagage is not rush, remove all line in BAGAGE_A_POUR_PARTICULARITE corresponding to bagage id SqlCommand cmd2 = new SqlCommand(DELETE_PARTICULARITE, cnx); cmd2.Parameters.AddWithValue("@ID_BAGAGE", bagage.IdBagage); cmd2.ExecuteScalar(); } } // return the bagage updated return(GetBagage(bagage.IdBagage)); }
private void button3_Click(object sender, EventArgs e) { BagageDefinition bagage = MyAirport.Pim.Model.Factory.Model.GetBagage(this.tbCodeIata.Text); if (null != bagage) { // Fetch value and put into fields this.tbClasseBag.Text = bagage.ClasseBagage.ToString(); this.tbCodeIata.Text = bagage.CodeIata; this.tbCompagnie.Text = bagage.Compagnie; this.cbContinuation.Checked = bagage.Continuation; this.tbItineraire.Text = bagage.Itineraire; this.tbJourExploitation.Text = bagage.JourExploitation.ToString(); this.tbLigne.Text = bagage.Ligne.ToString(); this.tbAlpha.Text = bagage.LigneAlpha.ToString(); this.cbRush.Checked = bagage.Rush; setOnReadOnlyFields(); // Bagage found: impossible de create a new one, so disable Créer button this.createButton.Enabled = false; } else if (false) { // Check if there is multiple bagages MessageBox.Show("Erreur: Plusieurs bagages ont été trouvés."); } else { setOnWriteFields(); this.textBox1.ReadOnly = true; this.createButton.Enabled = true; } }
private static BagageDefinition readBagageAttributes() { string iata = readInput("IATA? (ex: 23232342)"); string compagnie = readInput("Compagnie? (ex: UE)"); string ligne = readInput("Ligne? (ex: 7594)"); string escale = readInput("Escale? (ex: CDG)"); string prioritaire = readInput("Prioritaire? (Y/N)"); string en_continuationion = readInput("En continuation? (Y/N)"); BagageDefinition bagage = new BagageDefinition(); try { bagage.CodeIata = iata; bagage.Compagnie = compagnie; bagage.Ligne = ligne; bagage.Itineraire = escale; bagage.Prioritaire = prioritaire == "Y" ? true : false; bagage.EnContinuation = en_continuationion == "Y" ? true : false; } catch (Exception) { return(null); } return(bagage); }
public override List <BagageDefinition> GetBagage(string codeIataBagage) { List <BagageDefinition> bagsRes = new List <BagageDefinition>(); using (SqlConnection cnx = new SqlConnection(strCnx)) { SqlCommand cmd = new SqlCommand(this.commandGetBagageIata, cnx); cmd.Parameters.AddWithValue("@codeIata", codeIataBagage); cnx.Open(); using (SqlDataReader sdr = cmd.ExecuteReader()) { while (sdr.Read()) { BagageDefinition bagRes = new BagageDefinition(); bagRes.CodeIata = sdr.GetString(sdr.GetOrdinal("code_iata")); bagRes.Compagnie = sdr.GetString(sdr.GetOrdinal("compagnie")); bagRes.DateVol = sdr.GetDateTime(sdr.GetOrdinal("date_creation")); bagRes.EnContinuation = sdr.GetBoolean(sdr.GetOrdinal("continuation")); bagRes.IdBagage = sdr.GetInt32(sdr.GetOrdinal("id_bagage")); bagRes.Itineraire = sdr.GetString(sdr.GetOrdinal("escale")); bagRes.Ligne = sdr.GetString(sdr.GetOrdinal("ligne")); bagRes.Prioritaire = sdr.GetBoolean(sdr.GetOrdinal("prioritaire")); bagsRes.Add(bagRes); } } } return(bagsRes); }
public override BagageDefinition GetBagage(int idBagage) { BagageDefinition bagRes = null; using (SqlConnection cnx = new SqlConnection(strCnx)) { SqlCommand cmd = new SqlCommand(this.commandGetBagageId, cnx); cmd.Parameters.AddWithValue("@id", idBagage); cnx.Open(); //Implémenter ici le code de récupération et de convertion using (SqlDataReader sdr = cmd.ExecuteReader()) { if (sdr.Read()) { bagRes = new BagageDefinition(); bagRes.CodeIata = sdr.GetString(sdr.GetOrdinal("code_iata")); bagRes.Compagnie = sdr.GetString(sdr.GetOrdinal("compagnie")); bagRes.DateVol = sdr.GetDateTime(sdr.GetOrdinal("date_creation")); bagRes.EnContinuation = sdr.GetBoolean(sdr.GetOrdinal("continuation")); bagRes.IdBagage = sdr.GetInt32(sdr.GetOrdinal("id_bagage")); bagRes.Itineraire = sdr.GetString(sdr.GetOrdinal("escale")); bagRes.Ligne = sdr.GetString(sdr.GetOrdinal("ligne")); bagRes.Prioritaire = sdr.GetBoolean(sdr.GetOrdinal("prioritaire")); } } } return(bagRes); }
/// <summary> /// Crée le bagage dans la base de données. /// Si le bagage est "rush", insère le bagage dans la table BAGAGE_A_POUR_PARTICULARITE. /// Utilise une transaction pour rendre le traitement atomique, et pouvoir annuler l'insertion du bagage en cas de problème. /// </summary> /// <param name="bag">Bagae à créer</param> /// <returns>True si le bagae a bien été inséré en base, False sinon.</returns> public override bool CreateBagage(BagageDefinition bag) { using (SqlConnection connection = new SqlConnection(this.connectionString)) { connection.Open(); SqlTransaction transaction = connection.BeginTransaction(); SqlCommand cmdCreateBagage = new SqlCommand(this.commandCreateBagage, connection); cmdCreateBagage.Parameters.AddWithValue("@codeIata", bag.CodeIata); cmdCreateBagage.Parameters.AddWithValue("@compagnie", bag.Compagnie); cmdCreateBagage.Parameters.AddWithValue("@ligne", bag.Ligne); cmdCreateBagage.Parameters.AddWithValue("@jourExploitation", bag.DateVol); cmdCreateBagage.Parameters.AddWithValue("@itineraire", bag.Itineraire); cmdCreateBagage.Parameters.AddWithValue("@classe", bag.Classe); cmdCreateBagage.Parameters.AddWithValue("@continuation", bag.EnContinuation ? 'Y' : 'N'); cmdCreateBagage.Connection = connection; cmdCreateBagage.Transaction = transaction; try { bool inserted = true; //Insertion du bagage inserted = cmdCreateBagage.ExecuteNonQuery() == 1; //Si le bagage est rush, on insère une entrée dans BAGAGE_A_POUR_PARTICULARITE. if (bag.Rush) { SqlCommand cmdAssociateBagageRush = new SqlCommand(this.commandAssociateBagageRush, connection); cmdAssociateBagageRush.Connection = connection; cmdAssociateBagageRush.Transaction = transaction; inserted &= cmdAssociateBagageRush.ExecuteNonQuery() == 1; } if (inserted) { transaction.Commit(); } else { transaction.Rollback(); } return(inserted); } catch { try { transaction.Rollback(); return(false); } catch { return(false); } } } }
public override BagageDefinition GetBagage(int idBagage) { var bagageDefinition = new BagageDefinition(); bagageDefinition.IdBagage = idBagage; return(bagageDefinition); }
public int CreateBagage(BagageDefinition bag) { NbAppelTotale++; this.NbAppelInstance++; int res = MyAirport.Pim.Models.Factory.Model.CreateBagage(bag); return(res); }
/// <summary> /// Valide les informations du bagage et appelle la factory pour créer le bagage. /// </summary> /// <param name="bag">Bagage à créer.</param> /// <returns>True si le bagage a bien été créé, False sinon.</returns> public bool CreateBagage(BagageDefinition bag) { this.ValidateBagageInput(bag); try { return(MyAirport.Pim.Models.Factory.Model.CreateBagage(bag)); } catch (Exception ex) { throw new FaultException(ex.Message); } }
public override int CreateBagage(BagageDefinition bag) { using (SqlConnection cnx = new SqlConnection(strCnx)) { SqlCommand cmd; if (bag.Rush) { cmd = new SqlCommand(this.commandAddBagageRush, cnx); } else { cmd = new SqlCommand(this.commandAddBagage, cnx); } Console.WriteLine("Prioritaire : " + bag.Prioritaire); cmd.Parameters.AddWithValue("@codeIata", bag.CodeIata); cmd.Parameters.AddWithValue("@compagnie", bag.Compagnie); cmd.Parameters.AddWithValue("@ligne", bag.Ligne); cmd.Parameters.AddWithValue("@jourExploi", "7"); cmd.Parameters.AddWithValue("@escale", bag.Itineraire); cmd.Parameters.AddWithValue("@classe", "Y"); cmd.Parameters.AddWithValue("@origine", "D"); cmd.Parameters.AddWithValue("@dateCrea", DateTime.Now); if (bag.Prioritaire) { cmd.Parameters.AddWithValue("@prioritaire", true); } else { cmd.Parameters.AddWithValue("@prioritaire", false); } if (bag.EnContinuation) { cmd.Parameters.AddWithValue("@continuation", "Y"); } else { cmd.Parameters.AddWithValue("@continuation", "N"); } cnx.Open(); var Idbag = Convert.ToInt32(cmd.ExecuteScalar()); bag.IdBagage = Idbag; return(bag.IdBagage); } }
/// <summary> /// Create a new bagage /// </summary> /// <param name="bag"></param> /// <returns>the ID_BAGAGE of the bagage created</returns> public int CreateBagage(BagageDefinition bag) { int id = 0; NbAppelTotale++; this.NbAppelInstance++; id = MyAirport.Pim.Models.Factory.Model.InsertBagage(bag); if (id == 0) { throw new FaultException("This company code iata does not exist !"); } return(id); }
public string printBagage(BagageDefinition bag) { string str = "Code IATA : " + (NullIfEmpty(bag.CodeIata) ?? "N/D") + "\n"; str += "ID bagage : " + (NullIfEmpty(bag.IdBagage.ToString()) ?? "N/D") + "\n"; str += "Compagnie : " + (NullIfEmpty(bag.Compagnie) ?? "N/D") + "\n"; str += "Ligne : " + ((NullIfEmpty(bag.Ligne) ?? NullIfEmpty(bag.LigneAlpha.ToString())) ?? "N/D") + "\n"; str += "Date du vol : " + (NullIfEmpty(bag.DateVol.ToString(CultureInfo.CurrentCulture)) ?? "N/D") + "\n"; str += "Itinéraire : " + (NullIfEmpty(bag.Itineraire) ?? "N/D") + "\n"; str += "Classe bagage : " + (NullIfEmpty(bag.ClasseBagage) ?? "N/D") + "\n"; str += "Continuation : " + (NullIfEmpty(bag.Continuation.ToString()) ?? "N/D") + "\n"; str += "Rush : " + (NullIfEmpty(bag.Rush.ToString()) ?? "N/D") + "\n"; str += "Jour d'exploitation : " + (NullIfEmpty(bag.JourExploitation.ToString()) ?? "N/D") + "\n\n"; return str; }
private void insertButton_Click(object sender, EventArgs e) { BagageDefinition bag = new BagageDefinition(); bag.Compagnie = this.tbCompagnie.Text; bag.Ligne = Convert.ToInt32(this.tbLigne.Text); bag.JourExploitation = Convert.ToInt32(this.tbJourExploitation.Text); bag.Itineraire = this.tbItineraire.Text; bag.ClasseBagage = Convert.ToChar(this.tbClasseBag.Text); bag.CodeIata = this.tbCodeIata.Text; bag.Continuation = this.cbContinuation.Checked; bag.Rush = this.cbRush.Checked; MyAirport.Pim.Model.Factory.Model.CreateBagage(bag); }
public BagageDefinition NewBagage(SqlDataReader sdr) { BagageDefinition bagRes = new BagageDefinition(); bagRes.IdBagage = sdr.GetInt32(sdr.GetOrdinal("id_bagage")); bagRes.CodeIata = sdr.GetString(sdr.GetOrdinal("code_iata")); bagRes.Compagnie = sdr.GetString(sdr.GetOrdinal("compagnie")); bagRes.Ligne = sdr.GetString(sdr.GetOrdinal("ligne")); bagRes.DateVol = sdr.GetDateTime(sdr.GetOrdinal("date_creation")); bagRes.Itineraire = sdr.GetString(sdr.GetOrdinal("escale")); bagRes.Prioritaire = sdr.GetBoolean(sdr.GetOrdinal("prioritaire")); bagRes.EnContinuation = sdr.GetBoolean(sdr.GetOrdinal("continuation")); bagRes.Rush = sdr.GetBoolean(sdr.GetOrdinal("rush")); return(bagRes); }
public override void CreateBagage(BagageDefinition bagage) { using (SqlConnection cnx = new SqlConnection(strCnx)) { SqlCommand cmd = new SqlCommand(this.commandInsertBagage, cnx); cmd.Parameters.AddWithValue("@iata", bagage.CodeIata); cmd.Parameters.AddWithValue("@compagnie", bagage.Compagnie); cmd.Parameters.AddWithValue("@ligne", bagage.Ligne); cmd.Parameters.AddWithValue("@escale", bagage.Itineraire); cmd.Parameters.AddWithValue("@prioritaire", bagage.Prioritaire); cmd.Parameters.AddWithValue("@en_continuation", bagage.EnContinuation); cmd.Parameters.AddWithValue("@jour_exploitation", 2); cmd.Parameters.AddWithValue("@origine_creation", "D"); cnx.Open(); cmd.ExecuteNonQuery(); } }
/// <summary> /// Get a bagage using its id from BAGAGE table /// </summary> /// <param name="idBagage"></param> /// <returns>the corresponding bagage</returns> public override BagageDefinition GetBagage(int idBagage) { BagageDefinition bag = null; using (SqlConnection cnx = new SqlConnection(strCnx)) { SqlCommand cmd = new SqlCommand(GET_BAGAGE + EXACT_ID, cnx); cmd.Parameters.AddWithValue("@ID_BAGAGE", idBagage); cnx.Open(); List <BagageDefinition> bagList = executeQuery(cmd); if (bagList.Count > 0) { bag = bagList[0]; } } return(bag); }
private void AjouterBtn_Click(object sender, EventArgs e) { var bagage = new BagageDefinition(); try { bagage.Compagnie = CompagnieTB.Text; bagage.ClasseBagage = ClasseBagageTB.Text; bagage.CodeIata = codeIATATB.Text; bagage.Rush = RushCB.Checked; bagage.Continuation = ContinuationCB.Checked; bagage.JourExploitation = short.Parse(JourExploitTB.Text); bagage.Ligne = string.IsNullOrEmpty(Ligne1TB.Text) ? Ligne2TB.Text : Ligne1TB.Text; bagage.Itineraire = ItineraireTB.Text; } catch (Exception) { MessageBox.Show("Erreur dans la consistance des données. Les données saisies ne correspondent pas avec ce qui est attendu.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { int nbLignes = _service.CreateBagage(bagage); if (nbLignes == 1) { MessageBox.Show("Bagage enregistré !", "Sauvegarde réussie", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (nbLignes == 0) { MessageBox.Show("Une erreur est survenue lors de la création du bagage.", "Erreur !", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show( "Une action inattendue s'est produite. Contactez un administrateur de toute urgence.\n" + nbLignes + " lignes ont été ajoutées.", "?", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception) { MessageBox.Show("Une erreur s’est produite.\nMerci de bien vouloir réessayer ultérieurement ou de contacter votre administrateur.", "Erreur !", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Create a new bagage on button click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void saveNewButton_Click(object sender, EventArgs e) { String codeIata = codeIataSave.Text; if (codeIata.Length == 12 && codeIata.Substring(codeIata.Length - 2).Equals("00")) { // if the iata code correspond to the format ____XXXXXX00 BagageDefinition bagage = new BagageDefinition(); bagage.CodeIata = codeIataSave.Text; bagage.Compagnie = companySave.Text; bagage.EnContinuation = continueSave.Checked; bagage.Itineraire = destinationSave.Text; bagage.Ligne = lineSave.Text; bagage.Prioritaire = prioritySave.Checked; bagage.Rush = rushSave.Checked; // save in the database and display a message whether it is saved try { bagage.IdBagage = proxy.CreateBagage(bagage); State = PimState.CreateBagage; MessageBox.Show("Bagage saved ! id=" + bagage.IdBagage); } catch (FaultException excp) { this.label12.Text += excp.Message; this.label12.Visible = true; } catch (AggregateException) { this.label12.Text += "Une erreur de communication s'est produite dans le traitement de votre demande"; this.label12.Visible = true; } catch (Exception) { this.label12.Text += "Une erreur s'est produite dans le traitement de votre demande"; this.label12.Visible = true; } } else { // if iata code format does not coresspond, display a message label12.Text = "Message : Le code iata ne correspond pas au bon format 12 caractères finissant par 00"; } }
private void createButton_Click(object sender, EventArgs e) { BagageDefinition bagage = new BagageDefinition(); try { MyAirport.Pim.Model.Factory.Model.CreateBagage(bagage); MessageBox.Show("Succès: création du bagage réussite."); resetFields(); } catch (Exception ex) { // TODO: Put the right exception when impossible to create a new bagage MessageBox.Show("Erreur: impossible de créer un nouveau bagage."); String tmp = this.textBox1.Text; resetFields(); this.textBox1.Text = tmp; } }
public BagageDefinition extSDR(SqlDataReader sdr) { BagageDefinition bag = new BagageDefinition { CodeIata = sdr.GetString(sdr.GetOrdinal("code_iata")), Compagnie = sdr.GetString(sdr.GetOrdinal("compagnie")), DateVol = sdr.GetDateTime(sdr.GetOrdinal("date_creation")), EnContinuation = sdr.GetBoolean(sdr.GetOrdinal("continuation")), IdBagage = sdr.GetInt32(sdr.GetOrdinal("id_bagage")), Itineraire = sdr.GetString(sdr.GetOrdinal("escale")), Ligne = sdr.GetString(sdr.GetOrdinal("ligne")), Prioritaire = sdr.GetBoolean(sdr.GetOrdinal("prioritaire")), Classe = sdr.GetString(sdr.GetOrdinal("classe")), Rush = sdr.GetBoolean(sdr.GetOrdinal("rush")) }; return(bag); }
public override BagageDefinition GetBagage(string codeIataBagage) { if (codeIataBagage.Length.Equals(12)) { codeIataBagage = "%" + codeIataBagage.Substring(4, 6) + "%"; } using (SqlConnection cnx = new SqlConnection(strCnx)) { SqlCommand cmd = new SqlCommand(commandGetBagageIata, cnx); cmd.Parameters.AddWithValue("@code_iata", codeIataBagage); cnx.Open(); SqlDataReader sdr = cmd.ExecuteReader(); BagageDefinition res = null; if (sdr.Read()) { res = new BagageDefinition() { // IdBagage = sdr.GetString(sdr.GetOrdinal("ID_BAGAGE")), CodeIata = sdr.GetString(sdr.GetOrdinal("CODE_IATA")), EnContinuation = sdr.GetString(sdr.GetOrdinal("CONTINUATION")).Equals("Y"), Ligne = sdr.GetString(sdr.GetOrdinal("LIGNE")), NomCompagnie = sdr.GetString(sdr.GetOrdinal("NOM")), Compagnie = sdr.GetString(sdr.GetOrdinal("COMPAGNIE")), DateVol = sdr.GetDateTime(sdr.GetOrdinal("DATE_CREATION")), ClasseBagage = sdr["CLASSE"] is DBNull ? "Y" : Convert.ToString(sdr["CLASSE"]), Prioritaire = sdr.GetBoolean(sdr.GetOrdinal("PRIORITAIRE")), Itineraire = sdr.GetString(sdr.GetOrdinal("ESCALE")), Rush = sdr.GetBoolean(sdr.GetOrdinal("RUSH")) }; // If some more bagages were found, raise an exception if (sdr.Read()) { throw new ApplicationException(); } return(res); } } return(null); }
static void Main(string[] args) { AbstractDefinition model = Factory.Model; // get either Natif or SQL model while (true) { Console.WriteLine("$ Type IATA code to search for luggages, or type 'quit' to quit"); Console.Write("> "); string input = Console.ReadLine(); if (input == "quit") { break; } Console.WriteLine("Looking for luggage " + input); List <BagageDefinition> bagageList = model.GetBagage(input); switch (bagageList.Count) { case 0: // TODO create BagageDefinition newBagage = readBagageAttributes(); if (newBagage == null) // user quit { Console.WriteLine("$ Bagage creation canceled"); continue; } model.CreateBagage(newBagage); Console.WriteLine("Created luggage " + newBagage.CodeIata); break; case 1: Console.WriteLine(bagageList.First()); break; default: Console.WriteLine("Several luggages have been found:"); foreach (var bagage in bagageList) { Console.WriteLine(" * " + bagage + "\n"); } break; } } }
public override List <BagageDefinition> GetBagage(string codeIataBagage) { var listBagages = new List <BagageDefinition>(); using (SqlConnection cnx = new SqlConnection(strCnx)) { SqlCommand cmd = new SqlCommand(this.commandGetBagageByCodeIata, cnx); cmd.Parameters.AddWithValue("@codeIATA", codeIataBagage); cnx.Open(); //Implémenter ici le code de récupération et de convertion using (SqlDataReader sdr = cmd.ExecuteReader()) { while (sdr.Read()) { BagageDefinition bagRes = new BagageDefinition(); bagRes.CodeIata = sdr.GetString(sdr.GetOrdinal("code_iata")); try { bagRes.Compagnie = sdr.GetString(sdr.GetOrdinal("compagnie")); } catch (Exception exp) { bagRes.Compagnie = "INTROUVABLE"; Console.WriteLine("La compagnie associée au Code Iata " + bagRes.CodeIata + "est introuvable. \nVous référez à l'exception " + exp.Message); } bagRes.DateVol = sdr.GetDateTime(sdr.GetOrdinal("date_creation")); bagRes.EnContinuation = sdr.GetBoolean(sdr.GetOrdinal("continuation")); bagRes.IdBagage = sdr.GetInt32(sdr.GetOrdinal("id_bagage")); bagRes.Itineraire = sdr.GetString(sdr.GetOrdinal("escale")); bagRes.Ligne = sdr.GetString(sdr.GetOrdinal("ligne")); bagRes.Prioritaire = sdr.GetBoolean(sdr.GetOrdinal("prioritaire")); bagRes.Rush = sdr.GetBoolean(sdr.GetOrdinal("RUSH")); listBagages.Add(bagRes); } } } return(listBagages); }
public override BagageDefinition GetBagage(int idBagage) { BagageDefinition bagRes = null; using (SqlConnection cnx = new SqlConnection(strCnx)) { SqlCommand cmd = new SqlCommand(this.commandGetBagageId, cnx); cmd.Parameters.AddWithValue("@id", idBagage); cnx.Open(); using (SqlDataReader sdr = cmd.ExecuteReader()) { if (sdr.Read()) { bagRes = extSDR(sdr); } } } return(bagRes); }
private void SendBagageToScreen(BagageDefinition bagage) { CompagnieTB.Text = bagage.Compagnie; CompagnieTB.Enabled = false; Ligne1TB.Text = bagage.Ligne; Ligne1TB.Enabled = false; Ligne2TB.Text = bagage.LigneAlpha.ToString(); Ligne2TB.Enabled = false; JourExploitTB.Text = bagage.JourExploitation.ToString(); JourExploitTB.Enabled = false; ItineraireTB.Text = bagage.Itineraire; ItineraireTB.Enabled = false; ClasseBagageTB.Text = bagage.ClasseBagage; ClasseBagageTB.Enabled = false; ContinuationCB.Checked = bagage.Continuation; ContinuationCB.Enabled = false; RushCB.Checked = bagage.Rush; RushCB.Enabled = false; AjouterBtn.Enabled = false; }