Exemple #1
0
        private void appendFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string _appendFileName = ofd.FileName;
                System.IO.StreamReader streamReader = new System.IO.StreamReader(_appendFileName);

                if (streamReader.ReadLine() != "--university database--")
                {
                    MessageBox.Show("Invalid file, please choose a university database file.");
                    return;
                }

                string line = "";
                while (streamReader.Peek() >= 0)
                {
                    line = streamReader.ReadLine();
                    string[] temp = line.Split('_');

                    //add paper or student to university object base on line header
                    if (temp[0] == "paper")
                    {
                        var      paper  = new EnrolmentSystemModel.Paper(temp[1], temp[2], temp[3]);
                        string[] member = streamReader.ReadLine().Split('_');
                        for (int i = 1; i < member.Length; i++)
                        {
                            if (member[i] != null && member[i] != "")
                            {
                                paper.AddStudent(member[i]);
                            }
                        }
                        _university.AddPaper(paper);
                    }
                    else if (temp[0] == "student")
                    {
                        var student = new EnrolmentSystemModel.Student(temp[1], temp[2], temp[3], temp[4]);
                        _university.AddStudent(student);
                    }
                    else
                    {
                        continue;
                    }
                }
            }

            PaperListInitiate();
            StudentListInitiate();
        }
Exemple #2
0
        private bool UniversityInitiate(string filename)
        {
            _university = new EnrolmentSystemModel.University();
            System.IO.StreamReader streamReader = new System.IO.StreamReader(filename);

            if (streamReader.ReadLine() != "--university database--")
            {
                MessageBox.Show("Invalid file, please choose a university database file.");
                return(false);
            }

            string line = "";

            while (streamReader.Peek() >= 0)
            {
                line = streamReader.ReadLine();
                string[] temp = line.Split('_');

                //add paper or student to university object base on line header
                if (temp[0] == "paper")
                {
                    var      paper  = new EnrolmentSystemModel.Paper(temp[1], temp[2], temp[3]);
                    string[] member = streamReader.ReadLine().Split('_');
                    for (int i = 1; i < member.Length; i++)
                    {
                        if (member[i] != null && member[i] != "")
                        {
                            paper.AddStudent(member[i]);
                        }
                    }
                    _university.AddPaper(paper);
                }
                else if (temp[0] == "student")
                {
                    var student = new EnrolmentSystemModel.Student(temp[1], temp[2], temp[3], temp[4]);
                    _university.AddStudent(student);
                }
                else
                {
                    continue;
                }
            }

            streamReader.Close();
            return(true);
        }