Beispiel #1
0
        private void SelectFileBtn_Click(object sender, EventArgs e)
        {
            //opens 'select file' box
            DialogResult result = openFileDialog1.ShowDialog();

            //if we clicked ok - get the file name, which includes the full file path
            if (result == DialogResult.OK)
            {
                string filePath = openFileDialog1.FileName;

                //if it ends in csv then we can look at getting the data, else prompt them to select the right type of file
                if (filePath.EndsWith(".csv"))
                {
                    CSVReadWriter csvReader = new CSVReadWriter();
                    studentData = csvReader.GetStudentDataFromCSV(filePath);

                    if (studentData != null && studentData.Count > 0)
                    {
                        SetDetailsInForm(currentStudentCounter);
                    }
                }
                else
                {
                    MessageBox.Show("Select a .csv file", "Wrong File Type Selected", MessageBoxButtons.OK);
                }
            }
        }
Beispiel #2
0
 private void SaveReportsToFile(object sender, EventArgs e)
 {
     //checks if all reports have been completed before saving, and gives warning if not
     if (currentStudentCounter + 1 != totalStudents)
     {
         DialogResult result = MessageBox.Show("Not all student reports completed", "Warning", MessageBoxButtons.OKCancel);
         if (result == DialogResult.OK)
         {
             CSVReadWriter fileWriter = new CSVReadWriter();
             // fileWriter.SaveReportsToTextFile(reports);
             fileWriter.SaveReportsToCSV(studentData);
         }
     }
     else
     {
         CSVReadWriter fileWriter = new CSVReadWriter();
         // fileWriter.SaveReportsToTextFile(reports);
         fileWriter.SaveReportsToCSV(studentData);
     }
 }