-
Notifications
You must be signed in to change notification settings - Fork 1
/
GroupsHome.aspx.vb
executable file
·232 lines (170 loc) · 8.32 KB
/
GroupsHome.aspx.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
Imports System.Collections.Generic
Imports System.Data.SqlClient
Imports System.Globalization
Imports System.Data
Partial Class GroupsHome
Inherits System.Web.UI.Page
Dim countMembers As Integer = 2
Dim controlIdList As New List(Of String)()
Protected Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init
End Sub
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
'check if user logged in or not. Role must be either Admin or Member
If Session("Role") Is Nothing Then
Response.Redirect("Login.aspx")
Else
' getGroupsSubscribedTo()
End If
End Sub
'Protected Sub getGroupsSubscribedTo()
' Dim findPassword As String = Nothing
' Dim conn As SqlConnection
' Dim cmd As SqlCommand
' Dim GroupArray As New ArrayList
' Try
' 'Define new connection and open it
' conn = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
' conn.Open()
' 'define the sqlcommand ro select the password of the username and the connection
' cmd = New SqlCommand("SELECT GroupId FROM GroupMembers WHERE StudentId = '" + Session("UserId").ToString + "'", conn)
' 'Return the first row, since username is primary key
' Dim groupReader As SqlDataReader = cmd.ExecuteReader()
' Do While groupReader.Read
' GroupArray.Add(groupReader.GetValue(0))
' Loop
' conn.Close()
' Session("UserGroups") = GroupArray
' Dim i As Integer = 0
' Do While i < GroupArray.Count
' i = i + 1
' Loop
' conn.Close()
' Catch ex As Exception
' MsgBox(ex.ToString)
' End Try
'End Sub
Protected Overrides Sub LoadViewState(savedState As Object)
MyBase.LoadViewState(savedState)
controlIdList = DirectCast(ViewState("controlIdList"), List(Of String))
For Each Id As String In controlIdList
countMembers = countMembers + 1
Dim txtMembers As New TextBox
Dim lineBreak As New LiteralControl("</br>")
txtMembers.ID = Id
MembersPlaceHolder.Controls.Add(txtMembers)
MembersPlaceHolder.Controls.Add(lineBreak)
Next
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles cmdAddMember.Click
Dim txtMembers As New TextBox
Dim lineBreak As New LiteralControl("</br>")
txtMembers.ID = "members" + countMembers.ToString
countMembers = countMembers + 1
Me.MembersPlaceHolder.Controls.Add(txtMembers)
MembersPlaceHolder.Controls.Add(lineBreak)
controlIdList.Add(txtMembers.ID)
ViewState("controlIdList") = controlIdList
End Sub
Protected Sub cmdCreateGroup_Click(sender As Object, e As EventArgs) Handles cmdCreateGroup.Click
Dim findPassword As String = Nothing
Dim conn As SqlConnection
Dim cmdStr As String
Dim cmd As SqlCommand
Try
'Define new connection and open it
conn = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
conn.Open()
cmdStr = "Insert into GroupDetails (GroupName) values ('" + txtGroupName.Text + "')"
cmd = New SqlCommand(cmdStr, conn)
cmd.ExecuteNonQuery()
cmd.CommandText = " Select SCOPE_IDENTITY()"
Dim tempid As Integer = cmd.ExecuteScalar()
cmd.CommandText = "Insert into GroupMembers values ('" + Session("UserId").ToString + "', " + tempid.ToString + ", 'A', 'C')"
cmd.ExecuteNonQuery()
Dim countM As Integer = 1
Do While countM < countMembers
Dim tb As New TextBox
' tb.ID = "memebers" + countM.ToString
Dim ntb As String = "memebers" + countM.ToString
tb = MembersPlaceHolder.FindControl("members" + countM.ToString)
' MsgBox(tb.Text)
cmd.CommandText = "Insert into GroupMembers values ('" + tb.Text + "', " + tempid.ToString + ", 'M', 'P')"
cmd.ExecuteNonQuery()
countM = countM + 1
Loop
GridView1.DataBind()
conn.Close()
Catch ex As Exception
'Temp msgfor development stage
MsgBox(ex.ToString)
End Try
End Sub
Protected Sub imgButtonAddMeeting_Click(sender As Object, e As ImageClickEventArgs)
End Sub
Private Function getWeekNumber(ByVal termStart As Date, ByVal currentDate As Date) As Integer
Dim starterm = termStart
Dim temptime As Date = starterm
Dim weekNumber As Integer = 0
While temptime.DayOfWeek <> DayOfWeek.Monday
temptime = temptime.AddDays(-1)
End While
While currentDate.DayOfWeek <> DayOfWeek.Monday
currentDate = currentDate.AddDays(-1)
End While
'maybe i will add && tempdate <> endterm
Do While temptime < currentDate
temptime = temptime.AddDays(7)
weekNumber = weekNumber + 1
Loop
Return weekNumber
End Function
'This function loops through termdates.csv and determin which semester is it depending on the date entered
Private Function getCurrentTermDates(ByVal reqDate As Date) As Date
Dim PrevYearTerm(), CurrentYearTerm() As String
Dim sr As New System.IO.StreamReader(HttpContext.Current.Server.MapPath("Data/termdates.csv"))
'read first line to skip the header
sr.ReadLine()
Do While sr.Peek() >= 0 ' Is -1 when no data exists on the next line of the CSV file
Dim temp As String = sr.ReadLine
Dim tempYear As Integer = reqDate.Year
PrevYearTerm = temp.Split(",")
If (reqDate.Year - CInt(PrevYearTerm(1).Substring(0, 4)) = 1) Then
temp = sr.ReadLine()
CurrentYearTerm = temp.Split(",")
Exit Do
End If
Loop
Dim NextStartTermDate, PrevStartTermDate As Date
PrevStartTermDate = DateTime.ParseExact(PrevYearTerm(1), "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture)
NextStartTermDate = DateTime.ParseExact(CurrentYearTerm(1), "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture)
If reqDate <= NextStartTermDate.AddDays(-1) Then
Return PrevStartTermDate
Else
Return NextStartTermDate
End If
End Function
Protected Sub ViewDetails(sender As Object, e As EventArgs)
'Dim lnkView As LinkButton = TryCast(sender, LinkButton)
'Dim row As GridViewRow = TryCast(lnkView.NamingContainer, GridViewRow)
'Dim id As String = lnkView.CommandArgument
'Dim name As String = row.Cells(0).Text
'Dim country As String = TryCast(row.FindControl("txtCountry"), TextBox).Text
'ClientScript.RegisterStartupScript(Me.[GetType](), "alert", (Convert.ToString((Convert.ToString((Convert.ToString("alert('Id: ") & id) + " Name: ") & name) + " Country: ") & country) + "')", True)
End Sub
Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles GridView1.RowCommand
Session("groupId") = e.CommandName
Dim weeknumber As Integer = getWeekNumber(getCurrentTermDates(Today.Date), Today.Date)
Session("weekNumber") = weeknumber
Response.Redirect("table.aspx")
End Sub
Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound
'If e.Row.RowType = DataControlRowType.DataRow Then
' Dim lnkView As New LinkButton()
' lnkView.ID = "lnkView"
' lnkView.Text = "View"
' AddHandler lnkView.Click, AddressOf imgButtonAddMeeting_Click
' lnkView.CommandArgument = TryCast(e.Row.DataItem, DataRowView).Row("GroupName").ToString()
' e.Row.Cells(0).Controls.Add(lnkView)
'End If
End Sub
End Class