-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormMonthHours.cs
More file actions
125 lines (103 loc) · 4.74 KB
/
FormMonthHours.cs
File metadata and controls
125 lines (103 loc) · 4.74 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
using CSEmployeeAttendance25.Data;
using CSEmployeeAttendance25.Reports;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CSEmployeeAttendance25
{
public partial class FormMonthHours : Form
{
private BiometricLogDBHelper _biometricLogHelper;
private EmployeeDBHelper _employeeHelper;
List<EmployeeMonthSalaryDTO> EmployeeMonthSalaryData;
List<BiometricLogDTOEmployeeMonthHour> BiometricLogMonthHourData;
List<BiometricLogDTOWithEmployee> BiometricLogEmployeeData;
public FormMonthHours()
{
InitializeComponent();
_biometricLogHelper = new BiometricLogDBHelper();
_employeeHelper = new EmployeeDBHelper();
DateTime now = DateTime.Now;
// Get the first day of the previous month
DateTime firstDayOfPreviousMonth = new DateTime(now.Year, now.Month, 1).AddMonths(-1);
// Get the last day of the previous month
DateTime lastDayOfPreviousMonth = firstDayOfPreviousMonth.AddMonths(1).AddDays(-1);
dtpStartDate.Value = firstDayOfPreviousMonth;
dtpEndDate.Value = lastDayOfPreviousMonth;
dgvBiometricLogs.AutoGenerateColumns = false;
dgvMonthHours.AutoGenerateColumns = false;
dgvMonthSalary.AutoGenerateColumns = false;
}
private void buttonLoadData_Click(object sender, EventArgs e)
{
DateTime SD = dtpStartDate.Value;
DateTime ED = dtpEndDate.Value;
DateTime startDate = new DateTime(SD.Year, SD.Month, SD.Day, 0, 1, 0);
DateTime endDate = new DateTime(ED.Year, ED.Month, ED.Day, 23, 59, 0);
EmployeeMonthSalaryData = _biometricLogHelper.GetEmployeeMonthSalary(startDate, endDate);
dgvMonthSalary.DataSource = EmployeeMonthSalaryData;
BiometricLogMonthHourData = _biometricLogHelper.GetBiometricLogsForEmployeeMonthHour(startDate, endDate);
BiometricLogEmployeeData = _biometricLogHelper.GetBiometricLogsForEmployeeMonthLog(startDate, endDate);
}
private void dtpStartDate_ValueChanged(object sender, EventArgs e)
{
dtpEndDate.Value = dtpStartDate.Value.AddMonths(1).AddDays(-1);
}
private void buttonClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void dgvMonthSalary_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == dgcViewSalaryDetails.Index || e.ColumnIndex == dgcSalaryPrint.Index)
{
LoadSelectedEmployeeData();
if (e.ColumnIndex == dgcViewSalaryDetails.Index)
{
tabControlMain.SelectedTab = tabPageDailyHours; // Ensure the tab is selected
tabPageDailyHours.Focus(); // Set focus on the tab
}
if (e.ColumnIndex == dgcSalaryPrint.Index)
{
FormReportViewer formReportViewer = new FormReportViewer((List<BiometricLogDTOEmployeeMonthHour>)dgvMonthHours.DataSource);
formReportViewer.ShowDialog();
}
}
}
private void LoadSelectedEmployeeData()
{
if (BiometricLogEmployeeData != null && BiometricLogMonthHourData != null)
{
int.TryParse(dgvMonthSalary.CurrentRow.Cells[dgcSalaryBMEmployeeId.Name].Value.ToString(), out int salaryBMEmployeeId);
dgvMonthHours.DataSource = BiometricLogMonthHourData
.Where(x => x.BMEmployeeId == salaryBMEmployeeId)
.ToList();
tabPageDailyHours.Text = "#Month Hours (" + dgvMonthHours.RowCount + ")";
dgvBiometricLogs.DataSource = BiometricLogEmployeeData
.Where(x => x.BMEmployeeId == salaryBMEmployeeId)
.ToList();
tabPageMonthLog.Text = "#Month Log (" + dgvBiometricLogs.RowCount + ")";
}
else
{
MessageBox.Show("First LOAD data for selected month!");
buttonLoadData.Focus();
}
}
private void buttonPrintAll_Click(object sender, EventArgs e)
{
if (dgvMonthSalary.RowCount > 0 && BiometricLogMonthHourData.Count > 0)
{
FormReportViewer formReportViewer = new FormReportViewer((List<BiometricLogDTOEmployeeMonthHour>)BiometricLogMonthHourData
.ToList());
formReportViewer.ShowDialog();
}
}
}
}