My code is as follow
The output is null, I should use while loop as you see, but somewhere in my code is not working properly.
and I'm not able to use any other library
I need an hours array and rate array for employeeId==1 and the same for other employees(the CSV file is larger than what I pasted here)
public static List<PayRecord> ImportPayRecords(string file)
{
List<PayRecord> payRecords = new List<PayRecord>();
StreamReader reader = new StreamReader(file);
int EmployeeId;
int i = 0;
int id;
string Visa = "";
string YearToDate = "";
string record;
string[] strArr;
double[] Hours = new double[10];
double[] Rate = new double[10];
record = reader.ReadLine();
strArr = record.Split(',');
while (record != null)
{
EmployeeId = int.Parse(strArr[0]);
if (strArr[3] != "")
{
Visa = strArr[3];
YearToDate = strArr[4];
}
id = EmployeeId;
while (record != null && id == int.Parse(strArr[0]))
{
Hours[i] = double.Parse(strArr[1]);
Rate[i] = double.Parse(strArr[2]);
i++;
record = reader.ReadLine();
if (record != null)
{
strArr = record.Split(',');
}
}
PayRecord rec = CreatePayRecord(EmployeeId, Hours, Rate, Visa, YearToDate);
payRecords.Add(rec);
double gross = rec.Gross;
i = 0;
Array.Clear(Hours, i, 10);
Array.Clear(Rate, i, 10);
}
return payRecords;
}
the CSV file is like this:
EmployeeId,Hours,Rate,Visa,YearToDate
1,2,25,,
1,3,25,,
1,3,25,,
1,4,25,,
1,5,32,,
1,6,32,,
2,2,25,417,47520
2,2,25,417,47520
2,2,25,417,47520
2,2,25,417,47520
2,2,25,417,47520
2,2,28,417,47520
2,2,28,417,47520
2,2,28,417,47520