Exemplo n.º 1
0
 private void Exit_Clicked(object sender, EventArgs e)
 {
     for (int i = 0; i < ExercisesTest.exercisesTest.Count; i++)
     {
         DBSaverLoader.SAVE_EXERCISE(ExercisesTest.exercisesTest[i], App.Database);
     }
     App.UpdateMainTableList();
     Navigation.PushAsync(new ProfilePage());
 }
Exemplo n.º 2
0
        private void CreateApproachButton_Clicked(object sender, EventArgs e)
        {
            if (TypePicker.SelectedIndex == -1 || NameEntry == null || NameEntry.Text == "" || NameEntry.Text == null)
            {
                DisplayAlert("Помилка", "Ви не вибрали тип або не ввели ім'я!", "Добре");
                if (TypePicker.SelectedIndex == -1)
                {
                    PickerStackLayout.BorderColor  = Color.Red;
                    PickerStackLayout.CornerRadius = 10;
                }
                else
                {
                    PickerStackLayout.BorderColor  = Color.Black;
                    PickerStackLayout.CornerRadius = 10;
                }
                if (NameEntry == null || NameEntry.Text == "" || NameEntry.Text == null)
                {
                    NameStackLayout.BorderColor  = Color.Red;
                    NameStackLayout.CornerRadius = 10;
                }
                else
                {
                    NameStackLayout.BorderColor  = Color.Black;
                    NameStackLayout.CornerRadius = 10;
                }
            }
            else
            {
                try
                {
                    if (NameEntry != null && PurposeEntry != null && NameEntry.Text != "" && TypePicker.SelectedIndex != -1)
                    {
                        switch (TypePicker.SelectedIndex)
                        {
                        case 0:
                            DBSaverLoader.SAVE_EXERCISE(new ExercisesCount()
                            {
                                Name        = NameEntry.Text,
                                Information = InformationEditor.Text,
                                LinkName    = NameLinkEntry.Text,
                                LinkURL     = UrlLinkEntry.Text,
                                Purpose     = Int32.Parse(PurposeEntry.Text)
                            }, App.Database);
                            App.UpdateMainTableList(); break;

                        case 1:
                            List <int> ApproachListInt = new List <int>();
                            for (int i = 0; i < ApproachStackLayout.Children.Count; ++i)
                            {
                                Frame       frame       = ApproachStackLayout.Children[i] as Frame;
                                StackLayout stackLayout = frame.Content as StackLayout;
                                Entry       entry       = stackLayout.Children[1] as Entry;
                                ApproachListInt.Add(Int32.Parse(entry.Text));
                            }
                            DBSaverLoader.SAVE_EXERCISE(new ExercisesApproach()
                            {
                                Name         = NameEntry.Text,
                                Information  = InformationEditor.Text,
                                LinkName     = NameLinkEntry.Text,
                                LinkURL      = UrlLinkEntry.Text,
                                ApproachList = ApproachListInt
                            }, App.Database);
                            App.UpdateMainTableList(); break;

                        case 2:
                            DBSaverLoader.SAVE_EXERCISE(new ExercisesTime()
                            {
                                Name        = NameEntry.Text,
                                Information = InformationEditor.Text,
                                LinkName    = NameLinkEntry.Text,
                                LinkURL     = UrlLinkEntry.Text,
                                Time        = new TimeSpan(0, 0, Int32.Parse(PurposeEntry.Text))
                            }, App.Database);
                            App.UpdateMainTableList(); break;
                        }
                    }
                    Navigation.PushAsync(new ProfilePage());
                }
                catch (Exception)
                {
                    bool tryParse = Int32.TryParse(PurposeEntry.Text, out int result);
                    if (tryParse == false)
                    {
                        DisplayAlert("Помилка. Формат цілі.", "Невірно введена кількість!", "Добре");
                        PickerStackLayout.BorderColor   = Color.Black;
                        PickerStackLayout.CornerRadius  = 10;
                        NameStackLayout.BorderColor     = Color.Black;
                        NameStackLayout.CornerRadius    = 10;
                        MissionStackLayout.BorderColor  = Color.Red;
                        MissionStackLayout.CornerRadius = 10;
                    }
                }
            }
        }