Ejemplo n.º 1
0
        public void Init(ObjectId lecteurId)
        {
            m_lecteurId = lecteurId;
            LecteurResult lr = Lecteur.TrouverLecteurParId(lecteurId);

            lblNom.Text    = lr.infoLecteur.nom;
            lblPrenom.Text = lr.infoLecteur.prénom;
            lblTitre.Text  = lr.lecteur.titre;
            FillPrêts();
            timer1.Start();
        }
Ejemplo n.º 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            // Ajouter ou supprimer un exemplaire
            var           collNotice  = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio").GetCollection <Notice>("Notice");
            var           collEmprunt = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio").GetCollection <Emprunt>("Emprunt");
            List <Notice> tmp         = collNotice.Find(new BsonDocument("exemplaires.codeBarre", txtNewExplaire.Text)).ToList();

            if (tmp != null && tmp.Count == 1)
            {
                // Cet exemplaire est-il disponible?
                List <Emprunt> emprunts = collEmprunt.Find(
                    Builders <Emprunt> .Filter.And(
                        Builders <Emprunt> .Filter.Eq(a => a.IdExemplaire, tmp[0].exemplaires.Find(a => a.codeBarre == txtNewExplaire.Text)._id),
                        Builders <Emprunt> .Filter.Eq(a => a.etat, 1)
                        )
                    ).ToList();
                if (emprunts == null || emprunts.Count == 0)
                {
                    // L'ajouter pour ce lecteur
                    Emprunt emprunt = new Emprunt()
                    {
                        idLecteur        = m_lecteurId,
                        IdExemplaire     = tmp[0].exemplaires.Find(a => a.codeBarre == txtNewExplaire.Text)._id,
                        etat             = 1,
                        dateEmprunt      = DateTime.Now,
                        dateRetourPrévue = DateTime.Now.AddDays(21)
                    };
                    collEmprunt.InsertOne(emprunt);
                    FillPrêts();
                }
                else if (emprunts.Count > 0)
                {
                    // Est-ce le lecteur en cours
                    if (emprunts[0].idLecteur == m_lecteurId)
                    {
                        // Le supprimer de la liste des emprunts de ce lecteur
                        collEmprunt.UpdateOne(Builders <Emprunt> .Filter.Eq(a => a._id, emprunts[0]._id),
                                              Builders <Emprunt> .Update.Set(a => a.etat, 2).CurrentDate(a => a.dateRetourEffective));
                        FillPrêts();
                    }
                    else
                    {
                        // Retrouver le lecteur
                        LecteurResult lr = Lecteur.TrouverLecteurParId(emprunts[0].idLecteur);
                        if (lr != null)
                        {
                            MessageBox.Show($"Ce document est déjà emprunté par {lr.infoLecteur.nom} {lr.infoLecteur.prénom} ({lr.lecteur.titre})");
                        }
                    }
                }
            }
            txtNewExplaire.SelectAll();
        }
Ejemplo n.º 3
0
        public void Init(ObjectId lecteur)
        {
            LecteurResult lr = Lecteur.TrouverLecteurParId(lecteur);

            if (lr != null)
            {
                var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio");
                infoLecteurBindingSource.DataSource = db.GetCollection <InfoLecteur>("InfoLecteur").Find(a => a.lecteurId == lr.lecteur._id).ToList();
                lecteurBindingSource.DataSource     = new List <Lecteur>()
                {
                    lr.lecteur
                };
                lecteurBindingSource.Position = 0;
            }
        }
Ejemplo n.º 4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            // Ajouter ou supprimer un exemplaire
            var           collNotice  = new MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio").GetCollection <Notice>("Notice");
            var           collEmprunt = new MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio").GetCollection <Emprunt>("Emprunt");
            List <Notice> tmp         = collNotice.Find(new BsonDocument("exemplaires.codeBarre", txtNewExplaire.Text)).ToList();

            if (tmp != null && tmp.Count == 1)
            {
                // Cet exemplaire est-il disponible?
                List <Emprunt> emprunts = collEmprunt.Find(
                    Builders <Emprunt> .Filter.And(
                        Builders <Emprunt> .Filter.Eq(a => a.IdExemplaire, tmp[0].exemplaires.Find(a => a.codeBarre == txtNewExplaire.Text)._id),
                        Builders <Emprunt> .Filter.Eq(a => a.etat, 1)
                        )
                    ).ToList();
                if (emprunts == null || emprunts.Count == 0)
                {
                    // L'ajouter pour ce lecteur
                    Emprunt emprunt = new Emprunt()
                    {
                        idLecteur        = m_lecteur.infoLecteur._id,
                        IdExemplaire     = tmp[0].exemplaires.Find(a => a.codeBarre == txtNewExplaire.Text)._id,
                        etat             = 1,
                        dateEmprunt      = DateTime.Now,
                        dateRetourPrévue = DateTime.Now.AddDays(21)
                    };
                    collEmprunt.InsertOne(emprunt);
                    FillPrêts();
                }
                else if (emprunts.Count > 0)
                {
                    // Est-ce le lecteur en cours
                    if (emprunts[0].idLecteur == m_lecteur.infoLecteur._id)
                    {
                        // Le supprimer de la liste des emprunts de ce lecteur
                        collEmprunt.UpdateOne(Builders <Emprunt> .Filter.Eq(a => a._id, emprunts[0]._id),
                                              Builders <Emprunt> .Update.Set(a => a.etat, 2).CurrentDate(a => a.dateRetourEffective));
                        FillPrêts();
                    }
                    else
                    {
                        // Retrouver le lecteur
                        LecteurResult lr = Lecteur.TrouverLecteurParId(emprunts[0].idLecteur);
                        if (lr != null)
                        {
                            MessageBox.Show($"Ce document est déjà emprunté par {lr.infoLecteur.nom} {lr.infoLecteur.prénom} ({lr.lecteur.titre})");
                        }
                    }
                }
            }
            else if (tmp.Count != null && tmp.Count > 1)
            {
                MessageBox.Show($"Ce code exemplaire existe {tmp.Count} fois.\r\nCorrigez la base");
            }
            else
            {
                if (MessageBox.Show("Ce code exemplaire n'existe pas.\r\nVoulez-vous quand même le prêter et l'ajouter à l'inventaire plus tard ?", "Erreur", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    Emprunt emprunt = new Emprunt()
                    {
                        idLecteur = m_lecteur.infoLecteur._id,
                        //IdExemplaire = tmp[0].exemplaires.Find(a => a.codeBarre == txtNewExplaire.Text)._id,
                        etat             = 1,
                        dateEmprunt      = DateTime.Now,
                        dateRetourPrévue = DateTime.Now.AddDays(21)
                    };
                    Notice notice = new Notice()
                    {
                        isbn = txtNewExplaire.Text, indexes = new BsonDocument("ajouterLecteur", emprunt.ToBsonDocument()).Add("Status", ctrlAttente.A_TRAITER)
                    };
                    new MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio").GetCollection <Notice>("NoticeAttente").InsertOne(notice);
                }
            }
            txtNewExplaire.SelectAll();
        }
Ejemplo n.º 5
0
        private void btnCirculation_Click(object sender, EventArgs e)
        {
            var collNotice  = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio").GetCollection <Notice>("Notice");
            var collEmprunt = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio").GetCollection <Emprunt>("Emprunt");

            // Chercher lecteur ou exemplaire emprunté
            if (txtSearchCirculation.Text.All(char.IsDigit))
            {
                List <Notice> tmp = collNotice.Find(new BsonDocument("exemplaires.codeBarre", txtSearchCirculation.Text)).ToList();
                if (tmp != null)
                {
                    if (tmp.Count == 1)
                    {
                        Exemplaire exemplaire = tmp[0].exemplaires.Find(a => a.codeBarre == txtSearchCirculation.Text);
                        if (exemplaire != null)
                        {
                            // Retrouver le lecteur concerné
                            List <Emprunt> tmp2 = collEmprunt.Find(
                                Builders <Emprunt> .Filter.And(
                                    Builders <Emprunt> .Filter.Eq(a => a.IdExemplaire, exemplaire._id),
                                    Builders <Emprunt> .Filter.Eq(a => a.etat, 1))
                                ).ToList();
                            if (tmp2 != null && tmp2.Count > 0)
                            {
                                AffichageLecteur(Lecteur.TrouverLecteurParId(tmp2[0].idLecteur));
                            }
                        }
                        else
                        {
                            MessageBox.Show("Erreur interne 1");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Il existe plusieurs exemplaires ce qui est anormal");
                    }
                }
                else
                {
                    MessageBox.Show("Cet exemplaire n'existe pas");
                }
            }
            else
            {
                // Cherche le lecteur
                List <LecteurResult> lr = Lecteur.TrouverLecteursParSearch(txtSearchCirculation.Text);
                if (lr.Count > 0)
                {
                    if (lr.Count == 1)
                    {
                        AffichageLecteur(lr[0]);
                    }
                    else
                    {
                        ctrlChoixLecteur choix = new ctrlChoixLecteur()
                        {
                            Dock = DockStyle.Fill
                        };
                        choix.Init(lr);
                        choix.ChoixLecteurEvent += Choix_ChoixLecteurEvent;
                        pnlCirculation.Controls.Clear();
                        pnlCirculation.Controls.Add(choix);
                    }
                }
                else
                {
                    pnlCirculation.Controls.Clear();
                    MessageBox.Show("Pas de lecteur à ce nom");
                }
            }
            txtSearchCirculation.SelectAll();
        }