-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUploadExamDialog.xaml.cs
137 lines (121 loc) · 3.87 KB
/
UploadExamDialog.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using MultiDF.VM;
using Model;
using System;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Interop;
using Common;
namespace MultiDF.Views
{
/// <summary>
/// Interaction logic for InputBox.xaml
/// </summary>
public partial class UploadExamDialog : Window
{
#region Hide System Menu and Close Button
private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x80000;
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//Do not show Close button
var hwnd = new WindowInteropHelper(this).Handle;
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
}
#endregion
private ICollectionView QAs => (this.Resources["QACVS"] as CollectionViewSource).View;
public UploadExamDialog(UploadExamVM vm)
{
InitializeComponent();
this.DataContext = vm;
}
private void OK_Click(object sender, RoutedEventArgs e)
{
var VM = (this.DataContext as UploadExamVM);
VM.CreateNew = (this.TabControl.SelectedIndex == 0);
if (VM.CreateNew)
{
if (string.IsNullOrEmpty(VM.NewExamNumber) || string.IsNullOrEmpty(VM.NewExamName))
ViewModelLocator.DialogService.ShowMessage($"Exam number and name must be supplied.", true);
else
{
VM.CheckExamNumberExists().ContinueWith(t =>
{
if (t.Result)
ViewModelLocator.DialogService.ShowMessage($"Specified Master File number '{VM.NewExamNumber}' already exists on the server. Please specify a different number.", true);
else
{
GalaSoft.MvvmLight.Threading.DispatcherHelper.CheckBeginInvokeOnUI(() =>
{
this.DialogResult = true;
this.Close();
});
}
});
}
}
else
{
if (VM.SelectedExam == null)
{
ViewModelLocator.DialogService.ShowMessage("Please select a Master File from the list to update.", true);
}
else
{
this.DialogResult = true;
this.Close();
}
}
}
private void Cancel_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
this.Close();
}
private void ClearButton_Click(object sender, RoutedEventArgs e)
{
SearchBox.Text = "";
//Refresh filtering
if (QAs != null)
QAs.Refresh();
}
private void SearchBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
if (QAs != null)
{
//Refresh filtering
QAs.Refresh();
}
else
ViewModelLocator.DialogService.ShowMessage("List of QAs is empty. There is nothing to search.", false);
}
}
private void SearchButton_Click(object sender, RoutedEventArgs e)
{
//Refresh filtering
if (QAs != null)
QAs.Refresh();
else
ViewModelLocator.DialogService.ShowMessage("List of QAs is empty. There is nothing to search.", false);
}
private void CollectionViewSource_Filter(object sender, System.Windows.Data.FilterEventArgs e)
{
if (e.Item is MasterFile MF)
{
e.Accepted =
MF.number.IndexOf(SearchBox.Text, StringComparison.OrdinalIgnoreCase) >= 0 ||
MF.name.IndexOf(SearchBox.Text, StringComparison.OrdinalIgnoreCase) >= 0 ||
MF.origfilename.IndexOf(SearchBox.Text, StringComparison.OrdinalIgnoreCase) >= 0;
}
}
}
}