예제 #1
0
파일: Program.cs 프로젝트: ivdinkov/C-sharp
        // Overload
        // Collect and store user data in temp list
        private static List <Object> TempUserInfoHolder(Dictionary <string, string> fieldNames, int status)
        {
            // local variable to hold the new values
            var temp = CollegeLists.TempObjectList();


            foreach (KeyValuePair <string, string> kvp in fieldNames)
            {
                // Find what type of data we have to collect
                if (kvp.Value.Contains("integer"))
                {
                    // collect data => student status
                    temp.Add(status + 1);
                }
                else if (kvp.Value.Contains("decimal"))
                {
                    // collect data => salary
                    temp.Add(CollectDecimalData(kvp.Key));
                }
                else if (kvp.Value.Contains("id"))
                {
                    // GENERATE data => lecturerId/studentId
                    temp.Add(GenerateID(status + 1));
                }
                else
                {
                    // Normal string data
                    temp.Add(ReadInput(kvp.Key));
                }
            }
            return(temp);
        }
예제 #2
0
파일: Program.cs 프로젝트: ivdinkov/C-sharp
        // Create new student
        // account with data stored in PersonData
        private static void CreateNewStudentAccount(PersonData data)
        {
            Student student = new Student(data.Ppsn, data.Fname, data.Lname, data.Address, data.Phone, data.Email, data.Id, data.StudentStatus);
            // Run validation abd display errors
            ValidationContext context = new ValidationContext(student, null, null);
            var  result = CollegeLists.ValidationResultList();
            bool valid  = Validator.TryValidateObject(student, context, result, true);

            if (!valid)
            {
                foreach (ValidationResult x in result)
                {
                    Console.WriteLine(x.ErrorMessage);
                }
                Console.WriteLine("\nPlease try again. ");
                Console.WriteLine("\nPress enter key to continue..");
                Console.ReadLine();
                DisplayMainMenu();
            }
            else
            {
                AddNewAccountToList(student);
                DisplayMainMenu();
            };
        }
예제 #3
0
파일: Program.cs 프로젝트: ivdinkov/C-sharp
        // Prepare new lecturer Account
        public static void PrepareDataForNewLecturerAccount()
        {
            // Get all properties names and types
            // and use them to collect user info
            var fieldNames = CollegeLists.LecturerFields();


            // Create new PersonData object
            PersonData lecturer = new PersonData();


            // Collect user info => tempUserInfoHolder return list<Object>
            // and
            // Save list<Object> to struct PersonData
            lecturer.SetLecturerData(TempUserInfoHolder(fieldNames, STATUSLECTURER));


            // Check if collected PPSN exist in users list and reasign new one if true
            if (IsPpsnExistInList(lecturer.Ppsn))
            {
                do
                {
                    if (ReadInput("PPSN already exist do you want to enter a new one? Y/N ").ToUpper() == "N")
                    {
                        // Answer 'N', Drop the list and go to Main menu
                        DisplayMainMenu();
                        break;
                    }
                    string newPpsn = ReadInput("Enter new PPSN... ");
                    if (!IsPpsnExistInList(newPpsn))
                    {
                        lecturer.Ppsn = newPpsn;
                        break;
                    }
                } while (true);
            }


            // Everything is clear so we can
            // Create new Lecturer Account
            CreateNewLecturerAccount(lecturer);
        }
예제 #4
0
파일: Program.cs 프로젝트: ivdinkov/C-sharp
        // Collect and store
        // user data in temp list
        private static List <Object> TempUserInfoHolder(Dictionary <string, string> fieldNames)
        {
            // local variable to hold the new values
            var temp = CollegeLists.TempObjectList();

            // Read student status
            int status = ReadStudentStatus();

            foreach (KeyValuePair <string, string> kvp in fieldNames)
            {
                if (kvp.Value.Contains("decimal"))
                {
                    // collect data => salary
                    temp.Add(CollectDecimalData(kvp.Key));
                }
                else if (kvp.Value.Contains("id"))
                {
                    // GENERATE data => lecturerId/studentId
                    try
                    {
                        temp.Add(GenerateID(status + 1));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    // Normal string data
                    temp.Add(ReadInput(kvp.Key));
                }
            }
            temp.Add(status);
            return(temp);
        }