-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormManageMissingLog.cs
More file actions
239 lines (196 loc) · 8.64 KB
/
FormManageMissingLog.cs
File metadata and controls
239 lines (196 loc) · 8.64 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
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
using CSEmployeeAttendance25.Data;
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;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace CSEmployeeAttendance25
{
public partial class FormManageMissingLog : Form
{
private BiometricLogDBHelper _biometricLogHelper;
private EmployeeDBHelper _employeeHelper;
public FormManageMissingLog()
{
InitializeComponent();
_biometricLogHelper = new BiometricLogDBHelper();
_employeeHelper = new EmployeeDBHelper();
// Visible for super admin only
if (Program.loginUser.Role == (int)enumMyUserRoles.SuperAdmin)
{
buttonDeleteLog.Visible = true;
//dgcHistoryDelete.Visible = true;
}
dgvBiometricLogs.AutoGenerateColumns = false;
dgvOneEntry.AutoGenerateColumns = false;
dgvTwoPlusEntry.AutoGenerateColumns = false;
LoadBatchCode();
}
private void LoadBatchCode()
{
DataTable batchCodesTable = _biometricLogHelper.GetDistinctBatchCodesWithoutInOut();
comboBoxBatchCode.DataSource = batchCodesTable;
comboBoxBatchCode.DisplayMember = "BatchName";
comboBoxBatchCode.ValueMember = "BatchCode";
}
private void buttonLoadData_Click(object sender, EventArgs e)
{
LoadGridviewData();
buttonApplyInOut.Enabled = false;
if (dgvOneEntry.RowCount == 0 && dgvTwoPlusEntry.RowCount == 0)
buttonApplyInOut.Enabled = true;
}
private void LoadGridviewData()
{
if (comboBoxBatchCode.SelectedValue != null)
{
string batchCode = comboBoxBatchCode.SelectedValue.ToString();
if (batchCode == null)
{
MessageBox.Show("Select batch to proceed!", "Alert");
return;
}
LoadBioMetricData(batchCode);
LoadOneEntryData(batchCode);
//LoadTwoPlusEntryData(batchCode);
LoadDuplicateEntryData(batchCode);
tabControlMain.SelectedTab = tabPageAllRecords; // Ensure the tab is selected
tabPageAllRecords.Focus(); // Set focus on the tab
}
else
{
MessageBox.Show("Select Batch Code!", "Batch Code");
comboBoxBatchCode.Focus();
}
}
private void LoadBioMetricData(string batchCode)
{
dgvBiometricLogs.DataSource = _biometricLogHelper.GetBiometricLogsWithEmployee(batchCode);
tabPageAllRecords.Text = "#All Records (" + dgvBiometricLogs.RowCount + ") ";
}
private void LoadOneEntryData(string batchCode)
{
dgvOneEntry.DataSource = _biometricLogHelper.GetBiometricLogsWithEmployeeOneEntry(batchCode);
tabPageOneEntry.Text = "#One Entry (" + dgvOneEntry.RowCount + ") ";
}
//private void LoadTwoPlusEntryData(string batchCode)
//{
// dgvTwoPlusEntry.DataSource = _biometricLogHelper.GetBiometricLogsWithEmployeeTwoPlusEntry(batchCode);
// tabPageDuplicateEntry.Text = "#Two Plus Entry (" + dgvTwoPlusEntry.RowCount + ") ";
//}
private void LoadDuplicateEntryData(string batchCode)
{
dgvTwoPlusEntry.DataSource = _biometricLogHelper.GetBiometricLogsWithEmployeeTwoPlusEntry(batchCode);
tabPageDuplicateEntry.Text = "#Duplicate Entry (" + dgvTwoPlusEntry.RowCount + ") ";
}
private void buttonApplyInOut_Click(object sender, EventArgs e)
{
if (comboBoxBatchCode.SelectedValue == null)
{
MessageBox.Show("Select batch to process!");
return;
}
if (_biometricLogHelper.ApplyInOut(comboBoxBatchCode.SelectedValue.ToString()))
{
MessageBox.Show("In/Out applied successfully!", "Process Complete");
dgvBiometricLogs.DataSource = null;
dgvOneEntry.DataSource = null;
dgvTwoPlusEntry.DataSource = null;
LoadBatchCode();
}
else
{
MessageBox.Show("Error appling In/Out!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonDeleteLog_Click(object sender, EventArgs e)
{
if (comboBoxBatchCode.SelectedValue == null)
{
MessageBox.Show("Select batch to delete!", "Alert");
return;
}
if (MessageBox.Show("Do you want to delete log data for selected Batch?", "Confirm Delete", MessageBoxButtons.YesNo) == DialogResult.No)
{
return;
}
if (_biometricLogHelper.DeleteBatchHistory(comboBoxBatchCode.SelectedValue.ToString()))
{
MessageBox.Show("Batch data deleted successfully!", "Process Complete");
LoadBatchCode();
}
else
{
MessageBox.Show("Error deleting employee.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void dgvOneEntry_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == dgcOneAddLog.Index)
{
int employeeId = Convert.ToInt32(dgvOneEntry.Rows[e.RowIndex].Cells[dgcOneEmployeeId.Name].Value);
int logId = Convert.ToInt32(dgvOneEntry.Rows[e.RowIndex].Cells[dgcOneLogId.Name].Value);
EmployeeDTO employee = _employeeHelper.GetEmployeeById(employeeId);
BiometricLogDTO biometricLog = _biometricLogHelper.GetBiometricLogById(logId);
if (employee != null && biometricLog != null)
{
FormAddLogManually formAddManualLogAdv = new FormAddLogManually(employee, biometricLog);
formAddManualLogAdv.ShowDialog();
LoadBioMetricData(biometricLog.BatchCode);
LoadOneEntryData(biometricLog.BatchCode);
tabControlMain.SelectedTab = tabPageOneEntry; // Ensure the tab is selected
tabPageOneEntry.Focus(); // Set focus on the tab
}
}
}
private void dgvTwoPlusEntry_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
string batchCode = comboBoxBatchCode.SelectedValue.ToString();
if (e.ColumnIndex == dgcTwoDelete.Index)
{
if (MessageBox.Show("Do you want to delete this log?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
int id = Convert.ToInt32(dgvTwoPlusEntry.Rows[e.RowIndex].Cells[dgcTwoLogId.Name].Value);
_biometricLogHelper.DeleteBiometricLog(id);
LoadBioMetricData(batchCode);
//LoadTwoPlusEntryData(batchCode);
LoadDuplicateEntryData(batchCode);
tabControlMain.SelectedTab = tabPageDuplicateEntry; // Ensure the tab is selected
tabPageDuplicateEntry.Focus(); // Set focus on the tab
}
}
}
private void buttonAutoDeleteDuplicates_Click(object sender, EventArgs e)
{
if (dgvTwoPlusEntry.RowCount == 0)
{
buttonAutoDeleteDuplicates.Enabled = false;
return;
}
if (comboBoxBatchCode.SelectedValue == null)
{
MessageBox.Show("Seelct Batch!");
return;
}
string batchCode = comboBoxBatchCode.SelectedValue.ToString();
if (MessageBox.Show("Do you want to delete duplucate punch times?", "Time-span 15 Minutes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
_biometricLogHelper.DeleteBiometricLogDuplicateEntry(batchCode);
LoadBioMetricData(batchCode);
LoadDuplicateEntryData(batchCode);
tabControlMain.SelectedTab = tabPageDuplicateEntry; // Ensure the tab is selected
tabPageDuplicateEntry.Focus(); // Set focus on the tab
}
}
}