/
LookupView.xaml.cs
84 lines (72 loc) · 2.51 KB
/
LookupView.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;
using Microsoft.Phone.Net.NetworkInformation;
using Microsoft.Phone.Tasks;
using Microsoft.Phone.Shell;
using KanjiFlashcards.Core;
using System.Text;
using KanjiDatabase;
using System.ComponentModel;
using KanjiFlashcards.ViewModels;
namespace KanjiFlashcards.Views
{
public partial class LookupView : PhoneApplicationPage
{
private bool isLoading;
private LookupViewModel vm;
public LookupView()
{
InitializeComponent();
isLoading = false;
vm = new LookupViewModel();
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
progressBar.Visibility = System.Windows.Visibility.Collapsed;
vm.Load();
this.DataContext = vm;
// LookupMessageListBox.ItemsSource = vm.LookupMessages;
}
private void Submit_Click(object sender, RoutedEventArgs e)
{
if (isLoading) {
return;
}
isLoading = true;
progressBar.Visibility = System.Windows.Visibility.Visible;
App.KanjiMode = Mode.Lookup;
var worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(ParseAsync);
worker.WorkerReportsProgress = false;
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(ParseCompleted);
worker.RunWorkerAsync();
}
private void ParseAsync(object sender, DoWorkEventArgs e)
{
vm.Parse();
}
private void ParseCompleted(object sender, RunWorkerCompletedEventArgs e)
{
var result = vm.Save();
isLoading = false;
progressBar.Visibility = System.Windows.Visibility.Collapsed;
if (result.Result == Result.Failure) {
MessageBox.Show(result.Message);
} else {
this.NavigationService.Navigate(new Uri("/Views/KanjiView.xaml", UriKind.Relative));
}
}
}
}