Example #1
0
        public void ReadFile(HonorsStudentDictionary studentDictionary)
        {
            StreamReader infile;
            char         delimiter = ',';
            string       line;

            string[] fields = new string[22];

            if (File.Exists("honorsstudentfile.csv"))
            {
                infile = File.OpenText("honorsstudentfile.csv");
                while (!infile.EndOfStream)
                {
                    line   = infile.ReadLine();
                    fields = line.Split(delimiter);
                    HonorsStudent student = new HonorsStudent();
                    student.ccriID           = fields[0];
                    student.name             = fields[1];
                    student.termHours        = fields[2];
                    student.race             = fields[3];
                    student.GPAint           = fields[4];
                    student.GPAoverall       = fields[5];
                    student.age              = fields[6];
                    student.gender           = fields[7];
                    student.firstGen         = fields[8];
                    student.financialAid     = fields[9];
                    student.readScore        = fields[10];
                    student.readTestDate     = fields[11];
                    student.mathScore        = fields[12];
                    student.mathTestDate     = fields[13];
                    student.academicStanding = fields[14];
                    student.major            = fields[15];
                    student.courseID         = fields[16];
                    student.courseTitle      = fields[17];
                    student.grade            = fields[18];
                    student.instructor       = fields[19];
                    student.department       = fields[20];
                    student.term             = fields[21];
                    studentDictionary.AddStudent(student);
                }
                infile.Close();
            }
        }
        private void btnSaveStudent_Click(object sender, EventArgs e)
        {
            if (addingStudent == true)
            {
                try
                {
                    btnRemoveStudent.Text = "Remove Student";
                    if (cboCCID.Text != string.Empty || txtName.Text != string.Empty)
                    {
                        DateTime readDate = dtpReadDate.Value;
                        DateTime mathDate = dtpMathDate.Value;

                        HonorsStudent newStudent = new HonorsStudent();
                        newStudent.ccriID = cboCCID.Text;
                        newStudent.name   = txtName.Text;
                        newStudent.age    = txtAge.Text;

                        if (cboRace.Text != "N/A")
                        {
                            newStudent.race = cboRace.Text;
                        }
                        else
                        {
                            newStudent.race = String.Empty;
                        }

                        if (cboGender.Text != "N/A")
                        {
                            newStudent.gender = cboGender.Text;
                        }
                        else
                        {
                            newStudent.gender = String.Empty;
                        }

                        if (cboFinancialAid.Text != "N/A")
                        {
                            newStudent.financialAid = cboFinancialAid.Text;
                        }
                        else
                        {
                            newStudent.financialAid = String.Empty;
                        }

                        if (cboFirstGen.Text != "N/A")
                        {
                            newStudent.firstGen = cboFirstGen.Text;
                        }
                        else
                        {
                            newStudent.firstGen = String.Empty;
                        }

                        if (cboAcademicStanding.Text != "N/A")
                        {
                            newStudent.academicStanding = cboAcademicStanding.Text;
                        }
                        else
                        {
                            newStudent.academicStanding = String.Empty;
                        }

                        newStudent.GPAint     = txtGPAinst.Text;
                        newStudent.GPAoverall = txtGPAoverall.Text;
                        newStudent.termHours  = txtTermHours.Text;
                        newStudent.readScore  = txtReadScore.Text;
                        if (chkReadDate.Checked)
                        {
                            newStudent.readTestDate = readDate.ToString("MM/dd/yyyy");
                        }
                        else
                        {
                            newStudent.readTestDate = String.Empty;
                        }
                        newStudent.mathScore = txtMathScore.Text;
                        if (chkMathDate.Checked)
                        {
                            newStudent.mathTestDate = mathDate.ToString("MM/dd/yyyy");
                        }
                        else
                        {
                            newStudent.mathTestDate = String.Empty;
                        }
                        newStudent.major       = txtMajor.Text;
                        newStudent.instructor  = txtInstructor.Text;
                        newStudent.department  = txtDepartment.Text;
                        newStudent.courseTitle = txtCourseTitle.Text;
                        newStudent.courseID    = txtCourseID.Text;
                        newStudent.grade       = txtGrade.Text;
                        newStudent.term        = txtTerm.Text;

                        studentDictionary.AddStudent(newStudent);
                        FillCombo();
                        ClearFields();
                        DeactivateUI();

                        btnAddStudent.Text = "Add Student";

                        btnAddStudent.Enabled    = true;
                        btnSaveStudent.Enabled   = false;
                        btnRemoveStudent.Enabled = true;
                        btnCancel.Enabled        = false;

                        btnSaveChanges.Enabled = true;
                        FillCombo();
                        btnAddStudent.Enabled = true;
                        btnLoadFile.Enabled   = true;
                    }
                    else
                    {
                        MessageBox.Show("Missing Name or CCRI ID", "Error");
                    }
                }
                catch
                {
                    MessageBox.Show("Duplicate Entry", "Error");
                }
            }
        }
Example #3
0
        public void ReadLoadedFile(HonorsStudentDictionary studentDictionary, StreamReader file)
        {
            StreamReader infile = file;

            char   delimiter = ',';
            string line;

            string[] fields;

            string id;
            bool   exists      = false;
            int    dupeCounter = 0;

            while (!infile.EndOfStream)
            {
                line   = infile.ReadLine();
                fields = line.Split(delimiter);
                foreach (HonorsStudent aStudent in studentDictionary.AllStudents)
                {
                    id = aStudent.ccriID;
                    if (fields[0] == aStudent.ccriID)
                    {
                        exists = true;
                    }
                }

                if (exists != true)
                {
                    HonorsStudent student = new HonorsStudent();
                    student.ccriID           = fields[0];
                    student.name             = fields[1];
                    student.termHours        = fields[2];
                    student.race             = fields[3];
                    student.GPAint           = fields[4];
                    student.GPAoverall       = fields[5];
                    student.age              = fields[6];
                    student.gender           = fields[7];
                    student.firstGen         = fields[8];
                    student.financialAid     = fields[9];
                    student.readScore        = fields[10];
                    student.readTestDate     = fields[11];
                    student.mathScore        = fields[12];
                    student.mathTestDate     = fields[13];
                    student.academicStanding = fields[14];
                    student.major            = fields[15];
                    student.courseID         = fields[16];
                    student.courseTitle      = fields[17];
                    student.grade            = fields[18];
                    student.instructor       = fields[19];
                    student.department       = fields[20];
                    if (fields.Length == 21)
                    {
                        student.term = string.Empty;
                    }
                    else if (fields.Length == 22)
                    {
                        student.term = fields[21];
                    }
                    studentDictionary.AddStudent(student);
                }
                else
                {
                    dupeCounter++;
                }

                exists = false;
            }

            if (dupeCounter > 0)
            {
                frmMain.showDupeNum(dupeCounter);
            }

            infile.Close();
        }
Example #4
0
 public void AddStudent(HonorsStudent student)
 {
     studentList.Add(student.ccriID, student);
 }