Пример #1
0
        /*
         * /// <summary>
         * /// Creates a random list of teachers and returns the result
         * /// </summary>
         * /// <param name="numberOfTeacher">An integer value</param>
         * /// <returns>An array of teachers</returns>
         * public static Teacher[] Create(int numberOfTeacher)
         * {
         *  List<Teacher> result = new List<Teacher>();
         *
         *  List<string> listOfField = FileHelper.GetListOfField();
         *  Random rnd = new Random();
         *
         *  for (uint i = 0; i < numberOfTeacher; i++)
         *  {
         *      //id
         *      String uuid = Guid.NewGuid().ToString();
         *
         *      //gender
         *      bool gender = rnd.Next(2) == 1;
         *
         *      //name
         *      string fullName = GenerateDataHelper.GetRandomNameByGender(gender);
         *
         *      //Field
         *      int index = rnd.Next(listOfField.Count);
         *      string[] fields = listOfField[index].Split(',');
         *      string field = fields[0].Trim();
         *
         *      result.Add(new Teacher(uuid, fullName, gender, field));
         *  }
         *  return result.ToArray();
         * }*/

        /// <summary>
        /// Creates a random list of teachers and returns the result
        /// </summary>
        /// <returns>An array of teachers</returns>
        public static Teacher[] Create()
        {
            List <Teacher> result = new List <Teacher>();

            Field[] listOfField = DataList.FieldList;
            Random  rnd         = new Random();

            while (true)
            {
                //id
                string uuid = Guid.NewGuid().ToString();

                //gender
                bool gender = rnd.Next(2) == 1;

                //name
                string fullName = GenerateDataHelper.GetRandomNameByGender(gender);

                //field
                int    index = rnd.Next(listOfField.Length);
                string field = listOfField[index].UUID;

                Teacher x = new Teacher(uuid, fullName, gender, field);
                result.Add(x);
                int num = Attendance.Create(uuid, field);
                if (num == 0)
                {
                    result.Remove(x);
                    break;
                }
            }
            return(result.ToArray());
        }
Пример #2
0
        /*
         * /// <summary>
         * /// Creates a random list of students and returns the result
         * /// </summary>
         * /// <param name="numberOfStudent">An integer value</param>
         * /// <returns>An array of students</returns>
         * public static Student[] Create(int numberOfStudent)
         * {
         *  List<Student> result = new List<Student>();
         *
         *  Random rnd = new Random();
         *
         *  List<string> listOfClasses = FileHelper.GetListOfClass();
         *
         *  int currentTotal = 0;
         *  int quantity;
         *  for (int i = 0; i < listOfClasses.Count; i++)
         *  {
         *      if (i == listOfClasses.Count)
         *      {
         *          quantity = numberOfStudent - currentTotal;
         *      }
         *      else
         *      {
         *          quantity = rnd.Next(30, 51);
         *      }
         *
         *      string[] classs = listOfClasses[i].Split(',');
         *      string classInfo = classs[0].Trim();
         *      string levelId = classs[1].Trim();
         *      string level = FileHelper.GetLevelByPrimaryKey(levelId).Split(',')[1];
         *
         *      for (int j = 0; j < quantity; j++)
         *      {
         *          //id
         *          string uuid = Guid.NewGuid().ToString();
         *
         *          //gender
         *          bool gender = rnd.Next(2) == 1;
         *
         *          //name
         *          string fullName = GenerateDataHelper.GetRandomNameByGender(gender);
         *
         *          //birthdate
         *          DateTime birthdate = GenerateDataHelper.GetRandomBirthdayByLevel(level);
         *
         *          result.Add(new Student(uuid, fullName, birthdate, gender, classInfo));
         *          currentTotal++;
         *      }
         *  }
         *  return result.ToArray();
         * }*/

        /// <summary>
        /// Creates a random list of students and returns the result
        /// </summary>
        /// <param name="numberOfStudent">An integer value</param>
        /// <returns>An array of students</returns>
        public static Student[] Create(int numberOfStudent)
        {
            List <Student> result = new List <Student>();

            Random rnd = new Random();

            Level[] listOfLevel     = DataList.LevelList;
            int     amountEachLevel = (int)Math.Ceiling((double)numberOfStudent / listOfLevel.Length) + 1;
            int     levelIndex      = 0;
            int     count           = 0;

            for (int i = 0; i < numberOfStudent; i++)
            {
                //id
                string uuid = Guid.NewGuid().ToString();

                //gender
                bool gender = rnd.Next(2) == 1;

                //name
                string fullName = GenerateDataHelper.GetRandomNameByGender(gender);

                //birthdate
                string   level     = listOfLevel[levelIndex].Name;
                DateTime birthdate = GenerateDataHelper.GetRandomBirthdayByLevel(level);

                result.Add(new Student(uuid, fullName, birthdate, gender, listOfLevel[levelIndex].UUID));
                if (count == amountEachLevel)
                {
                    levelIndex++;
                    amountEachLevel--;
                    count = 0;
                }
            }
            return(result.ToArray());
        }
Пример #3
0
        /// <summary>
        /// Show CLI message
        /// </summary>
        /// <param name="args">An array of strings</param>
        /// <returns>CLI message</returns>
        public static String ShowCLI(string[] args)
        {
            string helpString = @"  Help: 
./schoolDatabaseGenerator <<school_name>>: Generate a school database with number students in range 500 to 3000, and the largest number rooms is 100 
./schoolDatabaseGenerator <<school_name>> -s <<number_students>>: Generate a school database with <<number_students>> in range 500 to 3000 and the largest number rooms is 100 
./schoolDatabaseGenerator <<school_name>> -r <<number_rooms>>: Generate a school database with <<number_rooms>> and number students in range 500 to 3000.
./schoolDatabaseGenerator <<school_name>> -s <<number_students>> -r <<number_rooms>>: Generate a school database with <<number_students>> and <<number_rooms>>.";
            int    numberOfStudent = 0, numberOfRoom = 0;

            if ((args.Length == 0) || (args.Length == 1 && args[0].Equals("-h")))
            {
                return(helpString);
            }
            else if (args.Length > 0 && !args[0].Equals("-h") && (args[0].Equals("-s") || args[0].Equals("-r")))
            {
                return("Please input school name.");
            }
            else
            {
                _schoolName = args[0];
                int indexStudent = CheckContain(args, "-s");
                int indexRoom    = CheckContain(args, "-r");

                if (indexStudent != -1)
                {
                    if ((indexStudent + 1) == args.Length || !Int32.TryParse(args[indexStudent + 1], out numberOfStudent))
                    {
                        return("ERROR: Your CLI format is not correct.");
                    }
                    else
                    {
                        if (GenerateDataHelper.CheckStudentAmount(numberOfStudent) == -1)
                        {
                            return("ERROR: You must input number student in range 500 to 3000");
                        }
                    }
                }
                if (indexRoom != -1)
                {
                    if ((indexRoom + 1) == args.Length || !Int32.TryParse(args[indexRoom + 1], out numberOfRoom))
                    {
                        return("ERROR: Your CLI format is not correct.");
                    }
                    else
                    {
                        if (GenerateDataHelper.CheckRoomAmount(numberOfRoom) == -1)
                        {
                            return("ERROR: You must input number room smaller than 100");
                        }
                    }
                }
                if (numberOfStudent > 0 && numberOfRoom > 0)
                {
                    bool check = GenerateDataHelper.CheckValidNumber(numberOfStudent, numberOfRoom);
                    if (!check)
                    {
                        return("Error: Invalid number of student or room. (Each room can only contains 30-50 students)");
                    }
                }
            }
            _numberOfStudent = numberOfStudent;
            _numberOfRoom    = numberOfRoom;
            return("");
        }
Пример #4
0
        /// <summary>
        /// Performs functions.
        /// </summary>
        /// <param name="args">A string array contains command from command-line</param>
        public static void Main(string[] args)
        {
            m p1 = new m();

            p1.x = 100;
            p1.y = 100;
            m p2 = p1;

            p2.x = 900;
            Console.WriteLine("{0} {1}", p1.x, p2.x);
            Console.ReadLine();
            string info = CLIHelper.ShowCLI(args);

            if (info == "")
            {
                string schoolName = CLIHelper.SchoolName;
                int    student    = CLIHelper.NumberOfStudent;
                int    room       = CLIHelper.NumberOfRoom;
                School school     = new School(schoolName);
                //string directoryPath = @"..\..\..\" + schoolName;
                string directoryPath = schoolName;
                Directory.CreateDirectory(directoryPath);

                if (student == 0 && room == 0)
                {
                    student = GenerateDataHelper.GenerateRandomStudentAmount();
                    room    = GenerateDataHelper.GenerateRoomAmountByStudent(student);
                }
                else if (student == 0 && room > 0)
                {
                    student = GenerateDataHelper.GenerateStudentAmountByRoom(room);
                }
                else if (student > 0 && room == 0)
                {
                    room = GenerateDataHelper.GenerateRoomAmountByStudent(student);
                }

                DataList.CreateDataList(student, room);

                school.Level = DataList.LevelList.ToList();
                school.SaveLevel(directoryPath + "\\" + "Level.csv");

                school.Field = DataList.FieldList.ToList();
                school.SaveField(directoryPath + "\\" + "Field.csv");

                school.Room = DataList.RoomList.ToList();
                school.SaveRoom(directoryPath + "\\" + "Room.csv");

                school.Class = DataList.ClassList.ToList();
                school.SaveClass(directoryPath + "\\" + "Class.csv");

                school.Subject = DataList.SubjectList.ToList();
                school.SaveSubject(directoryPath + "\\" + "Subject.csv");

                school.Student = DataList.StudentList.ToList();
                school.SaveStudent(directoryPath + "\\" + "Student.csv");

                school.Teacher = DataList.TeacherList.ToList();
                school.SaveTeacher(directoryPath + "\\" + "Teacher.csv");

                school.Attendance = DataList.AttendanceList.ToList();
                school.SaveAttendance(directoryPath + "\\" + "Attendance.csv");

                school.Grade = DataList.GradeList.ToList();
                school.SaveGrade(directoryPath + "\\" + "Grade.csv");

                Console.WriteLine("Succesful: You have a new school database with " + student + " students and " + room + " rooms");

                school.SaveSchool(directoryPath + "\\" + schoolName + ".json");
            }
            else
            {
                Console.WriteLine(info);
            }
        }