Пример #1
0
        public void addUser(string username, string password, string fname, string mname, string lname, string status, string filepath)
        {
            string fileLine = username.PadRight(11) + password.PadRight(11) + fname.PadRight(16) + mname.PadRight(16) + lname.PadRight(16) + status.PadRight(10);

            if (status == "admin")
            {
                admin newAdm = new admin(fname, mname, lname, username, password);
                adminLst.Add(newAdm);
            }
            else if (status == "faculty")
            {
                faculty newFac = new faculty(fname, mname, lname, username, password);
                facLst.Add(newFac);
            }
            else if (status == "manager")
            {
                manager newMan = new manager(fname, mname, lname, username, password);
                manLst.Add(newMan);
            }
            else
            {
                student newStd = new student(fname, mname, lname, status, username, password);
                stdLst.Add(newStd);
                foreach (faculty fac in facLst)
                {
                    if (newStd.advisor.Trim() == fac.username.Trim())
                    {
                        fac.addAdvisee(newStd);
                    }
                }
            }
        }
Пример #2
0
        // Construct the database and update it
        public userDatabase(string filepath)
        {
            stdLst   = new List <student>();
            facLst   = new List <faculty>();
            adminLst = new List <admin>();
            manLst   = new List <manager>();

            string line;

            System.IO.StreamReader input = new System.IO.StreamReader(filepath);
            while ((line = input.ReadLine()) != null)
            {
                string username   = line.Substring(0, 10).Trim().ToLower();
                string password   = line.Substring(11, 10).Trim();
                string firstName  = line.Substring(22, 10).Trim();
                string middleName = line.Substring(38, 15).Trim();
                string lastName   = line.Substring(54, 15).Trim();
                string status     = line.Substring(70).Trim().ToLower();

                if (status == "faculty")
                {
                    faculty fac = new faculty(firstName, middleName, lastName, username, password);
                    facLst.Add(fac);
                }
                else if (status == "admin")
                {
                    admin adm = new admin(firstName, middleName, lastName, username, password);
                    adminLst.Add(adm);
                }
                else if (status == "manager")
                {
                    manager man = new manager(firstName, middleName, lastName, username, password);
                    manLst.Add(man);
                }
                else
                {
                    student std = new student(firstName, middleName, lastName, status, username, password);
                    stdLst.Add(std);
                }
            }

            foreach (student std in stdLst)
            {
                for (int i = 0; i < facLst.Count(); i++)
                {
                    if (std.advisor == facLst[i].username)
                    {
                        facLst[i].addAdvisee(std);
                        break;
                    }
                }
            }
            input.Close();
        }