コード例 #1
0
ファイル: PieceDB.cs プロジェクト: GroupeStageSPPP/Mission1
        public static Piece Get(Int32 Identifiant)
        {
            Piece piece = new Piece();

            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = select+" WHERE Identifiant = @Identifiant;";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres
            commande.Parameters.AddWithValue("Identifiant", Identifiant);

            //Execution
            try
            {
                connection.Open();

                SqlDataReader dataReader = commande.ExecuteReader();

                while (dataReader.Read())
                {
                    piece.Identifiant = dataReader.GetInt32(0);
                    piece.ID_Vehicule = dataReader.GetInt32(1);
                    piece.ID_SousCat = dataReader.GetInt32(2);
                    piece.Nom = SousCatDB.Get(piece.ID_SousCat).Nom;
                }

                dataReader.Close();

            }
            catch (Exception)
            {
                piece = null;
            }
            finally
            {
                connection.Close();
            }

            return piece;
        }
コード例 #2
0
ファイル: PieceDB.cs プロジェクト: GroupeStageSPPP/Mission1
        public static Boolean Insert(Piece piece)
        {
            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = @"INSERT INTO Piece (" + champs + ") VALUES (@ID_Vehicule,@ID_SousCat);";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres
            commande.Parameters.AddWithValue("ID_Vehicule", piece.ID_Vehicule);
            commande.Parameters.AddWithValue("ID_SousCat", piece.ID_SousCat);
            //Execution
            try
            {
                connection.Open();
                commande.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                connection.Close();
            }
        }
コード例 #3
0
ファイル: PieceDB.cs プロジェクト: GroupeStageSPPP/Mission1
        public static Boolean Update(Piece piece)
        {
            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = @"UPDATE Piece
                               SET ID_Vehicule=@ID_Vehicule,ID_SousCat=@ID_SousCat
                               WHERE Identifiant=@Identifiant ;";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres
            commande.Parameters.AddWithValue("Identifiant",piece.Identifiant);
            commande.Parameters.AddWithValue("ID_Vehicule", piece.ID_Vehicule);
            commande.Parameters.AddWithValue("ID_SousCat", piece.ID_SousCat);
            //Execution
            try
            {
                connection.Open();
                commande.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                connection.Close();
            }
        }
コード例 #4
0
 private void BaddPieceE2_Click(object sender, EventArgs e)
 {
     if (CBtypeE2.SelectedItem != null)
         {
             Piece piece = new Piece();
             piece.ID_Vehicule = Vehicule.Identifiant;
             piece.ID_SousCat = (Int32)CBtypeE2.SelectedValue;
             PieceDB.Insert(piece);
             RefreshPieceE2();
         }
 }