-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
100 lines (75 loc) · 3.5 KB
/
Program.cs
File metadata and controls
100 lines (75 loc) · 3.5 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
using Miracle.Arguments;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading;
using WorkingHoursWShifts12Day24Off12Night48Off;
namespace GenerateEmployeeScheduleReport
{
class Program
{
static ResourceManager rm;
static void Main(string[] args)
{
try
{
if (args != null && args.Any())
{
rm = new ResourceManager("GenerateEmployeeScheduleReport.Resources.Resources", typeof(Program).Assembly);
var arg = args.ParseCommandLine<SetUpArgs>();
var startDate = DateTime.Parse(arg.StartDate);
var checkDate = DateTime.Parse(arg.CheckDate);
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(arg.Language);
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(arg.Language);
StringBuilder strOutput = new StringBuilder();
WorkingHours wschedule;
int lastCheckedMonth = startDate.Month;
bool newYear = false;
strOutput.AppendLine(string.Format(GetFromResource("Title"), arg.EmployeeName, DateTime.Now.Year));
strOutput.AppendLine(startDate.ToString("MMMM").ToUpper());
var currentYear = startDate.Year;
foreach (var day in EachDay(startDate, checkDate))
{
wschedule = new WorkingHours(startDate);
var result = wschedule.GetWorkingType(day);
if (result != WorkingType.Off)
{
if (lastCheckedMonth != day.Month)
{
strOutput.AppendLine(Environment.NewLine);
if (currentYear != day.Year || newYear)
{
currentYear = day.Year;
newYear = true;
strOutput.AppendLine("(" + currentYear +") "+ day.ToString("MMMM").ToUpper());
}
else
strOutput.AppendLine(day.ToString("MMMM").ToUpper());
lastCheckedMonth = day.Month;
}
string outputResult = string.Format("{0}:{1}", day.Day.ToString("00"), (result == WorkingType.Day ? GetFromResource("DayShift") : GetFromResource("NightShift")));
strOutput.Append(outputResult);
strOutput.Append("\t");
}
}
new PDFGenerator().GeneratePDF($"{arg.EmployeeName} {GetFromResource("ReportName")} {DateTime.Now.Year}.pdf", strOutput);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
static IEnumerable<DateTime> EachDay(DateTime from, DateTime thru)
{
for (var day = from.Date; day.Date <= thru.Date; day = day.AddDays(1))
yield return day;
}
static string GetFromResource(string resID)
{
return rm.GetString(resID);
}
}
}