Ejemplo n.º 1
0
        /// <summary>
        /// Constructeur
        /// </summary>
        /// <param name="nav"></param>
        public ViewModelListeClientPage(INavigation nav)
        {
            Clients = new ObservableCollection <Client>();
            DBClient     dbClient     = new DBClient();
            DBEstimation dbEstimation = new DBEstimation();

            //Récupération des client et leur estimation
            foreach (Client client in dbClient.GetAllByCommercial(Global.commercial.ID))
            {
                if (client.Estimations == null)
                {
                    client.Estimations = new ObservableCollection <Estimation>();
                }

                foreach (Estimation estimation in dbEstimation.GetAll())
                {
                    if (estimation.IDClient == client.ID)
                    {
                        client.Estimations.Add(estimation);
                    }
                }
                Clients.Add(client);
            }

            _Navigation = nav;

            _EstimationCommand = new DelegateCommand(ExecuteEstimationCommand);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Ajout d'une estimation
        /// </summary>
        /// <param name="obj"></param>
        private void ExecuteEstimerCommand(object obj)
        {
            DBEstimation dbEstimation = new DBEstimation();
            DBClient     dbClient     = new DBClient();

            //TODO Ajouter les vérification sur les champs du formulaire
            if (ValidationFormulaire() == true)
            {
                if (Client.ID == 0)
                {
                    Client.Estimations  = new ObservableCollection <Estimation>();
                    Client.IDCommercial = Global.commercial.ID;
                    Client.Estimations.Add(Estimation);
                    Client.IsSynchro = false;
                    dbClient.Add(Client);
                    Estimation.IDClient  = Client.ID;
                    Estimation.IsSynchro = false;
                    dbEstimation.Add(Estimation);
                }
                else
                {
                    Client.IsSynchro    = false;
                    Client.IDCommercial = Global.commercial.ID;
                    dbClient.Update(Client);

                    if (EstimationSelectVerif == false)
                    {
                        Estimation.IDClient  = Client.ID;
                        Estimation.IsSynchro = false;
                        dbEstimation.Add(Estimation);
                        Client.Estimations.Add(Estimation);
                    }
                    else
                    {
                        SelectEstimation.IsSynchro = false;
                        dbEstimation.Update(SelectEstimation);
                    }
                }
                //Ouvre la popup pour afficher la consommation en Watt
                OpenPopup();
            }
            else
            {
                //Message pour prévenir de remplir tous les champs
                MessageService.message("Merci de compléter tous les champs au bon format");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Synchro des clients
        /// </summary>
        private async void SyncClients()
        {
            DBClient      db          = new DBClient();
            DBEstimation  dbe         = new DBEstimation();
            List <Client> clientstest = db.GetAllByCommercial(Global.commercial.ID);
            List <Client> clients     = db.getAllNoSynchroByCommercial(Global.commercial.ID);

            foreach (Client c in clients)
            {
                List <Estimation> estimations = dbe.GetNoSynchroByClient(c.ID);
                c.Estimations = new System.Collections.ObjectModel.ObservableCollection <Estimation>(estimations);
            }
            IsBusy = true;
            WSClient ws = new WSClient();
            await ws.PostClients(Global.commercial.Token, clients, SyncCallback);

            IsBusy = false;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// WS Login callback
        /// </summary>
        /// <param name="obj"></param>
        private void LoginCallback(IRestResponse obj)
        {
            if (obj.StatusCode == System.Net.HttpStatusCode.OK)
            {
                // Convert json to commercial
                WSCommercial ws = new WSCommercial();
                Commercial   c  = ws.JSONToCommercial(obj.Content);

                DBUtilisateur dbu = new DBUtilisateur();
                DBClient      dbc = new DBClient();
                DBEstimation  dbe = new DBEstimation();
                // Insert // Update commercial
                Commercial commercialFound = dbu.GetByIdServeur(c.IDServeur);
                if (commercialFound != null)
                {
                    dbu.UpdateByIdServeur(c);
                }
                else
                {
                    dbu.Add(c);
                }
                commercialFound   = dbu.GetByIdServeur(c.IDServeur);
                Global.commercial = commercialFound;
                // INSERT / UPDATE clients du commercial
                foreach (Client client in c.Clients)
                {
                    Client clientFound = dbc.GetByIdServeur(client.IDServeur);
                    client.IsSynchro = true;
                    if (clientFound != null)
                    {
                        dbc.UpdateByIdServeur(client);
                    }
                    else
                    {
                        client.IDCommercial = commercialFound.ID;
                        dbc.Add(client);
                    }
                    clientFound = dbc.GetByIdServeur(client.IDServeur);
                    // INSERT / UPDATE estimations des clients du commercial
                    foreach (Estimation e in client.Estimations)
                    {
                        Estimation estimationFound = dbe.GetByIdServeur(e.IDServeur);
                        e.IsSynchro = true;
                        if (estimationFound != null)
                        {
                            dbe.UpdateByIdServeur(e);
                        }
                        else
                        {
                            e.IDClient = clientFound.ID;
                            dbe.Add(e);
                        }
                    }
                }
                NavigateToAccueil();
            }
            else if (obj.StatusCode == System.Net.HttpStatusCode.InternalServerError)
            {
                MessageService.message("Impossible de joindre le serveur");
            }
            else if (obj.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                MessageService.message("Identifiants incorrects");
            }
            else if (obj.StatusCode == System.Net.HttpStatusCode.NoContent)
            {
                MessageService.message("Identifiants incorrects");
            }
            else if (obj.StatusCode == 0)
            {
                MessageService.message("Identifiants incorrects");
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Sync callback
 /// </summary>
 /// <param name="obj"></param>
 private void SyncCallback(IRestResponse obj)
 {
     if (obj.StatusCode == System.Net.HttpStatusCode.OK)
     {
         MessageService.message("Synchronisation réussie");
         WSClient      ws      = new WSClient();
         List <Client> clients = ws.JSONToListClients(obj.Content);
         DBClient      dbc     = new DBClient();
         DBEstimation  dbe     = new DBEstimation();
         foreach (Client client in clients)
         {
             Client clientFound = dbc.GetByIdServeur(client.IDServeur);
             client.IsSynchro = true;
             if (clientFound != null)
             {
                 dbc.UpdateByIdServeur(client);
             }
             else
             {
                 client.IDCommercial = Global.commercial.ID;
                 dbc.Add(client);
             }
             clientFound = dbc.GetByIdServeur(client.IDServeur);
             // INSERT / UPDATE estimations des clients du commercial
             foreach (Estimation e in client.Estimations)
             {
                 Estimation estimationFound = dbe.GetByIdServeur(e.IDServeur);
                 e.IsSynchro = true;
                 if (estimationFound != null)
                 {
                     dbe.UpdateByIdServeur(e);
                 }
                 else
                 {
                     e.IDClient = clientFound.ID;
                     dbe.Add(e);
                 }
             }
         }
         IEnumerable <Client> allClient = dbc.GetAll();
         foreach (Client item in allClient)
         {
             bool canDelete = true;
             foreach (Client item2 in clients)
             {
                 if (item.IDServeur == item2.IDServeur)
                 {
                     canDelete = false;
                     break;
                 }
             }
             if (canDelete == true)
             {
                 dbc.Delete(item.ID);
             }
         }
     }
     else
     {
         MessageService.message("Synchronisation impossible");
     }
 }