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

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);
}

Edited 2 Years Ago by Momerath

Comments
Also helpfull for me!

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

This article has been dead for over six months. Start a new discussion instead.