public static LivreBO InsertLivre(LivreBO pObjLivre, Int32 AdministrateurId)
        {
            LivreBO oLivreBoResult;
            try {
                using (var livreProxy = new LivreDAL(Util.GetConnection())) {
                    oLivreBoResult = (LivreBO)livreProxy.LivreDAL_InsertLivre(
                        pObjLivre.BibliothequeId,
                        pObjLivre.RefLivreId,
                        pObjLivre.RefLivre.ISBN,
                        pObjLivre.RefLivre.Titre,
                        pObjLivre.RefLivre.Description,
                        pObjLivre.RefLivre.Auteur,
                        pObjLivre.RefLivre.Langue,
                        pObjLivre.RefLivre.Editeur,
                        pObjLivre.RefLivre.Published,
                        pObjLivre.RefLivre.ImageUrl,
                        AdministrateurId
                        ).ToList()[0];

                        oLivreBoResult.RefLivre = RefLivreBL.SelectById(oLivreBoResult.RefLivreId);
                        oLivreBoResult.Bibliotheque = BibliothequeBL.SelectById(oLivreBoResult.BibliothequeId);
                }
            } catch (Exception ex) {
                throw;
            }
            return oLivreBoResult;
        }
        public void SetForm(LivreBO pLivre)
        {
            CGlobalCache.ActualBibliothequeChangeEventHandler += ActualBibliothequeChange;
            cmbBibliotheque.Items.AddRange(CGlobalCache.SessionManager.Personne.Administrateur.LstBibliotheque.ToArray());
            cmbBibliotheque.SelectedItem = CGlobalCache.ActualBibliotheque;

            txtAuteur.Text = pLivre.RefLivre.Auteur;
            txtRef.Text = pLivre.InternalReference;
            //txtBibliotheque.Text = pLivre.Bibliotheque.ToString();
            cmbBibliotheque.SelectedItem = pLivre.Bibliotheque;
            //txtBibliotheque.Text = frmMdi.Bibliotheque.ToString();
            txtTitle.Text = pLivre.RefLivre.Titre;
            txtISBN.Text = pLivre.RefLivre.ISBN;
            webDescription.DocumentText = pLivre.RefLivre.Description;
            // Sensé permettre l'édition du texte
            //webDescription.Document.DomDocument.GetType().GetProperty("designMode").SetValue(webDescription.Document.DomDocument, "On", null);
            datePicker.Text = pLivre.RefLivre.Published.ToShortDateString();

            // Create a web request to the URL for the picture
            WebRequest webRequest = WebRequest.Create(pLivre.RefLivre.ImageUrl);
            // Execute the request synchronuously
            var webResponse = (HttpWebResponse)webRequest.GetResponse();

            // Create an image from the stream returned by the web request
            picBook.Image = new Bitmap(webResponse.GetResponseStream());
        }
 /// <summary>
 /// Rempli un objet livre avec des données de référence de livre
 /// </summary>
 /// <param name="pObjRefLivre"></param>
 public void FillForm(RefLivreBO pObjRefLivre)
 {
     var oLivre = new LivreBO();
     oLivre.RefLivre = pObjRefLivre;
     oLivre.Bibliotheque = CGlobalCache.ActualBibliotheque;
     ObjLivre = (LivreBO)oLivre.Clone();
     livreFormulaire1.SetForm(oLivre);
     btnCreate.Enabled = true;
 }
        internal void SetFicheDeLivre(LivreBO pLivreBo, FicheLivreBO ficheLivre)
        {
            if (ficheLivre == null){
                MessageBox.Show("Erreur lors de la récupération de la fiche du livre!");
                return;
            }
            lblReservationStatus.Visible = false;
            lblReservationTitle.Visible = false;

            lblTitre.Text = ficheLivre.RefLivre.Titre;
            webDescription.DocumentText = ficheLivre.RefLivre.Description;
            lblAuteurs.Text = ficheLivre.RefLivre.Auteur;
            lblPublication.Text = ficheLivre.RefLivre.Published.ToShortDateString();

            Action<String> getImage = (imageUrl) => {
                // Create a web request to the URL for the picture
                var webRequest = WebRequest.Create(imageUrl);
                // Execute the request synchronuously
                var webResponse = (HttpWebResponse)webRequest.GetResponse();

                // Create an image from the stream returned by the web request
                picBook.Image = new Bitmap(webResponse.GetResponseStream());
            };

            getImage(ficheLivre.RefLivre.ImageUrl);

            lblBibliotheque.Text = pLivreBo.Bibliotheque.BibliothequeName;
            if (ficheLivre.LstEmprunt.Any()){
                var lastEmpruntState = ficheLivre.LstEmprunt[ficheLivre.LstEmprunt.Count() - 1];
                lblEmpruntStatus.Text = lastEmpruntState.Transition + "\n" + lastEmpruntState.CreatedAt.ToShortDateString();
            } else{
                lblEmpruntStatus.Text = "";
            }

            String newDemandeReservation = "", oldDemandeReservation = "";
            foreach (var objDr in ficheLivre.LstDemandeReservation.OrderByDescending(xx => xx.CreatedAt)) {
                if (objDr.Valide == 1) {
                    newDemandeReservation += ((newDemandeReservation == "") ? "": "\n" ) + "Depuis: " + objDr.CreatedAt.ToShortDateString();
                } else {
                    oldDemandeReservation += ((oldDemandeReservation == "") ? "": "\n" ) + "Anciennes demandes: " + objDr.CreatedAt.ToShortDateString();
                }
            }
            lblDemandeReservationStatus.Text = newDemandeReservation + "\n" + oldDemandeReservation;

            var empruntByClient = CGlobalCache.LstEmpruntByClient.LastOrDefault(xx => xx.Livre.RefLivreId == ficheLivre.RefLivre.RefLivreId);
            if (empruntByClient != null && empruntByClient.State == "emp") {
                lblEmpruntStatus.Text = String.Format("Emprunté depuis le: {0}",empruntByClient.CreatedAt.ToShortDateString());
            } else if (empruntByClient != null && empruntByClient.State == "res") {
                lblEmpruntStatus.Text = String.Format("Reservé depuis le: {0}",empruntByClient.CreatedAt.ToShortDateString());
            } else if (empruntByClient != null && empruntByClient.State == "reg") {
                lblEmpruntStatus.Text = String.Format("Dernier emprunt le: {0}",empruntByClient.CreatedAt.ToShortDateString());
            } else{
                lblEmpruntStatus.Text = "";
            }
        }
 public LivreBO InsertLivre(String token, LivreBO pObjLivre, Int32 pAdministrateurId)
 {
     if (!Autorization.Validate(token, Autorization.Role.ADMIN)) {
         return null;
     }
     try {
         return LivreBL.InsertLivre(pObjLivre, pAdministrateurId);
     } catch (Exception ex) {
         throw;
     }
 }
 /// <summary>
 /// Vérifie si des champs ont été modifiés
 /// </summary>
 /// <param name="objLivre"></param>
 public void CheckField(LivreBO objLivre)
 {
     if (objLivre.CreatedAt.ToShortDateString() != datePicker.Text) {
         objLivre.CreatedAt = DateTime.Parse(datePicker.Text);
     }
     if (!objLivre.RefLivre.ISBN.Equals(txtISBN.Text)) {
         objLivre.RefLivre.ISBN = txtISBN.Text;
     }
     if (!objLivre.RefLivre.Titre.Equals(txtTitle.Text)) {
         objLivre.RefLivre.Titre = txtTitle.Text;
     }
     if (!objLivre.RefLivre.Auteur.Equals(txtAuteur.Text)) {
         objLivre.RefLivre.Auteur = txtAuteur.Text;
     }
 }
        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 Boolean InsertLivre(LivreBO pObjLivre)
 {
     LivreBO Livre;
     try {
         using (var livreProxy = new LivreIFACClient()) {
             Livre = livreProxy.InsertLivre(CGlobalCache.SessionManager.Token, pObjLivre, CGlobalCache.SessionManager.Personne.Administrateur.AdministrateurId);
         }
     } catch (Exception ex) {
         throw;
     }
     if (Livre == null) {
         return false;
     }
     // Ajout du livre au cache
     CGlobalCache.LstLivreSelectAll.Add(Livre);
     if (CGlobalCache.SessionManager.Personne.Client != null && Livre.BibliothequeId == CGlobalCache.SessionManager.Personne.Client.BibliothequeId) {
         CGlobalCache.LstLivreByBibliotheque.Add(Livre);
     }
     return true;
 }
 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);
 }
        /// <summary>
        /// Ajoute un livre à la base de données
        /// </summary>
        /// <param name="pObjLivre"></param>
        /// <returns></returns>
        private Boolean InsertLivre(LivreBO pObjLivre)
        {
            Boolean result = false;

            // Vérifie si une reflivre a déjà cet isbn et l'ajoute au livre
            RefLivreBO objRefLivre = CGlobalCache.LstRefLivreSelectAll.FirstOrDefault(xx => xx.ISBN == pObjLivre.RefLivre.ISBN);
            if (objRefLivre != null && objRefLivre.RefLivreId != 0) {
                pObjLivre.RefLivreId = objRefLivre.RefLivreId;
            }

            // Appel au webservice
            try {
                result = _objFrmMdi.InsertLivre(pObjLivre);
            } catch (Exception ex) {
                throw;
            }
            return result;
        }
        private void LoadFicheLivre(LivreBO pLivreBo)
        {
            CreateFicheLivre();
            var livreIFac = new LivreIFACClient();

            AsyncGuiFicheDeLivreSelectForClientById asyncExecute = livreIFac.SelectFicheLivreForClientByLivreId;
            try {
                asyncExecute.BeginInvoke(CGlobalCache.SessionManager.Token, CGlobalCache.SessionManager.Personne.Client.ClientId, pLivreBo.LivreId, xx => {
                    var samplePersDelegate = (AsyncGuiFicheDeLivreSelectForClientById)((AsyncResult)xx).AsyncDelegate;
                    _actualFicheLivre = samplePersDelegate.EndInvoke(xx);
                    if (_ficheDeLivre == null || _actualFicheLivre == null) {
                        livreIFac.Close();
                        return;
                    }
                    _ficheDeLivre.SetFicheDeLivre(pLivreBo, _actualFicheLivre);
                    livreIFac.Close();
                }, null);
            } catch(Exception) {
                livreIFac.Close();
                MessageBox.Show(Resources.DashboardManager_loadFicheLivre_Erreur_lors_de_la_recuperation_des_informations_sur_le_livre_demande_);
            }
        }
        private void LivreStatusLocal_MouseDown(object sender, MouseEventArgs e)
        {
            var listBox = (ListBox)sender;

            listBox.SelectedIndex = listBox.IndexFromPoint(e.Location);
            if (listBox.SelectedIndex == -1) {
                return;
            }

            CleanListBoxSelected(listBox);

            if (e.Button == MouseButtons.Right) {
                //select the item under the mouse pointer
                contextMenuStrip1.Show(Cursor.Position);
                _livreSelected = (LivreBO)listBox.SelectedItem;

            }
            if (e.Button == MouseButtons.Left) {
                LoadFicheLivre((LivreBO)listBox.SelectedItem);
            }
        }
 private void dataGridSearchResult_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex < 0) {
         return;
     }
     _livreSelected = CGlobalCache.LstLivreSelectAll.FirstOrDefault(xx => xx.RefLivre.ISBN.Equals(dataGridSearchResult.Rows[e.RowIndex].Cells[2].Value));
     dataGridSearchResult.Rows[e.RowIndex].Selected = true;
     btnSelection.Enabled = ((String)cmbBibliotheque.SelectedValue) != "other";
 }
        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_);
            }
        }