Exemplo n.º 1
0
        // Fill the list with GetEvent() data: MySeance Event become EventCell and there are grouped in EventCellGroup for each day
        private void FillMySeanceList()
        {
            var MySeanceList          = new List <EventCellGroup>();
            var CurrentEventCellGroup = new EventCellGroup()
            {
                Title = "Aucune inscription"
            };

            foreach (var Event in MySeances)
            {
                if (Event.Date.Date.ToString("dddd d MMMM") != CurrentEventCellGroup.Title)
                {
                    if (CurrentEventCellGroup.Count != 0)
                    {
                        MySeanceList.Add(CurrentEventCellGroup);
                    }
                    CurrentEventCellGroup = new EventCellGroup()
                    {
                        Title = Event.Date.Date.ToString("dddd d MMMM")
                    };
                }

                ImageSource ImageSource;
                if (Event.Type_ID == 1)
                {
                    ImageSource = "Musculation.png";
                }
                else if (Event.Type_ID == 2)
                {
                    ImageSource = "Fitness.png";
                }
                else
                {
                    ImageSource = "Exterieur.png";
                }
                CurrentEventCellGroup.Add(new EventCell()
                {
                    ID          = Event.ID,
                    Name        = Event.Name,
                    Description = Event.Description,
                    Coach       = Event.Surname,
                    Time        = Event.Date.ToString("HH:mm"),
                    PlaceStatus = Color.FromHex("#4169E1"),
                    TypePicture = ImageSource,
                    Owner_ID    = Event.Owner_ID
                });
            }
            MySeanceList.Add(CurrentEventCellGroup);
            MySeanceListView.ItemsSource = MySeanceList;
        }
Exemplo n.º 2
0
        // Fill the list with GetEvent() data: History Event become EventCell and there are grouped in EventCellGroup for each day
        private void FillHistoryList()
        {
            var HistoryList           = new List <EventCellGroup>();
            var CurrentEventCellGroup = new EventCellGroup()
            {
                Title = "Aucun historique"
            };

            foreach (var Event in History)
            {
                if (Event.Date.Date.ToString("dddd d MMMM") != CurrentEventCellGroup.Title)
                {
                    if (CurrentEventCellGroup.Count != 0)
                    {
                        HistoryList.Add(CurrentEventCellGroup);
                    }
                    CurrentEventCellGroup = new EventCellGroup()
                    {
                        Title = Event.Date.Date.ToString("dddd d MMMM")
                    };
                }

                ImageSource ImageSource;
                if (Event.Type_ID == 1)
                {
                    ImageSource = "Musculation.png";
                }
                else if (Event.Type_ID == 2)
                {
                    ImageSource = "Fitness.png";
                }
                else
                {
                    ImageSource = "Exterieur.png";
                }
                CurrentEventCellGroup.Add(new EventCell()
                {
                    ID          = Event.ID,
                    Name        = Event.Name,
                    Description = Event.Description,
                    Coach       = Event.Surname,
                    Time        = Event.Date.ToString("HH:mm"),
                    PlaceStatus = Color.Gray,
                    TypePicture = ImageSource,
                    Owner_ID    = Event.Owner_ID
                });
            }
            HistoryList.Add(CurrentEventCellGroup);
            HistoryListView.ItemsSource = HistoryList;
        }
        // Algorithme principale de l'application (timer threading)
        private async Task MainAppThreadAsync()
        {
            TimerEnabled = false;
            if (ClientReservationStatus == ReservationStatus.Guest) // Si invité
            {
                string Reference = (await Data.Settings.Read())[2];
                if (Reference != "null")                                                 // Si référence enregistrée
                {
                    string JsonDataGuest = await Requests.SelectReservInvite(Reference); // On récupère la réservation

                    if (JsonDataGuest == "")
                    {
                        await Data.Settings.Write("null", "null", "null");

                        TimerEnabled = true;
                        return;
                    }
                    JsonDataGuest = JsonDataGuest.Replace("null", $"\"1998-05-26 14:12:34\""); // On évite les champs null dans la déserialisation
                    JsonDataGuest = JsonDataGuest.Replace($"\"Place_ID\":\"1998-05-26 14:12:34\"", $"\"Place_ID\":0");
                    var Reservation = JsonConvert.DeserializeObject <List <Reservation> >(JsonDataGuest)[0];

                    if (Reservation.Depart != new DateTime(1998, 5, 26, 14, 12, 34)) // Si réservation finie
                    {
                        AccessButton.IsEnabled = true;                               // Peut accéder
                        ReferenceLabel.Text    = "-";
                        FloorLabel.Text        = "-";
                        LaneLabel.Text         = "-";
                        PlaceLabel.Text        = "-";
                        RemainingTime.Text     = "Pas de réservation en cours";

                        await Data.Settings.Write("null", "null", "null");
                    }
                    else
                    {
                        AccessButton.IsEnabled = false;                 // Ne peut pas re-acceder au parking
                        if (Reservation.Fin_Reservation < DateTime.Now) // Si dépassement de + de 15 minutes = alerte
                        {
                            DisplayAlert("Attention", "Vous avez dépassé l'heure de fin de réservation. Vous devez sortir du parking.", "OK");
                            RemainingTime.Text = "Temps dépassé";
                        }
                        else
                        {
                            RemainingTime.Text = (Reservation.Fin_Reservation - DateTime.Now).Hours.ToString() + " heure(s) et " + (Reservation.Fin_Reservation - DateTime.Now).Minutes.ToString() + " minute(s) ";
                        }

                        var CurrentPlace = await Requests.SelectPlace(Reference); // On récupère la place où le client est garé

                        if (CurrentPlace != null)
                        {
                            ReferenceLabel.Text = Reference;
                            FloorLabel.Text     = CurrentPlace.Etage.ToString();
                            LaneLabel.Text      = CurrentPlace.Allee;
                            PlaceLabel.Text     = CurrentPlace.Numero.ToString();
                        }
                    }
                }
                else
                {
                    AccessButton.IsEnabled = true; // Peut accéder
                    foreach (var Page in Children)
                    {
                        Page.ToolbarItems.Clear();
                        Page.ToolbarItems.Add(new ToolbarItem("AutoUpdateIndicator", "ProcessOK.png", () => { }));
                    }
                }
            }
            else
            {
                string JsonData = await Requests.SelectReserv(ConnectedClient.ID); // On récupère les réservations du client

                if (JsonData != "")
                {
                    if (JsonData == "No result found") // Pas de réservation
                    {
                        UpdateNoReservation();         // Refactorisation
                        TimerEnabled = true;
                        return;
                    }

                    JsonData     = JsonData.Replace("null", $"\"1998-05-26 14:12:34\""); // On évite les champs null dans la déserialisation
                    JsonData     = JsonData.Replace($"\"Place_ID\":\"1998-05-26 14:12:34\"", $"\"Place_ID\":0");
                    Reservations = JsonConvert.DeserializeObject <List <Reservation> >(JsonData);
                    Reservations.Sort((x, y) => x.Fin_Reservation.CompareTo(y.Fin_Reservation)); // On trie les réservations depuis plus récente
                    Reservations.Reverse();

                    // Reservations[0] est la dernière réservation effectuée
                    if (Reservations[0].Depart != new DateTime(1998, 5, 26, 14, 12, 34))       // Si pas de reservation validé
                    {
                        UpdateNoReservation();                                                 // Refactorisation
                    }
                    else if (Reservations[0].Arrivee != new DateTime(1998, 5, 26, 14, 12, 34)) // Si reservation en cours (dans le parking)
                    {
                        ClientReservationStatus             = ReservationStatus.InProgress;    // Mis a jour du status de la réservation client
                        ValidateDeleteReservation.Text      = "Annuler";
                        ValidateDeleteReservation.IsEnabled = false;                           // Ne peut pas annuler sa réservation
                        AccessButton.IsEnabled = false;                                        // Ne peut pas re-acceder au parking
                        Reference.Text         = Reservations[0].Reference;
                        UpdatePickers(Reservations[0].Debut_Reservation, Reservations[0].Fin_Reservation);
                        var CurrentPlace = await Requests.SelectPlace(Reservations[0].Reference); // On récupère la place où le client est garé

                        if (CurrentPlace != null)
                        {
                            ReferenceLabel.Text = Reservations[0].Reference;
                            FloorLabel.Text     = CurrentPlace.Etage.ToString();
                            LaneLabel.Text      = CurrentPlace.Allee;
                            PlaceLabel.Text     = CurrentPlace.Numero.ToString();
                        }
                        if (Reservations[0].Fin_Reservation < DateTime.Now) // Si dépassement de + de 15 minutes = alerte
                        {
                            DisplayAlert("Attention", "Vous avez dépassé l'heure de fin de réservation. Vous devez sortir du parking.", "OK");
                            RemainingTime.Text = "Temps dépassé";
                        }
                        else
                        {
                            RemainingTime.Text = (Reservations[0].Fin_Reservation - DateTime.Now).Hours.ToString() + " heure(s) et " + (Reservations[0].Fin_Reservation - DateTime.Now).Minutes.ToString() + " minute(s) ";
                        }
                        Reservations.Remove(Reservations[0]); // On affichera pas la réservation en cours dans l'historique
                    }
                    else // Si reservation valider (hors parking)
                    {
                        ClientReservationStatus             = ReservationStatus.Validate; // Mis a jour du status de la réservation client
                        ValidateDeleteReservation.Text      = "Annuler";
                        ValidateDeleteReservation.IsEnabled = true;                       // Peut annuler sa réservation
                        AccessButton.IsEnabled = true;                                    // Peut acceder
                        Reference.Text         = Reservations[0].Reference;
                        RemainingTime.Text     = "Pas de réservation en cours";
                        UpdatePickers(Reservations[0].Debut_Reservation, Reservations[0].Fin_Reservation);
                        if (Reservations[0].Debut_Reservation.AddMinutes(15) < DateTime.Now) // Si dépassement de + de 15 minutes = annule
                        {
                            DisplayAlert("Attention", "Vous avez dépassé l'heure de début de réservation. La réservation est annulé.", "OK");
                            if (await Requests.DeleteReserv(Reference.Text))
                            {
                                Reference.Text                 = "-";
                                ClientReservationStatus        = ReservationStatus.None;
                                ValidateDeleteReservation.Text = " Valider ";
                            }
                        }
                        Reservations.Remove(Reservations[0]);// On affichera pas la réservation en cours dans l'historique
                    }

                    // Affichage de l'historique des réservations de l'utilisateur avec tri par mois
                    var ReservationList       = new List <ReservationCellGroup>();
                    var CurrentEventCellGroup = new ReservationCellGroup()
                    {
                        Month = "Aucune réservation"
                    };
                    foreach (var Reservation in Reservations)
                    {
                        if (Reservation.Fin_Reservation.Date.ToString("MMMM yyyy") != CurrentEventCellGroup.Month)
                        {
                            if (CurrentEventCellGroup.Count != 0)
                            {
                                ReservationList.Add(CurrentEventCellGroup);
                            }
                            CurrentEventCellGroup = new ReservationCellGroup()
                            {
                                Month = Reservation.Fin_Reservation.Date.ToString("MMMM yyyy")
                            };
                        }

                        CurrentEventCellGroup.Add(new ReservationCell()
                        {
                            ID        = Reservation.ID,
                            Date      = "du " + Reservation.Debut_Reservation.ToString("ddd d à HH:mm") + " au " + Reservation.Fin_Reservation.ToString("ddd d à HH:mm"),
                            Duration  = "Durée: " + (Reservation.Fin_Reservation - Reservation.Debut_Reservation).ToString(@"hh\:mm"),
                            Reference = $"Reference {Reservation.Reference}"
                        });
                    }
                    ReservationList.Add(CurrentEventCellGroup);
                    ReservationHistoryListView.ItemsSource = ReservationList;
                }
            }
            TimerEnabled = true;
        }
Exemplo n.º 4
0
        // Fill the list with GetEvent() data: Event become EventCell and there are grouped in EventCellGroup for each day
        private void FillEventList()
        {
            var EventList             = new List <EventCellGroup>();
            var CurrentEventCellGroup = new EventCellGroup()
            {
                Title = "Aucun événement"
            };

            foreach (var Event in Events)
            {
                if (Event.Date.Date.ToString("dddd d MMMM") != CurrentEventCellGroup.Title)
                {
                    if (CurrentEventCellGroup.Count != 0)
                    {
                        EventList.Add(CurrentEventCellGroup);
                    }
                    CurrentEventCellGroup = new EventCellGroup()
                    {
                        Title = Event.Date.Date.ToString("dddd d MMMM")
                    };
                }

                Color StatusColor; ImageSource ImageSource;
                if (MySeances.Exists(p => p.ID == Event.ID))
                {
                    StatusColor = Color.FromHex("#4169E1");
                }
                else if (Event.Place == 0)
                {
                    StatusColor = Color.Red;
                }
                else if (Event.Place <= 3)
                {
                    StatusColor = Color.Orange;
                }
                else
                {
                    StatusColor = Color.LimeGreen;
                }
                if (Event.Type_ID == 1)
                {
                    ImageSource = "Musculation.png";
                }
                else if (Event.Type_ID == 2)
                {
                    ImageSource = "Fitness.png";
                }
                else
                {
                    ImageSource = "Exterieur.png";
                }
                CurrentEventCellGroup.Add(new EventCell()
                {
                    ID          = Event.ID,
                    Name        = Event.Name,
                    Description = Event.Description,
                    Coach       = Event.Surname,
                    Time        = Event.Date.ToString("HH:mm"),
                    PlaceStatus = StatusColor,
                    TypePicture = ImageSource,
                    Owner_ID    = Event.Owner_ID
                });
            }
            EventList.Add(CurrentEventCellGroup);
            EventListView.ItemsSource = EventList;
        }