Example #1
0
        public bool Add(Emprunt Ep)
        {
            if (lstEmprunts.Contains(Ep))
            {
                return(false);
            }

            lstEmprunts.Add(Ep);
            return(true);
        }
        private void bt_Ajouter_Click(object sender, EventArgs e)
        {
            try
            {
                Emprunt Ep = new Emprunt();
                Ep.IdAdhérent  = int.Parse(cmb_IdAdhérent.Text);
                Ep.CodeLivre   = int.Parse(cmb_CodeLivre.Text);
                Ep.DateEmprunt = dtp_dateEmprunt.Value;
                Ep.DateRetour  = dtp_dateRetour.Value;
                bool res = Form1.OurBib.EnsembleEmprunts.Add(Ep);
                if (!res)
                {
                    throw new Exception("L'Emprunt existe déjà...");
                }
                MessageBox.Show("Emprunt ajouté avec succés...");

                //update the dataGridView's Content
                dataGridView1.DataSource = null;
                dataGridView1.DataSource = Form1.OurBib.EnsembleEmprunts.lstEmprunts;

                bool res1 = Form1.OurBib.EnsembleAdhérents.AddEmprunt(int.Parse(cmb_IdAdhérent.Text));
                if (!res1)
                {
                    throw new Exception("L'adhérent n'existe pas..");
                }
                bool res2 = Form1.OurBib.EnsembleLivres.AddEmprunt(int.Parse(cmb_CodeLivre.Text));
                if (!res2)
                {
                    throw new Exception("Le livre n'existe pas..");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }