private void AlertToMuchBook(PersonneBO pPersonneBo)
        {
            if (pPersonneBo == null){
                return;
            }
            //var empruntNumber = CGlobalCache.LstEmpruntSelectAll.FindAll(xx => xx.ClientId == pPersonneBo.PersonneId).GroupBy(yy => yy.LivreId).Select(zz => new{zz.Key, value = zz.Max(q => q.State)}).Count(gg => gg.value == "emp");
            var empruntNumber = CGlobalCache.LstEmpruntSelectAll.ToList().FindAll(xx => xx.ClientId == pPersonneBo.PersonneId);
            var maxActionId = empruntNumber.GroupBy(xx => xx.LivreId).Select(dd => new{LivreId = dd.Key, ActionId = dd.Max(qq => qq.ActionId)});
            var toCount = maxActionId.Select(dataInMaxActionResult => CGlobalCache.LstEmpruntSelectAll.ToList().Find(xx => xx.ActionId == dataInMaxActionResult.ActionId && xx.LivreId == dataInMaxActionResult.LivreId)).Where(result => result != null && result.State == "emp").ToList();

            lblInfo.Visible = true;
            lblInfo.Text = String.Format(@"Nombre de livre emprunté total {0}", toCount.Count());
            //_bTooMuchBook = (empruntNumber >= 3);
        }
        public static List<DemandeReservationBO> SelectByEmpruntId(int pEmpruntId, PersonneBO pPersonne, LivreBO pLivre)
        {
            List<DemandeReservationBO> lstDemandeReservation;

            try {
                using (var demandeReservationDal = new DemandeReservationDAL(Util.GetConnection())) {
                    lstDemandeReservation = demandeReservationDal.DemandeReservationDAL_SelectByEmpruntId(pEmpruntId).ToList();
                    foreach (var demandeReservationBo in lstDemandeReservation){
                        demandeReservationBo.RefLivre = pLivre.RefLivre;
                        demandeReservationBo.Personne = pPersonne;
                    }
                }
            } catch (Exception ex) {
                throw;
            }

            return lstDemandeReservation;
        }
 internal EmpruntBO SaveRetour(AdministrateurBO pAdministrateurBo, PersonneBO pPersonneBo, LivreBO livreBo)
 {
     var empruntIFac = new EmpruntIFACClient();
     return empruntIFac.InsertRetour(CGlobalCache.SessionManager.Token, pAdministrateurBo.AdministrateurId, livreBo.LivreId);
 }
 internal EmpruntBO SaveEmprunt(AdministrateurBO pAdministrateurBo, PersonneBO pPersonneBo, LivreBO livreBo, ReservationBO pReservationBo)
 {
     var empruntIFac = new EmpruntIFACClient();
     return pReservationBo != null ? empruntIFac.ConvertReservation(CGlobalCache.SessionManager.Token, pAdministrateurBo.AdministrateurId, pReservationBo.ReservationId) : empruntIFac.InsertEmprunt(CGlobalCache.SessionManager.Token,pAdministrateurBo.AdministrateurId , pPersonneBo.PersonneId, livreBo.LivreId);
 }
        private void FillCmpLivreField(PersonneBO pPersonneBo)
        {
            if (pPersonneBo == null || CGlobalCache.ActualBibliotheque == null){
                return;
            }
            var empruntNumber = CGlobalCache.LstEmpruntSelectAll.ToList().FindAll(xx => xx.ClientId == pPersonneBo.PersonneId);
            var maxActionId = empruntNumber.GroupBy(xx => xx.LivreId).Select(dd => new{LivreId = dd.Key, ActionId = dd.Max(qq => qq.ActionId)});
            var clientEmprunt = maxActionId.Select(dataInMaxActionResult => CGlobalCache.LstEmpruntSelectAll.ToList().Find(xx => xx.ActionId == dataInMaxActionResult.ActionId && xx.LivreId == dataInMaxActionResult.LivreId)).Where(result => result != null && result.State == "emp" && result.Livre.BibliothequeId == CGlobalCache.ActualBibliotheque.BibliothequeId).ToList();
            var lstResult = clientEmprunt.Select(empruntBo => empruntBo.Livre).ToList();

            cmbLivreField.DataSource = null;
            if (!lstResult.Any()){
                cmbLivreField.Enabled = false;
                return;
            }
            cmbLivreField.Enabled = true;
            _bCmbClientFieldToogle = false;
            var tmpClientDatas = lstResult.Select(yy => new { Key = yy.InternalReference + ": " + yy.ToString(), Value = yy }).ToList();
            tmpClientDatas.Insert(0, new { Key = "", Value = null as LivreBO });
            cmbLivreField.DataSource = tmpClientDatas;
            cmbLivreField.ValueMember = "Value";
            cmbLivreField.DisplayMember = "Key";
            _bCmbClientFieldToogle = true;
        }
 private void SearchReservationField(PersonneBO objPersonne)
 {
     var reservationIFac = new ReservationIFACClient();
     AsyncGuiSelectReservationByClientId asyncExecute = reservationIFac.SelectEnCoursValidByClientId;
     try{
         asyncExecute.BeginInvoke(CGlobalCache.SessionManager.Token, objPersonne.PersonneId, result =>{
             var sampleReservationDelegate = (AsyncGuiSelectReservationByClientId)((AsyncResult)result).AsyncDelegate;
             _lstReservationField = sampleReservationDelegate.EndInvoke(result);
             if (_lstReservationField.Count(xx => xx.Emprunt.Livre.BibliothequeId == CGlobalCache.ActualBibliotheque.BibliothequeId) > 0) {
                 _bCmbClientFieldToogle = false;
                 var tmpReservationDatas = _lstReservationField.Select(yy => new { Key = yy.ReservationId + ": " + yy.Emprunt.Livre.ToString(), Value = yy }).ToList();
                 tmpReservationDatas.Insert(0, new { Key = "", Value = null as ReservationBO });
                 cmbReservationField.DataSource = null;
                 cmbReservationField.DataSource = tmpReservationDatas;
                 cmbReservationField.ValueMember = "Value";
                 cmbReservationField.DisplayMember = "Key";
                 cmbReservationField.Enabled = true;
                 _bCmbClientFieldToogle = true;
             } else {
                 cmbReservationField.DataSource = null;
                 cmbReservationField.Enabled = false;
             }
         }, null);
     } catch(Exception ex){
         reservationIFac.Close();
         MessageBox.Show(Resources.EmpruntManagement_SearchReservationField_Erreur_lors_de_la_recuperation_des_informations_sur_la_reservation_demandee);
     }
 }