forked from zachtaylor1/SWProj
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoom.cs
More file actions
330 lines (288 loc) · 12.7 KB
/
Room.cs
File metadata and controls
330 lines (288 loc) · 12.7 KB
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
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.Input;
using System.Windows.Media;
namespace SWProjv1
{
class Room
{
public static Room selectedRoom { get; set; }
public Furniture selectedFurn;
public String roomNum { get; set; }
public String roomSide { get; set; }
public String building { get; set; }
public String phoneNumber { get; set; }
public String mailing { get; set; }
public String roomID { get; set; }
public List<Furniture> furnitureList { get; set;}
public ListBoxItem listboxitem;
public Grid grid;
DockPanel furnGrid;
DataGrid furniture;
TextBox n_txt;
TextBox sn_txt;
TabItem history;
Button edit_btn, save_btn;
StackPanel data;
TextBox roomNumber_txt;
TextBox roomSide_txt;
TextBox building_txt;
TextBox mailAddress_txt;
TextBox phone_txt;
public Room(String roomID, String roomSide, String building, String phoneNumber, String mailing, String roomNum)
{
this.roomID = roomID;
this.roomSide = roomSide;
this.roomNum = roomNum;
this.building = building;
this.phoneNumber = phoneNumber;
this.mailing = mailing;
grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition());
grid.RowDefinitions.Add(new RowDefinition());
grid.ColumnDefinitions.Add(new ColumnDefinition());
grid.ColumnDefinitions.Add(new ColumnDefinition());
}
private void Item_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
try
{
setGrid();
selectedRoom = this;
}
catch (InvalidOperationException) { }
}
public void setListBoxItem()
{
listboxitem = new ListBoxItem();
listboxitem.Content = roomNum + roomSide + " " + building;
listboxitem.PreviewMouseDown += Item_PreviewMouseDown;
}
public void setGrid()
{
grid.Children.Clear();
this.furnitureList = Server.getFurniture(roomID);
//top info
DockPanel basicInfo = GetBasicInfo();
Grid.SetRow(basicInfo, 0);
Grid.SetColumn(basicInfo, 0);
grid.Children.Add(basicInfo);
//furniture & history
TabControl tb = new TabControl();
Grid.SetRow(tb, 1);
Grid.SetColumn(tb, 0);
Grid.SetColumnSpan(tb, 2);
grid.Children.Add(tb);
TabItem furnitures = new TabItem();
furnitures.Header = "Furniture";
furnGrid = new DockPanel();
/*for (int i = 0; i < 4; i++)
{
ColumnDefinition cd = new ColumnDefinition();
cd.Width = new GridLength(20, GridUnitType.Auto);
furnGrid.ColumnDefinitions.Add(cd);
furnGrid.ColumnDefinitions.Add(new ColumnDefinition());
}*/
ScrollViewer scroller = new ScrollViewer();
//Grid.SetColumn(scroller, 0);
furniture = new DataGrid();
furniture.ItemsSource = furnitureList;
furniture.AutoGenerateColumns = false;
DataGridTextColumn furnitureNames = new DataGridTextColumn();
furnitureNames.Binding = new Binding("name");
furnitureNames.Header = "Item";
furnitureNames.Width = new DataGridLength(20,DataGridLengthUnitType.Star);
furniture.Columns.Add(furnitureNames);
DataGridTextColumn furnitureSN = new DataGridTextColumn();
furnitureSN.Binding = new Binding("serialNum");
furnitureSN.Header = "Serial Number";
furnitureSN.Width = new DataGridLength(20, DataGridLengthUnitType.Star);
furniture.Columns.Add(furnitureSN);
scroller.Content = furniture;
furnitures.Content = furnGrid;
tb.Items.Add(furnitures);
Grid optionInput = new Grid();
for (int i = 0; i < 5; i++)
{
RowDefinition rd = new RowDefinition();
rd.Height = new GridLength(20, GridUnitType.Star);
optionInput.RowDefinitions.Add(rd);
}
TextBlock n_lbl = new TextBlock();
n_lbl.Text = "Enter name of furniture";
n_lbl.HorizontalAlignment = HorizontalAlignment.Center;
n_lbl.VerticalAlignment = VerticalAlignment.Center;
Grid.SetRow(n_lbl, 0);
n_txt = new TextBox();
n_txt.HorizontalAlignment = HorizontalAlignment.Center;
n_txt.VerticalAlignment = VerticalAlignment.Center;
n_txt.MinWidth = 100;
Grid.SetRow(n_txt, 1);
TextBlock sn_lbl = new TextBlock();
sn_lbl.Text = "Enter serial number of furniture";
sn_lbl.HorizontalAlignment = HorizontalAlignment.Center;
sn_lbl.VerticalAlignment = VerticalAlignment.Center;
Grid.SetRow(sn_lbl, 2);
sn_txt = new TextBox();
sn_txt.HorizontalAlignment = HorizontalAlignment.Center;
sn_txt.VerticalAlignment = VerticalAlignment.Center;
sn_txt.MinWidth = 100;
Grid.SetRow(sn_txt, 3);
optionInput.Children.Add(n_lbl);
optionInput.Children.Add(n_txt);
optionInput.Children.Add(sn_lbl);
optionInput.Children.Add(sn_txt);
Grid someFurnOptions = new Grid();
for (int i = 0; i < 5; i++)
{
RowDefinition rd = new RowDefinition();
rd.Height = new GridLength(20, GridUnitType.Star);
someFurnOptions.RowDefinitions.Add(rd);
}
Button rm_btn = new Button();
rm_btn.Content = "Remove";
rm_btn.Click += remove_furniture_btn_Click;
Grid.SetRow(rm_btn, 1);
someFurnOptions.Children.Add(rm_btn);
Button add_btn = new Button();
add_btn.Content = "Add";
add_btn.Click += add_furniture_btn_Click;
Grid.SetRow(add_btn, 3);
someFurnOptions.Children.Add(add_btn);
StackPanel spacer = new StackPanel();
for (int i = 0; i < 5; i++)
{
TextBlock block = new TextBlock();
block.Text = " ";
spacer.Children.Add(block);
}
StackPanel spacer2 = new StackPanel();
for (int i = 0; i < 5; i++)
{
TextBlock block = new TextBlock();
block.Text = " ";
spacer2.Children.Add(block);
}
furnGrid.Children.Add(optionInput);
furnGrid.Children.Add(spacer);
furnGrid.Children.Add(someFurnOptions);
furnGrid.Children.Add(spacer2);
furnGrid.Children.Add(scroller);
history = new TabItem();
history.Header = "Room History";
history.PreviewMouseDown += history_MouseDown;
tb.Items.Add(history);
}
private void history_MouseDown(object sender, RoutedEventArgs e)
{
ListBox historyList = new ListBox();
historyList.ItemsSource = Server.getRoomHistory(roomID);
history.Content = historyList;
}
private void remove_furniture_btn_Click(object sender, RoutedEventArgs e)
{
Server.delFurniture(sn_txt.Text);
furniture.Items.Refresh();
}
private void add_furniture_btn_Click(object sender, RoutedEventArgs e)
{
try
{
selectedFurn = new Furniture(sn_txt.Text, n_txt.Text, roomID);
Server.addFurniture(selectedFurn.roomID, selectedFurn.serialNum, selectedFurn.name);
n_txt.Text = "";
sn_txt.Text = "";
furniture.Items.Refresh();
}
catch (Exception)
{
String mbMessage = "This furniture is already in another room.\nPlease remove it before adding to a new room.";
MessageBox.Show(mbMessage);
}
}
public DockPanel GetBasicInfo()
{
DockPanel basicInfo = new DockPanel();
StackPanel labels = new StackPanel();
TextBox roomNumber_lbl = new TextBox();
roomNumber_lbl.IsReadOnly = true;
roomNumber_lbl.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE5E5E5"));
roomNumber_lbl.BorderBrush = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE5E5E5")); roomNumber_lbl.Text = "Room Number:";
labels.Children.Add(roomNumber_lbl);
TextBox roomSide_lbl = new TextBox();
roomSide_lbl.Text = "Room Side:";
roomSide_lbl.IsReadOnly = true;
roomSide_lbl.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE5E5E5"));
roomSide_lbl.BorderBrush = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE5E5E5"));
labels.Children.Add(roomSide_lbl);
TextBox building_lbl = new TextBox();
building_lbl.IsReadOnly = true;
building_lbl.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE5E5E5"));
building_lbl.BorderBrush = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE5E5E5"));
building_lbl.Text = "Room Number:";
labels.Children.Add(building_lbl);
TextBox mailAddress_lbl = new TextBox();
mailAddress_lbl.IsReadOnly = true;
mailAddress_lbl.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE5E5E5"));
mailAddress_lbl.BorderBrush = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE5E5E5"));
mailAddress_lbl.Text = "Mailing Address:";
labels.Children.Add(mailAddress_lbl);
TextBox phone_lbl = new TextBox();
phone_lbl.IsReadOnly = true;
phone_lbl.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE5E5E5"));
phone_lbl.BorderBrush = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE5E5E5"));
phone_lbl.Text = "Room Number:";
labels.Children.Add(phone_lbl);
/*TextBox roomID_lbl = new TextBox();
roomID_lbl.IsReadOnly = true;
roomID_lbl.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE5E5E5"));
roomID_lbl.BorderBrush = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE5E5E5"));
roomID_lbl.Text = "Room ID:";
labels.Children.Add(roomID_lbl);*/
basicInfo.Children.Add(labels);
StackPanel spacer = new StackPanel();
for (int i = 0; i < labels.Children.Count; i++)
{
TextBlock block = new TextBlock();
block.Text = " ";
spacer.Children.Add(block);
}
basicInfo.Children.Add(spacer);
data = new StackPanel();
roomNumber_txt = new TextBox();
roomNumber_txt.IsReadOnly = true;
roomNumber_txt.Text = roomNum;
data.Children.Add(roomNumber_txt);
roomSide_txt = new TextBox();
roomSide_txt.IsReadOnly = true;
roomSide_txt.Text = roomSide;
data.Children.Add(roomSide_txt);
building_txt = new TextBox();
building_txt.IsReadOnly = true;
building_txt.Text = building;
data.Children.Add(building_txt);
mailAddress_txt = new TextBox();
mailAddress_txt.IsReadOnly = true;
mailAddress_txt.Text = mailing;
data.Children.Add(mailAddress_txt);
phone_txt = new TextBox();
phone_txt.IsReadOnly = true;
phone_txt.Text = phoneNumber;
data.Children.Add(phone_txt);
/*TextBox roomID_txt = new TextBox();
roomID_txt.IsReadOnly = true;
roomID_txt.Text = roomID;
data.Children.Add(roomID_txt);*/
basicInfo.Children.Add(data);
Grid.SetRow(basicInfo, 0);
Grid.SetColumn(basicInfo, 0);
return basicInfo;
}
}
}