-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmCreateNewBrand.frm
561 lines (544 loc) · 18 KB
/
frmCreateNewBrand.frm
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
VERSION 5.00
Object = "{CFC13920-9EF4-11D0-B72F-0000C04D4C0A}#6.0#0"; "mswless.ocx"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Begin VB.Form frmCreateNewBrand
BorderStyle = 1 'Fixed Single
Caption = "Create New Brand"
ClientHeight = 6090
ClientLeft = 45
ClientTop = 390
ClientWidth = 7710
HelpContextID = 20
Icon = "frmCreateNewBrand.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 6090
ScaleWidth = 7710
StartUpPosition = 2 'CenterScreen
Begin MSComCtl2.DTPicker dtFounded
Height = 495
Left = 4200
TabIndex = 5
ToolTipText = "Date when the brand was created"
Top = 3120
Width = 3135
_ExtentX = 5530
_ExtentY = 873
_Version = 393216
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
CustomFormat = "MM/dd/yyyy"
Format = 112132099
CurrentDate = 44707
End
Begin MSWLess.WLCombo cmbParent
Height = 390
Left = 360
TabIndex = 6
ToolTipText = "Manufacturer"
Top = 4080
Width = 3135
_ExtentX = 5530
_ExtentY = 688
_Version = 393216
Style = 2
ListCount = 27764
Text = "cmbParent"
ForeColor = -2147483640
BackColor = -2147483643
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
List = "frmCreateNewBrand.frx":3AFA
End
Begin MSWLess.WLText txtNumberEmployees
Height = 495
Left = 4200
TabIndex = 7
ToolTipText = "Number of employees working there"
Top = 4080
Width = 3135
_ExtentX = 5530
_ExtentY = 873
_Version = 393216
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin MSWLess.WLCommand btnReset
Height = 975
Left = 4200
TabIndex = 9
Top = 4920
Width = 2535
_ExtentX = 4471
_ExtentY = 1720
_Version = 393216
Caption = "&Reset"
ForeColor = -1
BackColor = -2147483633
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 14.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin MSWLess.WLText txtName
Height = 495
Left = 360
TabIndex = 0
ToolTipText = "Name of the brand"
Top = 1200
Width = 3135
_ExtentX = 5530
_ExtentY = 873
_Version = 393216
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin VB.Label Label9
Caption = "Parent Company"
BeginProperty Font
Name = "Consolas"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 360
TabIndex = 17
Top = 3840
Width = 3135
End
Begin MSWLess.WLCommand btnCreate
Height = 975
Left = 960
TabIndex = 8
Top = 4920
Width = 2535
_ExtentX = 4471
_ExtentY = 1720
_Version = 393216
Caption = "&Create"
ForeColor = -1
BackColor = -2147483633
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 14.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin MSWLess.WLText txtWebsite
Height = 495
Left = 360
TabIndex = 4
ToolTipText = "Website"
Top = 3120
Width = 3135
_ExtentX = 5530
_ExtentY = 873
_Version = 393216
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin MSWLess.WLText txtAreaServed
Height = 495
Left = 4200
TabIndex = 3
ToolTipText = "Countries where this brand is selling products"
Top = 2160
Width = 3135
_ExtentX = 5530
_ExtentY = 873
_Version = 393216
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin MSWLess.WLText txtHeadquarters
Height = 495
Left = 360
TabIndex = 2
ToolTipText = "Country where the headquarter is located"
Top = 2160
Width = 3135
_ExtentX = 5530
_ExtentY = 873
_Version = 393216
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin MSWLess.WLText txtOwner
Height = 495
Left = 4200
TabIndex = 1
ToolTipText = "Name of the brand owner"
Top = 1200
Width = 3135
_ExtentX = 5530
_ExtentY = 873
_Version = 393216
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin VB.Label lblTitle
Alignment = 2 'Center
Caption = "Brand"
BeginProperty Font
Name = "Javanese Text"
Size = 24
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 240
TabIndex = 10
Top = 0
Width = 7215
End
Begin VB.Label lblOwner
Caption = "Owner"
BeginProperty Font
Name = "Consolas"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 4200
TabIndex = 11
Top = 960
Width = 3135
End
Begin VB.Label lblHeadquarter
Caption = "Headquarter"
BeginProperty Font
Name = "Consolas"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 360
TabIndex = 12
Top = 1920
Width = 3135
End
Begin VB.Label lblAreaServed
Caption = "Area Served"
BeginProperty Font
Name = "Consolas"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 4200
TabIndex = 13
Top = 1920
Width = 3135
End
Begin VB.Label Label6
Caption = "Founded"
BeginProperty Font
Name = "Consolas"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 4200
TabIndex = 14
Top = 2880
Width = 3135
End
Begin VB.Label lblWebsite
Caption = "Website"
BeginProperty Font
Name = "Consolas"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 360
TabIndex = 15
Top = 2880
Width = 3135
End
Begin VB.Label lblNumberEmployees
Caption = "Number of Employees"
BeginProperty Font
Name = "Consolas"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 4200
TabIndex = 16
Top = 3840
Width = 3135
End
Begin VB.Label lblName
Caption = "Name"
BeginProperty Font
Name = "Consolas"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 360
TabIndex = 18
Top = 960
Width = 3135
End
End
Attribute VB_Name = "frmCreateNewBrand"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public PreviousName As String
Dim AlreadyMarked As Boolean
Private Sub btnCreate_Click()
On Error GoTo ErrHandler
ExecuteSQL "Select * from Brand where Brand_Name = '" & txtName & "'"
If IsInformationValid Then
If btnCreate.Caption = "&Create" Then
If Not rs.EOF Then
MsgBox "Brand already exists!", vbCritical, "Error"
Exit Sub
End If
rs.AddNew
MsgBox "New brand added successfully!", vbOKOnly, "Information"
ElseIf btnCreate.Caption = "&Update" Then
If BrandExists(txtName) Then Exit Sub
If cmbParent.Text = txtName Then
MsgBox "Parent Company can't be the same company", vbExclamation, "Error"
Exit Sub
End If
MsgBox "Brand updated successfully!", vbOKOnly, "Information"
End If
Else
MsgBox "Fill all the required spaces in the form", vbInformation, "Information"
CheckEmptyText
AlreadyMarked = True
Exit Sub
End If
rs.Fields!Brand_Name = txtName
rs.Fields!Owner = txtOwner
rs.Fields!Headquarter = txtHeadquarters
rs.Fields!Area_Served = txtAreaServed
rs.Fields!Website = txtWebsite
rs.Fields!Founded = CDate(dtFounded)
If cmbParent.ListIndex <> -1 Then
rs.Fields!Parent_Company = GetManufacturerID
End If
rs.Fields!Number_Employees = Replace(txtNumberEmployees.Text, ",", "")
rs.Fields!Available = True
rs.Update
AlreadyMarked = False
RemoveMark Me
ClearForm
LoadParents
Exit Sub
ErrHandler:
MsgBox "There was an error during the operation", vbCritical, "Error"
Exit Sub
End Sub
Function BrandExists(BrandName As String) As Boolean
Dim result As Boolean
ExecuteSQL2 "Select * from Brand where Brand_Name = '" & BrandName & "'"
If BrandName = PreviousName Then
result = False
ElseIf BrandName <> PreviousName And Not rs2.EOF Then
MsgBox "Brand already exists!", vbCritical, "Error"
result = True
End If
BrandExists = result
End Function
Sub CheckEmptyText()
AddRequiredMark lblName, vbRed, txtName
AddRequiredMark lblOwner, vbRed, txtOwner
AddRequiredMark lblHeadquarter, vbRed, txtHeadquarters
AddRequiredMark lblAreaServed, vbRed, txtAreaServed
AddRequiredMark lblWebsite, vbRed, txtWebsite
AddRequiredMark lblNumberEmployees, vbRed, txtNumberEmployees
End Sub
Function GetManufacturerID() As Integer
ExecuteSQL2 "Select * from Brand where Brand_Name = '" & cmbParent.Text & "'"
GetManufacturerID = rs2.Fields!ID
End Function
Function IsInformationValid() As Boolean
If txtName.Text <> "" And txtOwner.Text <> "" And txtHeadquarters.Text <> "" And _
txtAreaServed.Text <> "" And txtWebsite.Text <> "" And _
txtNumberEmployees.Text <> "" Then
IsInformationValid = True
Else
IsInformationValid = False
End If
End Function
Private Sub btnReset_Click()
ClearForm
End Sub
Sub ClearForm()
RemoveMark Me
AlreadyMarked = False
txtName.Text = ""
txtOwner.Text = ""
txtHeadquarters.Text = ""
txtAreaServed.Text = ""
txtWebsite.Text = ""
dtFounded.value = DateTime.Date
cmbParent.ListIndex = -1
txtNumberEmployees.Text = ""
End Sub
Private Sub Form_Load()
dtFounded.value = DateTime.Date
LoadParents
VerifyCurrentRole
End Sub
Sub VerifyCurrentRole()
If frmMain.CurrentUserRoleID = 1 Then
MsgBox "The current user does not have permission to add or modify brands information", vbInformation, "Information"
btnCreate.Enabled = False
End If
End Sub
Sub LoadParents()
ExecuteSQL "Select * from Brand order by Brand_Name asc"
cmbParent.Clear
While Not rs.EOF
cmbParent.AddItem (rs.Fields!Brand_Name)
rs.MoveNext
Wend
End Sub
Private Sub txtNumberEmployees_GotFocus()
If txtNumberEmployees.Text <> "" Then txtNumberEmployees.Text = Format(txtNumberEmployees.Text, "")
End Sub
Private Sub txtNumberEmployees_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And Not KeyAscii = 8 Then
KeyAscii = 0
MsgBox "Enter only numeric characters!", vbInformation, "Information"
End If
End Sub
Public Sub txtNumberEmployees_LostFocus()
txtNumberEmployees.Text = Format(txtNumberEmployees.Text, "###,###")
End Sub