private void dgINIT_CellEditEnded(object sender, DataGridCellEditEndedEventArgs e)
        {
            CsTypeDemande u = e.Row.DataContext as CsTypeDemande; //fetch the row data

            try
            {
                if (majData.Count > 0 && majData != null)
                {
                    if (majData.First(p => p.ROWID == u.ROWID) != null)
                    {
                        majData.Remove(u);
                        majData.Add(u);
                    }
                    else
                    {
                        majData.Add(u);
                    }
                }
                else
                {
                    majData.Add(u);
                }
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
        }
 void AjouterListeMaj(CsTypeDemande casSelected)
 {
     try
     {
         if (majData.Count > 0 && majData != null)
         {
             if (majData.First(p => p.ROWID == casSelected.ROWID) != null)
             {
                 majData.Remove(casSelected);
                 majData.Add(casSelected);
             }
             else
             {
                 majData.Add(casSelected);
             }
         }
         else
         {
             majData.Add(casSelected);
         }
     }
     catch (Exception ex)
     {
         string error = ex.Message;
     }
 }
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Voulez vous vraiment supprimer cet element", "Confirmation", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                CsTypeDemande selected = dgINIT.SelectedItem as CsTypeDemande;
                if (selected != null)
                {
                    ParametrageClient delete = new ParametrageClient(Utility.Protocole(), Utility.EndPoint("Parametrage"));
                    delete.Delete_TYPEDEMANDECompleted += (del, argDel) =>
                    {
                        if (argDel.Cancelled || argDel.Error != null)
                        {
                            string error = argDel.Error.Message;
                            MessageBox.Show(error, "Delete_TYPEDEMANDE", MessageBoxButton.OK);
                            desableProgressBar();
                            return;
                        }

                        if (argDel.Result == false)
                        {
                            MessageBox.Show("Error on insert/update ", "Delete_TYPEDEMANDE", MessageBoxButton.OK);
                            desableProgressBar();
                            return;
                        }

                        DonnesDatagrid.Remove(selected);
                    };
                    delete.Delete_TYPEDEMANDEAsync(selected.CENTRE, selected.TDEM);
                }
                else
                {
                    MessageBox.Show("vous devez selectionner un item dans la liste ");
                }
            }
        }
        private void dgINIT_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            CsTypeDemande demande = dgINIT.SelectedItem as CsTypeDemande;
            //CsTa event1 = listeTEvents.FirstOrDefault(p => p.PK_CODE == demande.EVT1);
            //CsTa event2 = listeTEvents.FirstOrDefault(p => p.PK_CODE == demande.EVT2);
            //CsTa event3 = listeTEvents.FirstOrDefault(p => p.PK_CODE == demande.EVT3);
            //CsTa event4 = listeTEvents.FirstOrDefault(p => p.PK_CODE == demande.EVT4);
            //CsTa event5 = listeTEvents.FirstOrDefault(p => p.PK_CODE == demande.EVT5);

            //cbo_evnt1.SelectedItem = event1;
            //cbo_evnt2.SelectedItem = event2;
            //cbo_evnt3.SelectedItem = event3;
            //cbo_evnt4.SelectedItem = event4;
            //cbo_evnt5.SelectedItem = event5;
        }
        private void cbo_evnt5_DropDownClosed(object sender, EventArgs e)
        {
            if (dgINIT.SelectedItem == null || cbo_evnt5.SelectedItem == null)
            {
                return;
            }
            CsTa index = new CsTa();

            index = cbo_evnt5.SelectedItem as CsTa;
            CsTypeDemande casSelected = dgINIT.SelectedItem as CsTypeDemande;

            //casSelected.EVT5 = index.PK_CODE;

            AjouterListeMaj(casSelected);
        }
        void InitialiserDonneeDataGrid(List <CsTypeDemande> listecas)
        {
            try
            {
                while (DonnesDatagrid.Count > 1)
                {
                    if (!string.IsNullOrEmpty(DonnesDatagrid[DonnesDatagrid.Count - 1].TDEM) &&
                        !string.IsNullOrEmpty(DonnesDatagrid[DonnesDatagrid.Count - 1].CENTRE))
                    {
                        DonnesDatagrid.RemoveAt(DonnesDatagrid.Count - 1);
                    }
                    else
                    {
                        DonnesDatagrid.RemoveAt(DonnesDatagrid.Count - 2);
                    }
                }

                foreach (CsTypeDemande cas in listecas)
                {
                    DonnesDatagrid.Add(cas);
                }

                CsTypeDemande casnull = DonnesDatagrid.FirstOrDefault(p => string.IsNullOrEmpty(p.CENTRE) && string.IsNullOrEmpty(p.TDEM));
                DonnesDatagrid.Remove(casnull);
                DonnesDatagrid.Add(new CsTypeDemande()
                {
                    DMAJ = DateTime.Now
                });

                majData.Clear();
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
        }