-
Notifications
You must be signed in to change notification settings - Fork 0
/
JobsOverview.aspx.cs
535 lines (448 loc) · 17.5 KB
/
JobsOverview.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
using System;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using ProfIT;
public partial class JobsOverview : BasePage
{
public int year = DateTime.Now.Year;
public Object sessionyearObject;
public int count;
public int yearcount;
int displayyear = 0;
protected void Page_Load(object sender, EventArgs e)
{
//MamutTest();
if (Session["Year"] == null)
{
Session.Add("Year", year);
}
sessionyearObject = Session["Year"];
if (sessionyearObject.ToString() == "1")
{
sessionyearObject = DateTime.Now.Year;
}
displayyear = Convert.ToInt32(sessionyearObject);
weeknumber.Text = "År " + displayyear;
}
protected void GetFullOverViewList(List<JobOverviewList> jobOverviewLists, int year)
{
string month = "";
for (int i = 1; i < 13; i++)
{
List<Job> jobsthismonth = new List<Job>();
DateTime dateTime = new DateTime(year, i, 01);
JobOverviewList jobOverview = new JobOverviewList(dateTime.ToString("MMMM"), jobsthismonth);
jobOverviewLists.Add(jobOverview);
}
var list = CheckForJobsFromSession();
if (list.Count > 0)
{
AddExtraJobs(list, jobOverviewLists);
}
for (int i = 1; i < jobOverviewLists.Count + 1; i++)
{
if (i < 10)
{
month = "0" + i;
}
else
{
month = i.ToString();
}
var jobs = SiteUtilities.GetJobsByMonth(year + "-" + month);
for (int j = 0; j < jobs.Count; j++)
{
if (jobs[j].ParentJobID != Guid.Empty)
{
return;
}
int startmonth = jobs[j].JobStartDate.Month - 1;
switch (jobs[j].JobStartDate.Month - 1)
{
case 0:
{
// Januari
jobOverviewLists[0].Jobs.Add(jobs[j]);
var months = CheckJobLenght(jobs[j]);
AddExtraMonths(jobOverviewLists, jobs[j], j, startmonth, months);
}
break;
case 1:
{
// Februari
jobOverviewLists[1].Jobs.Add(jobs[j]);
var months = CheckJobLenght(jobs[j]);
AddExtraMonths(jobOverviewLists, jobs[j], j, startmonth, months);
}
break;
case 2:
{
// Mars
jobOverviewLists[2].Jobs.Add(jobs[j]);
var months = CheckJobLenght(jobs[j]);
AddExtraMonths(jobOverviewLists, jobs[j], j, startmonth, months);
}
break;
case 3:
{
// April
jobOverviewLists[3].Jobs.Add(jobs[j]);
var months = CheckJobLenght(jobs[j]);
AddExtraMonths(jobOverviewLists, jobs[j], j, startmonth, months);
}
break;
case 4:
{
// Maj
jobOverviewLists[4].Jobs.Add(jobs[j]);
var months = CheckJobLenght(jobs[j]);
AddExtraMonths(jobOverviewLists, jobs[j], j, startmonth, months);
}
break;
case 5:
{
// Juni
jobOverviewLists[5].Jobs.Add(jobs[j]);
var months = CheckJobLenght(jobs[j]);
AddExtraMonths(jobOverviewLists, jobs[j], j, startmonth, months);
}
break;
case 6:
{
// Juli
jobOverviewLists[6].Jobs.Add(jobs[j]);
var months = CheckJobLenght(jobs[j]);
AddExtraMonths(jobOverviewLists, jobs[j], j, startmonth, months);
}
break;
case 7:
{
// Augusti
jobOverviewLists[7].Jobs.Add(jobs[j]);
var months = CheckJobLenght(jobs[j]);
AddExtraMonths(jobOverviewLists, jobs[j], j, startmonth, months);
}
break;
case 8:
{
// September
jobOverviewLists[8].Jobs.Add(jobs[j]);
var months = CheckJobLenght(jobs[j]);
AddExtraMonths(jobOverviewLists, jobs[j], j, startmonth, months);
}
break;
case 9:
{
// Oktober
jobOverviewLists[9].Jobs.Add(jobs[j]);
var months = CheckJobLenght(jobs[j]);
AddExtraMonths(jobOverviewLists, jobs[j], j, startmonth, months);
}
break;
case 10:
{
// November
jobOverviewLists[10].Jobs.Add(jobs[j]);
var months = CheckJobLenght(jobs[j]);
AddExtraMonths(jobOverviewLists, jobs[j], j, startmonth, months);
}
break;
case 11:
{
// December
jobOverviewLists[11].Jobs.Add(jobs[j]);
var months = CheckJobLenght(jobs[j]);
AddExtraMonths(jobOverviewLists, jobs[j], j, startmonth, months);
}
break;
}
}
}
}
private void AddExtraJobs(IEnumerable<Job> list, List<JobOverviewList> jobOverviewLists)
{
foreach (var job in list)
{
if (job.JobEndDate.Year.ToString() == sessionyearObject.ToString())
{
if (job.JobEndDate.Month > 0)
{
int startmonth = 0;
for (int k = 0; k < job.JobEndDate.Month; k++)
{
if (startmonth + k == 12)
return;
jobOverviewLists[startmonth + k].Jobs.Add(job);
}
for (int i = job.JobEndDate.Month; i < 12; i++)
{
if (i == 12)
return;
Job emptyjob = new Job(Guid.Empty, string.Empty, true, string.Empty, DateTime.MinValue, DateTime.MinValue, string.Empty, string.Empty, string.Empty, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, string.Empty, false, false, Guid.Empty, string.Empty, string.Empty, 0, string.Empty);
jobOverviewLists[i].Jobs.Add(emptyjob);
}
}
}
}
}
private List<Job> CheckForJobsFromSession()
{
List<Job> jobs = new List<Job>();
year = Convert.ToInt32(sessionyearObject);
for (int i = 0; i < Session.Count; i++)
{
try
{
Job job = Session[i] as Job;
if (job != null)
{
jobs.Add(job);
}
}
catch
{
}
}
return jobs;
}
private void AddExtraMonths(List<JobOverviewList> jobOverviewLists, Job job, int j, int startmonth, int months)
{
for (int i = 0; i <= startmonth; i++)
{
Job emptyjob = new Job(Guid.Empty, string.Empty, true, string.Empty, DateTime.MinValue, DateTime.MinValue, string.Empty, string.Empty, string.Empty, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, string.Empty, false, false, Guid.Empty, string.Empty, string.Empty, 0, string.Empty);
if (i == startmonth)
continue;
jobOverviewLists[i].Jobs.Add(emptyjob);
}
int after = startmonth + months;
for (int i = after; i < 12; i++)
{
if (job.JobEndDate.Month == i + 1)
{
continue;
}
Job emptyjob = new Job(Guid.Empty, string.Empty, true, string.Empty, DateTime.MinValue, DateTime.MinValue, string.Empty, string.Empty, string.Empty, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, string.Empty, false, false, Guid.Empty, string.Empty, string.Empty, 0, string.Empty);
jobOverviewLists[i].Jobs.Add(emptyjob);
}
for (int k = 1; k < months; k++)
{
if (startmonth + k == 12)
return;
jobOverviewLists[startmonth + k].Jobs.Add(job);
}
}
private int CheckJobLenght(Job job)
{
if (job.JobStartDate.Month != job.JobEndDate.Month || job.JobStartDate.Year != job.JobEndDate.Year)
{
if (job.JobStartDate.Year == job.JobEndDate.Year)
{
return job.JobEndDate.Month - job.JobStartDate.Month + 1;
}
if (job.JobStartDate.Year != job.JobEndDate.Year)
{
SaveJobToSession(job);
return 999;
}
}
return 0;
}
private void SaveJobToSession(Job job)
{
if (!Page.IsPostBack)
{
yearcount = Convert.ToInt32(sessionyearObject);
Session.Add("Job_" + job.JobId, job);
count++;
}
}
protected void NextYearLink(object sender, EventArgs e)
{
year = Convert.ToInt32(sessionyearObject);
// Add One Year
var newyear = year + 1;
if (Session["Year"] != null)
{
// Delete old value
Session.Remove("Year");
}
// Set new value
Session.Add("Year", newyear);
Response.Redirect(Request.Url.ToString(), false);
}
protected void PreviousYearLink(object sender, EventArgs e)
{
year = Convert.ToInt32(sessionyearObject);
// Add One Year
var newyear = year - 1;
if (Session["Year"] != null)
{
// Delete old value
Session.Remove("Year");
}
// Set new value
Session.Add("Year", newyear);
Response.Redirect(Request.Url.ToString(), false);
}
public class JobOverview
{
public DateTime JobStart { get; set; }
public DateTime JobEnd { get; set; }
public Job Job { get; set; }
public JobOverview(DateTime jobstart, DateTime jobend, Job job)
{
JobStart = jobstart;
JobEnd = jobend;
Job = job;
}
}
public class JobOverviewList
{
public string Month { get; set; }
public List<Job> Jobs { get; set; }
public JobOverviewList(string month, List<Job> jobs)
{
Month = month;
Jobs = jobs;
}
}
protected void GetAllMonths(object sender, EventArgs e)
{
if (Session["Year"] == null)
{
Session.Add("Year", year);
}
sessionyearObject = Session["Year"];
DateTime DisplayYear = new DateTime(Convert.ToInt16(sessionyearObject), 01, 01);
Repeater repeater = sender as Repeater;
List<JobOverviewList> jobOverviewLists = new List<JobOverviewList>();
GetFullOverViewList(jobOverviewLists, DisplayYear.Year);
// Sortering
//foreach (var jobOverviewList in jobOverviewLists)
//{
// jobOverviewList.Jobs.Reverse();
//}
repeater.DataSource = jobOverviewLists;
repeater.DataBind();
}
protected void initJobForMonth(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
var month = e.Item.FindControl("month") as Label;
Repeater repeater = e.Item.FindControl("jobs") as Repeater;
JobOverviewList jobOverviewList = e.Item.DataItem as JobOverviewList;
if (jobOverviewList != null && repeater != null && month != null)
{
month.Text = jobOverviewList.Month;
repeater.DataSource = jobOverviewList.Jobs;
repeater.DataBind();
}
}
}
protected void InitJob(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
var repeater = e.Item.Parent as Repeater;
RepeaterItem parent = repeater.Parent as RepeaterItem;
JobOverviewList jobOverviewList = parent.DataItem as JobOverviewList;
Job job = e.Item.DataItem as Job;
if (job != null && job.JobName == "")
{
var width1 = e.Item.FindControl("width") as HtmlGenericControl;
//width1.Attributes["Style"] = "visibility:hidden;height:50px;border:none;";
width1.Attributes["Style"] = "height:50px;border:none;";
return;
}
var width = e.Item.FindControl("width") as HtmlGenericControl;
SetJobStyle(job, width, jobOverviewList.Month);
}
}
private void SetJobStyle(Job job, HtmlGenericControl width, string month)
{
string color = "";
if (job.Type == SiteUtilities.IMPORT)
{
color = "red";
}
else if (job.Type == SiteUtilities.CONSTRUCTION)
{
color = "orange";
}
else if (job.Type == SiteUtilities.DESTRUCTION)
{
color = "yellow";
}
else if (job.Type == SiteUtilities.DESTRUCTIONFINNISHED)
{
color = "lightgreen";
}
else if (job.Type == SiteUtilities.CONSTRUCTIONFINNISHED)
{
color = "green";
}
if (job.JobStartDate.ToString("MMMM") == month && job.JobEndDate.ToString("MMMM") != month)
{
// This job shall be over the end of the month but not start from begging
DateTime LastDayOfMonth = new DateTime();
if (job.JobStartDate.Month < 12)
{
LastDayOfMonth = new DateTime(job.JobStartDate.Year, job.JobStartDate.Month + 1, 01).AddDays(-1);
}
else
{
LastDayOfMonth = new DateTime(job.JobStartDate.Year + 1, 01, 01).AddDays(-1);
}
double days = LastDayOfMonth.Day - job.JobStartDate.Day;
double week = days / 7;
width.Attributes["Style"] = "width:" + GetWidth(Math.Round(week)) + "%;overflow:hidden;height:50px;border:none;background-color:" + color + ";float:right;";
return;
}
if (job.JobEndDate.ToString("MMMM") == month && job.JobStartDate.ToString("MMMM") != month)
{
DateTime FirstDayOfMonth = new DateTime(job.JobEndDate.Year, job.JobEndDate.Month, 01);
double days = job.JobEndDate.Day - FirstDayOfMonth.Day;
double week = days / 7;
width.Attributes["Style"] = "width:" + GetWidth(Math.Round(week)) + "%;overflow:hidden;height:50px;border:none;background-color:" + color + ";";
return;
}
if (job.JobStartDate.ToString("MMMM") == month && job.JobEndDate.ToString("MMMM") == month)
{
DateTime LastDayOfMonth = new DateTime();
if (job.JobEndDate.Month < 12)
{
LastDayOfMonth = new DateTime(job.JobEndDate.Year, job.JobEndDate.Month + 1, 01).AddDays(-1);
}
else
{
LastDayOfMonth = new DateTime(job.JobEndDate.Year + 1, 01, 01).AddDays(-1);
}
double days = LastDayOfMonth.Day - job.JobEndDate.Day;
double week = days / 7;
width.Attributes["Style"] = "width:" + GetWidth(Math.Round(week)) + "%;overflow:hidden;height:50px;border:none;background-color:" + color + ";float:right;";
return;
}
width.Attributes["Style"] = "width:" + 100 + "%;overflow:hidden;height:50px;border:none;background-color:" + color + ";";
return;
}
private string GetWidth(double d)
{
int temp = Convert.ToInt16(d);
switch (temp)
{
case 0:
return "20";
case 1:
return "25";
case 2:
return "50";
case 3:
return "75";
case 4:
return "100";
}
return "100";
}
}