-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormImportAttendanceLog.cs
More file actions
164 lines (135 loc) · 5.47 KB
/
FormImportAttendanceLog.cs
File metadata and controls
164 lines (135 loc) · 5.47 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
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 System.IO;
namespace CSEmployeeAttendance25
{
public partial class FormImportAttendanceLog : Form
{
private BiometricLogDBHelper _biometricLogHelper;
public FormImportAttendanceLog()
{
InitializeComponent();
_biometricLogHelper = new BiometricLogDBHelper();
// Visible for super admin only
if (Program.loginUser.Role == (int)enumMyUserRoles.SuperAdmin)
{
//dgcHistoryDelete.Visible = true;
}
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;
dgvBatchHistory.AutoGenerateColumns = false;
LoadBatchHistory();
}
private void LoadBatchHistory()
{
DataTable batchCodesTable = _biometricLogHelper.GetDistinctBatchCodesAll();
dgvBatchHistory.DataSource = batchCodesTable;
dgvBiometricLogs.DataSource = null;
tabPageBatchHistory.Text = "#Batch History (" + dgvBatchHistory.RowCount + ") ";
tabPageRawLogs.Text = "#Raw Log Data (0) ";
}
private void buttonBrowseFile_Click(object sender, EventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Filter = "Backup File | *.dat";
fileDialog.ShowDialog();
string fileName = fileDialog.FileName;
textBoxFileName.Text = fileName;
}
private void buttonImportData_Click(object sender, EventArgs e)
{
if (textBoxFileName.Text == string.Empty)
{
MessageBox.Show("Select file to import data!", "Alert");
return;
}
try
{
string fileName = textBoxFileName.Text;
DateTime FD = dtpStartDate.Value;
DateTime TD = dtpEndDate.Value;
DateTime fromDate = new DateTime(FD.Year, FD.Month, FD.Day, 0, 1, 0);
DateTime toDate = new DateTime(TD.Year, TD.Month, TD.Day, 23, 59, 0);
if (File.Exists(fileName))
{
FormSplash formSplash = new FormSplash();
formSplash.Show();
Application.DoEvents();
string batchCode = _biometricLogHelper.ImportCSVToDatabaseSimple(fileName, fromDate, toDate);
formSplash.Close();
LoadBatchHistory();
LoadBatchData(batchCode);
}
else
{
MessageBox.Show("Data import canceld!");
}
}
catch (Exception ex)
{
MessageBox.Show("Data import failed!\n" + ex.Message);
}
}
private void LoadBatchData(string batchCode)
{
dgvBiometricLogs.DataSource = _biometricLogHelper.GetBiometricLogsWithEmployee(batchCode);
labelBatchCode.Text = "Batch Code\n" + batchCode;
tabPageRawLogs.Text = "#Raw Log Data (" + dgvBiometricLogs.RowCount + ") ";
tabControlMain.SelectedTab = tabPageRawLogs; // Ensure the tab is selected
tabPageRawLogs.Focus(); // Set focus on the tab
}
private void buttonClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void dtpStartDate_ValueChanged(object sender, EventArgs e)
{
dtpEndDate.Value = dtpStartDate.Value.AddMonths(1).AddDays(-1);
}
private void dgvBatchHistory_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
string batchCode = dgvBatchHistory.Rows[e.RowIndex].Cells[dgcHistoryBatchCode.Name].Value.ToString();
if (e.ColumnIndex == dgcHistoryViewDetails.Index)
{
if (batchCode != null && batchCode != string.Empty)
{
LoadBatchData(batchCode);
}
}
else if (e.ColumnIndex == dgcHistoryDeleteDetails.Index)
{
if (MessageBox.Show("Do you want to delete log data for selected Batch?", "Confirm Delete", MessageBoxButtons.YesNo) == DialogResult.No)
{
return;
}
if (_biometricLogHelper.DeleteBatchHistory(batchCode))
{
MessageBox.Show("Batch data deleted successfully!", "Process Complete");
LoadBatchHistory();
}
else
{
MessageBox.Show("Error deleting employee.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
}