This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFacility_SetupData.vb
299 lines (275 loc) · 12.8 KB
/
Facility_SetupData.vb
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
Imports System.Resources
Imports Svg
Imports System.IO
Imports System.Net
Public Class Facility_SetupData
Inherits BaseForm
Private FormPanel As New Transparent.FlowLayoutPanel
Protected Sub Facility_SetupData_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Name = "Setup Facility Data"
Dim Title As New Label With {
.Text = "Import Facility Data",
.AutoSize = True,
.MinimumSize = New Size(Me.Width - Globals.Unit(4), Globals.Unit(2)),
.MaximumSize = New Size(Me.Width - Globals.Unit(4), Globals.Unit(2)),
.Font = Globals.GetFont("Raleway", Globals.Unit(1.5), FontStyle.Bold),
.ForeColor = Globals.Palette("Primary"),
.TextAlign = ContentAlignment.MiddleCenter,
.Name = "Title"
}
Title.Location = New Point(
CInt(Me.Width * 0.5 - Title.Width * 0.5),
Globals.Unit(2)
)
Me.Contents.Controls.Add(Title)
Me.FormPanel.AutoScroll = True
Me.FormPanel.Size = New Size(
Me.Width - Globals.Unit(4) + SystemInformation.VerticalScrollBarWidth,
Me.Height - Globals.Unit(9)
)
Me.FormPanel.Location = New Point(
CInt(Me.Width * 0.5 - (Me.FormPanel.Width - SystemInformation.VerticalScrollBarWidth) * 0.5),
Globals.Unit(5)
)
Me.Contents.Controls.Add(Me.FormPanel)
Dim FacilitiesInput As New FileInputPanel With {
.Label = "Facilities",
.Description = "Upload .csv file of facilities.",
.Format = "facilityID, name, description"
}
Me.FormPanel.Controls.Add(FacilitiesInput)
Dim i As Integer = 0
For Each Control As Control In Me.FormPanel.Controls
Control.MinimumSize = New Size(Me.FormPanel.Width - SystemInformation.VerticalScrollBarWidth, 0)
Control.MaximumSize = New Size(Me.FormPanel.Width - SystemInformation.VerticalScrollBarWidth, 0)
If i Mod 2 = 0 Then
Control.Margin = New Padding(0, 0, 0, 0)
Else
Control.Margin = New Padding(Globals.Unit(2), 0, 0, 0)
End If
If i > 1 Then
Control.Margin = New Padding(
Control.Margin.Left,
Globals.Unit(1),
0,
0
)
End If
i = i + 1
Next
Dim SubmitButton As New BaseButton With {
.Name = "Submit",
.Text = "Submit"
}
SubmitButton.Location = New Point(
Me.FormPanel.Right - SubmitButton.Width,
Me.FormPanel.Bottom + Globals.Unit(1)
)
AddHandler SubmitButton.Click, Sub()
Dim Data As New Dictionary(Of String, String)
If FacilitiesInput.FilePath = "" Then
Dim Modal As New BaseModal With {
.Title = "Error",
.Message = "Please upload a .csv file for courses."
}
Modal.ShowDialog()
FacilitiesInput.Alert()
Exit Sub
Else
Try
Data.Add("facilities", File.ReadAllText(FacilitiesInput.FilePath))
Catch ex As Exception
Dim Modal As New BaseModal With {
.Title = "Error",
.Message = ex.Message
}
Modal.ShowDialog()
FacilitiesInput.Alert()
Exit Sub
End Try
End If
Try
Dim response As String = Globals.API("POST", "setup/facilities", Globals.DictionaryToJSON(Data))
Me.GoToForm(New Login)
Catch ex As WebException
Dim rep As HttpWebResponse = ex.Response
Using rdr As New StreamReader(rep.GetResponseStream())
Dim Modal As New BaseModal With {
.Title = "Error",
.Message = rep.StatusCode & ": " & rdr.ReadToEnd()
}
Modal.ShowDialog()
End Using
End Try
End Sub
Me.Contents.Controls.Add(SubmitButton)
Loaded = True
Me.Size = Globals.FormSize
End Sub
Protected Sub Facility_SetupData_Resize(sender As Object, e As EventArgs) Handles Me.Resize
If Me.Loaded Then
Me.Contents.Controls("Title").Location = New Point(
CInt(Me.Width * 0.5 - Me.Contents.Controls("Title").Width * 0.5),
Globals.Unit(2)
)
Me.FormPanel.Size = New Size(
Me.Width - Globals.Unit(4) + SystemInformation.VerticalScrollBarWidth,
Me.Height - Globals.Unit(9)
)
Me.FormPanel.Location = New Point(
CInt(Me.Width * 0.5 - (Me.FormPanel.Width - SystemInformation.VerticalScrollBarWidth) * 0.5),
Globals.Unit(5)
)
For Each Control As Control In Me.FormPanel.Controls
Control.MinimumSize = New Size(
Me.FormPanel.Width - SystemInformation.VerticalScrollBarWidth,
Control.MaximumSize.Height
)
Control.MaximumSize = New Size(
Me.FormPanel.Width - SystemInformation.VerticalScrollBarWidth,
Control.MaximumSize.Height
)
Next
Me.Contents.Controls("Submit").Location = New Point(
Me.FormPanel.Right - Me.Contents.Controls("Submit").Width,
Me.FormPanel.Bottom + Globals.Unit(1)
)
Dim Background As New Bitmap(Me.Contents.Width, Me.Contents.Height)
Dim BarCompliment_Top = Globals.LoadSvgFromResource("Bar Complement").Draw()
Dim Bar_Top = Globals.LoadSvgFromResource("Bar").Draw()
Dim BarCompliment_Bottom = Globals.LoadSvgFromResource("Bar Complement Bottom").Draw()
Dim Bar_Bottom = Globals.LoadSvgFromResource("Bar Bottom").Draw()
Using g As Graphics = Graphics.FromImage(Background)
g.DrawImage(
BarCompliment_Top,
-CInt(Me.Width * 0.25),
-CInt(Globals.Unit(12)),
CInt(Globals.Unit(13)),
CInt(Globals.Unit(15))
)
g.DrawImage(
Bar_Top,
CInt(Me.Width * 0.5),
-CInt(Globals.Unit(12)),
CInt(Globals.Unit(13)),
CInt(Globals.Unit(15))
)
g.DrawImage(
BarCompliment_Bottom,
-CInt(Me.Width * 0.25),
CInt(Me.Height * 0.75),
CInt(Globals.Unit(13)),
CInt(Globals.Unit(15))
)
g.DrawImage(
Bar_Bottom,
CInt(Me.Width * 0.875),
CInt(Me.Height * 0.75),
CInt(Globals.Unit(13)),
CInt(Globals.Unit(15))
)
End Using
Me.BackgroundBitmap = Background
End If
End Sub
Private Class FileInputPanel
Inherits Transparent.Panel
Public Property Label As String
Get
Return Me.Controls("Label").Text
End Get
Set(value As String)
Me.Controls("Label").Text = value
End Set
End Property
Public Property Description As String
Get
Return Me.Controls("Description").Text
End Get
Set(value As String)
Me.Controls("Description").Text = value
End Set
End Property
Public Property Format As String
Get
Return Me.Controls("Format").Text
End Get
Set(value As String)
Me.Controls("Format").Text = value
End Set
End Property
Public FilePath As String
Public Sub New()
Me.AutoSize = True
Dim Label As New Transparent.Label With {
.Text = "File",
.AutoSize = True,
.MinimumSize = New Size(Me.Width, Globals.Unit(1.25)),
.MaximumSize = New Size(Me.Width, Globals.Unit(1.25)),
.Location = New Point(0, 0),
.Font = Globals.GetFont("Raleway", Globals.Unit(0.75), FontStyle.Bold),
.ForeColor = Globals.Palette("Secondary"),
.TextAlign = ContentAlignment.MiddleLeft,
.Name = "Label"
}
Me.Controls.Add(Label)
Dim Description As New Transparent.Label With {
.Text = "Upload .csv file of courses.",
.AutoSize = True,
.MinimumSize = New Size(Me.Width, Globals.Unit(0.75)),
.MaximumSize = New Size(Me.Width, Globals.Unit(0.75)),
.Location = New Point(0, Globals.Unit(1.5)),
.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Regular),
.ForeColor = Globals.Palette("Plain Dark"),
.TextAlign = ContentAlignment.MiddleLeft,
.Name = "Description"
}
Me.Controls.Add(Description)
Dim FormatLabel As New Transparent.Label With {
.Text = "Format:",
.AutoSize = True,
.MinimumSize = New Size(Me.Width, Globals.Unit(0.75)),
.MaximumSize = New Size(Me.Width, Globals.Unit(0.75)),
.Location = New Point(0, Globals.Unit(2.5)),
.Font = Globals.GetFont("Raleway", Globals.Unit(0.5), FontStyle.Bold),
.ForeColor = Globals.Palette("Secondary"),
.TextAlign = ContentAlignment.MiddleLeft,
.Name = "FormatLabel"
}
Me.Controls.Add(FormatLabel)
Dim FormatDescription As New Transparent.Label With {
.Text = "Course Code, Course Title, Course Description, Course Units",
.AutoSize = True,
.MinimumSize = New Size(Me.Width, Globals.Unit(1)),
.MaximumSize = New Size(Me.Width, Globals.Unit(1)),
.Location = New Point(0, Globals.Unit(3)),
.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Regular),
.ForeColor = Globals.Palette("Plain Dark"),
.TextAlign = ContentAlignment.MiddleLeft,
.Name = "Format"
}
Me.Controls.Add(FormatDescription)
Dim FileInput As New BaseFileInput With {
.AutoSize = True,
.MaximumSize = New Size(Me.Width, Globals.Unit(3)),
.MinimumSize = New Size(Me.Width, Globals.Unit(3)),
.Location = New Point(0, Globals.Unit(4)),
.Name = "FileInput"
}
Me.Controls.Add(FileInput)
AddHandler FileInput.FileSelected, Sub()
Me.FilePath = FileInput.FilePath
End Sub
End Sub
Protected Sub FileInputPanel_Resize(sender As Object, e As EventArgs) Handles Me.Resize
For Each Control As Control In Me.Controls
Control.MinimumSize = New Size(Me.Width, Control.MaximumSize.Height)
Control.MaximumSize = New Size(Me.Width, Control.MaximumSize.Height)
Next
End Sub
Public Sub Alert()
Dim FileInput As BaseFileInput = Me.Controls("FileInput")
FileInput.Alert()
End Sub
End Class
End Class