void metroComboBoxLivre_Load(string numEtagere)
        {
            this.metroComboBoxLivre.Items.Clear();

            try
            {
                Gestionnaire.con.Open();
                SqlDataReader sdr;

                // Select etagere avec numEtagere
                sdr = Etagere.Select(0, numEtagere);
                int id_etagere = 0;
                if (sdr.Read())
                {
                    id_etagere = Convert.ToInt32(sdr["id"]);
                }
                sdr.Close();

                // Select livres avec id_etagere
                sdr = Livre.Select(0, "", id_etagere);
                while (sdr.Read())
                {
                    this.metroComboBoxLivre.Items.Add(sdr["code"].ToString());
                }
                sdr.Close();
            }catch (Exception ex)
            {
                MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Gestionnaire.con.Close();
            }
        }
예제 #2
0
        private void metroComboBoxEtagereRetire_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.metroComboBoxLivreRetire.Items.Clear();
            this.metroComboBoxEtagereRemplacant.Items.Clear();

            if (this.metroComboBoxLivreRemplacant.Enabled)
            {
                this.metroComboBoxLivreRemplacant.Items.Clear();
            }

            this.metroComboBoxLivreRetire.Enabled       = true;
            this.metroComboBoxEtagereRemplacant.Enabled = true;

            string numEtagere = this.metroComboBoxEtagereRetire.Text;
            int    id_etagere = 0;

            try
            {
                Gestionnaire.con.Open();
                SqlDataReader sdr;

                // select etageres
                sdr = Etagere.Select();
                while (sdr.Read())
                {
                    if (numEtagere == sdr["numero"].ToString())
                    {
                        id_etagere = Convert.ToInt32(sdr["id"]);
                        continue;
                    }
                    this.metroComboBoxEtagereRemplacant.Items.Add(sdr["numero"].ToString());
                }
                sdr.Close();

                this.metroComboBoxLivreRetire.Items.Clear();
                // select livre avec id_etagere
                sdr = Livre.Select(0, "", id_etagere);
                while (sdr.Read())
                {
                    metroComboBoxLivreRetire.Items.Add(sdr["code"]);
                }
                sdr.Close();
            }catch (Exception ex)
            {
                MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Gestionnaire.con.Close();
            }
        }
예제 #3
0
        private void buttonRemplacer_Click(object sender, EventArgs e)
        {
            this.erreurEtagereRetire.Visible     = false;
            this.erreurEtagereRemplacant.Visible = false;
            this.erreurLivreRemplacant.Visible   = false;
            this.erreurLivreRetire.Visible       = false;

            bool erreurInput = false;

            string numEtagere1 = this.metroComboBoxEtagereRetire.Text;

            if (numEtagere1 == "")
            {
                this.erreurEtagereRetire.Visible = true;
                erreurInput = true;
            }

            string numEtagere2 = this.metroComboBoxEtagereRemplacant.Text;

            if (numEtagere2 == "")
            {
                this.erreurEtagereRemplacant.Visible = true;
                erreurInput = true;
            }

            string code1 = this.metroComboBoxLivreRetire.Text;

            if (code1 == "")
            {
                this.erreurLivreRetire.Visible = true;
                erreurInput = true;
            }

            string code2 = this.metroComboBoxLivreRemplacant.Text;

            if (code2 == "")
            {
                this.erreurLivreRemplacant.Visible = true;
                erreurInput = true;
            }

            if (!erreurInput)
            {
                Livre livre       = null;
                int   id_livre    = 0;
                int   id_etagere1 = 0;
                int   id_etagere2 = 0;

                try
                {
                    Gestionnaire.con.Open();
                    SqlDataReader sdr;

                    // select livre avec code1
                    sdr = Livre.Select(0, code1);
                    if (sdr.Read())
                    {
                        id_livre    = Convert.ToInt32(sdr["id"]);
                        id_etagere1 = Convert.ToInt32(sdr["id_etagere"]);
                        livre       = new Livre(sdr["code"].ToString(), sdr["titre"].ToString(), Convert.ToDouble(sdr["prix"]));
                    }
                    sdr.Close();

                    // delete livre avec id_livre
                    Livre.Delete(id_livre);
                    Acceuil.livres.Add(livre);

                    // select livre avec code2
                    sdr = Livre.Select(0, code2);
                    if (sdr.Read())
                    {
                        id_livre    = Convert.ToInt32(sdr["id"]);
                        id_etagere2 = Convert.ToInt32(sdr["id"]);
                        livre       = new Livre(sdr["code"].ToString(), sdr["titre"].ToString(), Convert.ToDouble(sdr["prix"]));
                    }
                    sdr.Close();

                    // update livre avec id_livre
                    Livre.Update(id_livre, id_etagere1);

                    MetroFramework.MetroMessageBox.Show(this, "Le livre a été remplacé en succés", "Message", MessageBoxButtons.OK, MessageBoxIcon.Question);
                }
                catch (Exception ex)
                {
                    MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    Gestionnaire.con.Close();
                }
                this.Hide();
                this.RemplacerLivre_Load();
                this.Show();
            }
        }
        private void buttonAjouter_Click(object sender, EventArgs e)
        {
            this.erreurCode.Visible    = false;
            this.erreurEtagere.Visible = false;

            bool erreurInput = false;

            string code = metroComboBoxCode.Text;

            if (code == "")
            {
                this.erreurCode.Visible = true;
                erreurInput             = true;
            }

            string etagere = metroComboBoxEtagere.Text;

            if (etagere == "")
            {
                this.erreurEtagere.Visible = true;
                erreurInput = true;
            }

            if (!erreurInput)
            {
                int   id_etagere = 0;
                Livre livre      = null;

                // Chercher le livre dans la listes des livres Acceuil
                livre = Acceuil.rechercherLivre(code);

                // Chercher l'etagere dans la listes d'etageres Acceuil
                Etagere eta = Acceuil.RechercherEtagere(etagere);
                eta.livres.Add(livre);

                try
                {
                    Gestionnaire.con.Open();
                    SqlDataReader sdr;

                    // select livre avec code
                    sdr = Livre.Select(0, code);
                    if (sdr.HasRows)
                    {
                        throw new Exception("Un livre possédant le même code existe déjà");
                    }

                    sdr.Close();

                    // Select etagere avec numero etagere
                    sdr = Etagere.Select(0, etagere);
                    if (sdr.Read())
                    {
                        id_etagere = Convert.ToInt32(sdr["id"]);
                    }
                    sdr.Close();

                    // Insert livre
                    Livre.insert(livre, id_etagere);

                    Acceuil.livres.Remove(livre);

                    MetroFramework.MetroMessageBox.Show(this, "Le livre a été remis dans l'étagère en succés", "Message", MessageBoxButtons.OK, MessageBoxIcon.Question);
                }
                catch (Exception ex)
                {
                    MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    Gestionnaire.con.Close();
                }
                this.Hide();
                this.RemettreLivre_load();
                this.Show();
            }
        }