-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotificationsForm.vb
More file actions
182 lines (141 loc) · 5.61 KB
/
NotificationsForm.vb
File metadata and controls
182 lines (141 loc) · 5.61 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
''' <summary>Shows notifications of a User</summary>
Public Class NotificationsForm
'--------------------------------[Variables]--------------------------------
Private Structure NotificationStructure
Public Time As String
Public Notif As String
End Structure
Private ReadOnly ID As String
Private BWError As String = "ono"
Private notifs() As NotificationStructure
Private ReferencedObject As String
Private ServerMSG As String
'--------------------------------[Initialization]--------------------------------
''' <summary>Creates a new Notification Form</summary>
''' <param name="ID">ID of the user whos notifs u want this window to display</param>
Public Sub New(ID As String)
InitializeComponent()
Me.ID = ID
Text = "Notifications for " & ID
End Sub
Private Sub Begining() Handles Me.Shown
RefreshNotice.Show()
ListView1.Items.Clear()
Enabled = False
GetNotificationsBW.RunWorkerAsync()
End Sub
'--------------------------------[Buttons]--------------------------------
Private Sub ClosingTime() Handles OKBTN.Click
Close()
End Sub
Private Sub RemoveNotifTime() Handles RemoveNotifBTN.Click
ReferencedObject = ListView1.SelectedIndices(0)
RefreshNotice.Show()
Enabled = False
RemoveNotificationBW.RunWorkerAsync()
End Sub
Private Sub EnableRemoveNotifBTN() Handles ListView1.SelectedIndexChanged
RemoveNotifBTN.Enabled = True
End Sub
Private Sub ClearThemAll() Handles ClearNotifsBTN.Click
Enabled = False
RefreshNotice.Show()
ClearAllNotificationsBW.RunWorkerAsync()
End Sub
'--------------------------------[Background Workers]--------------------------------
''' <summary>Requests, and splits all notifications from the user this window was constructed to view</summary>
Public Sub GetNotifications_GET() Handles GetNotificationsBW.DoWork
BWError = "ono"
'Get the notificaitons
Dim servermsg = ReadNotifs(ID)
If servermsg = "N" Or servermsg = "E" Then
BWError = servermsg
Exit Sub
End If
'Split them
Dim Doot() As String = servermsg.Split("`")
Dim I As Integer = -1
Dim N As Integer = 0
'Add all the notifications to the notif array
Do
ReDim Preserve notifs(N)
I += 1
notifs(N).Time = Doot(I)
I += 1
notifs(N).Notif = Doot(I)
N += 1
If I = Doot.Count - 1 Then Exit Do
Loop
End Sub
''' <summary>Make sure that we have notifications, and the nenable the notification form</summary>
Private Sub GetNotifications_DO() Handles GetNotificationsBW.RunWorkerCompleted
If BWError = "N" Then
MsgBox("There's no notifications availale", vbInformation)
ListView1.Visible = False
RefreshNotice.Close()
Exit Sub
ElseIf BWError = "E" Then
MsgBox("A server side error has occurred. Contact CHOPO!", vbExclamation)
ListView1.Visible = False
RefreshNotice.Close()
Exit Sub
End If
Enabled = True
Populatelistview()
RefreshNotice.Close()
ListView1.Visible = True
End Sub
''' <summary>Asks the server to remove the specified notification</summary>
Private Sub RemoveNotificationBW_GET() Handles RemoveNotificationBW.DoWork
ServerMSG = RemoveNotif(ID, ReferencedObject)
End Sub
''' <summary>Parses server response, ensuring we did the do</summary>
Private Sub RemoveNotifications_DO() Handles RemoveNotificationBW.RunWorkerCompleted
Select Case ServerMSG
Case "E"
MsgBox("A server side error has occurred. Contact CHOPO!", vbExclamation)
Case "N"
MsgBox("There's No Notification File.", vbInformation)
Close()
Case "S"
If notifs.Count = 1 Then Close()
GetNotificationsBW.RunWorkerAsync()
End Select
Enabled = True
RemoveNotifBTN.Enabled = False
End Sub
''' <summary>Asks the server to clear notifications</summary>
Private Sub ClearNotification_GET() Handles ClearAllNotificationsBW.DoWork
ServerMSG = ClearNotifs(ID)
End Sub
''' <summary>Parses server response, making sure the action was complated</summary>
Private Sub ClearNotification_do() Handles ClearAllNotificationsBW.RunWorkerCompleted
Enabled = True
RefreshNotice.Close()
Select Case ServerMSG
Case "E"
MsgBox("A server side error has occurred. Contact CHOPO!", vbExclamation)
Case "N"
MsgBox("There's No Notification File.", vbInformation)
Close()
Case "S"
Close()
End Select
RemoveNotifBTN.Enabled = False
End Sub
'--------------------------------[Other Functions]--------------------------------
''' <summary>Populates the listview with the notifications</summary>
Private Sub Populatelistview()
ListView1.Items.Clear()
For I = 0 To notifs.Count - 1
Dim CLVI As ListViewItem
CLVI = New ListViewItem With {.Text = notifs(I).Time}
CLVI.SubItems.Add(notifs(I).Notif)
ListView1.Items.Add(CLVI)
Next
End Sub
''' <summary> Make Sure the MainScreen refreshes after this.</summary>
Private Sub MidClosing() Handles Me.Closing
VibeMainScreen.RefreshMe()
End Sub
End Class