//This method reads in the file and calls other methods which do the arithmetic, as well as adding each line as an object to recordList private void LoadFile() { rtbMain.Clear(); string lineFromFile; char[] deliminator = { ',' }; string[] lineFromFileSplit; try { using (StreamReader reader = new StreamReader(fileName)) { reader.ReadLine(); while (!reader.EndOfStream) { lineFromFile = reader.ReadLine(); lineFromFileSplit = lineFromFile.Split(deliminator); Charts.ProcessMonthlyTotal(lineFromFileSplit); Charts.RecordsPerMonth(lineFromFileSplit); Charts.ItemsSold(lineFromFileSplit); addToList(lineFromFileSplit); } whatGraph = 1; drawTotalBarChart(); lblTotalEntries.Text = Convert.ToString(recordList.Count + 1); } } catch (IOException ex) { MessageBox.Show("Error reading from file", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnOpenFile_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() != DialogResult.Cancel) { fileName = openFileDialog.FileName; directoryName = openFileDialog.InitialDirectory; if (fileOpen == false) { LoadFile(); fileOpen = true; } else { Charts.ClearVariables(); recordList.Clear(); LoadFile(); } } }