-
Notifications
You must be signed in to change notification settings - Fork 0
/
AttendanceReport.cs
133 lines (118 loc) · 4.49 KB
/
AttendanceReport.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HRM
{
public partial class AttendanceReport : Form
{
public AttendanceReport()
{
InitializeComponent();
}
private void SearchBtn_Click(object sender, EventArgs e)
{
if (SearchStaffID.Text.Trim() == "")
{
MessageBox.Show("Please Enter Staff ID");
SearchStaffID.Focus();
return;
}
if (Datefrom.Text.Trim() == "")
{
MessageBox.Show("Please Enter Date From ID");
Datefrom.Focus();
return;
}
if (dateto.Text.Trim() == "")
{
MessageBox.Show("Please Enter Date To ID");
dateto.Focus();
return;
}
AttenDanceGRID.Rows.Clear();
int SL = 1; string s1 = ""; string s2 = ""; string s3 = ""; string s4 = ""; string s5 = ""; string s6 = ""; string s7 = ""; string s8 = ""; string s9 = ""; string s10 = ""; string s11 = "";
string query = "SELECT * FROM AttendanceReportView WHERE StaffID = " + Convert.ToInt32(SearchStaffID.Text) + " AND Date BETWEEN '" +Datefrom.Value.ToString("yyyy/MM/dd")+ "' AND '" + dateto.Value.ToString("yyyy/MM/dd") + "'";
SqlDataReader reader = DbAccess.GetFromDB(query);
if (reader.HasRows)
{
while (reader.Read())
{
s1 = SL.ToString();
s2 = SearchStaffID.Text.ToString();
s3 = reader["StaffName"].ToString();
s4 = reader["Department"].ToString();
s5 = reader["Date"].ToString();
s6 = reader["InTime"].ToString();
s7 = reader["OutTime"].ToString();
s8 = reader["Status"].ToString();
AttenDanceGRID.Rows.Add(s1, s2, s3, s4, s5, s6, s7, s8);
SL++;
}
}
DbAccess.connnection.Close();
}
private void Reset()
{
SearchStaffID.Text = "";
Datefrom.Value = DateTime.Now.Date;
dateto.Value = DateTime.Now.Date;
AttenDanceGRID.Rows.Clear();
}
private void ExportBtn_Click(object sender, EventArgs e)
{
try
{
if (AttenDanceGRID.Rows.Count < 1)
{
MessageBox.Show("No rows exist to export exddcdwwwel!!!");
return;
}
if (AttenDanceGRID.Rows.Count > 0)
{
Microsoft.Office.Interop.Excel._Application XcelApp = new Microsoft.Office.Interop.Excel.Application();
XcelApp.Application.Workbooks.Add(Type.Missing);
for (int i = 0; i < AttenDanceGRID.Columns.Count; i++)
{
XcelApp.Cells[1, (i + 1)] = AttenDanceGRID.Columns[i].HeaderText;
}
for (int i = 0; i < AttenDanceGRID.Rows.Count - 1; i++)
{
for (int j = 0; j < AttenDanceGRID.Columns.Count; j++)
{
XcelApp.Cells[(i + 2), ((j + 1))] = " " + AttenDanceGRID.Rows[i].Cells[j].Value.ToString();
}
}
XcelApp.Columns.AutoFit();
XcelApp.Rows.AutoFit();
XcelApp.Visible = true;
}
}
catch (Exception ex)
{
throw new Exception("ExportToExcel: \n" + ex.Message);
}
}
private void SearchStaffID_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
}
private void Datefrom_ValueChanged(object sender, EventArgs e)
{
if (Datefrom.Value > dateto.Value)
{
MessageBox.Show("From Date Can not be greater tha TO date!!!");
Datefrom.Value = dateto.Value;
}
}
}
}