-
Notifications
You must be signed in to change notification settings - Fork 1
/
frmEmployeesRecord1.vb
executable file
·364 lines (310 loc) · 17.8 KB
/
frmEmployeesRecord1.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
Imports Excel = Microsoft.Office.Interop.Excel
Imports System.Data.OleDb
Public Class frmEmployeesRecord1
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 = ""
End Sub
Sub exportExcel()
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 EmployeeName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmployeeName.SelectedIndexChanged
Try
con = New oledbConnection(cs)
con.Open()
cmd = New OleDbCommand("select (EmployeeID) as [Employee ID], (EmployeeName) as [Employee Name],(Address) as [Address],(MobileNo) as [Mobile No],(Email) as [Email],(BloodGroup) as [Blood Group],(Department) as [Department],(Designation) as [Designation],(DateOfJoining) as [Date Of Joining],(Salary) as [Basic Salary],(BasicWorkingTime) as [Basic Working Time] from employeeregistration where Employeename = '" & EmployeeName.Text & "'", con)
Dim myDA As oledbDataAdapter = New oledbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "EmployeeRegistration")
DataGridView1.DataSource = myDataSet.Tables("EmployeeRegistration").DefaultView
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
exportExcel()
End Sub
Sub fillcombo()
Try
Dim CN As New oledbConnection(cs)
CN.Open()
adp = New oledbDataAdapter()
adp.SelectCommand = New oledbCommand("SELECT distinct (employeename) FROM employeeregistration", 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 EmployeesRecord_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
fillcombo()
End Sub
Private Sub TabControl1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.Click
DataGridView1.DataSource = Nothing
EmployeeName.Text = ""
DataGridView2.DataSource = Nothing
DateFrom.value = Today
DateTo.value = Today
DataGridView3.DataSource = Nothing
End Sub
Private Sub button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button5.Click
DataGridView2.DataSource = Nothing
DateFrom.value = Today
DateTo.value = Today
End Sub
Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.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
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
DataGridView3.DataSource = Nothing
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If DataGridView3.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 = DataGridView3.RowCount - 1
colsTotal = DataGridView3.Columns.Count - 1
With excelWorksheet
.Cells.Select()
.Cells.Delete()
For iC = 0 To colsTotal
.Cells(1, iC + 1).Value = DataGridView3.Columns(iC).HeaderText
Next
For I = 0 To rowsTotal - 1
For j = 0 To colsTotal
.Cells(I + 2, j + 1).value = DataGridView3.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 button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button4.Click
Try
con = New oledbConnection(cs)
con.Open()
cmd = New OleDbCommand("select (EmployeeID) as [Employee ID], (EmployeeName) as [Employee Name],(Address) as [Address],(MobileNo) as [Mobile No],(Email) as [Email],(BloodGroup) as [Blood Group],(Department) as [Department],(Designation) as [Designation],(DateOfJoining) as [Date Of Joining],(Salary) as [Basic Salary],(BasicWorkingTime) as [Basic Working Time] from employeeregistration where DateOfJoining between #" & DateFrom.value & "# And #" & DateTo.value & "# order by dateofjoining", con)
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "EmployeeRegistration")
DataGridView2.DataSource = myDataSet.Tables("EmployeeRegistration").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
con = New oledbConnection(cs)
con.Open()
cmd = New OleDbCommand("select (EmployeeID) as [Employee ID], (EmployeeName) as [Employee Name],(Address) as [Address],(MobileNo) as [Mobile No],(Email) as [Email],(BloodGroup) as [Blood Group],(Department) as [Department],(Designation) as [Designation],(DateOfJoining) as [Date Of Joining],(Salary) as [Basic Salary],(BasicWorkingTime) as [Basic Working Time] from employeeregistration order by EmployeeName,dateofjoining ", con)
Dim myDA As oledbDataAdapter = New oledbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "EmployeeRegistration")
DataGridView3.DataSource = myDataSet.Tables("EmployeeRegistration").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub DataGridView1_RowHeaderMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.RowHeaderMouseClick
Try
Dim dr As DataGridViewRow = DataGridView1.SelectedRows(0)
Me.Hide()
frmEmployee_registration.Show()
' or simply use column name instead of index
'dr.Cells["id"].Value.ToString();
frmEmployee_registration.EmployeeID.Text = dr.Cells(0).Value.ToString()
frmEmployee_registration.EmployeeName.Text = dr.Cells(1).Value.ToString()
frmEmployee_registration.Address.Text = dr.Cells(2).Value.ToString()
frmEmployee_registration.MobileNo.Text = dr.Cells(3).Value.ToString()
frmEmployee_registration.Email.Text = dr.Cells(4).Value.ToString()
frmEmployee_registration.BloodGroup.Text = dr.Cells(5).Value.ToString()
frmEmployee_registration.Department.Text = dr.Cells(6).Value.ToString()
frmEmployee_registration.Designation.Text = dr.Cells(7).Value.ToString()
frmEmployee_registration.DateOfJoining.Text = dr.Cells(8).Value.ToString()
frmEmployee_registration.Salary.Text = dr.Cells(9).Value.ToString()
frmEmployee_registration.BasicWorkingTime.Text = dr.Cells(10).Value.ToString()
frmEmployee_registration.Update_Record.Enabled = True
frmEmployee_registration.Delete.Enabled = True
frmEmployee_registration.Save.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub DataGridView2_RowHeaderMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView2.RowHeaderMouseClick
Try
Dim dr As DataGridViewRow = DataGridView2.SelectedRows(0)
Me.Hide()
frmEmployee_registration.Show()
' or simply use column name instead of index
'dr.Cells["id"].Value.ToString();
frmEmployee_registration.EmployeeID.Text = dr.Cells(0).Value.ToString()
frmEmployee_registration.EmployeeName.Text = dr.Cells(1).Value.ToString()
frmEmployee_registration.Address.Text = dr.Cells(2).Value.ToString()
frmEmployee_registration.MobileNo.Text = dr.Cells(3).Value.ToString()
frmEmployee_registration.Email.Text = dr.Cells(4).Value.ToString()
frmEmployee_registration.BloodGroup.Text = dr.Cells(5).Value.ToString()
frmEmployee_registration.Department.Text = dr.Cells(6).Value.ToString()
frmEmployee_registration.Designation.Text = dr.Cells(7).Value.ToString()
frmEmployee_registration.DateOfJoining.Text = dr.Cells(8).Value.ToString()
frmEmployee_registration.Salary.Text = dr.Cells(9).Value.ToString()
frmEmployee_registration.BasicWorkingTime.Text = dr.Cells(10).Value.ToString()
frmEmployee_registration.Update_Record.Enabled = True
frmEmployee_registration.Delete.Enabled = True
frmEmployee_registration.Save.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub DataGridView3_RowHeaderMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView3.RowHeaderMouseClick
Try
Dim dr As DataGridViewRow = DataGridView3.SelectedRows(0)
Me.Hide()
frmEmployee_registration.Show()
' or simply use column name instead of index
'dr.Cells["id"].Value.ToString();
frmEmployee_registration.EmployeeID.Text = dr.Cells(0).Value.ToString()
frmEmployee_registration.EmployeeName.Text = dr.Cells(1).Value.ToString()
frmEmployee_registration.Address.Text = dr.Cells(2).Value.ToString()
frmEmployee_registration.MobileNo.Text = dr.Cells(3).Value.ToString()
frmEmployee_registration.Email.Text = dr.Cells(4).Value.ToString()
frmEmployee_registration.BloodGroup.Text = dr.Cells(5).Value.ToString()
frmEmployee_registration.Department.Text = dr.Cells(6).Value.ToString()
frmEmployee_registration.Designation.Text = dr.Cells(7).Value.ToString()
frmEmployee_registration.DateOfJoining.Text = dr.Cells(8).Value.ToString()
frmEmployee_registration.Salary.Text = dr.Cells(9).Value.ToString()
frmEmployee_registration.BasicWorkingTime.Text = dr.Cells(10).Value.ToString()
frmEmployee_registration.Update_Record.Enabled = True
frmEmployee_registration.Delete.Enabled = True
frmEmployee_registration.Save.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub txtEmployee_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEmployee.TextChanged
Try
con = New OleDbConnection(cs)
con.Open()
cmd = New OleDbCommand("select (EmployeeID) as [Employee ID], (EmployeeName) as [Employee Name],(Address) as [Address],(MobileNo) as [Mobile No],(Email) as [Email],(BloodGroup) as [Blood Group],(Department) as [Department],(Designation) as [Designation],(DateOfJoining) as [Date Of Joining],(Salary) as [Basic Salary],(BasicWorkingTime) as [Basic Working Time] from employeeregistration where Employeename like '" & EmployeeName.Text & "%' order by EmployeeName", con)
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "EmployeeRegistration")
DataGridView1.DataSource = myDataSet.Tables("EmployeeRegistration").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Class