-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLevelsPage.xaml.cs
332 lines (275 loc) · 10.2 KB
/
LevelsPage.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
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 Dental.Core;
using Dental.DAL;
namespace Dental.PL
{
/// <summary>
/// Interaction logic for PatientMainPage.xaml
/// </summary>
public partial class LevelsPage : UserControl
{
public LevelsPage()
{
InitializeComponent();
for (int i = 0; i < 1100; i++)
temp.Add("");
}
int k = 0;
List<Level> items;
List<Work_level> itemswrk;
List<String> temp = new List<string>();
private void Radio3_Checked(object sender, RoutedEventArgs e)
{
Grid1.Visibility = Visibility.Hidden;
Grid3.Visibility = Visibility.Visible;
Grid2.Visibility = Visibility.Hidden;
Grid4.Visibility = Visibility.Hidden;
Refresh_DataGrid_ViewSearch();
}
private void Radio2_Checked(object sender, RoutedEventArgs e)
{
Grid1.Visibility = Visibility.Hidden;
Grid3.Visibility = Visibility.Hidden;
Grid2.Visibility = Visibility.Visible;
Grid4.Visibility = Visibility.Hidden;
Refresh_DataGrid_EditDelete();
}
private void Radio1_Checked(object sender, RoutedEventArgs e)
{
try
{
if (k != 0)
{
Grid1.Visibility = Visibility.Visible;
Grid3.Visibility = Visibility.Hidden;
Grid4.Visibility = Visibility.Hidden;
Grid2.Visibility = Visibility.Hidden;
}
k = 1;
}
catch (Exception ex)
{
}
}
private void Radio4_Checked(object sender, RoutedEventArgs e)
{
Grid1.Visibility = Visibility.Hidden;
Grid3.Visibility = Visibility.Hidden;
Grid4.Visibility = Visibility.Visible;
Grid2.Visibility = Visibility.Hidden;
Refresh_DataGrid_Prices_Levels();
}
private void ButtonAddLevel_Click(object sender, RoutedEventArgs e)
{
try
{
Level level = new Level();
level.name = TextBoxName.Text;
level.note = TextBoxNotes.Text;
if(level.name=="")
{
MessageBox.Show("أدخل اسم المرحلة");
}
else
{
LevelDB.insertLevel(level);
TextBoxName.Clear();
TextBoxNotes.Clear();
Snackbar_Added.IsActive = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void ButtonEditDG_Click(object sender, RoutedEventArgs e)
{
StackPanelEditAccount.Visibility = Visibility.Visible;
Level p = new Level();
p = items[DataGridEditDelete.SelectedIndex];
TextBoxNameEdit.Text = p.name;
TextBoxNotesEdit.Text = p.note;
TextBoxNameEdit.Uid = p.id.ToString();
}
private void Refresh_DataGrid_EditDelete()
{
items = LevelDB.selectLevels();
DataGridEditDelete.ItemsSource = items;
}
private void ButtonEdit_Click(object sender, RoutedEventArgs e)
{
Level p = new Level();
p.name = TextBoxNameEdit.Text;
p.note = TextBoxNotesEdit.Text;
p.id = int.Parse(TextBoxNameEdit.Uid);
LevelDB.updateLevel(p);
MessageBox.Show("تم التعديل");
StackPanelEditAccount.Visibility = Visibility.Hidden;
Refresh_DataGrid_EditDelete();
}
private void ButtonDelete_Click(object sender, RoutedEventArgs e)
{
int id = int.Parse(TextBoxDelete.Uid);
Level p = new Level();
p.id = id;
LevelDB.deleteLevel(p);
StackPanelDelete.Visibility = Visibility.Hidden;
MessageBox.Show("تم الحذف");
Refresh_DataGrid_EditDelete();
}
private void ButtonDeleteDG_Click(object sender, RoutedEventArgs e)
{
StackPanelDelete.Visibility = Visibility.Visible;
Level p = new Level();
p = items[DataGridEditDelete.SelectedIndex];
TextBoxDelete.Text = "هل أنت متأكد من حذف " + p.name + " ؟";
TextBoxDelete.Uid = p.id.ToString();
}
private void Refresh_DataGrid_ViewSearch()
{
items = LevelDB.selectLevels();
DataGridViewSearch.ItemsSource = items;
}
private void ButtonViewSearch1_Click(object sender, RoutedEventArgs e)
{
String search = TextBoxViewSearch1.Text;
if (search == "")
{
Refresh_DataGrid_ViewSearch();
}
else
{
List<Level> newItems = new List<Level>();
foreach (var item in items)
{
if (item.name.Contains(search))
{
newItems.Add(item);
}
}
DataGridViewSearch.ItemsSource = newItems;
}
}
private void ButtonViewSearch3_Click(object sender, RoutedEventArgs e)
{
String search = TextBoxViewSearch3.Text;
if (search == "")
{
Refresh_DataGrid_ViewSearch();
}
else
{
List<Level> newItems = new List<Level>();
foreach (var item in items)
{
if (item.note.Contains(search))
{
newItems.Add(item);
}
}
DataGridViewSearch.ItemsSource = newItems;
}
}
private void Refresh_DataGrid_Prices_Levels()
{
items = LevelDB.selectLevels();
DataGridPricesLevels.ItemsSource = items;
}
private void Refresh_DataGrid_Prices_Employees(int id)
{
itemswrk = Work_levelDB.SelectWork_levelIdFound(id);
DataGridPricesEmployees.ItemsSource = itemswrk;
}
private void ButtonSelectDG_Click(object sender, RoutedEventArgs e)
{
int index = DataGridPricesLevels.SelectedIndex;
int id = items[index].id;
ButtonAddWorkLevel.Uid = id.ToString();
ButtonEditWorkLevel.Uid = id.ToString();
ButtonDeleteWorkLevel.Uid = id.ToString();
GridEmployees.Visibility = Visibility.Visible;
Refresh_DataGrid_Prices_Employees(id);
}
private void ComboBoxEmployee_DropDownOpened(object sender, EventArgs e)
{
List<Employee> emps = EmployeeDB.selectEmployees();
List<Employee> empsCombo = new List<Employee>();
foreach(var item in emps)
{
int flag = 0;
foreach(var empItem in itemswrk)
{
if(item.id == empItem.employee.id)
{
flag = 1; break;
}
}
if(flag==0)
{
empsCombo.Add(item);
}
}
ComboBoxEmployee.ItemsSource = empsCombo;
ComboBoxEmployee.SelectedValuePath = "id";
ComboBoxEmployee.DisplayMemberPath = "name";
}
private void ButtonAddWorkLevel_Click(object sender, RoutedEventArgs e)
{
Work_level wrk = new Work_level();
Level level = new Level();
level.id = int.Parse(ButtonAddWorkLevel.Uid);
Employee employee = new Employee();
employee.id = int.Parse(ComboBoxEmployee.SelectedValue.ToString());
wrk.level = level;
wrk.employee = employee;
wrk.price = int.Parse(TextBoxPriceAddWorkLEVEL.Text);
Work_levelDB.insertWork_level(wrk);
Refresh_DataGrid_Prices_Employees(level.id);
TextBoxPriceAddWorkLEVEL.Clear();
ComboBoxEmployee.SelectedIndex = -1;
}
private void ButtonEditWorkLevel_Click(object sender, RoutedEventArgs e)
{
Work_level wrk = new Work_level();
wrk.id = int.Parse(ButtonEditWorkLevel.Uid);
wrk.price = int.Parse(TextBoxPriceEditWorkLEVEL.Text);
Employee emp = new Employee();
emp.id = itemswrk[DataGridPricesEmployees.SelectedIndex].employee.id;
wrk.employee = emp;
Level level = new Level();
level.id = int.Parse(ButtonAddWorkLevel.Uid);
wrk.level = level;
Work_levelDB.updateWork_level(wrk);
Refresh_DataGrid_Prices_Employees(level.id);
StackPanelWorkLevelEdit.Visibility = Visibility.Hidden ;
}
private void ButtonEditWorkLevelDG_Click(object sender, RoutedEventArgs e)
{
ButtonEditWorkLevel.Uid = itemswrk[DataGridPricesEmployees.SelectedIndex].id.ToString();
StackPanelWorkLevelEdit.Visibility = Visibility.Visible;
TextBoxPriceEditWorkLEVEL.Text = itemswrk[DataGridPricesEmployees.SelectedIndex].price.ToString();
}
private void ButtonDeleteWorkLevel_Click(object sender, RoutedEventArgs e)
{
Work_level wrk = new Work_level();
wrk.id = int.Parse(ButtonEditWorkLevel.Uid);
Work_levelDB.deleteWork_level(wrk);
Refresh_DataGrid_Prices_Employees(int.Parse(ButtonAddWorkLevel.Uid));
StackPanelWorkLevelEdit.Visibility = Visibility.Hidden;
}
}
}