I'm trying to parse this csv-like file, and I seem to be failing at it. Below is the contents of said file, and below that is the record format. Can someone give me a clue? Thank you.

Source Code
Click Here

CSV File
Click Here

Record Format
Click Here

Recommended Answers

All 3 Replies

You should have a class for each type of report and a class for displaying each type of report. You then have a class (Report class) that takes an instance of the class for the report and the class for displaying the report.

Then you'd have a factory class that you pass the string into, and it returns an instance of the Report class with the specific instances of report type and display report.

Why do it this way? If you have to add a new report format or display method you can do so knowing it won't break all the other report formats and display methods. The only class that needs changing is the factory.

I can show you an example of what I mean, if you'd like.

Also, you are doing way too much in your code, you need to break it out into methods. Something like

public void Main() {
    DisplayMedium whereToDisplay = null;
    StorageMedium whereToStore = null;

    List<Reports> theReports = GetReportData(<file path, database, whatever>);

    whereToDisplay = new ConsoleDisplayMedium();
    DisplayReportData(whereToDisplay, theReports);

    whereToDisplay = new PrinterDisplayMedium();
    DisplayReportData(whereToDisplay, theReports);

    PrintSingleReport(whereToDispaly, theReports[3]);

    whereToStore = new DatabaseReportStorage();
    StoreReports(whereToStore, theReports);
}
commented: Also helpfull for me! +15

Is my current CSV parsing fine though? That's half my issue.

You didn't post the ParseCSV code, so I can't tell you if you are parsing it correctly :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.