public List <DzienPracy> ReadFileCompany1() { List <DzienPracy> result = new List <DzienPracy>(); StreamReader dayReader = new StreamReader("rcp1.csv"); if (dayReader != null) { int line_number = 0; while (!dayReader.EndOfStream) { var line = dayReader.ReadLine(); if (line_number >= 0) { try { var values = line.Split(';'); if (!values[0].Equals("") && values[1] != null && values[2] != null && values[3] != null) { DzienPracy day = new DzienPracy(); day.KodPracownika = Convert.ToString(values[0]); day.Data = Convert.ToDateTime(values[1]); day.GodzinaWejscia = TimeSpan.Parse(values[2]); day.GodzinaWyjscia = TimeSpan.Parse(values[3]); result.Add(day); } else { continue; } } catch (System.FormatException ex) { continue; } } line_number++; } dayReader.Close(); } return(result); }
public List <DzienPracy> ReadFileCompany2() { List <DzienPracy> result = new List <DzienPracy>(); StreamReader dayReader = new StreamReader("rcp2.csv"); bool readOldLine = false; var line = ""; if (dayReader != null) { int line_number = 0; while (!dayReader.EndOfStream) { if (readOldLine) { readOldLine = false; } else { line = dayReader.ReadLine(); } if (line_number >= 0) { var values = line.Split(';'); if (!values[0].Equals("") && !values[1].Equals("") && !values[2].Equals("") && !values[3].Equals("")) { DzienPracy day = new DzienPracy(); day.KodPracownika = Convert.ToString(values[0]); day.Data = Convert.ToDateTime(values[1]); try { if (values[3] == "WE") { day.GodzinaWejscia = TimeSpan.Parse(values[2] + ":00"); var line2 = dayReader.ReadLine(); var values2 = line2.Split(';'); if (values2[0] == values[0] && values2[1] == values[1] && !values2[2].Equals("")) { day.GodzinaWyjscia = TimeSpan.Parse(values2[2] + ":00"); } else { line = line2; readOldLine = true; continue; } } else if (values[3] == "WY") { day.GodzinaWyjscia = TimeSpan.Parse(values[2] + ":00"); var line2 = dayReader.ReadLine(); var values2 = line2.Split(';'); if (values2[0] == values[0] && values2[1] == values[1] && !values2[2].Equals("")) { day.GodzinaWejscia = TimeSpan.Parse(values2[2] + ":00"); } else { line = line2; readOldLine = true; continue; } } else if (values[2] == null) { continue; } } catch (System.FormatException ex) { continue; } result.Add(day); } } line_number++; } dayReader.Close(); } return(result); }