-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfrmDeductionEntryRecord.vb
executable file
·206 lines (183 loc) · 9.24 KB
/
frmDeductionEntryRecord.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
Imports System.Data.OleDb
Imports Excel = Microsoft.Office.Interop.Excel
Public Class frmDeductionEntryRecord
Dim rdr As oledbDataReader = Nothing
Dim dtable As DataTable
Dim con As oledbConnection = Nothing
Dim adp As oledbDataAdapter
Dim ds As DataSet
Dim cmd As oledbCommand = Nothing
Dim dt As New DataTable
Dim cs As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\PayrollManagerDB.accdb;Persist Security Info=False;"
Private Sub button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button8.Click
DataGridView1.DataSource = Nothing
EmployeeName.Text = ""
Total.Visible = False
End Sub
Private Sub button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button4.Click
Try
GroupBox1.Visible = True
con = New oledbConnection(cs)
con.Open()
cmd = New OleDbCommand("select (workingdate) as [Entry Date], (EmployeeRegistration.EmployeeID) as [Employee ID],(EmployeeName) as [EmployeeName],(Deduction) as [Deduction] from Advanceentry,employeeRegistration where EmployeeRegistration.EmployeeID=AdvanceEntry.EmployeeID and Deduction > 0 and WorkingDate between #" & DateFrom.Text & "# And #" & DateTo.Text & "# order by workingdate", con)
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "AdvanceEntry")
myDA.Fill(myDataSet, "EmployeeRegistration")
DataGridView2.DataSource = myDataSet.Tables("AdvanceEntry").DefaultView
DataGridView2.DataSource = myDataSet.Tables("EmployeeRegistration").DefaultView
Dim sum As Double = 0
For Each r As DataGridViewRow In Me.DataGridView2.Rows
sum = sum + r.Cells(3).Value
Next
TextBox1.Text = sum
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button5.Click
DateFrom.value = Today
DateTo.value = Today
DataGridView2.DataSource = Nothing
GroupBox1.Visible = False
End Sub
Private Sub TabControl1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.Click
DateFrom.value = Today
DateTo.value = Today
DataGridView2.DataSource = Nothing
GroupBox1.Visible = False
DataGridView1.DataSource = Nothing
EmployeeName.Text = ""
Total.Visible = False
End Sub
Private Sub DeductionEntryRecord_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Me.Hide()
frmMainMenu.Show()
End Sub
Sub fillcombo()
Try
Dim CN As New oledbConnection(cs)
CN.Open()
adp = New oledbDataAdapter()
adp.SelectCommand = New OleDbCommand("SELECT distinct (employeename) FROM Advanceentry,employeeRegistration where EmployeeRegistration.EmployeeID=AdvanceEntry.EmployeeID", CN)
ds = New DataSet("ds")
adp.Fill(ds)
dtable = ds.Tables(0)
EmployeeName.Items.Clear()
For Each drow As DataRow In dtable.Rows
EmployeeName.Items.Add(drow(0).ToString())
'DocName.SelectedIndex = -1
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub DeductionEntryRecord_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
fillcombo()
End Sub
Private Sub EmployeeName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmployeeName.SelectedIndexChanged
Try
Total.Visible = True
con = New oledbConnection(cs)
con.Open()
cmd = New OleDbCommand("select (workingdate) as [Entry Date], (EmployeeRegistration.EmployeeID) as [Employee ID],(EmployeeName) as [EmployeeName],(deduction) as [Deduction] from Advanceentry,employeeRegistration where EmployeeRegistration.EmployeeID=AdvanceEntry.EmployeeID and deduction > 0 and Employeename = '" & EmployeeName.Text & "'order by workingdate", con)
Dim myDA As oledbDataAdapter = New oledbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "AdvanceEntry")
myDA.Fill(myDataSet, "EmployeeRegistration")
DataGridView1.DataSource = myDataSet.Tables("AdvanceEntry").DefaultView
DataGridView1.DataSource = myDataSet.Tables("EmployeeRegistration").DefaultView
Dim sum As Double = 0
For Each r As DataGridViewRow In Me.DataGridView1.Rows
sum = sum + r.Cells(3).Value
Next
TotalDeduction.Text = sum
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button6.Click
If DataGridView1.RowCount = Nothing Then
MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf & "Please retrieve data in datagridview", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True
rowsTotal = DataGridView1.RowCount - 1
colsTotal = DataGridView1.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = DataGridView1.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = DataGridView1.Rows(I).Cells(j).Value
Next j
Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12
.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If DataGridView2.RowCount = Nothing Then
MessageBox.Show("Sorry nothing to export into excel sheet.." & vbCrLf & "Please retrieve data in datagridview", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim rowsTotal, colsTotal As Short
Dim I, j, iC As Short
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
Dim xlApp As New Excel.Application
Try
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True
rowsTotal = DataGridView2.RowCount - 1
colsTotal = DataGridView2.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = DataGridView2.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = DataGridView2.Rows(I).Cells(j).Value
Next j
Next I
.Rows("1:1").Font.FontStyle = "Bold"
.Rows("1:1").Font.Size = 12
.Cells.Columns.AutoFit()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Cells(1, 1).Select()
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
'RELEASE ALLOACTED RESOURCES
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
xlApp = Nothing
End Try
End Sub
End Class