/
Tabel.aspx.cs
572 lines (446 loc) · 22 KB
/
Tabel.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
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Tabel : System.Web.UI.Page , ICallbackEventHandler
{
protected string StartDateOfPeriod;
protected string EndDateOfPeriod;
protected List<Employee> employees;
protected List<TimekeeperHours> hours;
protected List<HRHours> overhours;
protected int count_days;
protected string month;
protected string year;
protected string role;
protected bool closed;
protected bool check;
private string eventArgument;
public void RaiseCallbackEvent(string eventArgument)
{
this.eventArgument = eventArgument;
}
public string GetCallbackResult()
{
//SAPDB db = new SAPDB();
Display disp = new Display();
//List<Employee> emps = db.getEmployeeListForCurrentDepartment(StartDateOfPeriod, EndDateOfPeriod, "00000050", "1", eventArgument);
EmployeeList emp_list = new EmployeeList();
List<Employee> emps = null;// emp_list.getEmployeesOfDepartment(eventArgument, employees);
EmployeeComparerByPostASC cmpByPostASC = new EmployeeComparerByPostASC();
emps.Sort(cmpByPostASC);
string html = "";
html += eventArgument;
html += "||";
//int k = 0;
//for (int j = 0; j < 100; j++)
/*foreach (Employee em in emps)
{
//k++;
html += "<table cellpadding='0' cellspacing='0' border='0' class='employee'><tr><td class='employee_post'><div style='width: 105px; height: 80px; overflow: hidden;'>" + em.Post + "</div></td><td class='employee_id'>" + em.EmployeeID + "</td><td class='employee_name' ><img src='App_Resources/person.gif' style='cursor: hand; cursor: pointer;'> <span style='cursor: hand; cursor: pointer;' onclick='window.open(\"" + getCardUrl(em) + "\",\"_blank\",\"menubar=no,width=800,height=600,resizable=yes,scrollbars=yes\")'>" + em.FullName + CheckRedundantEmployee(em) + "</span></td><td>" + disp.DisplaySchedules(count_days, 18, em, em.PostID, eventArgument, hours, overhours, em.Schedule, em.ScheduleDeflection, role, check, closed, false) + "</td></tr></table>";
}
*/
html += "||";
DevDescriptionDB devDB = new DevDescriptionDB();
List<DevDescription> devdescription = devDB.getDevDescription();
html += "<table cellpadding='0' cellspacing='0' border='0' width='100%'><tr><td align='center' colspan='2'><b>Îáîçíà÷åíèÿ â SAP</b></td></tr>";
foreach (DevDescription dev in devdescription)
html += "<tr><td width='30px' align='center'><b>" + dev.Symbols + "</b></td><td>" + dev.Name + "</td></tr>";
html += "</table>";
return html;
}
public string CheckRedundantEmployee(Employee emp)
{
string msg = " ";
Date dt = new Date();
DateTime end_date = dt.getDateFromSAPToSQL(emp.EndDate);
DateTime last_date_month = dt.getEndPeriodDate(month, year);
if ((DateTime.Now > end_date) && (end_date.Day < last_date_month.Day)) msg = "<br><span class='redundant'>(óâîëåí ñ " + end_date.AddDays(1).ToString("d") + ")</span>";
return msg;
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["User"] == null) Response.Redirect("Default.aspx");
Display disp = new Display();
Date dt = new Date();
SAPDB db = new SAPDB();
SQLDB sql = new SQLDB();
PeriodDB perdb = new PeriodDB();
Person user = (Person)Session["User"];
//List<Role> rol = user.Roles;
//foreach (Role r in rol)
// Response.Write(r.RoleID + " = " + r.RoleName);
if (!IsPostBack)
{
fillMonths();
if (Request.QueryString["data"] == null)
period.SelectedValue = dt.getMonthToday();
}
year = period.SelectedItem.Text.Substring(period.SelectedItem.Text.Length - 4);
month = period.SelectedItem.Value;
string fio = "";
string tab_number = "";
string post = "";
check = false;
closed = false;
count_days = dt.getCountDays(Convert.ToInt32(month), Convert.ToInt32(year));
if (Request.QueryString["type"] != null) role = Request.QueryString["type"].ToString();
Period per = perdb.getPeriod(Convert.ToInt32(month), Convert.ToInt32(year));
if (per.IsClosed == 1)
{
lbStatus.Text = "çàêðûò";
Traffic.Text = "<img alt='' src='App_Resources/red.bmp' style='position:relative; top:4px;' />";
closed = true;
}
else Traffic.Text = "<img alt='' src='App_Resources/green.bmp' style='position:relative; top:4px;' />";
if (Request.QueryString["data"] != null)
{
EncryptedQueryString QueryString = new EncryptedQueryString(Request.QueryString["data"]);
if (QueryString["fio"] != null) fio = QueryString["fio"];
if (QueryString["tab"] != null) tab_number = QueryString["tab"];
if (QueryString["post"] != null) post = QueryString["post"];
if (QueryString["role"] != null) role = QueryString["role"];
if (QueryString["check"] != null) check = true;
if (!QueryString["month"].Equals(period.SelectedItem.Value))
{
fio = "";
tab_number = "";
post = "";
check = false;
}
}
//Response.Write(month);
//Response.Write("fio=" + fio + "tab=" + tab_number + " - " + month + "<br>");
//Response.Write(post + "<br>");
string start_date = dt.getSAPStartPeriodDate(month, year);
string end_date = dt.getSAPEndPeriodDate(month, year);
StartDateOfPeriod = start_date;
EndDateOfPeriod = end_date;
//Response.Write(start_date + end_date);
Label lb = new Label();
lb.Text = disp.DisplayDaysTabel(count_days, 18);
days.Controls.Add(lb);
//Response.Write(start_date + end_date);
//Period period_time = perdb.getPeriod(Convert.ToInt32(month), Convert.ToInt32(year));
setButtons(role);
//Response.Write(start_date + "-" + end_date + "<br>");
this.employees = null;/// db.getEmployeeList(start_date, end_date, user.TabNum, this.role);
EmployeeList emp_list = new EmployeeList();
List<Post> post_list = null;/// pl.getPosts(db.getPostList(start_date, end_date, user.TabNum, this.role));
if (post_list != null)
{
fillPosts(post_list);
}
else
{
ListItem li = new ListItem("Âûáåðèòå äîëæíîñòü");
ddl_post.Items.Add(li);
}
/*if (post != "")
{
if (post != "ÂÑÅ")
{
EmployeeList empl = new EmployeeList();
// this.employees = empl.getEmployeesOnCurrentPost(post, employees);
}
}
if (fio != "")
{
EmployeeList emp_fio = new EmployeeList();
this.employees = emp_fio.getEmployeesByFIO(fio, employees);
}
if (tab_number != "")
{
EmployeeList emp_tab = new EmployeeList();
this.employees = emp_tab.getEmployeesByTab(tab_number, employees);
}*/
if (check)
{
EmployeeList emp_check = new EmployeeList();
/////this.employees = emp_check.getWrongCheckedEmployees(employees, count_days, hours, overhours);
}
if (employees != null)
{
DepartmentList department_list = new DepartmentList();
List<Department> departments = department_list.getDepartments(employees);
foreach (Department dep in departments)
{
Label depart = new Label();
depart.Text = disp.DisplayDepartmentName(dep.DepartmentName, dep.DepartmentID, StartDateOfPeriod);
content.Controls.Add(depart);
Label lbEmps = new Label();
lbEmps.Text = "<div id='" + dep.DepartmentID + "' style='display:none'>";
// çàãðóçêà âñåõ ãðàôèêîâ ïðè çàãðóçêå ñòðàíèöû
/*EmployeeList emp_list = new EmployeeList();
List<Employee> emps = emp_list.getEmployeesOfDepartment(dep.DepartmentID, employees);
EmployeeComparerByPostASC cmpByPostASC = new EmployeeComparerByPostASC();
emps.Sort(cmpByPostASC);
//for (int j = 0; j < 100; j++)
foreach (Employee em in emps)
{
lbEmps.Text += "<table cellpadding='0' cellspacing='0' border='0' class='employee'><tr><td class='main_info_left_no'> </td><td class='employee_post'>" + em.Post + "</td><td class='employee_id'>" + em.EmployeeID + "</td><td class='employee_name'><img src='App_Resources/person.gif' style='cursor: hand; cursor: pointer;'> <span style='cursor: hand; cursor: pointer;' onclick='window.open(\"" + getCardUrl(em.EmployeeID) +"\",\"displayWindow\",\"menubar=no,width=800,height=600,resizable=yes,scrollbars=yes\")'>" + em.FullName + "</span></td><td class='employee_grid_line_center'> </td><td>" + disp.DisplaySchedules(count_days, 18, em.EmployeeID, dep.DepartmentID, hours, overhours, em.Schedule, em.ScheduleDeflection, role, check, closed) + "</td><td class='main_info_right_no'></td></tr></table>";
}*/
lbEmps.Text += "</div>";
content.Controls.Add(lbEmps);
}
}
// ajax íà çàãðóçêó ñïèñêà ñîòðóäíèêîâ îïðåäåëåííîãî ïîäðàçäåëåíèÿ
string cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ClientCallback", "context");
string func_name = "FillEmployeesCallback";
string cbScript = "function " + func_name + "(arg, context)" + "{" + cbReference + ";" + "}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), func_name, cbScript, true);
}
public string getCardUrl(Employee emp)
{
EncryptedQueryString QueryString = new EncryptedQueryString();
QueryString.Add("start_date", StartDateOfPeriod);
QueryString.Add("end_date", EndDateOfPeriod);
QueryString.Add("role", role);
QueryString.Add("month_id", period.SelectedItem.Value);
QueryString.Add("date", period.SelectedItem.Text);
QueryString.Add("emp_id", emp.EmployeeID);
QueryString.Add("emp_begda", emp.BeginDate);
QueryString.Add("emp_endda", emp.EndDate);
QueryString.Add("count_days", count_days.ToString());
string url = "Card.aspx?card=" + QueryString.ToString();
return url;
}
private void fillMonths()
{
if (period.Items.Count != 0) return;
Date dt = new Date();
List<Period> periods = dt.getPeriodsToDropDownList();
string monthID = "";
foreach (Period p in periods)
{
monthID = p.MonthID.ToString();
if (monthID.Length == 1) monthID = monthID.Insert(0, "0");
ListItem li = new ListItem(p.MonthName.ToUpper(), monthID);
period.Items.Add(li);
}
//Response.Write("fillMonths<br>");
if (Request.QueryString["data"] != null)
{
EncryptedQueryString QueryString = new EncryptedQueryString(Request.QueryString["data"]);
foreach (string key in QueryString.Keys)
if (key == "month") period.SelectedValue = QueryString[key];
}
}
private void fillPosts(List<Post> post_list)
{
foreach (Post p in post_list)
{
ListItem li = new ListItem(p.Post_Name, p.Post_Name);
ddl_post.Items.Add(li);
}
}
protected void bt_filter_fio_Click(object sender, EventArgs e)
{
EncryptedQueryString QueryString = new EncryptedQueryString();
QueryString.Add("fio", filter_fio_text.Text);
QueryString.Add("month", period.SelectedItem.Value);
QueryString.Add("role", role);
//Server.Transfer("TimeTable.aspx?data=" + QueryString.ToString());
Response.Redirect("Tabel.aspx?data=" + QueryString.ToString());
}
protected void bt_filter_tab_Click(object sender, EventArgs e)
{
EncryptedQueryString QueryString = new EncryptedQueryString();
QueryString.Add("tab", filter_tab_text.Text);
QueryString.Add("month", period.SelectedItem.Value);
QueryString.Add("role", role);
//Server.Transfer("TimeTable.aspx?data=" + QueryString.ToString(`));
Response.Redirect("Tabel.aspx?data=" + QueryString.ToString());
}
protected void period_SelectedIndexChanged(object sender, EventArgs e)
{
ddl_post.Items.Clear();
Person user = (Person)Session["User"];
SAPDB db = new SAPDB();
EmployeeList emp_list = new EmployeeList();
List<Post> post_list = null;/// pl.getPosts(db.getPostList(StartDateOfPeriod, EndDateOfPeriod, user.TabNum, this.role));
ListItem li = new ListItem("Âûáåðèòå äîëæíîñòü");
ddl_post.Items.Add(li);
if (post_list != null) fillPosts(post_list);
PeriodDB perdb = new PeriodDB();
Period per = perdb.getPeriod(Convert.ToInt32(month), Convert.ToInt32(year));
if (per.IsClosed == 1) lbStatus.Text = "çàêðûò";
else lbStatus.Text = "îòêðûò";
}
protected void Refresh_Click(object sender, ImageClickEventArgs e)
{
//RefreshPage();
}
protected void RefreshPage()
{
EncryptedQueryString QueryString = new EncryptedQueryString();
QueryString.Add("month", period.SelectedItem.Value);
QueryString.Add("role", role);
//Server.Transfer("TimeTable.aspx?data=" + QueryString.ToString());
Response.Redirect("Tabel.aspx?data=" + QueryString.ToString());
}
protected void ddl_post_SelectedIndexChanged(object sender, EventArgs e)
{
EncryptedQueryString QueryString = new EncryptedQueryString();
QueryString.Add("post", ddl_post.SelectedItem.Value);
QueryString.Add("month", period.SelectedItem.Value);
QueryString.Add("role", role);
//Server.Transfer("TimeTable.aspx?data=" + QueryString.ToString());
Response.Redirect("Tabel.aspx?data=" + QueryString.ToString());
}
protected void Save_Click(object sender, ImageClickEventArgs e)
{
//Response.Write(Request.Form["test"]);
Person user = (Person)Session["User"];
PeriodDB perdb = new PeriodDB();
Period per = perdb.getPeriod(Convert.ToInt32(this.month), Convert.ToInt32(this.year));
if (this.employees != null)
{
DepartmentList department_list = new DepartmentList();
List<Department> departments = department_list.getDepartments(employees);
foreach (Department dep in departments)
{
EmployeeList emp_list = new EmployeeList();
List<Employee> emps = null;//// emp_list.getEmployeesOfDepartment(dep.DepartmentID, employees);
EmployeeComparerByPostASC cmpByPostASC = new EmployeeComparerByPostASC();
emps.Sort(cmpByPostASC);
foreach (Employee em in emps)
{
EmployeeList emplist = new EmployeeList();
List<TimekeeperHours> current = null;//emplist.getEmployeesTimekeeperHours(em);
List<HRHours> hr_current = null;/// emplist.getEmployeesHRHours(em);
for (int i = 1; i <= count_days; i++)
{
string textbox_id = "tb" + dep.DepartmentID + em.PostID + em.EmployeeID + i.ToString();
//string hr_id = "hr" + dep.DepartmentID + em.EmployeeID + i.ToString();
Date dt = new Date();
SQLDB db = new SQLDB();
string hour = Request.Form[textbox_id];
//string overhour = Request.Form[hr_id];
TimekeeperHours th = current.Find(delegate(TimekeeperHours ht) { return ht.Day == i.ToString(); });
decimal h = -1;
string sym = "";
if ((hour != "") && (hour != null))
{
if (HasSymbols(hour))
{
if (th == null)
db.insertTimekeeperHoursAndSymbols(em.EmployeeID, em.StartPeriod, em.BeginDate, em.EndDate, h, hour, user.TabNum, dep.DepartmentID, em.PostID, i.ToString(), month, year, per.PeriodID);
else
if (!th.Symbols.Equals(hour))
db.updateTimekeeperHoursAndSymbols(user.TabNum, h, hour, th.ID);
}
else
{
h = Convert.ToDecimal(hour);
if (th == null)
db.insertTimekeeperHoursAndSymbols(em.EmployeeID, em.StartPeriod, em.BeginDate, em.EndDate, h, sym, user.TabNum, dep.DepartmentID, em.PostID, i.ToString(), month, year, per.PeriodID);
else
if (th.Hours != h)
db.updateTimekeeperHoursAndSymbols(user.TabNum, h, sym, th.ID);
}
}
if ((hour == "") && (th != null)) db.deleteTimekeeperHours(th.ID);
}
}
}
}
EncryptedQueryString QueryString = new EncryptedQueryString();
QueryString.Add("month", period.SelectedItem.Value);
QueryString.Add("role", role);
//Server.Transfer("TimeTable.aspx?data=" + QueryString.ToString());
//Response.Redirect("Tabel.aspx?data=" + QueryString.ToString());
}
// ïðîâåðÿåì äàííûå - ÷èñëî ýòî èëè ñòðîêà
bool HasSymbols(string hour)
{
string alphabet = "ÀàÁáÂâÃãÄäÅ娸ÆæÇçÈèÉéÊêËëÌìÍíÎîÏïÐðÑñÒòÓóÔôÕõÖö×÷ØøÙùÚúÛûÜüÝýÞþßÿ";
for (int j = 0; j < hour.Length; j++)
if (alphabet.Contains(hour[j].ToString()))
return true;
return false;
}
protected void setButtons(string roleID)
{
switch (roleID)
{
case "1":
Check.Visible = true;
ClosePeriod.Visible = false;
break;
case "2":
Check.Visible = true;
ClosePeriod.Visible = false;
break;
case "3":
Check.Visible = true;
ClosePeriod.Visible = true;
break;
default:
Check.Visible = false;
ClosePeriod.Visible = false;
break;
}
}
protected void Check_Click(object sender, ImageClickEventArgs e)
{
EncryptedQueryString QueryString = new EncryptedQueryString();
QueryString.Add("month", period.SelectedItem.Value);
QueryString.Add("role", role);
QueryString.Add("check", "true");
Response.Redirect("Tabel.aspx?data=" + QueryString.ToString());
}
protected void ClosePeriod_Click(object sender, ImageClickEventArgs e)
{
/*
Person user = (Person)Session["User"];
PeriodDB perdb = new PeriodDB();
SAPDB db = new SAPDB();
Period per = perdb.getPeriod(Convert.ToInt32(this.month), Convert.ToInt32(this.year));
if (per.IsClosed == 1)
{
MessageBox.Show("Ïåðèîä óæå çàêðûò!");
}
else
{
MonthDB mondb = new MonthDB();
string month_name = mondb.getMonthName(Convert.ToInt32(this.month));
List<Employee> all_employees = db.getEmployeeList(StartDateOfPeriod, EndDateOfPeriod, user.TabNum, this.role);
if (all_employees == null)
{
MessageBox.Show("Íåâîçìîæíî çàêðûòü ïåðèîä! Ñïèñîê ñîòðóäíèêîâ çà ïåðèîä ïóñò!");
}
else
{
EmployeeList emp_check = new EmployeeList();
this.employees = emp_check.getWrongCheckedEmployees(all_employees, count_days, hours, overhours);
if (this.employees.Count > 0)
MessageBox.Show("Íåâîçìîæíî çàêðûòü ïåðèîä! Ïðîâåðüòå ãðàôèêè ñîòðóäíèêîâ!");
else
{
perdb.updatePeriodIsClosed(per.PeriodID, 2);
emp_check.getOvertimeHours(all_employees, count_days, hours, overhours, Convert.ToInt32(this.month), Convert.ToInt32(this.year), user.TabNum, per.PeriodID);
MessageBox.Show("Ïåðèîä çà " + month_name.ToLower() + " " + this.year + " ãîäà çàêðûò!");
}
}
}
ddl_post.Items.Clear();
PostList pl = new PostList();
List<Post> post_list = pl.getPosts(db.getPostList(StartDateOfPeriod, EndDateOfPeriod, user.TabNum, this.role));
ListItem li = new ListItem("Âûáåðèòå äîëæíîñòü");
ddl_post.Items.Add(li);
if (post_list != null)
{
fillPosts(post_list);
}
//RefreshPage();
*/
}
}