public UserControlChangeInfo() { InitializeComponent(); dbStudent = new DBStudent(); dtpBirthday.CustomFormat = "dd-MM-yyyy"; // định dạng ngày tháng dtpBirthday.Format = DateTimePickerFormat.Custom; }
private void UserControlStudent_Load(object sender, EventArgs e) { dbStudent = new DBStudent(); // khởi tạo lớp BAL LoadListStudent(); // load danh sách học sinh dtgvStudent.DataSource = studentList; // đẩy source vào cho datagridview }
public void ShowPersonalMessage(int id) { ICollection <Student> students = DBStudent.ReadStudents(); Student s = students.Where(st => st.Id == id).First(); ConsoleUI.ShowLine($"Hello {s.FirstName} {s.LastName}"); }
public static bool IsEmptyDB() { int UserSize = DBUser.ReadUsers().Count(); int AssignmentSize = DBAssignment.ReadAssignments().Count(); int StudentSize = DBStudent.ReadStudents().Count(); int CourseSize = DBCourse.ReadCourses().Count(); int TrainerSize = DBTrainer.ReadTrainers().Count(); bool basicEntities = UserSize == 0 && AssignmentSize == 0 && StudentSize == 0 && CourseSize == 0 && TrainerSize == 0; return(basicEntities); }
public void Read() { ICollection <Student> students = DBStudent.ReadStudents(); if (students.Count() == 0) { ConsoleUI.ShowLine("No students yet"); } else { foreach (Student s in students) { ConsoleUI.ShowLine(s); } } ConsoleUI.ReadKey(); ConsoleUI.Clear(); }
public UserControlRegister() { InitializeComponent(); // khởi tạo ban đầu cho quá trình đăng ký db = new DBStudent(); dbClassType = new DBClassType(); dtpBirthday.CustomFormat = "dd-MM-yyyy"; // custom kiểu hiện thị của DateTime dtpBirthday.Format = DateTimePickerFormat.Custom; dtpInputExamDate.CustomFormat = "dd-MM-yyyy"; dtpInputExamDate.Format = DateTimePickerFormat.Custom; rdNam.Checked = true; rdNu.Checked = false; cbStudyingTime.SelectedItem = cbStudyingTime.Items[0]; cbDateFirst.SelectedItem = cbDateFirst.Items[0]; cbDateSecond.SelectedItem = cbDateSecond.Items[0]; cbClassType.DataSource = dbClassType.GetListClassType(); // load danh sách loại lớp vào combo box cbClassType.DisplayMember = "ClassType_Name"; // lấy tên hiển thị //btnPrint.Enabled = false; }
public IActionResult Create([Bind("Student_ID,Student_Email,Student_FirstName,Student_LastName,Student_UniversityNumber,Student_ContactNumber,Student_Password,confirmPassword,University_Name,Campus_Name")] StudentRegister uc) { DBStudent cur = new DBStudent(); cur.Student_ID = uc.Student_ID; cur.Student_FirstName = uc.Student_FirstName; cur.Student_LastName = uc.Student_LastName; cur.Student_Password = uc.Student_Password; cur.Student_UniversityNumber = uc.Student_UniversityNumber; cur.Student_Email = uc.Student_Email; cur.Campus_ID = 1; cur.Student_ContactNumber = uc.Student_ContactNumber; try { _auc.Add(cur); _auc.SaveChanges(); ViewBag.message = "You have successfully registered"; return(View()); } catch (Exception e) { return(Index()); } }
public UserControlProcessView() { InitializeComponent(); dbStudent = new DBStudent(); }
public static void AutoGenerate() { ConsoleUI.ShowLine("Creating headmaster with username: '******' and password: '******'"); string encryptedPassword = CryptoManager.EncryptPassword("12345", out string encryptedSalt); try { int headMasterSaved = DBUser.CreateUser("hm", encryptedPassword, encryptedSalt, "headmaster", out int id); if (headMasterSaved == 0) { throw new Exception("head master NOT saved"); } } catch (Exception e) { ConsoleUI.ShowLine(e.Message); ConsoleUI.ReadKey(); return; } ConsoleUI.ShowLine("head master created"); ConsoleUI.ShowLine("creating students"); List <int> studentIDs = new List <int>(); List <int> trainerIDs = new List <int>(); List <int> assignmentIDs = new List <int>(); List <int> courseIDs = new List <int>(); int studentID; string studentUsername; string plainTextPassword; string studentFName; string studentLName; // 3 students for (int i = 0; i < 3; i++) { studentUsername = "******" + i; plainTextPassword = "******" + i; encryptedPassword = CryptoManager.EncryptPassword(plainTextPassword, out encryptedSalt); DBUser.CreateUser(studentUsername, encryptedPassword, encryptedSalt, "student", out studentID); ConsoleUI.ShowLine($"student user created u:{studentUsername} p:{plainTextPassword}"); studentFName = "studentFirstName" + i; studentLName = "studentLastName" + i; DBStudent.CreateStudent(studentFName, studentLName, new DateTime(2000, 1, 1), 20000, studentID); ConsoleUI.ShowLine($"student {studentFName} {studentLName} created"); studentIDs.Add(studentID); ConsoleUI.ChangeLine(); } int trainerID; string trainerUsername; string trainerFName; string trainerLName; string trainerSubject; // 2 trainers for (int i = 0; i < 2; i++) { trainerUsername = "******" + i; plainTextPassword = "******" + i; encryptedPassword = CryptoManager.EncryptPassword(plainTextPassword, out encryptedSalt); DBUser.CreateUser(trainerUsername, encryptedPassword, encryptedSalt, "trainer", out trainerID); ConsoleUI.ShowLine($"trainer user created u:{trainerUsername} p:{plainTextPassword}"); trainerFName = "trainerFirstName" + i; trainerLName = "trainerLastName" + i; trainerSubject = "trainerSubject" + i; DBTrainer.CreateTrainer(trainerFName, trainerLName, trainerSubject, trainerID); ConsoleUI.ShowLine($"trainer {trainerFName} {trainerLName} created"); trainerIDs.Add(trainerID); ConsoleUI.ChangeLine(); } string title; string description; // 2 assignments for (int i = 0; i < 2; i++) { title = "assignmentTitle" + i; description = "assignmentDescription" + i; DBAssignment.CreateAssignment(title, description, new DateTime(2019, 1, 1), 100, 100, out int assignmentID); assignmentIDs.Add(assignmentID); ConsoleUI.ShowLine($"assignment {title} with id: {assignmentID} created"); ConsoleUI.ChangeLine(); } // 3 courses for (int i = 0; i < 3; i++) { title = "courseTitle" + i; DBCourse.CreateCourse(title, "C#", "Full time", new DateTime(2019, 1, 1), new DateTime(2019, 2, 2), out int courseID); courseIDs.Add(courseID); ConsoleUI.ShowLine($"course {title} with id: {courseID} created"); ConsoleUI.ChangeLine(); } AssignmentPerStudentManager a = new AssignmentPerStudentManager(); //assignments-courses //all assignments to course 1 #region DBAssignmentsPerCourse.CreateAssignmentPerCourse(assignmentIDs[0], courseIDs[0]); a.CreateFromNewAssignment(assignmentIDs[0], courseIDs[0]); DBAssignmentsPerCourse.CreateAssignmentPerCourse(assignmentIDs[1], courseIDs[0]); a.CreateFromNewAssignment(assignmentIDs[1], courseIDs[0]); #endregion //first 3 assignments to course 1 #region DBAssignmentsPerCourse.CreateAssignmentPerCourse(assignmentIDs[0], courseIDs[1]); a.CreateFromNewAssignment(assignmentIDs[0], courseIDs[1]); DBAssignmentsPerCourse.CreateAssignmentPerCourse(assignmentIDs[1], courseIDs[1]); a.CreateFromNewAssignment(assignmentIDs[1], courseIDs[1]); #endregion //student courses //all students to course 1 #region DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[0], courseIDs[0]); a.CreateFromNewStudent(studentIDs[0], courseIDs[0]); DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[1], courseIDs[0]); a.CreateFromNewStudent(studentIDs[1], courseIDs[0]); DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[2], courseIDs[0]); a.CreateFromNewStudent(studentIDs[2], courseIDs[0]); #endregion // 2 students to course 2 #region DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[0], courseIDs[1]); a.CreateFromNewStudent(studentIDs[0], courseIDs[1]); DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[1], courseIDs[1]); a.CreateFromNewStudent(studentIDs[1], courseIDs[1]); #endregion // 2 courses to student 1 #region DBStudentsPerCourse.CreateStudentPerCourse(studentIDs[0], courseIDs[2]); a.CreateFromNewStudent(studentIDs[0], courseIDs[2]); #endregion //trainer courses //all trainers to course 1 #region DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[0], courseIDs[0]); DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[1], courseIDs[0]); #endregion // 2 trainers to course 2 #region DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[0], courseIDs[1]); DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[1], courseIDs[1]); #endregion //2 courses to trainer 1 #region DBTrainersPerCourse.CreateTrainerPerCourse(trainerIDs[0], courseIDs[2]); #endregion ConsoleUI.ShowLine("done"); }
public void Delete() { bool exit; ICollection <Student> students = DBStudent.ReadStudents(); if (students.Count() == 0) { ConsoleUI.ShowLine("No students yet"); ConsoleUI.ReadKey(); ConsoleUI.Clear(); return; } else { ConsoleUI.ShowLine("select student to delete, type 0 to exit"); foreach (Student s in students) { ConsoleUI.ShowLine(s); } } exit = ConsoleUI.GetInt(out int StudentID, "give student id: "); if (exit) { return; } Student student; try { student = students.Where(s => s.Id == StudentID).First(); } catch (Exception) { ConsoleUI.ShowLine($"NO STUDENT FOUND WITH ID: {StudentID}"); ConsoleUI.ReadKey(); return; } bool confirmed = ConsoleUI.GetConfirmation($"are you sure you want to delete student {student.FirstName} {student.LastName}? [y/n]: "); int result = 0; if (confirmed) { try { result = DBStudent.DeleteStudent(StudentID); if (result == 0) { throw new Exception("could NOT delete student"); } } catch (Exception e) { ConsoleUI.ShowLine(e.Message); ConsoleUI.ReadKey(); return; } try { result = DBUser.DeleteUser(StudentID); if (result == 0) { throw new Exception("could NOT delete user"); } } catch (Exception e) { ConsoleUI.ShowLine(e.Message); ConsoleUI.ReadKey(); return; } ConsoleUI.ShowLine("student deleted successfully"); ConsoleUI.ReadKey(); } }
public void Create() { bool exit; while (true) { ConsoleUI.Clear(); string baseMessage = "type student's information or type 0 to exit \n"; exit = ConsoleUI.GetString(out string username, $"{baseMessage}Student's username: "******"{baseMessage}Student's password: "******"{baseMessage}Student's first name: "); if (exit) { return; } exit = ConsoleUI.GetString(out string lname, $"{baseMessage}Student's last name: "); if (exit) { return; } exit = ConsoleUI.GetDate(out DateTime? dob, "Student's date of birth:\n"); if (exit) { return; } exit = ConsoleUI.GetDecimal(out decimal fees, "Student's fees: "); if (exit) { return; } int studentID; string encryptedPassword = CryptoManager.EncryptPassword(password, out string encryptedSalt); try { int userSaved = DBUser.CreateUser(username, encryptedPassword, encryptedSalt, "student", out studentID); if (userSaved == 0) { throw new Exception("user NOT saved"); } } catch (Exception e) { ConsoleUI.ShowLine(e.Message); ConsoleUI.ReadKey(); return; } ConsoleUI.ShowLine($"user {username} saved"); try { int studentSaved = DBStudent.CreateStudent(fname, lname, (DateTime)dob, fees, studentID); if (studentSaved == 0) { throw new Exception("student NOT saved"); } } catch (Exception e) { ConsoleUI.ShowLine(e.Message); ConsoleUI.ReadKey(); return; } ConsoleUI.ShowLine("student created"); ConsoleUI.ReadKey(); } }
public void Update() { bool exit; ICollection <Student> students = DBStudent.ReadStudents(); if (students.Count() == 0) { ConsoleUI.ShowLine("No students yet"); ConsoleUI.ReadKey(); ConsoleUI.Clear(); return; } else { ConsoleUI.ShowLine("select student to update, type 0 to exit"); foreach (Student s in students) { ConsoleUI.ShowLine(s); } } exit = ConsoleUI.GetInt(out int StudentID, "give student id: "); if (exit) { return; } ConsoleUI.Clear(); Student student; try { student = students.Where(s => s.Id == StudentID).First(); } catch (Exception) { ConsoleUI.ShowLine($"NO STUDENT FOUND WITH ID: {StudentID}"); ConsoleUI.ReadKey(); return; } ConsoleUI.ShowLine($"you selected to edit student: {student.FirstName} {student.LastName}"); ConsoleUI.ShowLine($"select attribute to edit, type 0 anytime to exit"); ConsoleUI.ShowLine("1. Username"); ConsoleUI.ShowLine("2. Password"); ConsoleUI.ShowLine("3. First name"); ConsoleUI.ShowLine("4. Last name"); ConsoleUI.ShowLine("5. Date of birth"); ConsoleUI.ShowLine("6. Fees"); exit = ConsoleUI.GetInt(out int choice); if (exit) { return; } ConsoleUI.Clear(); Object attribute; if (choice == 1 || choice == 2) { attribute = (UserAttributes)choice; } else { attribute = (StudentAttributes)choice; } string newInput = ""; DateTime?newDate; decimal newFees; int result = 0; try { switch (attribute) { case StudentAttributes.Fname: exit = ConsoleUI.GetString(out newInput, "enter new first name: "); if (exit) { return; } result = DBStudent.UpdateStudent(StudentID, attribute, newInput); if (result == 0) { throw new Exception("student NOT updated"); } break; case StudentAttributes.Lname: exit = ConsoleUI.GetString(out newInput, "enter new last name: "); if (exit) { return; } result = DBStudent.UpdateStudent(StudentID, attribute, newInput); if (result == 0) { throw new Exception("student NOT updated"); } break; case StudentAttributes.DOB: exit = ConsoleUI.GetDate(out newDate, "enter new date of birth: "); if (exit) { return; } result = DBStudent.UpdateStudent(StudentID, attribute, newDate); if (result == 0) { throw new Exception("student NOT updated"); } break; case StudentAttributes.Fees: exit = ConsoleUI.GetDecimal(out newFees, "enter new fees: "); if (exit) { return; } result = DBStudent.UpdateStudent(StudentID, attribute, newFees); if (result == 0) { throw new Exception("student NOT updated"); } break; case UserAttributes.Username: exit = ConsoleUI.GetString(out newInput, "enter new username: "******"user NOT updated"); } break; case UserAttributes.Password: exit = ConsoleUI.GetString(out newInput, "enter new password: "******"user NOT updated"); } break; default: break; } } catch (Exception e) { ConsoleUI.ShowLine(e.Message); } ConsoleUI.ShowLine("student updated successfully"); ConsoleUI.ReadKey(); }