private void MiseAjourDataGrille(CsLotScelle leLot)
        {
            var DataSource = (List <CsLotScelle>)DgLotMag.ItemsSource;
            int index      = DataSource.IndexOf((CsLotScelle)DgLotMag.SelectedItem);

            DataSource[index]    = leLot;
            DgLotMag.ItemsSource = DataSource;
        }
 private void CheckBox_Unchecked_1(object sender, RoutedEventArgs e)
 {
     try
     {
         if (DgLotMag.SelectedItem != null)
         {
             CsLotScelle SelectedObject = (CsLotScelle)DgLotMag.SelectedItem;
             SelectedObject.IsSelect = false;
             CheckUncheckObjet(SelectedObject);
         }
     }
     catch (Exception ex)
     {
         Message.ShowError(ex.Message, "Erreur");
     }
 }
        private void CheckUncheckObjet(CsLotScelle leLot)
        {
            try
            {
                //Récupération Nombre de Scellé demandé
                int Nbr_ScelleDemande = 0;
                int.TryParse(txtnombreDem.Text, out Nbr_ScelleDemande);
                leLot.IsSelect = false;
                var LotStat_Selectionner = ListLotStat_Selectionner.FirstOrDefault(c => c.Key.Id_LotMagasinGeneral == leLot.Id_LotMagasinGeneral);

                int Nbr_ScelleDemandeARestituer = 0;

                if (LotStat_Selectionner.Value != null)
                {
                    Nbr_ScelleDemandeARestituer = int.Parse(LotStat_Selectionner.Value);
                }
                //Mise à jour des info du lot en tenant compte du nombre de position des numero de depart et ou de fin
                var NouveauNumeroDeDepart = (int.Parse(leLot.Numero_depart) - Nbr_ScelleDemandeARestituer).ToString();
                //NouveauNumeroDeDepart = (int.Parse(leLot.Numero_depart) - Nbr_ScelleDemandeRestant_OverFlow).ToString();
                ListLotStat_Selectionner.Remove(LotStat_Selectionner.Key);

                var NombreDepositionAncienNumDepart = leLot.Numero_depart.Length;

                leLot.Numero_depart = NouveauNumeroDeDepart.PadLeft(NombreDepositionAncienNumDepart, '0');
                //leLot.Nbre_Scelles = leLot.Nbre_Scelles + Nbr_ScelleDemande;
                leLot.Nbre_Scelles = (int.Parse(leLot.Numero_fin) - int.Parse(leLot.Numero_depart)) + 1;
                //Nbr_ScelleDemandeRestant = Nbr_ScelleDemandeARestituer;
                TxtNbScelle.Text = leLot.Nbre_Scelles.ToString();

                CsLotScelle lot = this.lstLotBrut.FirstOrDefault(t => t.Id_LotMagasinGeneral == leLot.Id_LotMagasinGeneral);
                CsLotScelle a   = this.lesLotsChoisis.FirstOrDefault(t => t.Id_LotMagasinGeneral == leLot.Id_LotMagasinGeneral);
                this.lesLotsChoisis.Remove(a);

                this.total_selected      = this.total_selected - lot.Nbre_Scelles;
                Nbr_ScelleDemandeRestant = Nbr_ScelleDemandeRestant + lot.Nbre_Scelles;

                MiseAjourDataGrille(leLot);
                DgLotMag.SelectedItem = leLot;
                ListLotAffecter_Selectionner.Remove(leLot);
            }
            catch (Exception ex)
            {
                Message.ShowError(ex.Message, "Erreur");
            }
        }
        private void dgMyDataGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            DataGrid dg         = (sender as DataGrid);
            var      allObjects = dg.ItemsSource as List <CsLotScelle>;

            if (dg.SelectedItem != null)
            {
                CsLotScelle SelectedObject = (CsLotScelle)dg.SelectedItem;
                if (SelectedObject.IsSelect == false)
                {
                    SelectedObject.IsSelect = true;
                }
                else
                {
                    SelectedObject.IsSelect = false;
                }
            }
        }
        private void CheckBox_Checked_1(object sender, RoutedEventArgs e)
        {
            //Récupération du lot selectioné
            var leLot = (CsLotScelle)DgLotMag.SelectedItem;

            CsLotScelle lot = this.lstLotBrut.FirstOrDefault(t => t.Id_LotMagasinGeneral == leLot.Id_LotMagasinGeneral);

            CsLotScelle choix = new CsLotScelle();

            choix.Activite_ID                  = lot.Activite_ID;
            choix.CodeCentre                   = lot.CodeCentre;
            choix.Couleur_ID                   = lot.Couleur_ID;
            choix.Date_DerniereModif           = lot.Date_DerniereModif;
            choix.DateReception                = lot.DateReception;
            choix.Fournisseur_ID               = lot.Fournisseur_ID;
            choix.Id_Affectation               = lot.Id_Affectation;
            choix.Id_LotMagasinGeneral         = lot.Id_LotMagasinGeneral;
            choix.IsSelect                     = true;
            choix.Libelle_Couleur              = lot.Libelle_Couleur;
            choix.Libelle_Fournisseur          = lot.Libelle_Fournisseur;
            choix.Libelle_Origine              = lot.Libelle_Origine;
            choix.Matricule_AgentDerniereModif = lot.Matricule_AgentDerniereModif;
            choix.Matricule_AgentReception     = lot.Matricule_AgentReception;
            choix.Nbre_Scelles                 = lot.Nbre_Scelles;
            choix.Numero_depart                = lot.Numero_depart;
            choix.Numero_fin                   = lot.Numero_fin;
            choix.Origine_ID                   = lot.Origine_ID;
            choix.StatutLot_ID                 = lot.StatutLot_ID;

            this.lesLotsChoisis.Add(choix);

            this.total_selected = this.total_selected + lot.Nbre_Scelles;

            //Récupération Nombre de Scellé demandé
            int Nbr_ScelleDemande = Nbr_ScelleDemandeRestant;

            if (ListLotAffecter_Selectionner.Count <= 0)
            {
                int.TryParse(txtnombreDem.Text, out Nbr_ScelleDemande);
            }
            leLot.IsSelect = true;
            //Mise du lot
            leLot.Nbre_Scelles = leLot.Nbre_Scelles - Nbr_ScelleDemande;

            if (leLot.Nbre_Scelles <= 0)
            {
                OKButton.IsEnabled = true;

                //if (leLot.Nbre_Scelles == 0)
                if (int.Parse(txtnombreDem.Text) == this.total_selected)
                {
                    ListLotStat_Selectionner.Add(leLot, Nbr_ScelleDemande.ToString());
                    leLot.Numero_depart = leLot.Numero_fin;
                    leLot.Numero_fin    = leLot.Numero_fin;
                }
                //else
                else if (int.Parse(txtnombreDem.Text) > this.total_selected)
                {
                    ListLotStat_Selectionner.Add(leLot, (Nbr_ScelleDemande - (-(leLot.Nbre_Scelles))).ToString());
                    Message.ShowInformation("Veuillez sélectionner un autre lot afin de compléter les scellés", "Information");
                    Nbr_ScelleDemandeRestant          = -(leLot.Nbre_Scelles);
                    Nbr_ScelleDemandeRestant_OverFlow = Nbr_ScelleDemandeRestant;
                    leLot.Nbre_Scelles  = 0;
                    leLot.Numero_depart = leLot.Numero_fin;
                    leLot.Numero_fin    = leLot.Numero_fin;
                    OKButton.IsEnabled  = false;
                }
            }
            else
            {
                ListLotStat_Selectionner.Add(leLot, Nbr_ScelleDemande.ToString());
                //Mise à jour des info du lot en tenant compte du nombre de position des numero de depart et ou de fin
                var NouveauNumeroDeDepart = (int.Parse(leLot.Numero_depart) + Nbr_ScelleDemande).ToString();

                var NombreDepositionAncienNumDepart = leLot.Numero_depart.Length;

                leLot.Numero_depart      = NouveauNumeroDeDepart.PadLeft(NombreDepositionAncienNumDepart, '0');
                Nbr_ScelleDemandeRestant = 0;
                OKButton.IsEnabled       = true;
            }

            TxtNbScelle.Text = leLot.Nbre_Scelles.ToString();
            MiseAjourDataGrille(leLot);
            DgLotMag.SelectedItem = leLot;
            ListLotAffecter_Selectionner.Add(leLot);
        }