Exemplo n.º 1
0
        private void dgAppointments_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            af458_appointments appointment = (af458_appointments)dgAppointments.SelectedItem;

            date_input.DisplayDate = appointment.dateHour;
            subject_input.Text     = appointment.subject;
            hour_input.Text        = Convert.ToString(appointment.dateHour.Hour);
            minute_input.Text      = Convert.ToString(appointment.dateHour.Minute);
        }
Exemplo n.º 2
0
        private void Delete_Button(object sender, RoutedEventArgs e)
        {
            af458_appointments appointment        = (af458_appointments)dgAppointments.SelectedItem;
            af458_appointments af458_appointments = db.af458_appointments.Find(appointment.id);

            try
            {
                db.af458_appointments.Remove(af458_appointments);
                db.SaveChanges();
                MainWindow      main = Application.Current.MainWindow as MainWindow;
                ListAppointment ListAppointmentPage = new ListAppointment();
                main.MainFrame.Navigate(ListAppointmentPage);
                error_message.Text = "Le rendez-vous a bien été supprimé";
            }
            catch (DbEntityValidationException)
            {
                error_message.Text = "Le rendez-vous n'a pas pu être supprimé";
            }
        }
Exemplo n.º 3
0
        private void Button_Validation(object sender, RoutedEventArgs e)
        {
            bool formError = false;

            hour_error.Text     = "";
            subject_error.Text  = "";
            broker_error.Text   = "";
            customer_error.Text = "";
            af458_appointments appointment = new af458_appointments();

            if (date_input.SelectedDate != null)
            {
                DateTime date = (DateTime)date_input.SelectedDate;
                if (hour_input.Text != "")
                {
                    if (Regex.IsMatch(hour_input.Text, "^[0-1][0-9]|2[0-3]$"))
                    {
                        if (minute_input.Text != "")
                        {
                            if (Regex.IsMatch(minute_input.Text, "^[0-5][0-9]$"))
                            {
                                DateTime datehour = new DateTime(date.Year, date.Month, date.Day, Convert.ToInt32(hour_input.Text), Convert.ToInt32(minute_input.Text), 0);
                                appointment.dateHour = datehour;
                            }
                            else
                            {
                                hour_error.Text = "Les minutes du rendez-vous n'est pas de la bonne forme";
                                formError       = true;
                            }
                        }
                        else
                        {
                            minute_input.Text = "00";
                            DateTime datehour = new DateTime(date.Year, date.Month, date.Day, Convert.ToInt32(hour_input.Text), Convert.ToInt32(minute_input.Text), 0);
                            appointment.dateHour = datehour;
                        }
                    }
                    else
                    {
                        hour_error.Text = "L'heure du rendez-vous n'est pas de la bonne forme";
                        formError       = true;
                    }
                }
                else
                {
                    date_error.Text = "Veuillez renseigner l'heure du rendez-vous.";
                    formError       = true;
                }
            }
            else
            {
                date_error.Text = "Veuillez renseigner la date du rendez-vous.";
                formError       = true;
            }
            if (subject_input.Text != "")
            {
                appointment.subject = subject_input.Text;
                subject_error.Text  = "";
            }
            else
            {
                subject_error.Text = "Veuillez renseigner le prénom du client.";
                formError          = true;
            }
            af458_brokers broker = (af458_brokers)brokers_list.SelectedItem;

            if (broker != null)
            {
                appointment.id_af458_brokers = broker.id;
                broker_error.Text            = "";
            }
            else
            {
                broker_error.Text = "Veuillez renseigner le courtier.";
                formError         = true;
            }
            af458_customers customer = (af458_customers)customers_list.SelectedItem;

            if (customer != null)
            {
                appointment.id_af458_customers = customer.id;
                broker_error.Text = "";
            }
            else
            {
                broker_error.Text = "Veuillez renseigner le client.";
                formError         = true;
            }
            if (!formError)
            {
                try
                {
                    db.af458_appointments.Add(appointment);
                    db.SaveChanges();
                    query_message.Foreground = Brushes.Green;
                    query_message.Text       = "L'enregistrement a bien été effectué.";
                }
                catch (DbEntityValidationException)
                {
                    query_message.Foreground = Brushes.Red;
                    query_message.Text       = "L'enregistrement n'a pas pu être effectué. (1)";
                }
                catch (DbUpdateException)
                {
                    query_message.Foreground = Brushes.Red;
                    query_message.Text       = "L'enregistrement n'a pas pu être effectué. (2)";
                }
            }
            else
            {
                query_message.Foreground = Brushes.Red;
                query_message.Text       = "L'enregistrement n'a pas pu être effectué, des erreurs dans le formulaire sont présentes.";
            }
        }
Exemplo n.º 4
0
        private void Edit_Button(object sender, RoutedEventArgs e)
        {
            bool formError = false;

            error_message.Text = "";
            af458_appointments appointmentToEdit = (af458_appointments)dgAppointments.SelectedItem;
            af458_appointments appointment       = db.af458_appointments.Find(appointmentToEdit.id);

            if (date_input.SelectedDate != null)
            {
                DateTime date = (DateTime)date_input.SelectedDate;
                if (hour_input.Text != "")
                {
                    if (Regex.IsMatch(hour_input.Text, "^[0-1][0-9]|2[0-3]$"))
                    {
                        if (minute_input.Text != "")
                        {
                            if (Regex.IsMatch(minute_input.Text, "^[0-5][0-9]$"))
                            {
                                DateTime datehour = new DateTime(date.Year, date.Month, date.Day, Convert.ToInt32(hour_input.Text), Convert.ToInt32(minute_input.Text), 0);
                                appointment.dateHour = datehour;
                            }
                            else
                            {
                                error_message.Text = "Les minutes du rendez-vous n'est pas de la bonne forme";
                                formError          = true;
                            }
                        }
                        else
                        {
                            minute_input.Text = "00";
                            DateTime datehour = new DateTime(date.Year, date.Month, date.Day, Convert.ToInt32(hour_input.Text), Convert.ToInt32(minute_input.Text), 0);
                            appointment.dateHour = datehour;
                        }
                    }
                    else
                    {
                        error_message.Text = "L'heure du rendez-vous n'est pas de la bonne forme";
                        formError          = true;
                    }
                }
                else
                {
                    error_message.Text = "Veuillez renseigner l'heure du rendez-vous.";
                    formError          = true;
                }
            }
            //else
            //{
            //    error_message.Text = "Veuillez renseigner la date du rendez-vous.";
            //    formError = true;
            //}
            if (subject_input.Text != "")
            {
                appointment.subject = subject_input.Text;
            }
            else
            {
                error_message.Text = "Veuillez renseigner le sujet du rendez-vous.";
                formError          = true;
            }
            af458_brokers broker = (af458_brokers)brokers_list.SelectedItem;

            if (broker != null)
            {
                appointment.id_af458_brokers = broker.id;
            }
            af458_customers customer = (af458_customers)customers_list.SelectedItem;

            if (customer != null)
            {
                appointment.id_af458_customers = customer.id;
            }
            if (!formError)
            {
                try
                {
                    db.SaveChanges();
                    MainWindow      main = Application.Current.MainWindow as MainWindow;
                    ListAppointment ListAppointmentPage = new ListAppointment();
                    main.MainFrame.Navigate(ListAppointmentPage);
                }
                catch (DbEntityValidationException)
                {
                    error_message.Text = "Le client n'a pas pu être modifié";
                }
            }
        }