コード例 #1
0
        private void buttonConnexion_Click(object sender, EventArgs e)
        {
            if (LoginBox.Text != null && PassBox.Text != null)
            {
                string sql = "Select * " +
                             "From Abonné " +
                             "Where Login = '******' and Password = '******'";

                OleDbCommand    cmd    = new OleDbCommand(sql, dbCon);
                OleDbDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    int    code   = reader.GetInt32(0);
                    string nom    = reader.GetString(1);
                    string prenom = reader.GetString(2);
                    string login  = reader.GetString(3);
                    string pass   = reader.GetString(4);
                    int    pays   = reader.GetInt32(5);


                    abn = new Abonné()
                    {
                        Code_Abonné   = code,
                        Nom_Abonné    = nom,
                        Prénom_Abonné = prenom,
                        Login         = login,
                        Password      = pass,
                        Code_Pays     = pays
                    };
                }
            }

            chargerListeAlbum();
            checkBoxEmprunt.Enabled = abn != null;
        }
コード例 #2
0
 private void PopUpMessageNonRendu(Abonné a)
 {
     #region Pop up qui d'affiche si un abonné qu'on veut supprimer, n'a pas rendu son album
     string nonRetour = "Select COUNT(Emprunter.Code_Abonné) " +
                        "from Emprunter " +
                        "inner join Abonné on Abonné.Code_Abonné = Emprunter.Code_Abonné " +
                        "inner join Album on Album.Code_Album = Emprunter.Code_Album " +
                        "where Emprunter.Date_Retour is null and DATEDIFF(day, Date_Emprunt, GETDATE()) > 365 ";
     OleDbCommand    cmd    = new OleDbCommand(nonRetour, dbCon);
     OleDbDataReader reader = cmd.ExecuteReader();
     while (reader.Read())
     {
         if (reader.GetInt32(0) != 0)
         {
             string            message = a.Nom_Abonné + " " + a.Prénom_Abonné + " n'a pas rendu tous ses albums empruntés ou n'a pas emprunté depuis plus d'un an, voulez vous quand même le supprimer";
             MessageBoxButtons buttons = MessageBoxButtons.YesNo;
             var result = MessageBox.Show(message, "Erreur", buttons);
             if (result == DialogResult.Yes)
             {
                 SupprimerUnAbo(a.Code_Abonné);
                 labelMessage.Text = "Supression OK";
             }
         }
         else
         {
             SupprimerUnAbo(a.Code_Abonné);
             labelMessage.Text = "Supression OK";
         }
     }
     reader.Close();
     #endregion
 }
コード例 #3
0
        private void checkBoxEmprunt_CheckedChanged(object sender, EventArgs e)
        {
            listAlbums.Items.Clear();
            if (LoginBox.Text != null && PassBox.Text != null)
            {
                string sql = "Select *" +
                             " From Abonné" +
                             " Where Login = '******' and Password = '******'";
                OleDbCommand    cmd    = new OleDbCommand(sql, dbCon);
                OleDbDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    int    code   = reader.GetInt32(0);
                    string nom    = reader.GetString(1);
                    string prenom = reader.GetString(2);
                    string login  = reader.GetString(3);
                    string pass   = reader.GetString(4);
                    int    pays   = reader.GetInt32(5);


                    abn = new Abonné()
                    {
                        Code_Abonné   = code,
                        Nom_Abonné    = nom,
                        Prénom_Abonné = prenom,
                        Login         = login,
                        Password      = pass,
                        Code_Pays     = pays
                    };
                }
            }
            buttonProlonger.Enabled   = checkBoxEmprunt.Checked && listAlbums.SelectedItem != null;
            buttonPrologerAll.Enabled = checkBoxEmprunt.Checked;
            chargerListeAlbum();
        }
コード例 #4
0
        public void ChargerAbonneinactif()
        {
            #region Chargement des Abonnés inactifs
            YaTilAbonnésInactifs();
            // récupération de l'ensemble des abonné inactif
            string sql2 = "Select Distinct Abonné.Code_Abonné, Nom_Abonné, Prénom_Abonné " +
                          "from Abonné" +
                          " inner join Emprunter on Emprunter.Code_Abonné = Abonné.Code_Abonné" +
                          " inner join Album on Album.Code_Album = Emprunter.Code_Album " +
                          "Where DATEDIFF(day, Date_Emprunt, GETDATE()) > 365 ";
            OleDbCommand    cmd    = new OleDbCommand(sql2, dbCon);
            OleDbDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                // on récupère nom et prénom
                int    Code_Abonné   = reader.GetInt32(0);
                string Nom_Abonne    = reader.GetString(1);
                string Prenom_Abonne = reader.GetString(2);
                Abonné a             = new Abonné();
                // Ajout dans la ListBox
                a.Code_Abonné   = Code_Abonné;
                a.Prénom_Abonné = Prenom_Abonne;
                a.Nom_Abonné    = Nom_Abonne;

                listBox1.Items.Add(a);
            }
            reader.Close();
            #endregion
        }
コード例 #5
0
 public MesEmprunts()
 {
     InitializeComponent();
     dbCon = new OleDbConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
     dbCon.Open();
     abn = new Abonné();
     buttonProlonger.Enabled   = checkBoxEmprunt.Checked && listAlbums.SelectedItem != null;
     buttonPrologerAll.Enabled = checkBoxEmprunt.Checked;
     checkBoxEmprunt.Enabled   = abn == null;
 }
コード例 #6
0
        public void ChargerAbonne()
        {
            #region Chargement des Abonnés
            // récupération de l'ensemble des abonnés
            string sql = "Select distinct Abonné.Code_Abonné, Nom_Abonné, Prénom_Abonné " +
                         "from Abonné" +
                         " Order By Nom_Abonné";
            OleDbCommand    cmd    = new OleDbCommand(sql, dbCon);
            OleDbDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                // on récupère id, nom, prenom
                int    Code_Abonné   = reader.GetInt32(0);
                string Nom_Abonne    = reader.GetString(1);
                string Prenom_Abonne = reader.GetString(2);

                Abonné j   = new Abonné();
                string nom = "Sans nom";
                if (Nom_Abonne != null)
                {
                    string[] v = System.Text.RegularExpressions.Regex.Split(Nom_Abonne, "  ");
                    nom = v[0];
                }
                string prenom = "Sans nom";
                if (Prenom_Abonne != null)
                {
                    string[] v = System.Text.RegularExpressions.Regex.Split(Prenom_Abonne, "  ");
                    prenom = v[0];
                }

                // Ajout dans la ListBox
                j.Code_Abonné   = Code_Abonné;
                j.Prénom_Abonné = prenom;
                j.Nom_Abonné    = nom;
                if (dateEmpruntPlusRecente(j).ToString() == "01/01/0001 00:00:00")
                {
                    listBox2.Items.Add(j + " - Pas d'emprunt");
                }
                else
                {
                    listBox2.Items.Add(j + " - " + dateEmpruntPlusRecente(j));
                }
            }
            reader.Close();
            #endregion
        }
コード例 #7
0
 private void SupprimerAbo_Click(object sender, EventArgs e)
 {
     #region Supprimer un Abonné
     if (listBox1.SelectedItem != null)
     {
         // récupération Abonné  sélectionné
         Abonné a = (Abonné)listBox1.SelectedItem;
         PopUpMessageNonRendu(a);
         listBox1.Items.Clear();
         ChargerAbonneinactif();
         listBox2.Items.Clear();
         ChargerAbonne();
     }
     else
     {
         labelMessage.Text = "Erreur ! ";
     }
     #endregion
 }
コード例 #8
0
ファイル: Retards.cs プロジェクト: JonathanMoze/Discotheque
        private void listAbo_SelectedIndexChanged(object sender, EventArgs e)
        {
            #region affichage des informations sur l'abonné choisi


            Abonné a = (Abonné)listAbo.SelectedItem;
            textBoxLogin.Text = a.Login;
            listRetards.Items.Clear();

            foreach (Emprunter emp in emprunts)
            {
                if (emp.Code_Abonné == a.Code_Abonné)
                {
                    String sql = "Select * " +
                                 "From Album " +
                                 "Where Code_Album = " + emp.Code_Album.ToString();
                    OleDbCommand    cmd    = new OleDbCommand(sql, dbCon);
                    OleDbDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        int    codeAlb     = reader.GetInt32(0);
                        string titre       = reader.GetString(1);
                        int    annee       = reader.GetInt32(2);
                        int    codeGenre   = reader.GetInt32(3);
                        int    codeEditeur = reader.GetInt32(4);

                        Album album = new Album()
                        {
                            Code_Album   = codeAlb,
                            Titre_Album  = titre,
                            Année_Album  = annee,
                            Code_Genre   = codeGenre,
                            Code_Editeur = codeEditeur
                        };

                        listRetards.Items.Add(album);
                    }
                }
            }
            #endregion
        }
コード例 #9
0
        private DateTime dateEmpruntPlusRecente(Abonné a)
        {
            #region Trouver la date la plus récente
            DateTime dateARenvoyer      = new DateTime();
            string   dateDernierEmprunt = " Select Date_emprunt " +
                                          "from Emprunter" +
                                          " inner join Album on Album.Code_Album = Emprunter.Code_Album" +
                                          " inner join Abonné on Abonné.Code_Abonné = Emprunter.Code_Abonné" +
                                          " where Emprunter.Code_Abonné = " + a.Code_Abonné
                                          + " Order By Date_Emprunt";
            OleDbCommand    cmd    = new OleDbCommand(dateDernierEmprunt, dbCon);
            OleDbDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                dateARenvoyer = reader.GetDateTime(0);
            }
            return(dateARenvoyer);

            #endregion
        }
コード例 #10
0
 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     #region Sélectionner un abonné dans la liste des inactifs
     SupprimerAbo.Enabled = true;
     Abonné ab = (Abonné)listBox1.SelectedItem;
     if (listBox1.SelectedItems != null && ab != null)
     {
         string date = "select Date_Emprunt " +
                       "from Emprunter " +
                       "inner join Abonné on Abonné.Code_Abonné = Emprunter.Code_Abonné" +
                       " inner join Album on Album.Code_Album = Emprunter.Code_Album " +
                       " where Abonné.Code_Abonné like " + ab.Code_Abonné;
         OleDbCommand    cmd    = new OleDbCommand(date, dbCon);
         OleDbDataReader reader = cmd.ExecuteReader();
         while (reader.Read())
         {
             labelDate.Text      = " Dernier emprunt le " + reader.GetDateTime(0).ToString();
             labelDate.ForeColor = Color.Blue;
         }
         reader.Close();
     }
     #endregion
 }
コード例 #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            #region Récuperation de l'album et l'abonné
            Abonné abn = new Abonné();
            abn.Login = "******";
            bool emprunter = false;
            labelMessage.Text = "";
            label5.Text       = "";
            Album AlbSelection = new Album();
            try
            {
                if (listBox1.SelectedItem != null && !titreAlbum.Text.Contains("INDISPONIBLE"))
                {
                    string album = "SELECT Album.Code_Album, Album.Titre_Album FROM Album "
                                   + "WHERE Titre_Album = '" + listBox1.SelectedItem + "'"
                                   + "ORDER BY Titre_Album";
                    OleDbCommand    cmd    = new OleDbCommand(album, dbCon);
                    OleDbDataReader reader = cmd.ExecuteReader();
                    reader.Read();
                    int    id    = reader.GetInt32(0);
                    string titre = "Sans titre";
                    if (!reader.IsDBNull(1))
                    {
                        titre = reader.GetString(1);
                    }
                    AlbSelection = new Album(id, titre);
                    reader.Close();
                }
                else
                {
                    emprunter        = true;
                    label5.Text      = "Cet album est indisponible";
                    label5.ForeColor = Color.Red;
                }
            }
            catch
            {
                labelMessage.Text = "Veuillez choisir un autre album et cliquez sur emprunter ";
            }
            try
            {
                string abonne = "SELECT Abonné.Code_Abonné, Abonné.Login, Code_Pays FROM Abonné "
                                + "WHERE Login = '******'";
                OleDbCommand    cmd    = new OleDbCommand(abonne, dbCon);
                OleDbDataReader reader = cmd.ExecuteReader();
                reader.Read();
                abn.Code_Abonné = reader.GetInt32(0);
                abn.Login       = reader.GetString(1);
                reader.Close();
            } catch (Exception)
            {
                label5.Text      = "Entrez un login valide";
                label5.ForeColor = Color.Red;
            }
            // Verifier que l'album est disponible
            if (!emprunter)
            {
                string abonne = "SELECT COUNT(Emprunter.Code_Album) FROM Emprunter "
                                + "WHERE Date_Retour IS NULL AND Emprunter.Code_Album = '" + AlbSelection.Code_Album + "'";
                OleDbCommand    cmd    = new OleDbCommand(abonne, dbCon);
                OleDbDataReader reader = cmd.ExecuteReader();
                reader.Read();
                int cmpte = reader.GetInt32(0);
                if (cmpte != 0)
                {
                    emprunter        = true;
                    label5.Text      = "Cet album est indisponible";
                    label5.ForeColor = Color.Red;
                }
            }

            // Création d'emprunt
            if (listBox1.SelectedItem != null && abn.Login != "temp" && !emprunter)
            {
                try
                {
                    string insert = " insert into Emprunter (Code_Album, Code_Abonné, Date_Emprunt) " +
                                    "Values (?,?,?)";
                    OleDbCommand cmd = new OleDbCommand(insert, dbCon);
                    Console.WriteLine(abn.Code_Abonné);
                    cmd.Parameters.Add("Code_album", OleDbType.Integer).Value   = AlbSelection.Code_Album;
                    cmd.Parameters.Add("Code_abonné", OleDbType.Integer).Value  = abn.Code_Abonné;
                    cmd.Parameters.Add("Date_emprunt", OleDbType.VarChar).Value = DateTime.Now;
                    cmd.ExecuteNonQuery();
                    Login.Clear();
                    label5.Text         = "Emprunt OK";
                    label5.ForeColor    = Color.Red;
                    labelDate.Text      = "Album emprunté le " + DateTime.Now;
                    labelDate.ForeColor = Color.Blue;
                }
                catch
                {
                    label5.Text      = "Erreur !!";
                    label5.ForeColor = Color.Red;
                }
            }
            switch (comboBox1.SelectedItem)
            {
            case "Tout":
                ChargerTousAlbums();
                break;

            case "les albums disponibles uniquement":
                ChargeAlbumsDispo();
                break;

            case "les albums indisponibles uniquement":
                ChargerAlbumsNonDispo();
                break;

            default:
                ChargeAlbumsDispo();
                break;
            }
            #endregion
        }
コード例 #12
0
ファイル: Retards.cs プロジェクト: JonathanMoze/Discotheque
        private void chargeRetards()
        {
            #region chargement des données utiles pour cette page (Emprunts en retard + abonnés concernés)
            List <Emprunter> retards = new List <Emprunter>();
            string           sql     = "Select *" +
                                       "From Emprunter";
            OleDbCommand    cmd    = new OleDbCommand(sql, dbCon);
            OleDbDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                int      codeAbo = reader.GetInt32(0);
                int      codeAlb = reader.GetInt32(1);
                DateTime DateEmp = reader.GetDateTime(2);
                if (!reader.IsDBNull(3))
                {
                    DateTime DateRet = reader.GetDateTime(3);

                    retards.Add(new Emprunter()
                    {
                        Code_Abonné  = codeAbo,
                        Code_Album   = codeAlb,
                        Date_Emprunt = DateEmp,
                        Date_Retour  = DateRet
                    });
                }
                else
                {
                    retards.Add(new Emprunter()
                    {
                        Code_Abonné  = codeAbo,
                        Code_Album   = codeAlb,
                        Date_Emprunt = DateEmp
                    });
                }
            }

            foreach (Emprunter e in retards)
            {
                DateTime       dateEmprunt = (DateTime)e.Date_Emprunt;
                DateTimeOffset dateLimite  = new DateTimeOffset(dateEmprunt);
                dateLimite = dateLimite.AddMonths(1).AddDays(10);
                if (dateLimite <= DateTime.Today && e.Date_Retour == null)
                {
                    emprunts.Add(e);


                    sql = "Select * " +
                          "From Abonné " +
                          "Where Code_Abonné = " + e.Code_Abonné.ToString();

                    cmd    = new OleDbCommand(sql, dbCon);
                    reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        int    code   = reader.GetInt32(0);
                        string nom    = reader.GetString(1);
                        string prenom = reader.GetString(2);
                        string login  = reader.GetString(3);
                        string pass   = reader.GetString(4);
                        int    pays   = reader.GetInt32(5);


                        Abonné a = new Abonné()
                        {
                            Code_Abonné   = code,
                            Nom_Abonné    = nom,
                            Prénom_Abonné = prenom,
                            Login         = login,
                            Password      = pass,
                            Code_Pays     = pays
                        };
                        bool contient = false;
                        foreach (Abonné abn in abos)
                        {
                            if (abn.Code_Abonné == a.Code_Abonné)
                            {
                                contient = true;
                            }
                        }

                        if (!contient)
                        {
                            abos.Add(a);
                        }
                    }
                }
            }

            #endregion
        }