public static void ReadContactFileWithRequestedFields(string fileName, List <CsvHeader> requested) { var engine = new CsvParser(fileName, true); engine.SetOrderedFields(requested); var contacts = new List <Csv.Type.Contact.Contact>(); Console.WriteLine("**************************************"); Console.WriteLine($"Total Row Count : {engine.CsvHeader.Count()}"); Console.WriteLine("**************************************"); while (!engine.EndOfStream) { engine.ReadLine(); Console.WriteLine($"Surname : {engine.CsvItem("Surname")}"); Console.WriteLine($"Email : {engine.CsvItem("Email")}"); Console.WriteLine("-----------------------------------------------"); if (engine.CsvHeader.Count != engine.CsvLine.Count) { Console.Write($"Error line : { engine.ErrorRow}"); } else { contacts.Add(ContactData.GetLine(engine)); } } Console.WriteLine(contacts.Count()); Console.WriteLine(engine.CsvItem("Surname")); }
public static void ReadPayrollFile(string fileName) { var engine = new CsvParser(fileName, true); var payrollList = new Csv.Type.Common.CommonCsvList <Csv.Type.Payroll.Payroll>(); while (!engine.EndOfStream) { engine.ReadLine(); if (engine.CsvHeader.Count == engine.CsvLine.Count) { payrollList.Items.Add(PayrollData.GetLine(engine)); Console.WriteLine($"AccountOfficeReference : {engine.CsvItem("AccountOfficeReference")}"); Console.WriteLine($"Address1 : {engine.CsvItem("Address1")}"); Console.WriteLine($"CompanyName : {engine.CsvItem("CompanyName")}"); Console.WriteLine($"FourWeeklyDivisor : {engine.CsvItem("FourWeeklyDivisor")}"); Console.WriteLine($"TaxDistrict : {engine.CsvItem("TaxDistrict")}"); Console.WriteLine($"NormalPayDay : {engine.CsvItem("NormalPayDay")}"); Console.WriteLine($"EmployeeNoFormat : {engine.CsvItem("EmployeeNoFormat")}"); Console.WriteLine($"OmniSlip : {engine.CsvItem("OmniSlip")}"); Console.WriteLine($"PrintPaymentDate : {engine.CsvItem("PrintPaymentDate")}"); Console.WriteLine("-----------------------------------------------"); } else if (engine.CsvLine.Count > 0 && engine.CsvLine[0].Contains("EOF")) { payrollList.EndOfFile = true; payrollList.EndOfFileTimeStamp = (engine.CsvLine.Count < 2) ? "" : engine.CsvLine[1]?.ToString(); Console.WriteLine($"End of CSV File : Create TimeStamp @ {payrollList.EndOfFileTimeStamp}"); } else { Console.WriteLine($"Error line : { engine.ErrorRow}"); } var x = new Csv.Type.Payroll.Payroll(); CsvLib.WireupCSV <Csv.Type.Payroll.Payroll>(ref x, engine.CsvHeader, engine.CsvLine); var y = x.Address1; } Console.WriteLine($"Total Parsed Count : {payrollList.Count()}"); Console.WriteLine(engine.CsvItem("Address2")); }
public static void ReadP60File(string fileName) { var engine = new CsvParser(fileName, true); var p60 = new List <Csv.Type.P60.P60>(); int count = 0; int errorCount = 0; Console.WriteLine("**************************************"); Console.WriteLine($"Total Row Count : {engine.CsvHeader.Count()}"); Console.WriteLine("**************************************"); while (!engine.EndOfStream) { engine.ReadLine(); count++; Console.WriteLine($"Surname : {engine.CsvItem("Surname")}"); Console.WriteLine($"TaxCode : {engine.CsvItem("TaxCode")}"); Console.WriteLine($"DateOfBirth : {engine.CsvItem("DateOfBirth")}"); Console.WriteLine($"Address1 : {engine.CsvItem("Address1")}"); Console.WriteLine($"PeriodsPerYear : {engine.CsvItem("PeriodsPerYear")}"); Console.WriteLine("-----------------------------------------------"); if (engine.CsvHeader.Count != engine.CsvLine.Count) { Console.Write($"Error line : { engine.ErrorRow}"); errorCount++; } else { p60.Add(P60Data.GetLine(engine)); } } Console.WriteLine("**************************************"); Console.WriteLine($"Parsed Count : {count}"); Console.WriteLine($"Error Count : {errorCount}"); Console.WriteLine("**************************************"); }
public void GetCsvItem_WithDoubleType_ReturnsCorrectItem() { //Arrange var mockedValues = GetMockedValues(); var sut = new CsvParser(mockedValues.MockFileName, true, true, true); sut.ReadLine(); //Act var result = sut.CsvItem <string>("FourWeeklyDivisor"); //Assert result.Should().Be("13.035"); }
public void GetCsvItem_WithCorrectName_ReturnsItem() { //Arrange var mockedValues = GetMockedValues(); var sut = new CsvParser(mockedValues.MockFileName, true, true, true); sut.ReadLine(); //Act var result = sut.CsvItem <string>("Address1"); //Assert result.Should().Be("5 Cambridge Technopark"); }
public Contact(CsvParser cp) { if (cp.CsvLine != null && cp.CsvLine.Count > 0) { ContactType = cp.CsvItem <int>("ContactType"); Email = cp.CsvItem("Email"); Forename1 = cp.CsvItem("Forename1"); PhoneNo = cp.CsvItem("PhoneNo"); Surname = cp.CsvItem("Surname"); Title = cp.CsvItem <int>("Title"); MobileNo = cp.CsvItem("MobileNo"); } }
public static Csv.Type.P60.P60 GetLine(CsvParser cp) { var p60 = new Csv.Type.P60.P60(); if (cp.CsvLine != null && cp.CsvLine.Count > 0) { p60.Address1 = cp.CsvItem("Address1"); p60.Address2 = cp.CsvItem("Address2"); p60.Address3 = cp.CsvItem("Address3"); p60.Address4 = cp.CsvItem("Address4"); p60.Address5 = cp.CsvItem("Address5"); p60.ASPP = cp.CsvItem("ASPP"); p60.CoAddress1 = cp.CsvItem("CoAddress1"); p60.CoAddress2 = cp.CsvItem("CoAddress2"); p60.CoAddress3 = cp.CsvItem("CoAddress3"); p60.CoAddress4 = cp.CsvItem("CoAddress4"); p60.CoAddress5 = cp.CsvItem("CoAddress5"); p60.CompanyName = cp.CsvItem("CompanyName"); p60.CompanyNo = cp.CsvItem("CompanyNo"); p60.DateOfBirth = cp.CsvItem <DateTime>("DateOfBirth"); p60.Department = cp.CsvItem("Department"); p60.EdiCreatedDate = cp.CsvItem <DateTime>("EdiCreatedDate"); p60.EmployeeNo = cp.CsvItem("EmployeeNo"); p60.Forename1 = cp.CsvItem("Forename1"); p60.Forename2 = cp.CsvItem("Forename2"); p60.Gender = cp.CsvItem("Gender"); p60.Initials = cp.CsvItem("Initials"); p60.IsActive = cp.CsvItem("IsActive"); p60.IsAmended = cp.CsvItem("IsAmended"); p60.IsEdiCreated = cp.CsvItem("IsEdiCreated"); p60.IsPrinted = cp.CsvItem("IsPrinted"); p60.IsStudentLoan = cp.CsvItem("IsStudentLoan"); p60.JoinDate = cp.CsvItem <DateTime>("JoinDate"); p60.LeftDate = cp.CsvItem <DateTime>("LeftDate"); p60.NINumber = cp.CsvItem("NINumber"); p60.P35ASPP = cp.CsvItem <int>("P35ASPP"); p60.P35NIC = cp.CsvItem <double>("P35NIC"); p60.P35SAP = cp.CsvItem <int>("P35SAP"); p60.P35SMP = cp.CsvItem <double>("P35SMP"); p60.P35SPP = cp.CsvItem <int>("P35SPP"); p60.P35SSP = cp.CsvItem <double>("P35SSP"); p60.P35StudentLoan = cp.CsvItem <double>("P35StudentLoan"); p60.P35Tax = cp.CsvItem <double>("P35Tax"); p60.PayFrequency = cp.CsvItem <int>("PayFrequency"); p60.PayPrevious = cp.CsvItem <int>("PayPrevious"); p60.PayThis = cp.CsvItem <double>("PayThis"); p60.PeriodsPerYear = cp.CsvItem <int>("PeriodsPerYear"); p60.PrintedDate = cp.CsvItem <DateTime>("PrintedDate"); p60.SAP = cp.CsvItem <double>("SAP"); p60.Site = cp.CsvItem <double>("Site"); p60.SMP = cp.CsvItem <double>("SMP"); p60.SPP = cp.CsvItem <double>("SPP"); p60.SSP = cp.CsvItem <double>("SSP"); p60.StudentLoan = cp.CsvItem <double>("StudentLoan"); p60.Surname = cp.CsvItem("Surname"); p60.TaxBasis = cp.CsvItem("TaxBasis"); p60.TaxCode = cp.CsvItem("TaxCode"); p60.TaxDistrict = cp.CsvItem("TaxDistrict"); p60.TaxOfficeNo = cp.CsvItem <int>("TaxOfficeNo"); p60.TaxPrevious = cp.CsvItem <int>("TaxPrevious"); p60.TaxReference = cp.CsvItem("TaxReference"); p60.TaxThis = cp.CsvItem <double>("TaxThis"); p60.Title = cp.CsvItem("Title"); p60.WidowOrphan = cp.CsvItem("WidowOrphan"); p60.YearNumber = cp.CsvItem <int>("YearNumber"); } return(p60); }
public static Csv.Type.Payroll.Payroll GetLine(CsvParser cp) { var payroll = new Csv.Type.Payroll.Payroll(); if(cp.CsvLine != null && cp.CsvLine.Count > 0) { payroll.AccountOfficeReference = cp.CsvItem("AccountOfficeReference"); payroll.Address1 = cp.CsvItem("Address1"); payroll.Address2 = cp.CsvItem("Address2"); payroll.Address3 = cp.CsvItem("Address3"); payroll.Address4 = cp.CsvItem("Address4"); payroll.Address5 = cp.CsvItem("Address5"); payroll.BacsReferenceNo = cp.CsvItem("BacsReferenceNo"); payroll.BankAccountName = cp.CsvItem("BankAccountName"); payroll.BankAccountNo = cp.CsvItem("BankAccountNo"); payroll.BankBranch = cp.CsvItem("BankBranch"); payroll.BankName = cp.CsvItem("BankName"); payroll.BankSortCode = cp.CsvItem("BankSortCode"); payroll.CompanyName = cp.CsvItem("CompanyName"); payroll.CompanyNo = cp.CsvItem("CompanyNo"); payroll.CompanyWeeks = cp.CsvItem<int>("CompanyWeeks"); payroll.FourWeeklyDivisor = cp.CsvItem<double>("FourWeeklyDivisor"); payroll.HourlyDivisor = cp.CsvItem<double>("HourlyDivisor"); payroll.MonthlyDivisor = cp.CsvItem<int>("MonthlyDivisor"); payroll.PayFrequency = cp.CsvItem<int>("PayFrequency"); payroll.PeriodsPerYear = cp.CsvItem<int>("PeriodsPerYear"); payroll.QuarterlyDivisor = cp.CsvItem<double>("QuarterlyDivisor"); payroll.TaxDistrict = cp.CsvItem("TaxDistrict"); payroll.TaxOfficeNo = cp.CsvItem("TaxOfficeNo"); payroll.TaxReference = cp.CsvItem("TaxReference"); payroll.TwoWeeklyDivisor = cp.CsvItem<double>("TwoWeeklyDivisor"); payroll.WeeklyDivisor = cp.CsvItem<double>("WeeklyDivisor"); payroll.WebSystemType = cp.CsvItem<int>("WebSystemType"); payroll.AdditionalReports = cp.CsvItem<bool>("AdditionalReports"); payroll.EmailPayslips = cp.CsvItem<bool>("EmailPayslips"); payroll.EmailReports = cp.CsvItem<bool>("EmailReports"); payroll.OutputMethod = cp.CsvItem("OutputMethod"); payroll.P11D = cp.CsvItem<bool>("P11D"); payroll.PaidByBacs = cp.CsvItem<bool>("PaidByBacs"); payroll.PayByDirectDebit = cp.CsvItem<bool>("PayByDirectDebit"); payroll.PayDay = cp.CsvItem("PayDay"); payroll.PensionByWeb = cp.CsvItem<bool>("PensionByWeb"); payroll.PostMethod = cp.CsvItem<int>("PostMethod"); payroll.SecondaryBacs = cp.CsvItem<bool>("SecondaryBacs"); payroll.PrintReports = cp.CsvItem<bool>("PrintReports"); payroll.PrintEEsPayslip = cp.CsvItem<bool>("PrintEEsPayslip"); payroll.PrintERsPayslip = cp.CsvItem<bool>("PrintERsPayslip"); payroll.NormalPayDay = cp.CsvItem("NormalPayDay"); payroll.OrganisationName = cp.CsvItem("OrganisationName"); payroll.EmployeeNoFormat = cp.CsvItem("EmployeeNoFormat"); payroll.PayslipERsPension1 = cp.CsvItem<bool>("PayslipERsPension1"); payroll.PayslipERsPension2 = cp.CsvItem<bool>("PayslipERsPension2"); payroll.PrintPaymentDate = cp.CsvItem<bool>("PrintPaymentDate"); payroll.OmniSlip = cp.CsvItem<bool>("OmniSlip"); } return payroll; }
public P60(CsvParser cp) { if (cp.CsvLine != null && cp.CsvLine.Count > 0) { Address1 = cp.CsvItem("Address1"); Address2 = cp.CsvItem("Address2"); Address3 = cp.CsvItem("Address3"); Address4 = cp.CsvItem("Address4"); Address5 = cp.CsvItem("Address5"); ASPP = cp.CsvItem("ASPP"); CoAddress1 = cp.CsvItem("CoAddress1"); CoAddress2 = cp.CsvItem("CoAddress2"); CoAddress3 = cp.CsvItem("CoAddress3"); CoAddress4 = cp.CsvItem("CoAddress4"); CoAddress5 = cp.CsvItem("CoAddress5"); CompanyName = cp.CsvItem("CompanyName"); CompanyNo = cp.CsvItem("CompanyNo"); DateOfBirth = cp.CsvItem <DateTime>("DateOfBirth"); Department = cp.CsvItem("Department"); EdiCreatedDate = cp.CsvItem <DateTime>("EdiCreatedDate"); EmployeeNo = cp.CsvItem("EmployeeNo"); Forename1 = cp.CsvItem("Forename1"); Forename2 = cp.CsvItem("Forename2"); Gender = cp.CsvItem("Gender"); Initials = cp.CsvItem("Initials"); IsActive = cp.CsvItem("IsActive"); IsAmended = cp.CsvItem("IsAmended"); IsEdiCreated = cp.CsvItem("IsEdiCreated"); IsPrinted = cp.CsvItem("IsPrinted"); IsStudentLoan = cp.CsvItem("IsStudentLoan"); JoinDate = cp.CsvItem <DateTime>("JoinDate"); LeftDate = cp.CsvItem <DateTime>("LeftDate"); NINumber = cp.CsvItem("NINumber"); P35ASPP = cp.CsvItem <int>("P35ASPP"); P35NIC = cp.CsvItem <double>("P35NIC"); P35SAP = cp.CsvItem <int>("P35SAP"); P35SMP = cp.CsvItem <double>("P35SMP"); P35SPP = cp.CsvItem <int>("P35SPP"); P35SSP = cp.CsvItem <double>("P35SSP"); P35StudentLoan = cp.CsvItem <double>("P35StudentLoan"); P35Tax = cp.CsvItem <double>("P35Tax"); PayFrequency = cp.CsvItem <int>("PayFrequency"); PayPrevious = cp.CsvItem <int>("PayPrevious"); PayThis = cp.CsvItem <double>("PayThis"); PeriodsPerYear = cp.CsvItem <int>("PeriodsPerYear"); PrintedDate = cp.CsvItem <DateTime>("PrintedDate"); SAP = cp.CsvItem <double>("SAP"); Site = cp.CsvItem <double>("Site"); SMP = cp.CsvItem <double>("SMP"); SPP = cp.CsvItem <double>("SPP"); SSP = cp.CsvItem <double>("SSP"); StudentLoan = cp.CsvItem <double>("StudentLoan"); Surname = cp.CsvItem("Surname"); TaxBasis = cp.CsvItem("TaxBasis"); TaxCode = cp.CsvItem("TaxCode"); TaxDistrict = cp.CsvItem("TaxDistrict"); TaxOfficeNo = cp.CsvItem <int>("TaxOfficeNo"); TaxPrevious = cp.CsvItem <int>("TaxPrevious"); TaxReference = cp.CsvItem("TaxReference"); TaxThis = cp.CsvItem <double>("TaxThis"); Title = cp.CsvItem("Title"); WidowOrphan = cp.CsvItem("WidowOrphan"); YearNumber = cp.CsvItem <int>("YearNumber"); } }