public static bool LinkClientAndCarteBancaire(Client currentClient, CarteBancaire currentCard)
        {
            List<ClientCarteBancaire> clientCarteBancaireDB = ClientCarteBancaireDAO.Search("ID_CLIENT='" + currentClient.ClientId + "' AND ID_CARTE_BANCAIRE = '" + currentCard.BankCardId + "'");
            if (clientCarteBancaireDB.Any())
                return false;

            ClientCarteBancaire newCarte = new ClientCarteBancaire(currentClient, currentCard);
            ClientCarteBancaireDAO.Insert(newCarte);
            return true;
        }
        public String AddCarteForClient(int idClient, int numero, string dateExpi, int crypto, string typeCarte, string hisBank)
        {
            try
            {
                Client client = ClientDAO.Read(idClient);

                if (client == null || client.IsDelete)
                    throw new Exception("Le client n'existe pas");

                DateTime dateExpiration;
                if (!DateTime.TryParse(dateExpi, out dateExpiration))
                    throw new Exception("La date rentrée est invalide");

                List<TypeCarte> currentTypeCarte = TypeCarteDAO.Search("NOM='" + typeCarte + "'");
                if (!currentTypeCarte.Any())
                    throw new Exception ("Le type de carte n'existe pas");

                List<Banque> currentBank = BanqueDAO.Search("NOM='" + hisBank + "'");
                if (!currentBank.Any())
                    throw new Exception ("La banque n'existe pas");

                List<CarteBancaire> CarteBancaireDB = CarteBancaireDAO.Search("NUMERO = '" + numero.ToString() + "' AND DATE_EXPIRATION ='"
                    + dateExpiration.ToShortDateString() + "' AND CRYPTOGRAMME='" + crypto.ToString() + "' AND ID_TYPE_CARTE='" + currentTypeCarte.FirstOrDefault().CardTypeId +
                        "' AND ID_BANQUE='" + currentBank.FirstOrDefault().BankId + "'");
                if (CarteBancaireDB.Any())
                    throw new Exception ("La carte bancaire est déjà enregistrée");

                CarteBancaire newCarteBancaire = new CarteBancaire(numero, dateExpiration, crypto, currentTypeCarte.FirstOrDefault(), currentBank.FirstOrDefault());
                CarteBancaireDAO.Insert(newCarteBancaire);

                ClientCarteBancaire.LinkClientAndCarteBancaire(client, newCarteBancaire);

                BDDConnexion.CloseConnection();
            }
            catch(Exception ex)
            {
                return ex.Message;
            }
            return "La carte a été ajouté avec succès";
        }
 public static void Insert(CarteBancaire carteBancaire)
 {
     SqlCommand cmd = new SqlCommand();
     const string query = "INSERT INTO CARTE_BANCAIRE VALUES ('{0}','{1}','{2}','{3}','{4}','{5}')";
     cmd.CommandText = string.Format(query,carteBancaire.BankCardId.ToString(), carteBancaire.Number.ToString(), carteBancaire.ExperationDate.ToShortDateString()
         , carteBancaire.Cryctogramme, carteBancaire.TypeCard.CardTypeId, carteBancaire.Banque.BankId);
     cmd.CommandType = CommandType.Text;
     cmd.Connection = BDDConnexion.Conn;
     try
     {
         cmd.ExecuteNonQuery();
     }
     catch (Exception e)
     {
         throw (e);
     }
     finally
     {
         cmd.Dispose();
         cmd = null;
     }
 }
        private static List<CarteBancaire> ExecuteReader(SqlCommand cmd)
        {
            SqlDataReader reader;

            List<CarteBancaire> result = new List<CarteBancaire>();
            try
            {
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    CarteBancaire currentBankCard = new CarteBancaire(Convert.ToInt32(reader["ID_CARTE_BANCAIRE"]), Convert.ToInt32(reader["NUMERO"])
                        , DateTime.Parse(reader["DATE_EXPIRATION"].ToString()), Convert.ToInt32(reader["CRYPTOGRAMME"])
                        , TypeCarteDAO.Read(Convert.ToInt32(reader["ID_TYPE_CARTE"])), BanqueDAO.Read(Convert.ToInt32(reader["ID_BANQUE"])));
                    result.Add(currentBankCard);
                }
            }
            catch (Exception e)
            {
                throw (e);
            }

            reader.Close();
            reader.Dispose();
            reader = null;
            return result;
        }
 public ClientCarteBancaire(Client cli, CarteBancaire bankcard)
 {
     client = cli;
     bankCard = bankcard;
 }