コード例 #1
0
        private void goTest_Click(object sender, RoutedEventArgs e)
        {
            endTest = true;
            if (deckList.ItemContainerGenerator == null)
            {
                return;
            }
            var selectedListBoxItem = deckList.ItemContainerGenerator.ContainerFromItem(((MenuItem)sender).DataContext) as ListBoxItem;

            App.ViewModel.studyDeck = selectedListBoxItem.Content as Tables.DeckItem;
            queue = App.ViewModel.fillQueue();
            if (App.ViewModel.studyDeck.CardItems.Count > 0)
            {
                MainPivot.SelectedIndex = 0;
            }
            else
            {
                MessageBoxResult result =
                    MessageBox.Show(AppResources.MessageBox_Text,
                                    AppResources.MessageBox_caption, MessageBoxButton.OKCancel);

                if (result == MessageBoxResult.OK)
                {
                    workDeck = App.ViewModel.studyDeck;
                    MainPivot.SelectedIndex = 2;
                    deckShow.Text           = App.ViewModel.studyDeck.DeckName;
                }
            }
        }
コード例 #2
0
        // Загрузка данных для элементов ViewModel
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }

            if (App.ViewModel.DeckItems.Count > 0)
            {
                if (resultBorder.Visibility == Visibility.Collapsed)
                {
                    studingField.Visibility  = Visibility.Visible;
                    ifNoDeckField.Visibility = Visibility.Collapsed;
                }
                workDeck                = App.ViewModel.DeckItems[0]; //потом перенести в viewmodel и сделать рандомно
                deckShow.Text           = workDeck.DeckName;
                App.ViewModel.studyDeck = workDeck;
                queue = App.ViewModel.fillQueue();
                if (App.ViewModel.studyDeck.CardItems.Count > 0)
                {
                    radBtnFrontSide.IsChecked = true;
                    radBtnRandom.IsChecked    = true;
                }
            }
            else
            {
                ifNoDeckField.Visibility = Visibility.Visible;
                studingField.Visibility  = Visibility.Collapsed;
                resultBorder.Visibility  = Visibility.Collapsed;
                ApplicationBar.IsVisible = false;
            }
        }
コード例 #3
0
        private void deckList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Tables.DeckItem Deck = (Tables.DeckItem)deckList.SelectedItem;
            deckShow.Text           = Deck.DeckName;
            workDeck                = Deck;
            MainPivot.SelectedIndex = 2;

            this.Focus();
        }
コード例 #4
0
        private void createBtn_Click(object sender, RoutedEventArgs e)
        {
            Tables.DeckItem newDeck = new Tables.DeckItem {
                DeckDescription = deckDescriptionTB.Text, DeckName = deckNameTB.Text
            };
            App.ViewModel.createDeck(newDeck);
            createpanelSwitch();
            this.Focus();
            MessageBoxResult result =
                MessageBox.Show(AppResources.MessageBox_Text,
                                AppResources.MessageBox_caption, MessageBoxButton.OKCancel);

            if (result == MessageBoxResult.OK)
            {
                workDeck = newDeck;
                MainPivot.SelectedIndex = 2;
                deckShow.Text           = newDeck.DeckName;
            }
        }
コード例 #5
0
        private void deleteDeck_Click(object sender, RoutedEventArgs e)
        {
            if (deckList.ItemContainerGenerator == null)
            {
                return;
            }
            var selectedListBoxItem = deckList.ItemContainerGenerator.ContainerFromItem(((MenuItem)sender).DataContext) as ListBoxItem;

            if (selectedListBoxItem == null)
            {
                return;
            }
            var selectedIndex = deckList.ItemContainerGenerator.IndexFromContainer(selectedListBoxItem);

            Tables.DeckItem deckForDelete = selectedListBoxItem.Content as Tables.DeckItem;
            App.ViewModel.deleteDeck(deckForDelete);

            if (selectedIndex + 1 <= App.ViewModel.DeckItems.Count)
            {
                workDeck      = App.ViewModel.DeckItems[selectedIndex];
                deckShow.Text = workDeck.DeckName;
            }
            else
            {
                if (App.ViewModel.DeckItems.Count > 0)
                {
                    workDeck      = App.ViewModel.DeckItems[selectedIndex - 1];
                    deckShow.Text = workDeck.DeckName;
                }
                else
                {
                    workDeck                = null;
                    deckShow.Text           = "";
                    App.ViewModel.studyDeck = null;
                }
            }
        }
コード例 #6
0
        private void AnswerBtn_Click(object sender, RoutedEventArgs e)   //answer click on 1tab
        {
            if (App.ViewModel.studyDeck.CardItems.Count <= 0)
            {
                MessageBoxResult result =
                    MessageBox.Show(AppResources.MessageBox_Text,
                                    AppResources.MessageBox_caption, MessageBoxButton.OKCancel);

                if (result == MessageBoxResult.OK)
                {
                    workDeck = App.ViewModel.studyDeck;
                    MainPivot.SelectedIndex = 2;
                    deckShow.Text           = App.ViewModel.studyDeck.DeckName;
                }
            }
            else
            {
                answerCount++;
                endTest = false;
                (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = false;
                countAnsCards.Text = answerCount + "/" + App.ViewModel.studyDeck.CardItems.Count.ToString();
                if (QuestionTB.GetBindingExpression(TextBlock.TextProperty).ParentBinding.Path.Path == "curCard.CardFrontSide")
                {
                    if (App.ViewModel.curCard.CardBackSide == AnswerTB.Text)
                    {
                        AnswerPB.Value += 1;
                        appearanceFalse.Stop();
                        appearanceTrue.Begin();
                    }
                    else
                    {
                        appearanceTrue.Stop();
                        appearanceFalse.Begin();
                    }
                }
                else
                {
                    if (App.ViewModel.curCard.CardFrontSide == AnswerTB.Text)
                    {
                        AnswerPB.Value += 1;
                        appearanceFalse.Stop();
                        appearanceTrue.Begin();
                    }
                    else
                    {
                        appearanceTrue.Stop();
                        appearanceFalse.Begin();
                    }
                }
                AnswerTB.Text = "";
                if (answerCount < App.ViewModel.studyDeck.CardItems.Count)
                {
                    if ((bool)radBtnRandom.IsChecked)
                    {
                        queue.RemoveAt(cardIndex);
                        cardIndex             = rand.Next(App.ViewModel.studyDeck.CardItems.Count - answerCount - 1);
                        App.ViewModel.curCard = App.ViewModel.studyDeck.CardItems[queue[cardIndex]];
                    }
                }

                else
                {
                    studingField.Visibility         = Visibility.Collapsed;
                    resultBorder.Visibility         = Visibility.Visible;
                    resultBorder_answTrue.Text      = AnswerPB.Value.ToString() + "/" + App.ViewModel.studyDeck.CardItems.Count.ToString();
                    resultBorder_resultPercent.Text = ((int)((AnswerPB.Value / App.ViewModel.studyDeck.CardItems.Count) * 100)).ToString() + "%";
                }
            }
        }
コード例 #7
0
        private void MainPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ApplicationBarIconButton btn = ApplicationBar.Buttons[0] as ApplicationBarIconButton;

            switch (MainPivot.SelectedIndex)
            {
            case 0:
            {
                if (endTest)
                {
                    if (App.ViewModel.DeckItems.Count > 0)
                    {
                        if (App.ViewModel.studyDeck == null)
                        {
                            MessageBoxResult result =
                                MessageBox.Show(AppResources.MessageBoxNostudyDeck);

                            if (result == MessageBoxResult.OK)
                            {
                                MainPivot.SelectedIndex = 1;
                            }
                        }
                        else
                        if (App.ViewModel.studyDeck.CardItems.Count == 0)
                        {
                            MessageBoxResult result =
                                MessageBox.Show(AppResources.MessageBox_Text,
                                                AppResources.MessageBox_caption, MessageBoxButton.OKCancel);

                            if (result == MessageBoxResult.OK)
                            {
                                workDeck = App.ViewModel.studyDeck;
                                MainPivot.SelectedIndex = 2;
                                deckShow.Text           = App.ViewModel.studyDeck.DeckName;
                            }
                        }
                        else
                        {
                            answerCount           = 0;
                            cardIndex             = rand.Next(App.ViewModel.studyDeck.CardItems.Count - 1);
                            App.ViewModel.curCard = App.ViewModel.studyDeck.CardItems[cardIndex];
                            AnswerPB.Maximum      = App.ViewModel.studyDeck.CardItems.Count;
                            AnswerPB.Value        = 0;
                            countAnsCards.Text    = "0/" + App.ViewModel.studyDeck.CardItems.Count.ToString();
                        }
                    }
                }
                btn.IsEnabled       = endTest;
                btn.Click          -= AddNewCard_Click;
                btn.Click          -= NewDeck_Click;
                btn.Click          += setTest_Click;
                btn.IconUri         = new Uri(@"Assets\AppBarButtons\feature.settings.png", UriKind.Relative);
                btn.Text            = AppResources.AppBarButtonSettings;
                ApplicationBar.Mode = ApplicationBarMode.Minimized;
                if (App.ViewModel.DeckItems.Count == 0)
                {
                    if (resultBorder.Visibility == Visibility.Collapsed)
                    {
                        ifNoDeckField.Visibility = Visibility.Visible;
                        studingField.Visibility  = Visibility.Collapsed;
                    }
                }
                else
                {
                    if (resultBorder.Visibility == Visibility.Collapsed)
                    {
                        ifNoDeckField.Visibility = Visibility.Collapsed;
                        studingField.Visibility  = Visibility.Visible;
                    }
                }
                if (ifNoDeckField.Visibility == Visibility.Visible)
                {
                    btn.IsEnabled = false;
                }
            }
            break;

            case 1:
            {
                btn.IsEnabled       = true;
                ApplicationBar.Mode = ApplicationBarMode.Default;
                btn.Click          -= AddNewCard_Click;
                btn.Click          -= setTest_Click;
                btn.Click          += NewDeck_Click;
                btn.IconUri         = new Uri(@"Assets\AppBarButtons\add.png", UriKind.Relative);
                btn.Text            = AppResources.AppBarButtonDeck;
            }
            break;

            case 2:
            {
                btn.IsEnabled       = true;
                ApplicationBar.Mode = ApplicationBarMode.Default;
                if (workDeck != null)
                {
                    App.ViewModel.CardsForDeck(workDeck);
                    ApplicationBar.IsVisible = true;
                    ApplicationBar.Mode      = ApplicationBarMode.Default;
                    btn.Click  -= NewDeck_Click;
                    btn.Click  -= setTest_Click;
                    btn.Click  += AddNewCard_Click;
                    btn.IconUri = new Uri(@"Assets\AppBarButtons\add.png", UriKind.Relative);
                    btn.Text    = AppResources.AppBarButtonCard;
                }
            }
            break;

            default: break;
            }
        }