public static Boolean LoadCache(FrmMdi pFrmMdi)
        {
            var bReturn = true;
            PersonneIFACClient personneIFac = null;
            EmpruntIFACClient locationIFac = null;
            ClientIFACClient clientIFac = null;
            PersonneIFACClient personneIFacById = null;

            try {
                ofrmMdi = pFrmMdi;
                personneIFac = new PersonneIFACClient();
                //AsyncGuiPersonne selectGuiSamplePersonneDelegate = personneIFac.SelectAll;
                var selectGuiSamplePersonneDelegate = new AsyncGuiPersonne(personneIFac.SelectAll);
                selectGuiSamplePersonneDelegate.BeginInvoke(PersonneResults, null);

                personneIFacById = new PersonneIFACClient();
                var selectGuiSamplePersonneByIdDelegate = new AsyncGuiPersonneById(personneIFacById.SelectById);
                selectGuiSamplePersonneByIdDelegate.BeginInvoke(1, PersonneByIdResult, null);

                //var selectGuiSamplePersonneByNameDelegate = new AsyncGuiPersonneByName(personneIFac.SelectByName);
                //selectGuiSamplePersonneByNameDelegate.BeginInvoke("toto", PersonneByNameResult, null);

                locationIFac = new EmpruntIFACClient();
                var selectGuiSampleEmpruntDelegate = new AsyncGuiEmprunt(locationIFac.SelectAll);
                selectGuiSampleEmpruntDelegate.BeginInvoke(EmpruntResults, null);

                clientIFac = new ClientIFACClient();
                var selectGuiSampleClientDelegate = new AsyncGuiClient(clientIFac.SelectAll);
                selectGuiSampleClientDelegate.BeginInvoke(ClientResults, null);

                while (!AutoEvent.WaitOne(50, true)) {
                    Application.DoEvents();
                }

            } catch (Exception) {
                bReturn = false;
            } finally {
                if (personneIFac != null) {
                    personneIFac.Close();
                }
                if (locationIFac != null) {
                    locationIFac.Close();
                }
                if (clientIFac != null) {
                    clientIFac.Close();
                }
                if (personneIFacById != null) {
                    personneIFacById.Close();
                }
                ofrmMdi.DecrementILockMDI();
            }
            return bReturn;
        }
        public static Boolean LoadCache(FrmMdi pFrmMdi)
        {
            var bReturn = true;
            PersonneIFACClient personneIFac = null;
            EmpruntIFACClient empruntIFac = null;
            ClientIFACClient clientIFac = null;
            PersonneIFACClient personneIFacById = null;
            RefLivreIFACClient refLivreIFacSelectAll = null;
            LivreIFACClient livreIFacSelectAll = null;
            LivreIFACClient livreIFacSelectByBliotheque = null;
            LivreStatusIFACClient livreStatusIFacSelectAll = null;
            BibliothequeIFACClient bibliothequeIFacSelectAll = null;
            DemandeReservationIFACClient demandeReservationIFacByClient = null;
            ReservationIFACClient reservationIfacClient = null;
            ItemIFACClient itemIfacClient = null;

            try {
                _ofrmMdi = pFrmMdi;
                personneIFac = new PersonneIFACClient();
                //AsyncGuiPersonne selectGuiSamplePersonneDelegate = personneIFac.SelectAll;
                var selectGuiSamplePersonneDelegate = new AsyncGuiPersonne(personneIFac.SelectAll);
                selectGuiSamplePersonneDelegate.BeginInvoke(SessionManager.Token, PersonneResults, null);

                empruntIFac = new EmpruntIFACClient();
                AsyncGuiEmpruntSelectAll selectGuiSampleEmpruntSelectAll = empruntIFac.SelectAll;
                selectGuiSampleEmpruntSelectAll.BeginInvoke(SessionManager.Token, EmpruntSelectAllResult, null);
                //personneIFacById = new PersonneIFACClient();
                //var selectGuiSamplePersonneByIdDelegate = new AsyncGuiPersonneById(personneIFacById.SelectById);
                //selectGuiSamplePersonneByIdDelegate.BeginInvoke(SessionManager.Token, 1, PersonneByIdResult, null);

                //var selectGuiSamplePersonneByNameDelegate = new AsyncGuiPersonneByName(personneIFac.SelectByName);
                //selectGuiSamplePersonneByNameDelegate.BeginInvoke("toto", PersonneByNameResult, null);

                clientIFac = new ClientIFACClient();
                var selectGuiSampleClientDelegate = new AsyncGuiClient(clientIFac.SelectAll);
                selectGuiSampleClientDelegate.BeginInvoke(SessionManager.Token, ClientResults, null);

                refLivreIFacSelectAll = new RefLivreIFACClient();
                var selectGuiSampleRefLivreDelegate = new AsyncGuiRefLivreSelectAll(refLivreIFacSelectAll.SelectAll);
                selectGuiSampleRefLivreDelegate.BeginInvoke(SessionManager.Token, RefLivreSelectAllResult, null);

                livreIFacSelectAll = new LivreIFACClient();
                var selectGuiSampleLivreDelegate = new AsyncGuiLivreSelectAll(livreIFacSelectAll.SelectAll);
                selectGuiSampleLivreDelegate.BeginInvoke(SessionManager.Token, LivreSelectAllResult, null);

                livreIFacSelectByBliotheque = new LivreIFACClient();
                AsyncGuiLivreSelectByBibliotheque selectGuiSampleLivreByBibliothequeDelegate = livreIFacSelectByBliotheque.SelectByBibliotheque;
                selectGuiSampleLivreByBibliothequeDelegate.BeginInvoke(SessionManager.Token, SessionManager.Personne.Client.Bibliotheque, LivreSelectByBibliothequeResult, null);

                demandeReservationIFacByClient = new DemandeReservationIFACClient();
                ASyncGuiDemandeReservationSelectByClient selectGuiSampleNewDemandeReservationByClientDelegate = demandeReservationIFacByClient.SelectNewByClient;
                selectGuiSampleNewDemandeReservationByClientDelegate.BeginInvoke(SessionManager.Token, SessionManager.Personne.Client, NewDemandeReservationResults, null);

                ASyncGuiDemandeReservationSelectByClient selectGuiSampleOldDemandeReservationByClientDelegate = demandeReservationIFacByClient.SelectOldByClient;
                selectGuiSampleOldDemandeReservationByClientDelegate.BeginInvoke(SessionManager.Token, SessionManager.Personne.Client, OldDemandeReservationResults, null);

                AyncGuiEmpruntSelectAllByClientId selectGuiSampleEmpruntDelegate = empruntIFac.SelectEmpruntByClientId;
                selectGuiSampleEmpruntDelegate.BeginInvoke(SessionManager.Token, SessionManager.PersonneId ,EmpruntResults, null);

                reservationIfacClient = new ReservationIFACClient();
                AsyncGuiReservationSelectEnCoursValidByClientId selectGuiSampleReservationEnCoursValidByClientIdDelegate = reservationIfacClient.SelectEnCoursValidByClientId;
                selectGuiSampleReservationEnCoursValidByClientIdDelegate.BeginInvoke(SessionManager.Token, SessionManager.PersonneId, ReservationSelectValidByClientIdResult, null);

                AsyncGuiReservationSelectAll selectGuiSampleReservationDelegate = reservationIfacClient.SelectAll;
                selectGuiSampleReservationDelegate.BeginInvoke(SessionManager.Token, ReservationResults, null);

                ASyncGuiDemandeReservationSelectAll selectGuiSampleDemandeReservationByClientDelegate = demandeReservationIFacByClient.SelectAll;
                selectGuiSampleDemandeReservationByClientDelegate.BeginInvoke(SessionManager.Token, DemandeReservationResults, null);

                if (SessionManager.IsAdministrateur){
                    itemIfacClient = new ItemIFACClient();
                    AsyncGuiItemSelectByAdministrateurId selectGuiSampleItemByAdministrateurId = itemIfacClient.SelectByAdministrateurId;
                    selectGuiSampleItemByAdministrateurId.BeginInvoke(SessionManager.Token, SessionManager.Personne.Administrateur.AdministrateurId, ItemSelectByAdministrateurIdResult, null);
                } else {
                    _ofrmMdi.SetLoadingText(@"Item");
                    DecrementILock();
                }

                livreStatusIFacSelectAll = new LivreStatusIFACClient();
                var selectGuiSampleLivreStatusDelegate = new ASyncGuiLivreStatusSelectAll(livreStatusIFacSelectAll.SelectAll);
                selectGuiSampleLivreStatusDelegate.BeginInvoke(SessionManager.Token, LivreStatusSelecAllResult, null);

                bibliothequeIFacSelectAll = new BibliothequeIFACClient();
                var selectGuiSampleBibliothequeDelegate = new ASyncGuiBibliothequeSelectAll(bibliothequeIFacSelectAll.SelectAll);
                selectGuiSampleBibliothequeDelegate.BeginInvoke(SessionManager.Token, BibliothequeSelectAllResult, null);

                while (!AutoEvent.WaitOne(50, true)) {
                    Application.DoEvents();
                }

            } catch (Exception) {
                bReturn = false;
            } finally {
                if (personneIFac != null) {
                    personneIFac.Close();
                }
                if (empruntIFac != null) {
                    empruntIFac.Close();
                }
                if (clientIFac != null) {
                    clientIFac.Close();
                }
                if (personneIFacById != null) {
                    personneIFacById.Close();
                }
                if (refLivreIFacSelectAll != null) {
                    refLivreIFacSelectAll.Close();
                }
                if (livreIFacSelectAll != null) {
                    livreIFacSelectAll.Close();
                }
                if (livreIFacSelectByBliotheque != null) {
                    livreIFacSelectByBliotheque.Close();
                }
                if (livreStatusIFacSelectAll != null) {
                    livreStatusIFacSelectAll.Close();
                }
                if (bibliothequeIFacSelectAll != null) {
                    bibliothequeIFacSelectAll.Close();
                }
                if (demandeReservationIFacByClient != null) {
                    demandeReservationIFacByClient.Close();
                }
                if (reservationIfacClient != null){
                    reservationIfacClient.Close();
                }
                _ofrmMdi.DecrementILockMdi();
            }
            return bReturn;
        }
        private void SelectPersonneFromEmpruntLivreId(LivreBO pLivreBo)
        {
            var empruntNumber = CGlobalCache.LstEmpruntSelectAll.ToList().FindAll(xx => xx.LivreId == pLivreBo.LivreId);
            var maxActionId = empruntNumber.GroupBy(xx => xx.LivreId).Select(dd => new{LivreId = dd.Key, ActionId = dd.Max(qq => qq.ActionId)});
            var lstObjEmprunt = 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();

            if (!lstObjEmprunt.Any()){
                return;
            }

            var objEmprunt = lstObjEmprunt.Last(xx => xx.LivreId == pLivreBo.LivreId);
            if (objEmprunt == null){
                return;
            }
            var personneIFac = new PersonneIFACClient();

            AsyncGuiSelectPersonneFromEmpruntId asyncExecute = personneIFac.SelectByLivreEmpruntId;
            try {
                asyncExecute.BeginInvoke(CGlobalCache.SessionManager.Token, objEmprunt.EmpruntId, result => {
                    var samplePersDelegate = (AsyncGuiSelectPersonneFromEmpruntId)((AsyncResult)result).AsyncDelegate;
                    var objPersonneField = samplePersDelegate.EndInvoke(result);
                    lblInfo.Visible = false;
                    if (objPersonneField != null && (cmbClientField.SelectedValue!= null && objPersonneField.PersonneId != ((PersonneBO)cmbClientField.SelectedValue).PersonneId) || cmbClientField.SelectedValue == null) {
                        _bCmbClientFieldToogle = false;
                        var lstPersonne = new List<PersonneBO> {objPersonneField};
                        var tmpClientDatas = lstPersonne.Select(yy => new { Key = yy.PersonneMatricule + ": " + yy.ToString(), Value = yy }).ToList();
                        //tmpClientDatas.Insert(0, new { Key = "", Value = null as PersonneBO });
                        cmbClientField.DataSource = null;
                        cmbClientField.DataSource = tmpClientDatas;
                        cmbClientField.ValueMember = "Value";
                        cmbClientField.DisplayMember = "Key";
                        cmbClientField.SelectedValue = objPersonneField;
                        cmbClientField.Enabled = true;
                        _bCmbClientFieldToogle = true;
                        txtClientName.Text = objPersonneField.ToString();
                        txtClientId.Text = objPersonneField.PersonneId.ToString(CultureInfo.InvariantCulture);
                        cbAdministrateur.Checked = (objPersonneField.Administrateur != null);
                    }
                    personneIFac.Close();
                }, null);
            } catch(Exception) {
                personneIFac.Close();
                MessageBox.Show(Resources.EmpruntManagement_SearchLivreField_Erreur_lors_de_la_recuperation_des_informations_sur_le_livre_demande_);
            }
        }
        private void GetPersonne(ClientBO pClient)
        {
            var personneIFac = new PersonneIFACClient();

            AsyncGuiSelectPersonneById asyncExecute = personneIFac.SelectById;
            try {
                asyncExecute.BeginInvoke(CGlobalCache.SessionManager.Token, pClient.ClientId, xx => {
                    var samplePersDelegate = (AsyncGuiSelectPersonneById)((AsyncResult)xx).AsyncDelegate;
                    var objPersonne = samplePersDelegate.EndInvoke(xx);
                    if (objPersonne != null) {
                        txtClientName.Text = objPersonne.ToString();
                        cbAdministrateur.Checked = (objPersonne.Administrateur != null);
                    }
                    personneIFac.Close();
                }, null);
            } catch(Exception) {
                personneIFac.Close();
                MessageBox.Show(Resources.ReservationManagement_GetPersonne_Erreur_lors_de_la_recuperation_des_informations_sur_le_livre_demande_);
            }
        }
        private void SearchClientField()
        {
            lblAlert.Enabled = false;
            var personneIFac = new PersonneIFACClient();

            AsyncGuiSelectListPersonne asyncExecute = personneIFac.SelectByInfo;
            try {
                asyncExecute.BeginInvoke(CGlobalCache.SessionManager.Token, txtClientField.Text, xx => {
                    var samplePersDelegate = (AsyncGuiSelectListPersonne)((AsyncResult)xx).AsyncDelegate;
                    _lstPersonneField = samplePersDelegate.EndInvoke(xx);
                    if (_lstPersonneField != null && _lstPersonneField.Any()) {
                        _bCmbClientFieldToogle = false;
                        var tmpClientDatas = _lstPersonneField.Select(yy => new { Key = yy.PersonneMatricule + ": " + yy.ToString(), Value = yy }).ToList();
                        tmpClientDatas.Insert(0, new { Key = "", Value = null as PersonneBO });
                        cmbClientField.DataSource = tmpClientDatas;
                        cmbClientField.ValueMember = "Value";
                        cmbClientField.DisplayMember = "Key";
                        cmbClientField.Enabled = true;
                        _bCmbClientFieldToogle = true;
                    }
                    personneIFac.Close();
                }, null);
            } catch(Exception) {
                personneIFac.Close();
                MessageBox.Show(Resources.EmpruntManagement_SearchLivreField_Erreur_lors_de_la_recuperation_des_informations_sur_le_livre_demande_);
            }
        }