C# - C Sharp: Students Management System

Các khóa học qua video:
Python SQL Server PHP C# Lập trình C Java HTML5-CSS3-JavaScript
Học trên YouTube <76K/tháng. Đăng ký Hội viên
Viết nhanh hơn - Học tốt hơn
Giải phóng thời gian, khai phóng năng lực

File IStudent.cs:

using System;

namespace Practical4_Exercise1
{
  interface IStudent
  {
    int ID
    {
      get;
      set;
    }

    string FullName
    {
      get;
      set;
    }

    DateTime DateofBirth
    {
      get;
      set;
    }

    string Native
    {
      get;
      set;
    }

    string Class
    {
      get;
      set;
    }

    string PhoneNo
    {
      get;
      set;
    }

    int Mobile
    {
      get;
      set;
    }

    void Display();
  }
}

File Student.cs:

using System;

namespace Practical4_Exercise1
{
  class Student : IStudent
  {
    string ClassName;
    public string Class
    {
      get
      {
        return ClassName;
      }
    
      set
      {
        ClassName = value;
      }
    }
  
    DateTime dateofBirth;
    public DateTime DateofBirth
    {
      get
      {
        return dateofBirth;
      }
    
      set
      {
        dateofBirth = value;
      }
    }
  
    string fullName;
    public string FullName
    {
      get
      {
        return fullName;
      }
    
      set
      {
        fullName = value;
      }
    }
  
    int id;
    public int ID
    {
      get
      {
        return id;
      }
    
      set
      {
        id = value;
      }
    }
  
    int mobile;
    public int Mobile
    {
      get
      {
        return mobile;
      }
    
      set
      {
        mobile = value;
      }
    }
  
    string native;
    public string Native
    {
      get
      {
        return native;
      }
    
      set
      {
        native = value;
      }
    }
  
    string phoneNo;
    public string PhoneNo
    {
      get
      {
        return phoneNo;
      }
    
      set
      {
        phoneNo = value;
      }
    }
  
    public void Display()
    {
      Console.WriteLine("Full Name: " + FullName);
      Console.WriteLine("Date of Birth: " + DateofBirth.ToString("dd/MM/yyyy"));
      Console.WriteLine("Native: " + Native);
      Console.WriteLine("Class: " + Class);
      Console.WriteLine("Phone No : " + PhoneNo);
      Console.WriteLine("Mobile : " + Mobile);
    }
  }
}

File Program.cs có chứa phương thức main():

using System;
using System.Collections.Generic;

namespace Practical4_Exercise1
{
  class Program
  {
    static Dictionary<int, Student> listDictionary = new Dictionary<int, Student>();
    static void Main(string[] args)
    {
      while (true)
      {
        Console.WriteLine("+----------------------------+");
        Console.WriteLine("| STUDENTS MANAGEMENT SYSTEM |");
        Console.WriteLine("+----------------------------+");
        Console.WriteLine("|1. Insert new Student       |");
        Console.WriteLine("|2. View list of Students    |");
        Console.WriteLine("|3. Search Students          |");
        Console.WriteLine("|4. Exit                     |");
        Console.WriteLine("+----------------------------+");
        Console.Write("Your choice: ");
        int choice = int.Parse(Console.ReadLine());
        switch (choice)
        {
          case 1:
            InsertStudent();
            break;
          case 2:
            ViewList();
            break;
          case 3:
            Search();
            break;
          case 4:
            return;
        }
      }
    }
  
    private static void Search()
    {
      bool found = false;
      Console.Write("Input Class: ");
      String search = Console.ReadLine();
      Console.WriteLine("All student of class " + search);
      foreach (Student student in listDictionary.Values)
      {
        if(student.Class.Equals(search))
        //if (String.Compare(student.Class, search, true) == 0)
        {
          Console.WriteLine("----------------------------");
          student.Display();
          found = true;
        }
      }
      if (!found)
      {
        Console.WriteLine("No students were found!");
      }
    }
  
    private static void ViewList()
    {
      foreach (Student i in listDictionary.Values)
      {
        Console.WriteLine("----------------------------");
        i.Display();
      }
    }
  
    private static void InsertStudent()
    {
      Student student = new Student();
  
      //Increament ID
      student.ID = listDictionary.Count + 1;
  
      //Input name
      Console.Write("Enter Fullname: ");
      student.FullName = Console.ReadLine();
  
      //Input date
      while (true)
      {
        Console.Write("Enter Date of Birth: ");
        DateTime dDate;
        try
        {
          student.DateofBirth = DateTime.Parse(Console.ReadLine());
          break;
        }catch(Exception ex)
        {
          Console.WriteLine("The date is not in the correct format!");
          Console.WriteLine(ex.Message);
        }
      }
  
      //Input Native
      Console.Write("Enter Native: ");
      student.Native = Console.ReadLine();
  
      //Input Class
      Console.Write("Enter Class: ");
      student.Class = Console.ReadLine();
  
      //Input Phone No
      Console.Write("Enter Phone No: ");
      student.PhoneNo = Console.ReadLine();
  
      //Input Mobile
      while (true) {
        Console.Write("Enter Mobile: ");
        try
        {
          student.Mobile = int.Parse(Console.ReadLine());
          break;
        }catch(Exception ex)
        {
          Console.WriteLine("The number is not in the correct format!");
          Console.WriteLine(ex.Message);
        }
      }
  
      listDictionary.Add(student.ID, student);
      Console.WriteLine("Successfully inserted a student!");
    }
  }
}
» Tiếp: Football Management System
« Trước: News Management System
Các khóa học qua video:
Python SQL Server PHP C# Lập trình C Java HTML5-CSS3-JavaScript
Học trên YouTube <76K/tháng. Đăng ký Hội viên
Viết nhanh hơn - Học tốt hơn
Giải phóng thời gian, khai phóng năng lực
Copied !!!