Skip to content

Commit

Permalink
Add Features and Bug Fixes
Browse files Browse the repository at this point in the history
# AdminHomeStarted
# - Add Refresh Button
# - Data will only be refresh when the refresh button has been clicked
#
# ManageParty
# - Hide Buttons When the election already started
#
# Position
# - Bug fixes, NullPointerException
#
# Votes
# - Add GetAllVotes Function
#
# VoteCount
# - Features added to VotersPanel
#

Signed-off-by: Lenard Mangay-ayam <lenard.mangayayam@gmail.com>
  • Loading branch information
lenard123 committed Dec 17, 2020
1 parent 4755061 commit f70c4c0
Show file tree
Hide file tree
Showing 12 changed files with 729 additions and 193 deletions.
75 changes: 37 additions & 38 deletions Voting-SystemVB/AdminController/AdminHomeStarted.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 36 additions & 20 deletions Voting-SystemVB/AdminController/AdminHomeStarted.vb
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
Imports System.Windows.Forms.DataVisualization.Charting
' Good Luck sa nag babasa netong code nato
' Kahit ako di ko na maintindihan
' saka nakaka tamad irefactor

Imports System.Windows.Forms.DataVisualization.Charting
Imports Guna.UI2.WinForms

Public Class AdminHomeStarted

Private Shared StudentsCount As Integer = 0
Private Shared VotersCount As Integer = 0
Private Shared Candidates As New Dictionary(Of Integer, List(Of Candidate))
Private Shared SelectedPosition = 1
Private Shared SelectedPosition As Guna2Button
Private Shared Results As New Dictionary(Of Integer, Dictionary(Of Integer, Integer))
Private Shared LastRefresh As Date

'Creates Only One Instances
Private Shared Instance As AdminHomeStarted
Expand Down Expand Up @@ -48,30 +55,49 @@ Public Class AdminHomeStarted
End Sub
Private Sub BackgroundWorkerInit_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorkerInit.RunWorkerCompleted
President.PerformClick()
RefreshData()
End Sub

'Refresh Data
Public Sub RefreshData()
If BackgroundWorkerRefresh.IsBusy Then Return
StartLoading()
BackgroundWorkerRefresh.RunWorkerAsync(SelectedPosition)
BackgroundWorkerRefresh.RunWorkerAsync()
End Sub
Private Sub BackgroundWorkerRefresh_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorkerRefresh.DoWork
VotersCount = Votes.CountAllDone()
e.Result = Votes.CountVotes(e.Argument)
Results = Votes.CountAllVotes
LastRefresh = Date.Now()
End Sub
Private Sub BackgroundWorkerRefresh_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorkerRefresh.RunWorkerCompleted
StopLoading()
DisplayChart()
End Sub

Dim Tally As Dictionary(Of Integer, Integer) = e.Result
Private Function GetVoteCount(item As Candidate) As Integer
Dim Result = 0
If Results.ContainsKey(item.PositionID) AndAlso Results(item.PositionID).ContainsKey(item.ID) Then
Result = Results(item.PositionID)(item.ID)
End If
Return Result
End Function

Chart1.Series.Clear()
Private Sub ButtonRefresh_Click(sender As Object, e As EventArgs) Handles ButtonRefresh.Click
RefreshData()
End Sub

ShowCandidates.Text = "Results as of: " & Date.Now().ToString("hh:mm:ss tt")
For Each item In Candidates(SelectedPosition)
Dim vote = 0
If Tally.ContainsKey(item.ID) Then vote = Tally(item.ID)
'Display Chart
Private Sub ButtonPosition_Click(sender As Guna2Button, e As EventArgs) Handles President.Click, VPresident.Click, Treasurer.Click, Secretary.Click, PRO.Click, Auditor.Click
SelectedPosition = sender
DisplayChart()
End Sub

Private Sub DisplayChart()
Chart1.Series.Clear()
Dim SelectedPositionID = Integer.Parse(SelectedPosition.Tag)
ShowCandidates.Text = "Results as of: " & LastRefresh.ToString("hh:mm:ss tt")
For Each item In Candidates(SelectedPositionID)
Dim vote = GetVoteCount(item)
Dim seriesItem = New Series()
Dim nPoint As New DataPoint()
nPoint.SetValueY(vote)
Expand All @@ -84,17 +110,7 @@ Public Class AdminHomeStarted
'pero may bug sa display ng chart
'pag wala to eh
Chart1.ResetAutoValues()


End Sub
Private Sub ButtonRefresh_Click(sender As Object, e As EventArgs)
RefreshData()
End Sub

'Display Chart
Private Sub DisplayChart(sender As Object, e As EventArgs) Handles President.Click, VPresident.Click, Treasurer.Click, Secretary.Click, PRO.Click, Auditor.Click
SelectedPosition = Integer.Parse(sender.tag)
RefreshData()
End Sub
End Class

Loading

0 comments on commit f70c4c0

Please sign in to comment.