private void ValiderAnnulation()
        {
            CsEnteteFacture laFactureSelect = (CsEnteteFacture)this.cmbFacture.SelectedItem;

            laDetailDemande.LaDemande.USERMODIFICATION = UserConnecte.matricule;

            ServiceAccueil.AcceuilServiceClient services = new ServiceAccueil.AcceuilServiceClient(Utility.ProtocoleFacturation(), Utility.EndPoint("Accueil"));
            services.ValiderAnnulationFactureCompleted += (ss, argss) =>
            {
                if (argss.Cancelled || argss.Error != null)
                {
                    string error = argss.Error.Message;
                    Message.ShowError(error, this.Title.ToString());
                    return;
                }
                if (string.IsNullOrEmpty(argss.Result))
                {
                    Message.ShowInformation("Demande validée avec succès", this.Title.ToString());

                    if (this.chk_Quitance.IsChecked == true)
                    {
                        List <CsEnteteFacture> lstFacture = (List <CsEnteteFacture>) this.dtg_DetailFacture.ItemsSource;
                        Utility.ActionDirectOrientation <ServicePrintings.CsEnteteFacture, ServiceFacturation.CsEnteteFacture>(lstFacture, null, SessionObject.CheminImpression, "QuittanceAnnulation", "Facturation", false);
                    }

                    this.DialogResult = true;
                }
                else
                {
                    Message.ShowError(argss.Result, this.Title.ToString());
                }
            };
            services.ValiderAnnulationFactureAsync(laDetailDemande, laFactureSelect.PK_ID);
            services.CloseAsync();
        }
        private void MiseAjourDemande()
        {
            try
            {
                ServiceAccueil.CsEvenement ev  = new ServiceAccueil.CsEvenement();
                CsEnteteFacture            ent = (CsEnteteFacture)this.cmbFacture.SelectedItem;

                ev.LOTRI            = ent.LOTRI;
                ev.FK_IDABON        = ent.FK_IDABON;
                ev.FACTURE          = ent.FACTURE;
                ev.PERIODE          = ent.PERIODE;
                ev.USERMODIFICATION = UserConnecte.matricule;
                ev.NUMDEM           = this.laDetailDemande.LaDemande.NUMDEM;
                ev.FK_IDDEMANDE     = this.laDetailDemande.LaDemande.PK_ID;


                this.laDetailDemande.LstEvenement.Clear();
                this.laDetailDemande.LstEvenement.Add(ev);
                this.laDetailDemande.LaDemande.ORDRE            = txtOrdre.Text;
                this.laDetailDemande.LaDemande.CLIENT           = ent.CLIENT;
                this.laDetailDemande.LaDemande.SITE             = Txt_CodeSite.Text;
                this.laDetailDemande.LaDemande.CENTRE           = ent.CENTRE;
                this.laDetailDemande.LaDemande.FK_IDCENTRE      = ent.FK_IDCENTRE;
                this.laDetailDemande.LaDemande.DATEMODIFICATION = DateTime.Now;
                this.laDetailDemande.LaDemande.USERMODIFICATION = UserConnecte.matricule;
                this.laDetailDemande.LaDemande.MOTIF            = txtMotifDemande.Text;
                this.laDetailDemande.LaDemande.ISMETREAFAIRE    = false;
                this.laDetailDemande.LaDemande.TYPEDEMANDE      = SessionObject.LstTypeDemande.First(a => a.CODE == "15").CODE;  //AnnulationFacture
                this.laDetailDemande.LaDemande.FK_IDTYPEDEMANDE = SessionObject.LstTypeDemande.First(a => a.CODE == "15").PK_ID; //AnnulationFacture



                ServiceAccueil.AcceuilServiceClient clientDevis = new ServiceAccueil.AcceuilServiceClient(Utility.ProtocoleFacturation(), Utility.EndPoint("Accueil"));
                clientDevis.ValidationDemandeCompleted += (ss, b) =>
                {
                    prgBar.Visibility = System.Windows.Visibility.Collapsed;

                    if (b.Cancelled || b.Error != null)
                    {
                        string error = b.Error.Message;
                        Message.ShowError(error, this.Title.ToString());
                        return;
                    }
                    if (string.IsNullOrEmpty(b.Result))
                    {
                        Message.ShowInformation("Demande transmise avec succès", this.Title.ToString());
                        this.DialogResult = true;
                    }
                    else
                    {
                        Message.ShowError(b.Result, this.Title.ToString());
                    }
                };
                clientDevis.ValidationDemandeAsync(laDetailDemande, true);
            }
            catch (Exception ex)
            {
                Message.ShowError("Une erreur s'est produite à la validation ", this.Title.ToString());
            }
        }
        private void MiseAjourDemande()
        {
            try
            {
                ServiceAccueil.CsEvenement ev = new ServiceAccueil.CsEvenement();
                CsEvenement leVt = (CsEvenement)this.Cbo_Compteur.SelectedItem;

                ev.PK_ID             = leVt.PK_ID;
                ev.INDEXEVT          = int.Parse(this.Txt_NouvIndex.Text);
                ev.INDEXEVTPRECEDENT = int.Parse(this.Txt_AncIndex.Text);
                ev.USERMODIFICATION  = UserConnecte.matricule;
                ev.NUMDEM            = this.laDetailDemande.LaDemande.NUMDEM;
                ev.FK_IDDEMANDE      = this.laDetailDemande.LaDemande.PK_ID;


                this.laDetailDemande.LstEvenement.Clear();
                this.laDetailDemande.LstEvenement.Add(ev);
                this.laDetailDemande.LaDemande.ORDRE            = txtOrdre.Text;
                this.laDetailDemande.LaDemande.PRODUIT          = leVt.PRODUIT;
                this.laDetailDemande.LaDemande.FK_IDPRODUIT     = leVt.FK_IDPRODUIT;
                this.laDetailDemande.LaDemande.CLIENT           = leVt.CLIENT;
                this.laDetailDemande.LaDemande.SITE             = Txt_CodeSite.Text;
                this.laDetailDemande.LaDemande.CENTRE           = leVt.CENTRE;
                this.laDetailDemande.LaDemande.FK_IDCENTRE      = leVt.FK_IDCENTRE;
                this.laDetailDemande.LaDemande.DATEMODIFICATION = DateTime.Now;
                this.laDetailDemande.LaDemande.USERMODIFICATION = UserConnecte.matricule;
                this.laDetailDemande.LaDemande.MOTIF            = txtMotifDemande.Text;
                this.laDetailDemande.LaDemande.ISMETREAFAIRE    = false;
                this.laDetailDemande.LaDemande.TYPEDEMANDE      = SessionObject.LstTypeDemande.First(a => a.CODE == SessionObject.Enumere.ReprisIndex).CODE;
                this.laDetailDemande.LaDemande.FK_IDTYPEDEMANDE = SessionObject.LstTypeDemande.First(a => a.CODE == SessionObject.Enumere.ReprisIndex).PK_ID;



                ServiceAccueil.AcceuilServiceClient clientDevis = new ServiceAccueil.AcceuilServiceClient(Utility.Protocole(), Utility.EndPoint("Accueil"));
                clientDevis.ValidationDemandeCompleted += (ss, b) =>
                {
                    if (b.Cancelled || b.Error != null)
                    {
                        string error = b.Error.Message;
                        Message.ShowError(error, "Reprise d'index");
                        return;
                    }
                    if (string.IsNullOrEmpty(b.Result))
                    {
                        Message.ShowInformation("Demande transmise avec succès", "Reprise d'index");
                        this.DialogResult = true;
                    }
                    else
                    {
                        Message.ShowError(b.Result, "Reprise d'index");
                    }
                };
                clientDevis.ValidationDemandeAsync(laDetailDemande, true);
            }
            catch (Exception ex)
            {
                Message.ShowError("Une erreur s'est produite à la validation ", "Reprise d'index");
            }
        }
        private void ChargeDetailDEvis(int IdDemandeDevis)
        {
            ServiceAccueil.AcceuilServiceClient client = new ServiceAccueil.AcceuilServiceClient(Utility.ProtocoleFacturation(), Utility.EndPoint("Accueil"));
            client.ChargerDetailDemandeCompleted += (ssender, args) =>
            {
                if (args.Cancelled || args.Error != null)
                {
                    LayoutRoot.Cursor = Cursors.Arrow;
                    string error = args.Error.Message;
                    Message.ShowError(error, this.Title.ToString());
                    return;
                }
                if (args.Result == null)
                {
                    LayoutRoot.Cursor = Cursors.Arrow;
                    Message.ShowError(Silverlight.Resources.Devis.Languages.AucunesDonneesTrouvees, this.Title.ToString());
                    return;
                }
                else
                {
                    laDetailDemande             = new ServiceAccueil.CsDemande();
                    laDetailDemande             = args.Result;
                    this.Txt_CodeSite.Text      = laDetailDemande.LaDemande.NUMDEM.Substring(3, 3);
                    this.Txt_CodeCentre.Text    = laDetailDemande.LaDemande.CENTRE;
                    this.txtClient.Text         = laDetailDemande.LaDemande.CLIENT;
                    this.txtOrdre.Text          = laDetailDemande.LaDemande.ORDRE;
                    this.Txt_NomAbon.Text       = laDetailDemande.LeClient.NOMABON;
                    this.Txt_Produit.Text       = laDetailDemande.LaDemande.LIBELLEPRODUIT;
                    this.Txt_PeriodeEnCour.Text = Shared.ClasseMEthodeGenerique.FormatPeriodeMMAAAA(laDetailDemande.LstEvenement.First().PERIODE);

                    if (this.Cbo_Compteur.ItemsSource != null)
                    {
                        this.Cbo_Compteur.SelectedItem = ((List <CsEvenement>) this.Cbo_Compteur.ItemsSource).First(a => a.FK_IDCOMPTEUR == laDetailDemande.LstEvenement.First().FK_IDCOMPTEUR);
                    }
                    this.txtDemande.Text      = laDetailDemande.LaDemande.NUMDEM;
                    this.txtMotifDemande.Text = laDetailDemande.LaDemande.MOTIF;
                    this.txtMotifRejet.Text   = laDetailDemande.AnnotationDemande.First().COMMENTAIRE;
                    this.Txt_AncIndex.Text    = laDetailDemande.LstEvenement.First().INDEXEVTPRECEDENT.ToString();
                    this.Txt_NouvIndex.Text   = laDetailDemande.LstEvenement.First().INDEXEVT.ToString();

                    CsClient rech = new CsClient();

                    rech.FK_IDABON    = laDetailDemande.LstEvenement.First().FK_IDABON;
                    rech.FK_IDPRODUIT = laDetailDemande.LstEvenement.First().FK_IDPRODUIT;
                    rech.FK_IDCENTRE  = laDetailDemande.LstEvenement.First().FK_IDCENTRE;
                    rech.CENTRE       = laDetailDemande.LstEvenement.First().CENTRE;
                    rech.REFCLIENT    = laDetailDemande.LstEvenement.First().CLIENT;
                    rech.ORDRE        = laDetailDemande.LstEvenement.First().ORDRE;
                    rech.PRODUIT      = laDetailDemande.LstEvenement.First().PRODUIT;
                    rech.PERIODE      = Shared.ClasseMEthodeGenerique.FormatPeriodeAAAAMM(this.Txt_PeriodeEnCour.Text);
                    RetourneEvenement(rech);
                }
            };
            client.ChargerDetailDemandeAsync(IdDemandeDevis, string.Empty);
        }
        private void ChargeDetailDEvis(int IdDemandeDevis)
        {
            ServiceAccueil.AcceuilServiceClient client = new ServiceAccueil.AcceuilServiceClient(Utility.ProtocoleFacturation(), Utility.EndPoint("Accueil"));
            client.ChargerDetailDemandeCompleted += (ssender, args) =>
            {
                if (args.Cancelled || args.Error != null)
                {
                    LayoutRoot.Cursor = Cursors.Arrow;
                    string error = args.Error.Message;
                    Message.ShowError(error, this.Title.ToString());
                    return;
                }
                if (args.Result == null)
                {
                    LayoutRoot.Cursor = Cursors.Arrow;
                    Message.ShowError(Silverlight.Resources.Devis.Languages.AucunesDonneesTrouvees, this.Title.ToString());
                    return;
                }
                else
                {
                    laDetailDemande          = new ServiceAccueil.CsDemande();
                    laDetailDemande          = args.Result;
                    this.Txt_CodeSite.Text   = laDetailDemande.LaDemande.NUMDEM.Substring(3, 3);
                    this.Txt_CodeCentre.Text = laDetailDemande.LaDemande.CENTRE;
                    this.txtClient.Text      = laDetailDemande.LaDemande.CLIENT;
                    this.txtOrdre.Text       = laDetailDemande.LaDemande.ORDRE;
                    this.txtNom.Text         = laDetailDemande.LeClient.NOMABON;

                    this.Txt_CodeSite.Tag   = LstCentrePerimetre.First(r => r.PK_ID == laDetailDemande.LaDemande.FK_IDCENTRE).FK_IDCODESITE;
                    this.Txt_CodeCentre.Tag = laDetailDemande.LaDemande.FK_IDCENTRE;


                    this.TxtDemande.Text      = laDetailDemande.LaDemande.NUMDEM;
                    this.txtMotifDemande.Text = laDetailDemande.LaDemande.MOTIF;

                    if (laDetailDemande.AnnotationDemande != null && laDetailDemande.AnnotationDemande.Count > 0)
                    {
                        this.txtMotifRejet.Text       = laDetailDemande.AnnotationDemande.First().COMMENTAIRE;
                        this.txtMotifRejet.Visibility = System.Windows.Visibility.Visible;
                        this.labMotifRejet.Visibility = System.Windows.Visibility.Visible;
                    }

                    RecherCherFacture();
                }
            };
            client.ChargerDetailDemandeAsync(IdDemandeDevis, string.Empty);
        }
        private void VerifieExisteDemande(ServiceAccueil.CsClient leClient)
        {
            try
            {
                if (!string.IsNullOrEmpty(leClient.REFCLIENT) && leClient.REFCLIENT.Length == SessionObject.Enumere.TailleClient)
                {
                    leClient.PERIODE     = Shared.ClasseMEthodeGenerique.FormatPeriodeAAAAMM(this.Txt_PeriodeEnCour.Text);
                    leClient.TYPEDEMANDE = SessionObject.Enumere.ReprisIndex;

                    ServiceAccueil.AcceuilServiceClient service = new ServiceAccueil.AcceuilServiceClient(Utility.ProtocoleFacturation(), Utility.EndPoint("Accueil"));
                    service.RetourneDemandeClientTypeCompleted += (s, args) =>
                    {
                        if (args != null && args.Cancelled)
                        {
                            return;
                        }
                        if (args.Result != null)
                        {
                            if (args.Result.DATEFIN == null && args.Result.ISSUPPRIME != true)
                            {
                                Message.ShowInformation("Il existe une demande numéro " + args.Result.NUMDEM + " sur ce client", "Accueil");
                                return;
                            }
                        }

                        int      idcentre          = int.Parse(this.Txt_CodeCentre.Tag.ToString());
                        CsClient leClientRecherche = new CsClient();
                        leClientRecherche.CENTRE    = Txt_CodeCentre.Text;
                        leClientRecherche.REFCLIENT = this.txtClient.Text;
                        leClientRecherche.PRODUIT   = this.Txt_Produit.Tag.ToString();

                        leClientRecherche.FK_IDCENTRE = idcentre;
                        leClientRecherche.ORDRE       = leClient.ORDRE;


                        RetourneInfoClient(leClientRecherche);
                    };
                    service.RetourneDemandeClientTypeAsync(leClient);
                    service.CloseAsync();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void ChargeDetailDEvis(int IdDemandeDevis)
        {
            ServiceAccueil.AcceuilServiceClient client = new ServiceAccueil.AcceuilServiceClient(Utility.ProtocoleFacturation(), Utility.EndPoint("Accueil"));
            client.ChargerDetailDemandeCompleted += (ssender, args) =>
            {
                if (args.Cancelled || args.Error != null)
                {
                    LayoutRoot.Cursor = Cursors.Arrow;
                    string error = args.Error.Message;
                    Message.ShowError(error, this.Title.ToString());
                    return;
                }
                if (args.Result == null)
                {
                    LayoutRoot.Cursor = Cursors.Arrow;
                    Message.ShowError(Silverlight.Resources.Devis.Languages.AucunesDonneesTrouvees, this.Title.ToString());
                    return;
                }
                else
                {
                    laDetailDemande             = new ServiceAccueil.CsDemande();
                    laDetailDemande             = args.Result;
                    this.Txt_CodeSite.Text      = laDetailDemande.LaDemande.NUMDEM.Substring(3, 3);
                    this.Txt_CodeCentre.Text    = laDetailDemande.LaDemande.CENTRE;
                    this.txtClient.Text         = laDetailDemande.LaDemande.CLIENT;
                    this.txtOrdre.Text          = laDetailDemande.LaDemande.ORDRE;
                    this.Txt_NomAbon.Text       = laDetailDemande.LeClient.NOMABON;
                    this.Txt_Produit.Text       = laDetailDemande.LaDemande.LIBELLEPRODUIT;
                    this.Txt_PeriodeEnCour.Text = Shared.ClasseMEthodeGenerique.FormatPeriodeMMAAAA(laDetailDemande.LstEvenement.First().PERIODE);
                    this.txtCompteur.Text       = laDetailDemande.LstEvenement.First().COMPTEUR;
                    this.Txt_Demande.Text       = laDetailDemande.LaDemande.NUMDEM;

                    if (laDetailDemande.AnnotationDemande != null && laDetailDemande.AnnotationDemande.Count > 0)
                    {
                        this.txtMotifRejet.Text       = laDetailDemande.AnnotationDemande.First().COMMENTAIRE;
                        this.txtMotifRejet.Visibility = System.Windows.Visibility.Visible;
                        this.labMotifRejet.Visibility = System.Windows.Visibility.Visible;
                    }
                    this.txtMotifDemande.Text = laDetailDemande.LaDemande.MOTIF;
                    this.Txt_AncIndex.Text    = laDetailDemande.LstEvenement.First().INDEXEVTPRECEDENT.ToString();
                    this.Txt_NouvIndex.Text   = laDetailDemande.LstEvenement.First().INDEXEVT.ToString();
                }
            };
            client.ChargerDetailDemandeAsync(IdDemandeDevis, string.Empty);
        }
 private void RemplirTypeDemande()
 {
     try
     {
         if (SessionObject.LstTypeDemande == null || SessionObject.LstTypeDemande.Count == 0)
         {
             ServiceAccueil.AcceuilServiceClient service1 = new ServiceAccueil.AcceuilServiceClient(Utility.Protocole(), Utility.EndPoint("Accueil"));
             service1.RetourneOptionDemandeCompleted += (sr, res) =>
             {
                 if (res != null && res.Cancelled)
                 {
                     return;
                 }
                 SessionObject.LstTypeDemande = res.Result;
             };
             service1.RetourneOptionDemandeAsync();
             service1.CloseAsync();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }