-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
203 lines (174 loc) · 6.89 KB
/
MainWindow.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BVCareManager.Models;
using BVCareManager.ViewModels;
using BVCareManager.Repository;
using BVCareManager.Controls;
using BVCareManager.Converter;
using MartinCostello.SqlLocalDb;
namespace BVCareManager
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///
public partial class MainWindow : Window
{
object createNewGroupBoxViewModel;
object searchAndModifyViewModel;
public MainWindow()
{
InitializeComponent();
CreateLocalDb();
MyTabs.SelectedIndex = 0;
CreateNewListBox.SelectedIndex = 0;
ComboBoxSearchCategory.SelectedIndex = 0;
}
private void CreateNewListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
CreateNewDockPanel.Children.Clear();
int createNewListBoxIndex = CreateNewListBox.SelectedIndex;
switch (createNewListBoxIndex)
{
case 0:
CreateNewDockPanel.Children.Add(new InsuredNew());
if (!(createNewGroupBoxViewModel is NewInsuredViewModel))
createNewGroupBoxViewModel = new NewInsuredViewModel();
break;
case 1:
CreateNewDockPanel.Children.Add(new ContractNew());
if (!(createNewGroupBoxViewModel is NewContractViewModel))
createNewGroupBoxViewModel = new NewContractViewModel();
break;
case 2:
CreateNewDockPanel.Children.Add(new PolicyNew());
if (!(createNewGroupBoxViewModel is NewPolicyViewModel))
createNewGroupBoxViewModel = new NewPolicyViewModel();
break;
default:
break;
}
CreateNewGrid.DataContext = createNewGroupBoxViewModel;
}
private void ButtonSearch_Click(object sender, RoutedEventArgs e)
{
ModifyDockPanel.Children.Clear();
string searchCategory = ComboBoxSearchCategory.SelectedItem.ToString();
string searchText = SearchTextBox.Text;
switch (searchCategory)
{
case "Nhân viên":
ModifyDockPanel.Children.Add(new InsuredModify());
searchAndModifyViewModel = new ModifyInsuredViewModel(searchText);
break;
case "Hợp đồng":
ModifyDockPanel.Children.Add(new ContractModify());
searchAndModifyViewModel = new ModifyContractViewModel(searchText);
break;
case "Đơn bảo hiểm":
ModifyDockPanel.Children.Add(new PolicyModify());
searchAndModifyViewModel = new ModifyPolicyViewModel(searchText);
break;
}
ModifyGrid.DataContext = searchAndModifyViewModel;
}
private void MyTabs_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
UpdateTabs();
}
private void UpdateTabs()
{
if (NewTab.IsSelected == false)
{
CreateNewListBox.SelectedIndex = 0;
CreateNewGrid.DataContext = new NewInsuredViewModel();
}
if (ModifyTab.IsSelected == false)
{
ModifyDockPanel.Children.Clear();
SearchTextBox.Text = String.Empty;
}
if (ClaimTab.IsSelected == false)
{
ClaimManagerDockPanel.Children.Clear();
}
if (ClaimTab.IsSelected == true)
{
if (ClaimManagerDockPanel.Children.Count == 0)
{
ClaimManagerDockPanel.Children.Add(new ClaimManager());
ClaimGrid.DataContext = new ClaimBaseViewModel();
}
}
if (ReportTab.IsSelected == false)
{
ReportDockPanel.Children.Clear();
}
if (ReportTab.IsSelected == true)
{
if (ReportDockPanel.Children.Count == 0)
{
ReportDockPanel.Children.Add(new Report());
ReportDockPanel.DataContext = new ReportViewModel();
}
}
}
private void TopControlBar_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
this.DragMove();
}
private void CreateLocalDb()
{
string connection = System.Configuration.ConfigurationManager.ConnectionStrings["BVCareManager.Properties.Settings.BVCareManagerConnectionString"].ConnectionString;
string localDbstring = @"(LocalDB)\";
int pFrom = connection.IndexOf(localDbstring) + localDbstring.Length;
int pTo = connection.LastIndexOf(";AttachDbFilename");
string resultLocalDb = connection.Substring(pFrom, pTo - pFrom);
#region SqlLocalDb Handle
var localDb = new SqlLocalDbApi();
ISqlLocalDbInstanceInfo localDbInstance = localDb.GetInstanceInfo(resultLocalDb);
string localDbVersion = localDbInstance.LocalDbVersion.ToString().Substring(0, 2);
if (localDbVersion == "0.")
{
try
{
localDb.CreateInstance(resultLocalDb, "12.0");
}
catch
{
MessageBox.Show("Phiên bản SQL Server LocalDB hiện tại không phù hợp. Hãy cài đặt phiên bản 12.0 (SQL Server 2014 Express LocalDb)");
Environment.Exit(1);
}
}
else if (localDbVersion != "0." && localDbVersion != "12")
{
localDb.StopInstance(resultLocalDb);
localDb.DeleteInstance(resultLocalDb);
try
{
localDb.CreateInstance(resultLocalDb, "12.0");
}
catch
{
MessageBox.Show("Phiên bản SQL Server LocalDB hiện tại không phù hợp. Hãy cài đặt phiên bản 12.0 (SQL Server 2014 Express LocalDb)");
Environment.Exit(1);
}
}
localDb.StartInstance(resultLocalDb);
#endregion
}
}
}