-
Notifications
You must be signed in to change notification settings - Fork 0
/
EstimateReader.cs
81 lines (71 loc) · 2.71 KB
/
EstimateReader.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
using System;
using System.Text;
using OfficeOpenXml;
using Serilog;
namespace Population.IO
{
public class EstimateReader : ICommandReader<Estimate>
{
private int _rowId = 1;
private readonly ExcelWorksheet _estimateWorksheet;
private ILogger Logger { get; }
public EstimateReader(ExcelWorksheet estimateWorksheet, ILogger logger)
{
_estimateWorksheet = estimateWorksheet;
Logger = logger;
}
public Estimate Current { get; private set; }
public bool MoveNext()
{
if (_estimateWorksheet != null)
{
try
{
if (_rowId == 1)
{
ExcelRow headerRow = _estimateWorksheet.Row(_rowId);
if (headerRow == null)
{
Logger.Error("Estimates Worksheet has no rows");
return false;
}
Logger.Information("Reading Estimates ...");
}
Current = new Estimate();
++_rowId;
ExcelRow dataRow = _estimateWorksheet.Row(_rowId);
if (dataRow == null)
{
Logger.Warning("Finished reading Estimates worksheet");
return false;
}
bool sayTrue = false;
if (_estimateWorksheet.Cells[_rowId, 1].Value != null)
{
Current.State = Convert.ToInt32(_estimateWorksheet.Cells[_rowId, 1].Value);
sayTrue = true;
}
if (_estimateWorksheet.Cells[_rowId, 2].Value != null)
{
Current.Districts = Convert.ToInt32(_estimateWorksheet.Cells[_rowId, 2].Value);
}
if (_estimateWorksheet.Cells[_rowId, 3].Value != null)
{
Current.EstimatesPopulation = Convert.ToInt32(_estimateWorksheet.Cells[_rowId, 3].Value);
}
if (_estimateWorksheet.Cells[_rowId, 4].Value != null)
{
Current.EstimateHoseholds = Convert.ToInt32(_estimateWorksheet.Cells[_rowId, 4].Value);
}
return sayTrue;
}
catch (ArgumentOutOfRangeException)
{
Logger.Warning("RowId out of range");
}
}
Logger.Warning("Finished reading Estimates");
return false;
}
}
}