-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
266 lines (226 loc) · 10.2 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
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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
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;
namespace Auction
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
DataCxt dataCxt;
ControlFunctions controlFunctions;
AuctionItem auctionItem;
AuctionLocation auctionLocation;
AuctionEvent auctionEvent;
AuctionItem auctionItemCopy;
AuctionLocation auctionLocationCopy;
int auctionItemSelectedIndex = -1;
int auctionLocationSelectedIndex = -1;
int auctionEventSelectedIndex = -1;
public MainWindow() {
initiateComponent(1);
}
public MainWindow(Users users) {
initiateComponent(users.userType);
}
private void initiateComponent(int userType) {
//System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de");
InitializeComponent();
// Enable-Disable and Show-Hide Windows Components based on the User Privileges
controlFunctions = new ControlFunctions(userType);
// Item Sources
lbxItem_Grid.ItemsSource = controlFunctions.auctionItems;
lbxLocation_Grid.ItemsSource = controlFunctions.auctionLocations;
lbxEvent_Grid.ItemsSource = controlFunctions.auctionEvents;
// Data Context Objects
dataCxt = new DataCxt { aItem = new AuctionItem(), aLocation = new AuctionLocation() };
this.DataContext = dataCxt;
if(userType>2)
{
btnEvent_Add.Visibility = Visibility.Hidden;
tabAuctionItem.Visibility = Visibility.Hidden;
tabAuctionLocation.Visibility = Visibility.Hidden;
}
}
private void Item_Reset(AuctionItem ai) {
dataCxt = new DataCxt { aItem = ai, aLocation = dataCxt.aLocation };
this.DataContext = dataCxt;
Item_ResetLbl();
}
private void Location_Reset(AuctionLocation al) {
dataCxt = new DataCxt { aItem = dataCxt.aItem, aLocation = al };
this.DataContext = dataCxt;
Location_ResetLbl();
}
private void Item_ResetLbl() {
lblItem_Error.Visibility = Visibility.Hidden;
lblItem_Success.Visibility = Visibility.Hidden;
lblItem_ValueNotDefined.Visibility = Visibility.Hidden;
lblItem_NoChangeInValue.Visibility = Visibility.Hidden;
lblItem_ValueNotUpdatedError.Visibility = Visibility.Hidden;
lblItem_DefineMandatoryValues.Visibility = Visibility.Hidden;
}
private void Location_ResetLbl() {
lblLocation_Error.Visibility = Visibility.Hidden;
lblLocation_Success.Visibility = Visibility.Hidden;
lblLocation_ValueNotDefined.Visibility = Visibility.Hidden;
lblLocation_NoChangeInValue.Visibility = Visibility.Hidden;
lblLocation_ValueNotUpdatedError.Visibility = Visibility.Hidden;
lblLocation_DefineMandatoryValues.Visibility = Visibility.Hidden;
}
public void FocusLostInt(object sender, RoutedEventArgs e) {
string txt = ((TextBox)sender).Text;
if (txt == "" || !int.TryParse(txt, out int n))
((TextBox)sender).Text = "0";
}
/* *************************** CODE RELATED TO AUCTION ITEM *************************** */
public void DblClickItem_Grid(object sender, MouseEventArgs e) {
auctionItem = (AuctionItem)lbxItem_Grid.SelectedItem;
auctionItemSelectedIndex = lbxItem_Grid.SelectedIndex;
Item_Reset(new AuctionItem(auctionItem));
}
public void ClickItem_Submit(object sender, RoutedEventArgs e) {
Item_ResetLbl();
AuctionItem aItem = dataCxt.aItem;
if (aItem == null) {
lblItem_ValueNotDefined.Visibility = Visibility.Visible;
return;
}
// No Change In Values
if (auctionItem!=null && aItem.toString().Equals(auctionItem.toString())) {
lblItem_NoChangeInValue.Visibility = Visibility.Visible;
return;
}
// Mandatory Values Check
if (!aItem.mandatoryCheck()) {
lblItem_DefineMandatoryValues.Visibility = Visibility.Visible;
return;
}
// Insert/Update Values
int selectedIndex = controlFunctions.submitItem(aItem, auctionItemSelectedIndex);
if(selectedIndex>0) {
Item_Reset(new AuctionItem());
lbxItem_Grid.SelectedIndex = selectedIndex-1;
lblItem_Success.Visibility = Visibility.Visible;
}
else if (selectedIndex > -1) {
lblItem_ValueNotUpdatedError.Visibility = Visibility.Visible;
}
else {
lblItem_Error.Visibility = Visibility.Visible;
}
}
public void ClickItem_Reset(object sender, RoutedEventArgs e) {
Item_Reset(new AuctionItem());
}
public void TxtChngItem_Filter_Search(object sender, TextChangedEventArgs e) {
string q = txtItem_Filter_SearchQuantity.Text;
string ip = txtItem_Filter_SearchPrice.Text;
AuctionItem ai = new AuctionItem {
itemName = txtItem_Filter_SearchName.Text,
itemType = txtItem_Filter_SearchType.Text,
additionalInfo = txtItem_Filter_SearchInformation.Text,
owner = txtItem_Filter_SearchOwner.Text,
quantity = int.TryParse(q, out int n) ? int.Parse(q) : -1,
initialPrice = int.TryParse(ip, out int m) ? int.Parse(ip) : -1
};
controlFunctions.searchItem(ai);
}
public void ClickItem_Copy(object sender, RoutedEventArgs e){
if (auctionItem != null) {
auctionItemCopy = new AuctionItem(auctionItem);
Item_Reset(new AuctionItem());
}
}
/* *************************** CODE RELATED TO AUCTION LOCATION *************************** */
public void DblClickLocation_Grid(object sender, MouseEventArgs e) {
auctionLocation = (AuctionLocation)lbxLocation_Grid.SelectedItem;
auctionLocationSelectedIndex = lbxLocation_Grid.SelectedIndex;
Location_Reset(new AuctionLocation(auctionLocation));
}
public void ClickLocation_Submit(object sender, RoutedEventArgs e) {
Location_ResetLbl();
AuctionLocation aLocation = dataCxt.aLocation;
if (aLocation == null){
lblLocation_ValueNotDefined.Visibility = Visibility.Visible;
return;
}
// No Change In Values
if (auctionLocation != null && aLocation.toString().Equals(auctionLocation.toString())){
lblLocation_NoChangeInValue.Visibility = Visibility.Visible;
return;
}
// Mandatory Values Check
if (!aLocation.mandatoryCheck()){
lblLocation_DefineMandatoryValues.Visibility = Visibility.Visible;
return;
}
// Insert/Update Values
int selectedIndex = controlFunctions.submitLocation(aLocation, auctionLocationSelectedIndex);
if (selectedIndex > 0){
Location_Reset(new AuctionLocation());
lbxItem_Grid.SelectedIndex = selectedIndex-1;
lblLocation_Success.Visibility = Visibility.Visible;
}
else if (selectedIndex > -1){
lblLocation_ValueNotUpdatedError.Visibility = Visibility.Visible;
}
else{
lblLocation_Error.Visibility = Visibility.Visible;
}
}
public void ClickLocation_Reset(object sender, RoutedEventArgs e) {
Location_Reset(new AuctionLocation());
}
public void TxtChngLocation_Filter_Search(object sender, TextChangedEventArgs e) {
string cap = txtLocation_Filter_SearchCapacity.Text;
var al = new AuctionLocation {
locationName = txtLocation_Filter_SearchName.Text,
address = txtLocation_Filter_SearchAddress.Text,
place = txtLocation_Filter_SearchPlace.Text,
contactPerson = txtLocation_Filter_SearchContactPerson.Text,
availability = txtLocation_Filter_SearchAvailability.Text,
capacity = int.TryParse(cap, out int n) ? int.Parse(cap) : -1
};
controlFunctions.searchLocation(al);
}
public void ClickLocation_Copy(object sender, RoutedEventArgs e) {
if(auctionLocation!=null) {
auctionLocationCopy = new AuctionLocation(auctionLocation);
Location_Reset(new AuctionLocation());
}
}
/* *************************** CODE RELATED TO AUCTION Event *************************** */
public void DblClickEvent_Grid(object sender, MouseEventArgs e)
{
auctionEvent = (AuctionEvent)lbxEvent_Grid.SelectedItem;
auctionEventSelectedIndex = lbxEvent_Grid.SelectedIndex;
// TODO - Need to add logic to show the data somewhere
//Item_Reset(new AuctionEvent().setAuctionItem(auctionItem));
}
public void ClickEvent_Add(object sender, RoutedEventArgs e) {
// Show the main window
AddEvent addEvent = new AddEvent(auctionItemCopy, auctionLocationCopy, this);
addEvent.Show();
}
public void clearCopyItem() {
auctionItemCopy = null;
auctionLocationCopy = null;
controlFunctions.searchEvent();
}
}
}