-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
98 lines (84 loc) · 2.89 KB
/
Program.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
// See https://aka.ms/new-console-template for more information
using JournalGenerator.Utils;
Console.WriteLine("Hello, World!");
while (true)
{
Console.Clear();
Console.WriteLine("Applications");
Console.WriteLine(" 1: Generate Journal from Islandsbanki Foreign Payments");
Console.WriteLine();
Console.WriteLine("Enter the number of application to run or press 'x' to exit: ");
string input = Console.ReadLine().ToLower();
if (input == "x")
{
break;
}
int applicationNr = -1;
if (!int.TryParse(input, out applicationNr))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Only input numbers ");
Console.ResetColor();
Console.ReadKey();
}
else
{
switch (applicationNr)
{
case 1:
GenerateJournalFromIslandsbankiForeignPayments();
break;
default:
Console.Write("Invalid applicaiton number");
Console.ResetColor();
Console.ReadKey();
break;
}
}
}
static void GenerateJournalFromIslandsbankiForeignPayments()
{
string filePath;
FileInfo fileInfo;
while (true)
{
Console.WriteLine("Enter file path: ");
//filePath = Console.ReadLine();
filePath = @"C:\Users\egill\Desktop\October.xlsx"; // DEBUG
if (!File.Exists(filePath))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error: File not found");
Console.ResetColor();
continue;
}
fileInfo = new FileInfo(filePath);
if (string.IsNullOrWhiteSpace(fileInfo.Extension) || !fileInfo.Extension.Equals(".xlsx", StringComparison.InvariantCultureIgnoreCase))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error: File must be an Excel (.xlsx) file");
Console.ResetColor();
}
else
{
break;
}
}
try
{
byte[] fileBytes = File.ReadAllBytes(filePath);
var outputFilePath = string.Format("{0}_ouput.xlsx", filePath.Replace(fileInfo.Extension, string.Empty));
(byte[] outputBytes, int journalEntriesCount) = PaydayJournalUtils.GenerateJournalFromIslandsbankiForeignPayments(fileBytes);
File.WriteAllBytes(outputFilePath, outputBytes);
Console.WriteLine(string.Format("Successfully generated {0} journal entries to file: {1}", journalEntriesCount, outputFilePath));
Console.ReadLine();
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
string message = string.Format("{0} {1}", ex.Message, ex.InnerException != null ? ex.InnerException.Message : string.Empty);
Console.WriteLine(string.Format("Error: {0}", message));
Console.ResetColor();
Console.ReadLine();
}
}