-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDashboard.aspx.cs
More file actions
274 lines (238 loc) · 9.79 KB
/
Dashboard.aspx.cs
File metadata and controls
274 lines (238 loc) · 9.79 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class Dashboard : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["user"] == null)
Response.Redirect("Login.aspx");
if (!IsPostBack)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select top 10 ProjectName, Deadline, FirstName, LastName, Budget from Projects, Employee where Deadline is not null and Projects.ManagerID = Employee.EmployeeID order by Deadline asc;";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
Repeater1.DataSource = dt;
Repeater1.DataBind();
AddDepartmentstoSidebar();
AddPrivateBoards();
DashBoardMetrics();
con.Close();
}
}
protected void logoutbtn_Click(object sender, EventArgs e)
{
Session.Remove("user");
Response.Redirect("~/Login.aspx");
}
protected void Search_Click(object sender, EventArgs e)
{
Session["query"] = searchInput.Text;
Response.Redirect("EmpSearch.aspx");
}
protected void AddPrivateBoards()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select ProjectID, ProjectName from Projects where ManagerID=" + Session["emp"] + " and isPublic=0 ";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
Repeater3.DataSource = dt;
Repeater3.DataBind();
}
protected void AddDepartmentstoSidebar()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select distinct Department.DepartmentID, Department.DepartmentName from Department, Projects, Works_On where Department.DepartmentID = Projects.DepartmentID and Projects.ProjectID = Works_On.ProjectID and Works_On.EmployeeID = " + Session["emp"];
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
Repeater2.DataSource = dt;
Repeater2.DataBind();
}
private void Insert()
{
//encrypt user/pass and create new connection
SqlConnection attach = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
SqlCommand cmd = attach.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into Projects(ProjectName, isPublic, StartDate, Deadline, ManagerID) values ('" + ProjName.Text + "', 0,'" + StartDate.Text + "', '" + EndDate.Text + "'," + Session["emp"] + " );";
try
{
//Response.Write(ProjName.Text);
//Response.Write(StartDate.Text);
//Response.Write(EndDate.Text);
//Response.Write(Session["emp"]);
attach.Open();
cmd.ExecuteNonQuery();
Response.Write("Project Saved");
}
catch
{
Response.Write("Error when saving on database. Please input values");
attach.Close();
}
StartDate.Text = "";
EndDate.Text = "";
attach.Close();
}
protected void getProjectID()
{
//encrypt user/pass and create new connection
SqlConnection attach = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
attach.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT TOP 1 * FROM Projects ORDER BY ProjectID DESC";
cmd.Connection = attach;
SqlDataReader rd = cmd.ExecuteReader();
while (rd.Read())
{
Session["prgID"] = rd[0];
}
attach.Close();
}
protected void getPhaseID()
{
//encrypt user/pass and create new connection
SqlConnection attach = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
attach.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT TOP 1 * FROM Phase ORDER BY PhaseID DESC";
cmd.Connection = attach;
SqlDataReader rd = cmd.ExecuteReader();
while (rd.Read())
{
Session["phsID"] = rd[0];
Session["prgggID"] = rd[1];
}
attach.Close();
}
protected void addTemplatedPhases_tasks()
{
getProjectID();
//encrypt user/pass and create new connection
SqlConnection attach = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
SqlCommand cmd = attach.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into Phase(ProjectID, PhaseName, CurrentPosition) values(" + Session["prgID"] + ", 'In-Progress', 1); insert into Phase(ProjectID, PhaseName, CurrentPosition) values(" + Session["prgID"] + ", 'To-Do', 2);insert into Phase(ProjectID, PhaseName, CurrentPosition) values(" + Session["prgID"] + ", 'Completed', 3);";
attach.Open();
cmd.ExecuteNonQuery();
Response.Write("Project Saved");
getPhaseID();
insertTasks();
attach.Close();
}
protected void insertTasks()
{
getProjectID();
//encrypt user/pass and create new connection
SqlConnection attach = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
SqlCommand cmd = attach.CreateCommand();
cmd.CommandType = CommandType.Text;
int phase = Convert.ToInt32(Session["phsID"]);
int phase1 = phase - 1;
int phase2 = phase1 - 1;
cmd.CommandText = "insert into Tasks(PhaseID, ProjectID, StartDate, TaskName, CurrentPosition, DateCompleted, AssignedEmployeeID) values(" + phase + " , " + Session["prgggID"] + " , '2018-03-30', 'Task 3', 1, '2018-04-03', " + Session["emp"] + ");insert into Tasks(PhaseID, ProjectID, StartDate, TaskName, CurrentPosition, DateCompleted, AssignedEmployeeID) values(" + phase1 + " , " + Session["prgggID"] + " , '2018-03-30', 'Task 2', 1, '2018-04-03', " + Session["emp"] + ");insert into Tasks(PhaseID, ProjectID, StartDate, TaskName, CurrentPosition, DateCompleted, AssignedEmployeeID) values(" + phase2 + " , " + Session["prgggID"] + " , '2018-03-30', 'Task 1', 1, '2018-04-03', " + Session["emp"] + ");";
attach.Open();
cmd.ExecuteNonQuery();
attach.Close();
}
protected void button2_Click(object sender, EventArgs e)
{
StartDate.Text += ":00";
EndDate.Text += ":00";
Insert();
addTemplatedPhases_tasks();
Response.Redirect(Request.RawUrl);
}
protected void DashBoardMetrics()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select COUNT(*) OVER () as cnt from Projects where isPublic=1;";
cmd.ExecuteNonQuery();
SqlDataReader rd = cmd.ExecuteReader();
while (rd.Read())
{
Session["1"] = rd[0];
}
Proj.Text = "" + Session["1"];
con.Close();
DashBoardMetrics1();
DashBoardMetrics2();
DashBoardMetrics3();
}
protected void DashBoardMetrics1()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select count(*) from Employee;";
cmd.ExecuteNonQuery();
SqlDataReader rd = cmd.ExecuteReader();
while (rd.Read())
{
Session["2"] = rd[0];
}
Emp.Text = "" + Session["2"];
con.Close();
}
protected void DashBoardMetrics2()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select sum(Budget) as budgetsum from Projects where isPublic=1;";
cmd.ExecuteNonQuery();
SqlDataReader rd = cmd.ExecuteReader();
while (rd.Read())
{
Session["3"] = rd[0];
}
budg.Text = "" + Session["3"];
budg.Text = string.Concat(budg.Text.Reverse().Skip(3).Reverse());
con.Close();
}
protected void DashBoardMetrics3()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select count(*) from Department;";
cmd.ExecuteNonQuery();
SqlDataReader rd = cmd.ExecuteReader();
while (rd.Read())
{
Session["123"] = rd[0];
}
deppp.Text = "" + Session["123"];
con.Close();
}
}