Exemplo n.º 1
0
        /// <summary>
        /// Method Name: LoadContainer
        /// The function is called to populate the container object with the data from the database file
        /// </summary>
        /// <param name="fileName">the Name of the database file</param>
        /// <returns>A boolean indicating whether the operation was successful</returns>
        public bool LoadContainer()
        {
            bool result = true;

            string[] fileContents; // create string to hold file contents
            string[] input;
            Int32    validCount = 0;
            Int32    lineCount  = 0;
            Int32    entryCount = 0;
            Employee e          = new Employee();
            bool     duplicate  = false;

            fileContents = dbFile.dBaseOpen_R(); // fill the string with file contents
            container.Clear();
            Console.Clear();
            foreach (string s in fileContents)
            {
                lineCount++;
                if (s != "")
                {
                    input = s.Split('|');
                    if (s[0] == 'F')
                    {
                        entryCount++;
                        FulltimeEmployee f = new FulltimeEmployee();
                        if (!f.SetLastName(input[1]) || !f.SetFirstName(input[2]) || !f.SetSIN(input[3]) || !f.SetDOB(input[4]) || !f.SetDateOfHire(input[5]) || !f.SetDateOfTermination(input[6]) || !f.SetSalary(input[7]))
                        {
                            log.writeLog(f.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                            result = false;
                        }
                        else
                        {
                            foreach (Object o in container)
                            {
                                e = (Employee)o;
                                if (e.GetSIN() == f.GetSIN())
                                {
                                    duplicate = true;
                                }
                            }
                            if (duplicate == false)
                            {
                                container.Add(f);
                                validCount++;
                            }
                            else
                            {
                                log.writeLog(f.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                                duplicate = false;
                                result    = false;
                            }
                        }
                    }
                    else if (s[0] == 'P')
                    {
                        entryCount++;
                        ParttimeEmployee p = new ParttimeEmployee();
                        if (!p.SetLastName(input[1]) || !p.SetFirstName(input[2]) || !p.SetSIN(input[3]) || !p.SetDOB(input[4]) || !p.SetDateOfHire(input[5]) || !p.SetDateOfTermination(input[6]) || !p.SetHourlyRate(input[7]))
                        {
                            log.writeLog(p.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                            result = false;
                        }
                        else
                        {
                            foreach (Object o in container)
                            {
                                e = (Employee)o;
                                if (e.GetSIN() == p.GetSIN())
                                {
                                    duplicate = true;
                                }
                            }
                            if (duplicate == false)
                            {
                                container.Add(p);
                                validCount++;
                            }
                            else
                            {
                                log.writeLog(p.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                                duplicate = false;
                                result    = false;
                            }
                        }
                    }
                    else if (s[0] == 'C')
                    {
                        entryCount++;
                        ContractEmployee c = new ContractEmployee();
                        if (!c.SetLastName(input[1]) || !c.SetFirstName(input[2]) || !c.SetSIN(input[3]) || !c.SetDOB(input[4]) || !c.SetContractStartDate(input[5]) || !c.SetContractEndDate(input[6]) || !c.SetFixedContractAmt(input[7]))
                        {
                            log.writeLog(c.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                            result = false;
                        }
                        else
                        {
                            foreach (Object o in container)
                            {
                                e = (Employee)o;
                                if (e.GetSIN() == c.GetSIN())
                                {
                                    duplicate = true;
                                }
                            }
                            if (duplicate == false)
                            {
                                container.Add(c);
                                validCount++;
                            }
                            else
                            {
                                log.writeLog(c.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                                duplicate = false;
                                result    = false;
                            }
                        }
                    }
                    else if (s[0] == 'S')
                    {
                        entryCount++;
                        SeasonalEmployee n = new SeasonalEmployee();
                        if (!n.SetLastName(input[1]) || !n.SetFirstName(input[2]) || !n.SetSIN(input[3]) || !n.SetDOB(input[4]) || !n.SetSeason(input[5]) || !n.SetPiecePay(input[6]))
                        {
                            log.writeLog(n.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                            result = false;
                        }
                        else
                        {
                            foreach (Object o in container)
                            {
                                e = (Employee)o;
                                if (e.GetSIN() == n.GetSIN())
                                {
                                    duplicate = true;
                                }
                            }
                            if (duplicate == false)
                            {
                                container.Add(n);
                                validCount++;
                            }
                            else
                            {
                                log.writeLog(n.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                                duplicate = false;
                                result    = false;
                            }
                        }
                    }
                }
            }
            Console.WriteLine("\n\n>>>>>>>>>>>>>>>> TOTAL LINES READ           : " + lineCount);
            Console.WriteLine(">>>>>>>>>>>>>>>> TOTAL ENTRIES FOUND        : " + entryCount);
            Console.WriteLine(">>>>>>>>>>>>>>>> TOTAL VALID ENTRIES LOADED : " + validCount);
            return(result);
        }