/// <summary>
        /// Initializes the only instance of this class.
        /// If the file already exists, it loads the data from file, if not, it creates a file.
        /// </summary>
        /// <param name="folderName">The folder name ("myfolder")</param>
        /// <param name="fileName">The file name ("myfile.txt")</param>
        /// <returns>Returns the only instance of this class.</returns>
        public static ApplicantDatabase InitializeDatabase(string folderName, string fileName)
        {
            if (_instance == null)
            {
                _instance = new ApplicantDatabase();
            }

            Path = folderName + "\\" + fileName;

            try
            {
                if (File.Exists(Path))
                {
                    _instance = LoadFromFile(Path);
                }
                else
                {
                    Database.CreateDatabase(folderName);
                    Database.CreateTable(Path);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            FileName   = fileName;
            FolderName = folderName;
            return(_instance);
        }
Пример #2
0
        /// <summary>
        /// Deletes a database.
        /// It sets the only instance to null.
        /// </summary>
        public void DeleteDatabase()
        {
            Debug.Assert(FolderName != null);
            Database.DeleteDatabase(FolderName);

            _instance = null;
        }
        /// <summary>
        /// It loads the database from file.
        /// </summary>
        /// <param name="fileName">The file from which to load the database.</param>
        /// <returns>Returns an Applicant Database</returns>
        public static ApplicantDatabase LoadFromFile(string fileName)
        {
            string            line;
            Applicant         applicant;
            ApplicantDatabase applicantDatabase = new ApplicantDatabase();

            StreamReader file = new StreamReader(fileName);

            while ((line = file.ReadLine()) != null)
            {
                applicant = new Applicant(line);
                applicantDatabase.ApplicantList.Add(applicant);
            }

            file.Close();
            return(applicantDatabase);
        }
Пример #4
0
        private void publishResults_Click(object sender, EventArgs e)
        {
            IApplicantDatabase appDatabase = ApplicantDatabase.InitializeDatabase("applicantTable.txt");

            TestPopulateDatabase(appDatabase);

            List <Applicant> listApplicants = appDatabase.SelectAllRecords();

            SortedList listApplicantsSortedByGrade = new SortedList();

            for (int iApp = 0; iApp < listApplicants.Count; iApp++)
            {
                Applicant applicant = listApplicants[iApp];

                double avgPonderateGrade = (applicant.BacGrade + applicant.InfoGrade + applicant.MathGrade) / 3;

                listApplicantsSortedByGrade.Add(avgPonderateGrade, applicant);
            }

            WriteResultsToPdfFile(listApplicantsSortedByGrade);
        }
        /// <summary>
        /// Deletes a database.
        /// It sets the only instance to null.
        /// </summary>
        public void DeleteDatabase()
        {
            Database.DeleteDatabase(FolderName);

            _instance = null;
        }