-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathEmpSearch.aspx.cs
205 lines (175 loc) · 7.61 KB
/
EmpSearch.aspx.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
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
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 EmpSearch : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["user"] == null)
Response.Redirect("Login.aspx");
try
{
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, c.* FROM Tasks c where freetext(*, '" + Session["query"] + "')";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
//specifically update the number of results returned
Object o = dt.Rows[0]["cnt"];
Label1.Text = Convert.ToString(o);
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
catch (Exception)
{
Response.Write("Search Bar is Empty Please enter Value");
}
AddDepartmentstoSidebar();
AddPrivateBoards();
}
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);
}
}