private void Txt_PeriodeEnCour_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (LaDemande.LeTypeDemande.CODE == SessionObject.Enumere.FactureManuelle ||
         LaDemande.LeTypeDemande.CODE == SessionObject.Enumere.AvoirConsomation)
     {
         if (this.Txt_PeriodeEnCour.Text.Length == 7)
         {
             if (ClasseMEthodeGenerique.IsFormatPeriodeValide(Txt_PeriodeEnCour.Text))
             {
                 this.Txt_FinPeriode.Text   = ClasseMEthodeGenerique.DernierJourDuMois(int.Parse(Txt_PeriodeEnCour.Text.Substring(0, 2)), int.Parse(Txt_PeriodeEnCour.Text.Substring(3, 4)));
                 this.Txt_DebutPeriode.Text = "01" + "/" + Txt_PeriodeEnCour.Text.Substring(0, 2).PadLeft(2, '0') + "/" + Txt_PeriodeEnCour.Text.Substring(3, 4);
             }
         }
     }
 }
        private void   OKButton_Click(object sender, RoutedEventArgs e)
        {
            string IdCoupure = string.Empty;

            try
            {
                CsAvisCoupureEdition avisCoupure = new CsAvisCoupureEdition();
                bntPrinting.IsEnabled = false;
                aCampagne      Campagne = new aCampagne();
                aDisconnection dis      = new aDisconnection();

                avisCoupure.Matricule            = UserConnecte.matricule;
                avisCoupure.AgentPia             = UserConnecte.matricule;
                avisCoupure.referenceClientDebut = string.IsNullOrEmpty(this.Txt_Client.Text) ? string.Empty : this.Txt_Client.Text;
                avisCoupure.OrdreTourneDebut     = string.IsNullOrEmpty(this.Txt_Ordre.Text) ? string.Empty : this.Txt_Ordre.Text;
                string DueDate = (string.IsNullOrEmpty(this.dtpDate.Text)) ? null : dtpDate.Text;
                if (this.Cbo_Regcli.Tag != null)
                {
                    avisCoupure.ListeRegroupement = (List <ServiceRecouvrement.CsRegCli>) this.Cbo_Regcli.Tag;
                }

                avisCoupure.MontantRelancable = string.IsNullOrEmpty(this.Txt_MontantExigible.Text) ? 0 : Convert.ToDecimal(this.Txt_MontantExigible.Text);
                avisCoupure.Exigible          = this.dtpDate.SelectedDate;
                if (this.Txt_LibelleCentre.Tag != null)
                {
                    List <CsCentre> lstCentreCampage = new List <CsCentre>();
                    List <string>   lstCodeCentre    = (List <string>) this.Txt_LibelleCentre.Tag;
                    foreach (var item in lstCodeCentre)
                    {
                        lstCentreCampage.Add(new CsCentre {
                            CODE = item
                        });
                    }
                    avisCoupure.Centre_Campagne = lstCentreCampage;
                }
                if (string.IsNullOrEmpty(avisCoupure.MatriculeDebut) && !string.IsNullOrEmpty(avisCoupure.MatriculeFin))
                {
                    Message.ShowInformation("Entrez la première référence !", Galatee.Silverlight.Resources.Langue.errorTitle);
                    return;
                }
                if (!string.IsNullOrEmpty(avisCoupure.MatriculeDebut) && string.IsNullOrEmpty(avisCoupure.MatriculeFin))
                {
                    Message.ShowInformation("Entrez la deuxième référence!", Galatee.Silverlight.Resources.Langue.errorTitle);
                    return;
                }
                if (this.chk_ParAbonnement.IsChecked == true)
                {
                    avisCoupure.IsParAbonnement = true;
                }
                else
                {
                    avisCoupure.IsParAbonnement = false;
                }

                if (chk_ResilierExclus.IsChecked == true)
                {
                    avisCoupure.ClientResilie = true;
                }
                else
                {
                    avisCoupure.ClientResilie = false;
                }

                if (!string.IsNullOrEmpty(this.Txt_DateDebut.Text) && ClasseMEthodeGenerique.IsFormatPeriodeValide(this.Txt_DateDebut.Text))
                {
                    avisCoupure.PeriodeDebut = ClasseMEthodeGenerique.FormatPeriodeAAAAMM(this.Txt_DateDebut.Text);
                }


                if (!string.IsNullOrEmpty(this.Txt_DateFin.Text) && ClasseMEthodeGenerique.IsFormatPeriodeValide(this.Txt_DateFin.Text))
                {
                    avisCoupure.PeriodeFin = ClasseMEthodeGenerique.FormatPeriodeAAAAMM(this.Txt_DateFin.Text);
                }

                ligne.Clear();
                prgBar.Visibility = System.Windows.Visibility.Visible;
                LayoutRoot.Cursor = Cursors.Wait;
                RecouvrementServiceClient proxy = new RecouvrementServiceClient(Utility.ProtocoleFacturation(), Utility.EndPoint("Recouvrement"));
                proxy.TraitementAvisCoupureGCAsync(avisCoupure, dis, IsPreavis);
                proxy.TraitementAvisCoupureGCCompleted += (ssn, results) =>
                {
                    try
                    {
                        if (results.Cancelled || results.Error != null)
                        {
                            string error = results.Error.Message;
                            Message.ShowError("Erreur d'invocation du service. Réessayer svp !", Galatee.Silverlight.Resources.Langue.errorTitle);
                            bntPrinting.IsEnabled = true;
                            LayoutRoot.Cursor     = Cursors.Arrow;
                            prgBar.Visibility     = System.Windows.Visibility.Collapsed;
                            return;
                        }

                        if (results.Result == null || results.Result.Count == 0)
                        {
                            Message.ShowError("Aucune donnée de campagne retournée!", Galatee.Silverlight.Resources.Langue.errorTitle);
                            bntPrinting.IsEnabled = true;
                            LayoutRoot.Cursor     = Cursors.Arrow;
                            prgBar.Visibility     = System.Windows.Visibility.Collapsed;
                            return;
                        }

                        ligne.Clear();
                        ligne.AddRange(results.Result);
                        ServiceRecouvrement.CsRegCli lereg = ((List <ServiceRecouvrement.CsRegCli>) this.Cbo_Regcli.Tag).First();
                        string key = Utility.getKey();
                        Dictionary <string, string> param = new Dictionary <string, string>();
                        if (param.Count != 0)
                        {
                            param.Clear();
                        }
                        if (this.chk_ParAbonnement.IsChecked == true)
                        {
                            if (IsPreavis)
                            {
                                param.Add("PpChefService", leParam != null && !string.IsNullOrEmpty(leParam.NOMCHEFSERVICE) ? leParam.NOMCHEFSERVICE : string.Empty);
                                Utility.ActionExportation <ServicePrintings.CsLclient, ServiceRecouvrement.CsLclient>(ligne, param, string.Empty, SessionObject.CheminImpression, "PreavisDeCoupurParAbon", "Recouvrement", true, "doc");
                            }
                            else
                            {
                                param.Add("PpNomDonneurOrdre", leParam != null && !string.IsNullOrEmpty(leParam.NOMCHEFSERVICE)? leParam.NOMCHEFSERVICE : string.Empty);
                                param.Add("PpTitreDonneurOrdre", leParam != null && !string.IsNullOrEmpty(leParam.TITRE_DONNEURORDRE)? leParam.TITRE_DONNEURORDRE:string.Empty);
                                param.Add("PpContactDonneurOrdre", leParam != null && !string.IsNullOrEmpty(leParam.CONTACT_DONNEURORDRE)? leParam.CONTACT_DONNEURORDRE :string.Empty);
                                param.Add("PpStructureExecution", leParam != null && !string.IsNullOrEmpty(leParam.STRUCTURE_EXECUTION)? leParam.STRUCTURE_EXECUTION :string.Empty);
                                param.Add("PpNomAgentExecution", leParam != null && !string.IsNullOrEmpty(leParam.AGENT_EXECUTION)? leParam.AGENT_EXECUTION :string.Empty);
                                param.Add("PpMatriculeAgent", leParam != null && !string.IsNullOrEmpty(leParam.MATRICULE_EXECUTION) ? leParam.MATRICULE_EXECUTION : string.Empty);

                                Utility.ActionExportation <ServicePrintings.CsLclient, ServiceRecouvrement.CsLclient>(ligne, param, string.Empty, SessionObject.CheminImpression, "OrdreDeCoupurParAbon", "Recouvrement", true, "doc");
                            }
                        }
                        else
                        {
                            if (IsPreavis)
                            {
                                param.Add("PpChefService", leParam != null && !string.IsNullOrEmpty(leParam.NOMCHEFSERVICE) ? leParam.NOMCHEFSERVICE : string.Empty);
                                Utility.ActionExportation <ServicePrintings.CsLclient, ServiceRecouvrement.CsLclient>(ligne, param, string.Empty, SessionObject.CheminImpression, "PreavisDeCoupur", "Recouvrement", true, "doc");
                            }
                            else
                            {
                                param.Add("PpNomDonneurOrdre", leParam != null && !string.IsNullOrEmpty(leParam.NOMCHEFSERVICE) ? leParam.NOMCHEFSERVICE : string.Empty);
                                param.Add("PpTitreDonneurOrdre", leParam != null && !string.IsNullOrEmpty(leParam.TITRE_DONNEURORDRE) ? leParam.TITRE_DONNEURORDRE : string.Empty);
                                param.Add("PpContactDonneurOrdre", leParam != null && !string.IsNullOrEmpty(leParam.CONTACT_DONNEURORDRE) ? leParam.CONTACT_DONNEURORDRE : string.Empty);
                                param.Add("PpStructureExecution", leParam != null && !string.IsNullOrEmpty(leParam.STRUCTURE_EXECUTION) ? leParam.STRUCTURE_EXECUTION : string.Empty);
                                param.Add("PpNomAgentExecution", leParam != null && !string.IsNullOrEmpty(leParam.AGENT_EXECUTION) ? leParam.AGENT_EXECUTION : string.Empty);
                                param.Add("PpMatriculeAgent", leParam != null && !string.IsNullOrEmpty(leParam.MATRICULE_EXECUTION) ? leParam.MATRICULE_EXECUTION : string.Empty);

                                Utility.ActionExportation <ServicePrintings.CsLclient, ServiceRecouvrement.CsLclient>(ligne, param, string.Empty, SessionObject.CheminImpression, "OrdreDeCoupur", "Recouvrement", true, "doc");
                            }
                        }


                        LayoutRoot.Cursor     = Cursors.Arrow;
                        prgBar.Visibility     = System.Windows.Visibility.Collapsed;
                        bntPrinting.IsEnabled = true;
                    }
                    catch (Exception ex)
                    {
                        prgBar.Visibility     = System.Windows.Visibility.Collapsed;
                        LayoutRoot.Cursor     = Cursors.Arrow;
                        bntPrinting.IsEnabled = true;
                        Message.ShowError(ex, Galatee.Silverlight.Resources.Langue.errorTitle);
                    }
                };
            }
            catch (Exception ex)
            {
                bntPrinting.IsEnabled = true;
                prgBar.Visibility     = System.Windows.Visibility.Collapsed;
                LayoutRoot.Cursor     = Cursors.Arrow;
                Message.ShowError(ex, Galatee.Silverlight.Resources.Langue.errorTitle);
            }
        }