-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeDashboard.vb
More file actions
204 lines (157 loc) · 7.41 KB
/
EmployeeDashboard.vb
File metadata and controls
204 lines (157 loc) · 7.41 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
Imports MySql.Data.MySqlClient
Imports System.Windows.Forms.VisualStyles.VisualStyleElement
Imports System.Runtime.InteropServices
Imports System.Globalization
Imports OxyPlot
Imports OxyPlot.Series
Imports OxyPlot.WindowsForms
Imports System.IO
Imports System.Windows.Forms.VisualStyles
Public Class EmployeeDashboard
Private plotView As PlotView
Dim qry As String
Dim cmd As MySqlCommand
Dim Reader As MySqlDataReader
Protected Overrides ReadOnly Property CreateParams As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H2000000 ' WS_EX_COMPOSITED
Return cp
End Get
End Property
Private Sub EmployeeDashboard_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'chart code
conn.Close()
Setform(Me)
'main code
billhistory.Close()
loginform.Close()
ManagerInsert.Close()
EmployeeInsert.Close()
Billadd.Close()
product.Close()
Barcodegenerate.Close()
fetchcompany()
dashdetail()
Me.BackgroundImage = My.Resources.bg
Me.BackgroundImageLayout = ImageLayout.Stretch
Dim screenWidth As Integer = Screen.PrimaryScreen.Bounds.Width
Dim screenHeight As Integer = Screen.PrimaryScreen.Bounds.Height
Me.Size = New Size(screenWidth, screenHeight)
Me.WindowState = FormWindowState.Maximized
Timer1.Enabled = True
Me.FormBorderStyle = FormBorderStyle.Sizable
InitializeSalesPieChart()
Label1.Text = "Welcome " + username
Label2.Left = (Me.ClientSize.Width - Label2.Width) / 2
Label2.Text = "EMPLOYEE PANEL"
Label12.Text = "BUSINESS NAME:"
Label13.Text = "BRANCH NAME:"
Label14.Text = "GSTIN:"
End Sub
Private Sub InitializeSalesPieChart()
Dim plotModel As New PlotModel() With {
.Title = "Sales Distribution by Payment Method"
}
Dim pieSeries As New PieSeries() With {
.StartAngle = 90,
.AngleSpan = 360
}
Dim currentUser As String = userid
Dim query As String = "SELECT b.mode, SUM(bd.pro_total) AS total_sales FROM bill_data bd " &
"JOIN bills b ON bd.bill_id = b.bill_id " &
"WHERE b.mode IN ('CASH', 'CARD', 'UPI') " &
"AND b.userid = @currentUser " &
"GROUP BY b.mode ORDER BY total_sales DESC;"
conn.Open()
Using cmd As New MySqlCommand(query, conn)
cmd.Parameters.AddWithValue("@currentUser", currentUser)
Using reader As MySqlDataReader = cmd.ExecuteReader()
While reader.Read()
Dim mode As String = reader("mode").ToString()
If String.IsNullOrEmpty(mode) Then
mode = "Unknown"
End If
Dim totalSales As Double = Convert.ToDouble(reader("total_sales"))
pieSeries.Slices.Add(New PieSlice(mode, totalSales) With {
.IsExploded = False
})
End While
End Using
End Using
plotModel.Series.Add(pieSeries)
PlotView1.Model = plotModel
conn.Close()
End Sub
Public Sub fetchcompany()
Try
Call connect()
qry = "SELECT businessname, branch, gstin FROM company WHERE comid = 1"
cmd = New MySqlCommand(qry, conn)
Dim reader As MySqlDataReader = cmd.ExecuteReader()
If reader.Read() Then
Label17.Text = reader("businessname").ToString()
Label16.Text = reader("branch").ToString()
Label15.Text = reader("gstin").ToString()
End If
reader.Close()
conn.Close()
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
If conn.State = ConnectionState.Open Then conn.Close()
End Try
End Sub
Public Sub dashdetail()
Try
Call connect()
Dim currentUser As String = userid
Dim query As String = "SELECT " &
"(SELECT SUM(netamount) FROM bills WHERE DATE(date) = CURDATE() AND userid = @currentUser) AS today_sales, " &
"(SELECT COUNT(*) FROM products) AS total_products, " &
"(SELECT COUNT(*) FROM bills WHERE DATE(date) = CURDATE() AND userid = @currentUser) AS total_bills, " &
"(SELECT SUM(netamount) FROM bills WHERE MONTH(date) = MONTH(CURDATE()) AND YEAR(date) = YEAR(CURDATE()) AND userid = @currentUser) AS monthly_sales"
Using cmd As New MySqlCommand(query, conn)
cmd.Parameters.AddWithValue("@currentUser", currentUser)
Using reader As MySqlDataReader = cmd.ExecuteReader()
If reader.Read() Then
Label8.Text = If(IsDBNull(reader("today_sales")), "0.00", Convert.ToDecimal(If(IsDBNull(reader("today_sales")), 0, reader("today_sales"))).ToString("F2"))
Label10.Text = If(IsDBNull(reader("total_products")), "0", reader("total_products").ToString())
Label9.Text = If(IsDBNull(reader("total_bills")), "0", reader("total_bills").ToString())
Label11.Text = If(IsDBNull(reader("monthly_sales")), "0.00", Convert.ToDecimal(If(IsDBNull(reader("monthly_sales")), 0, reader("monthly_sales"))).ToString("F2"))
End If
Label8.Left = (Panel2.ClientSize.Width - Label8.Width) / 2
Label10.Left = (Panel4.ClientSize.Width - Label10.Width) / 2
Label9.Left = (Panel5.ClientSize.Width - Label9.Width) / 2
Label11.Left = (Panel6.ClientSize.Width - Label11.Width) / 2
End Using
End Using
conn.Close()
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
If conn.State = ConnectionState.Open Then conn.Close()
End Try
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Label7.Text = DateTime.Now.ToString("dddd")
Label7.Text += " " & DateTime.Now.ToString("dd MMMM yyyy") & " " & TimeOfDay()
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Billadd.Show()
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
billhistory.Show()
End Sub
Private Sub Panel3_Paint(sender As Object, e As PaintEventArgs) Handles Panel3.Paint
End Sub
Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
Dim confirm As DialogResult = MessageBox.Show("Are you sure you want to logout.?", "Confirm LOGOUT", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If confirm = DialogResult.Yes Then
loginform.Show()
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Barcodegenerate.Show()
End Sub
End Class