예제 #1
0
        private async void Potvrdi_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(DanCombo.Text))
            {
                MessageBox.Show("Odaberite dan termina.");
                return;
            }
            if (string.IsNullOrWhiteSpace(TimePickerOd.Value.ToString()) || string.IsNullOrWhiteSpace(TimePickerDo.Value.ToString()))
            {
                MessageBox.Show("Popunite termine.");
                return;
            }
            Func <DateTime?, DateTime?, bool> compare = (a, b) => a?.TimeOfDay.CompareTo(b?.TimeOfDay) > 0;

            if (compare(TimePickerOd.Value, TimePickerDo.Value))
            {
                MessageBox.Show("Termin početka mora biti prije termina završetka.");
                return;
            }

            using (ErsteModel ersteModel = new ErsteModel())
            {
                termin termin = await ersteModel.termini.FindAsync(item.termin.Id);

                if (termin != null)
                {
                    termin.Dan = DanCombo.Text;
                    if (TimePickerOd.Value != null)
                    {
                        termin.Od = TimePickerOd.Value.Value.TimeOfDay;
                    }
                    if (TimePickerDo.Value != null)
                    {
                        termin.Do = TimePickerDo.Value.Value.TimeOfDay;
                    }
                    if (GrupaCombo.Text != "Nije dodijeljena grupa" && !string.IsNullOrWhiteSpace(GrupaCombo.Text))
                    {
                        termin.GrupaId = (await ersteModel.grupe.FirstAsync(g => g.Naziv == GrupaCombo.Text)).Id;
                    }
                    await ersteModel.SaveChangesAsync();
                }
            }
            Close();
            refresh();
        }
예제 #2
0
        private async void Button1Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(NazivBox.Text))
            {
                MessageBox.Show("Odaberite naziv grupe.");
                return;
            }
            using (ErsteModel ersteModel = new ErsteModel())
            {
                if (await ersteModel.grupe.AnyAsync(g => g.Naziv == NazivBox.Text))
                {
                    MessageBox.Show("Grupa sa unesenim nazivom već postoji.");
                    return;
                }
            }
            if (string.IsNullOrWhiteSpace(JezikCombo.Text))
            {
                MessageBox.Show("Odaberite jezik.");
                return;
            }
            if (string.IsNullOrWhiteSpace(NivoKursaCombo.Text))
            {
                MessageBox.Show("Odaberite nivo kursa.");
                return;
            }
            if (TimePickerOd.SelectedDate is null)
            {
                MessageBox.Show("Odaberite početak kursa.");
                return;
            }
            if (TimePickerDo.SelectedDate is null)
            {
                MessageBox.Show("Odaberite kraj kursa.");
                return;
            }
            Func <DateTime?, DateTime?, bool> compare = (a, b) => a?.CompareTo(b) > 0;

            if (compare(TimePickerOd.SelectedDate, TimePickerDo.SelectedDate))
            {
                MessageBox.Show("Datum početka mora biti prije datuma završetka.");
                return;
            }

            try
            {
                using (ErsteModel ersteModel = new ErsteModel())
                {
                    ersteModel.grupe.Add(new grupa()
                    {
                        Naziv       = NazivBox.Text,
                        BrojClanova = 0,
                        kurs        = new kurs()
                        {
                            DatumOd = TimePickerOd.SelectedDate.Value,
                            DatumDo = TimePickerDo.SelectedDate.Value,
                            jezik   = await ersteModel.jezici.FirstAsync(j => j.Naziv == JezikCombo.Text),
                            Nivo    = NivoKursaCombo.Text
                        }
                    });
                    await ersteModel.SaveChangesAsync();
                }
                MessageBox.Show("Uspješno ste dodali novu grupu.");
            }
            catch (IOException ioException)
            {
                MessageBox.Show("Greška.");
            }

            if (Dispatcher != null)
            {
                await Dispatcher.InvokeAsync(Close);
            }
        }
예제 #3
0
        private async void Button1Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(DanCombo.Text))
            {
                MessageBox.Show("Odaberite dan termina.");
                return;
            }
            if (string.IsNullOrWhiteSpace(TimePickerOd.Value.ToString()) || string.IsNullOrWhiteSpace(TimePickerDo.Value.ToString()))
            {
                MessageBox.Show("Popunite termine.");
                return;
            }
            Func <DateTime?, DateTime?, bool> compare = (a, b) => a?.TimeOfDay.CompareTo(b?.TimeOfDay) > 0;

            if (compare(TimePickerOd.Value, TimePickerDo.Value))
            {
                MessageBox.Show("Termin početka mora biti prije termina završetka.");
                return;
            }

            try
            {
                TimeSpan @od = new TimeSpan();
                TimeSpan @do = new TimeSpan();
                string   dan = "";
                if (Dispatcher != null)
                {
                    await Dispatcher.InvokeAsync(() =>
                    {
                        if (TimePickerOd.Value == null || TimePickerDo.Value == null || DanCombo.SelectedValue == null)
                        {
                            return;
                        }
                        dan = DanCombo.Text;
                        @od = TimePickerOd.Value.Value.TimeOfDay;
                        @do = TimePickerDo.Value.Value.TimeOfDay;
                    });
                }

                using (ErsteModel ersteModel = new ErsteModel())
                {
                    ersteModel.termini.Add(new termin()
                    {
                        Dan     = dan,
                        Od      = @od,
                        Do      = @do,
                        grupa   = null,
                        GrupaId = null
                    });
                    await ersteModel.SaveChangesAsync();
                }
                MessageBox.Show("Uspješno ste dodali novi termin.");
            }
            catch (IOException ioException)
            {
                MessageBox.Show(ioException.StackTrace);
            }

            refresh();
            if (Dispatcher != null)
            {
                await Dispatcher.InvokeAsync(Close);
            }
        }