-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCEO_View_Leaves.cs
156 lines (136 loc) · 6.08 KB
/
CEO_View_Leaves.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ComponentFactory.Krypton;
using ComponentFactory.Krypton.Toolkit;
namespace Project01
{
public partial class CEO_View_Leaves : KryptonForm
{
EmployeeInfo obj = new EmployeeInfo();
public string EmpID { get; set; }
public CEO_View_Leaves(string empID)
{
InitializeComponent();
EmpID = empID;
}
private void CEO_View_Leaves_Load(object sender, EventArgs e)
{
show_EmpID.Text = EmpID;
DataTable dt = obj.display("select EmpID from LeaveRequest where Leavestatus='pending'");
combo_empID.DataSource = dt;
combo_empID.DisplayMember = "EmpID";
combo_empID.ValueMember = "EmpID";
/***/
string query = "SELECT LR.*, EI.First_Name AS Employee_Name " +
"FROM LeaveRequest LR " +
"JOIN EmployeeInfo EI ON LR.EmpId = EI.EmpID";
Grid_Leave_View.DataSource = obj.display(query);
}
private void combo_empID_SelectedIndexChanged(object sender, EventArgs e)
{
if (combo_empID.SelectedItem != null)
{
DataRowView selectedRow = (DataRowView)combo_empID.SelectedItem;
string empID = Convert.ToString(selectedRow["EmpID"]);
string q = "select * from LeaveRequest where empId=@EmpID AND leavestatus='Pending'";
DataRow EID = obj.GetEmployeeID(empID, q);
if (EID != null)
{
leavetype_combo.Text = EID["LeaveType"].ToString();
dateTimePicker1.Value = Convert.ToDateTime(EID["LeaveStartDate"]);
dateTimePicker2.Value = Convert.ToDateTime(EID["LeaveEndDate"]);
timeUnit_combo.Text = EID["TimeUnit"].ToString();
combo_status.Text = EID["LeaveStatus"].ToString();
DateTime startDate = dateTimePicker1.Value;//count dates
DateTime endDate = dateTimePicker2.Value;
TimeSpan timeSpan = endDate - startDate;
int numberOfDays = timeSpan.Days;
int totalDaysCount = numberOfDays + 1;
txt_Days.Text = totalDaysCount.ToString();
}
}
}
private void View_Leave_Update_Click(object sender, EventArgs e)
{
string query = "Update LeaveRequest set LeaveStatus = '" + combo_status.SelectedItem.ToString() + "'Where EmpID ='" + combo_empID.Text + "' and LeaveStatus='Pending' ";
int line = obj.Save_Update_Delete(query);
if (line == 1)
{
MessageBox.Show("Leave Status Update Successfully", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
// Fetch telephone number from the database
string empID = combo_empID.Text;
string q = "Select Telephone From EmployeeInfo where EmpID='" + empID + "'";
DataRow EID = obj.GetEmployeeID(empID, q);
if (EID != null)
{
string telephone = EID["Telephone"].ToString();
// Use the telephone number to send an SMS
string status = combo_status.SelectedItem.ToString();
string message = $"Your Leave Request is {status}.";
SMS s = new SMS();
s.Send(message, telephone);
// After sending the SMS, navigate to the next form
CEO_View_Leaves objnew = new CEO_View_Leaves(EmpID);
this.Close();
objnew.Show();
}
else
{
MessageBox.Show("Telephone number not found in the database.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
MessageBox.Show("Data Cannot Update", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void combo_Grid_Status_SelectedIndexChanged(object sender, EventArgs e)
{
if(combo_Grid_Status.SelectedIndex == 0)
{
string query = "SELECT LR.*, EI.First_Name AS EmployeeFirstName " +
"FROM LeaveRequest LR " +
"JOIN EmployeeInfo EI ON LR.EmpId = EI.EmpID " +
"WHERE LR.LeaveStatus = 'Pending'";
Grid_Leave_View.DataSource = obj.display(query);
}
else if(combo_Grid_Status.SelectedIndex==1)
{
string query = "SELECT LR.*, EI.First_Name AS EmployeeFirstName " +
"FROM LeaveRequest LR " +
"JOIN EmployeeInfo EI ON LR.EmpId = EI.EmpID " +
"WHERE LR.LeaveStatus = 'Accepted'";
Grid_Leave_View.DataSource = obj.display(query);
}
else if(combo_Grid_Status.SelectedIndex==2)
{
string query = "SELECT LR.*, EI.First_Name AS EmployeeFirstName " +
"FROM LeaveRequest LR " +
"JOIN EmployeeInfo EI ON LR.EmpId = EI.EmpID " +
"WHERE LR.LeaveStatus = 'Rejected'";
Grid_Leave_View.DataSource = obj.display(query);
}
else if (combo_Grid_Status.SelectedIndex == 3)
{
string query = "SELECT LR.*, EI.First_Name AS Employee_Name " +
"FROM LeaveRequest LR " +
"JOIN EmployeeInfo EI ON LR.EmpId = EI.EmpID";
Grid_Leave_View.DataSource = obj.display(query);
}
}
private void btn_back_Click(object sender, EventArgs e)
{
Executive_Management obj = new Executive_Management(EmpID);
this.Close();
obj.Show();
}
}
}