Mục Lục
Mục Lục
Giáo Trình Học EBook - Tài Liệu Học Lập Trình C Sharp Kiến Thức Căn Bản - Khai Báo Biến, Toán Tử, Mệnh Đề Điều Kiện, Lặp Video Giới thiệu về ngôn ngữ lập trình C# & .NET Framework + Khai báo biến trong C# Video Hướng dẫn tìm hiểu biến + toán tử trong lập trình C# Video Hướng dẫn tìm hiểu mệnh đề điều kiện if - else - switch trong C# In dãy Fibonacci trong C# - Tìm dãy số Fibonacci - Lập trình C# - Loop trong C# Giải phương trình bậc 2 - Lập Trình C# - Mệnh đề điều kiên if else trong # Viêt chương trình cho FlowChart - Lập trình C# - Tìm hiểu if else trong C# Hiển thị hình tam giác - Lập trình C# - Loop trong C# Viết chương trình ax + b = 0 bằng C#, C Sharp Xây dựng dự án Hello World trong C# - C Sharp Nhập và hiển thị thông tin sinh viên - Console trong C# Tìm dãy số nguyên tố - Lập trình C# - Loop trong C# Video Tìm dãy số nguyên tố - Lập trình C# - Loop trong C# In dãy số chẵn & lẻ từ mảng số nguyên - Lập trình C# - Loop trong C# Video In dãy số chẵn & lẻ từ mảng số nguyên - Lập trình C# - Loop trong C# Array trong C Sharp Video Array C# - Hướng dẫn tìm hiểu Array trong C#. C Sharp, Lập Trình C#, Lập Trình C Sharp Tính tổng số chắc & Tổng số lẻ trong chuỗi - Lập Trình C# - Array Trong C# OOP - Tính Chất Đóng Gói & Kế Thừa Video Học lập trình OOP C# - Tính chất đóng gói C# - Qua ví dụ quản lý sinh viên - Lập trình C# Bài 1: Chương trình quản lý sản phẩm - Lập Trình C# - Lập Trình C Sharp - Làm quen OOP Bài 2: Chương trình quản lý sản phẩm - Product - Lập Trình C# - Lập Trình C Sharp Chương trình quản lý công nhân - Lập Trình C# - Lập Trình C Sharp - Làm quen OOP Chương trình quản lý sách - Develop Book Project - Lập Trình C# - OOP trong C# - C Sharp Video Chương trình quản lý sách - Develop Book Project - Lập Trình C# - OOP trong C# - C Sharp - C2010G OOP - Tính Chất Đa Hình & Trừu Tượng & Interface Ôn tập OOP - Table - Trong C# - Lập Trình C# - Lập Trình C Sharp Chường trình quản lý sở thú - Lập trình C# - Lập trình C Sharp Bài tập ôn luyện OOP + Interface trong C# - Lập Trình C# - Lập Trình C Sharp Kiểm tra 30 phút - Chương trình quản lý thiết bị phòng lab cho trường học - Lập trình C# - Khoá học lập trình C Sharp Chương trình quản lý khách sạn - Develop Hotel Project - Lập Trình C# - Lập Trình C Sharp Video Chương trình quản lý khách sạn - Develop Hotel Project - Lập Trình C# - Lập Trình C Sharp Namespace & Delegate & Event Viết chương trình quản lý sinh viên + delegate & event trong C# - Lập Trình C# - Lập Trình C Sharp Examination & Test - Lập trình C# - Lập trình C Sharp Bài tập - Xây dựng chương trình quản lý sức khoẻ - Lập trình C# Viết chương trình quản lý tiêm chủng Vacxin COVID-19 - Lập trình C Sharp nâng cao. JSON & Extension - Partial - Type Anonymous Chương trình quản lý sinh viên C# + Import/Export JSON + File - Lập Trình C# - Lập Trình C Sharp Video Chương trình quản lý sinh viên C# + Import/Export JSON + File - Lập Trình C# - Lập Trình C Sharp Chương trình nhập xuất dữ liệu điểm thi - Lập Trình C# - Lập Trình C Sharp - Làm quen OOP Bài tập C Sharp - Chương trình quản lý cán bộ C# - C Sharp Kết Nối CSDL - C Sharp Video Quản lý sinh viên C# - Kết nối CSDL C# - Kết nối database C# Chương trình quản lý sách C# - Book project C# - CSDL Tools Import/Export JSON into Database C# - Nhập xuất JSON File vào CSDL C# - Quản lý sinh viên C# Bài tập - Viết chương trình quản lý nhập kho máy tính cho thegioididong.com C Sharp - Lập trình C Sharp Ôn Tập Tổng Quát Bài tập - Chương trình quản lý Mèo C# (C Sharp) | Chương trình quản lý Cat C# (C Sharp) Bài tập - Quản lý điểm thi Aptech bằng C# - Lập trình C Sharp [Examination] C# - Chương trình quản lý đội thi TechWiz toàn cầu Aptech Ấn Độ - C# Bài Tập - Quản lý nhà - Lập trình C# | C Sharp Bài tập - Quản lý rạp chiều phim C# - Lập trình C# Viết chương trình quản lý xe car bằng C # - C Sharp | Khoá học lập trình C# [Assignment] Bài tập ôn luyên tổng quát C# - Lập Trình C# - Lập Trình C Sharp 1000 Bài tập lập trình C# - Lập trình C# - Lập Trình C Sharp Ôn tập OOP - Table - Trong C# - Lập Trình C# - Lập Trình C Sharp
C Sharp Tutorial

[Video] Thêm chức năng mới : Chương trình quản lý sinh viên C# + Import/Export JSON + File - Lập Trình C# - Lập Trình C Sharp - C2009G


Link Video Bài Giảng

Chương trình quản lý sinh viên C# + Import/Export JSON + File - Lập Trình C# - Lập Trình C Sharp


#Program.cs


using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace BT1536
{
    delegate void SwitchCase();

    class Program
    {
        static List<ClassRoom> classList;

        static void Main(string[] args)
        {
            classList = new List<ClassRoom>();

            SwitchCase[] options = {Input, Display, SaveFileText, ReadFileText,
                SaveFileObject, ReadFileObject, SaveFileJson,
                ReadFileJson, ExitProgram};

            int choose;

            do
            {
                ShowMenu();
                choose = int.Parse(Console.ReadLine());

                if(choose > 0 && choose <= options.Length)
                {
                    options[choose - 1]();
                } else
                {
                    Console.WriteLine("Nhap lai!!!");
                }
            } while (choose != 9);
        }

        private static void Input()
        {
            Console.WriteLine("Nhap so lop hoc can them: ");
            int N = int.Parse(Console.ReadLine());

            for(int i=0;i<N;i++)
            {
                ClassRoom @class = new ClassRoom();
                @class.Input();

                classList.Add(@class);
            }
        }

        private static void Display()
        {
            Console.WriteLine("Thong tin lop hoc");
            foreach(ClassRoom @class in classList)
            {
                @class.Display();
            }
        }

        private static void SaveFileText()
        {
            //Dinh danh du lieu se luu trong students.txt
            string content = "";
            foreach(ClassRoom @class in classList)
            {
                content += @class.GetFileLine();
            }

            File.WriteAllText(@"students.txt", content);
        }

        private static void ReadFileText()
        {
            string content = File.ReadAllText(@"students.txt");
            string[] lines = content.Split("\n");

            ClassRoom currentClassRoom = null;

            foreach(string line in lines)
            {
                if (line == "") continue;
                string[] elements = line.Split(":");
                switch(elements[0])
                {
                    case "class":
                        currentClassRoom = new ClassRoom();
                        currentClassRoom.Parse(elements[1]);

                        classList.Add(currentClassRoom);
                        break;
                    case "student":
                        Student student = new Student();
                        student.Parse(elements[1]);

                        if(currentClassRoom != null)
                        {
                            currentClassRoom.StudentList.Add(student);
                        }
                        break;
                }
            }

            Display();
        }

        private static void SaveFileObject()
        {
            //serialize
            using (Stream stream = File.Open(@"students.dat", FileMode.Create))
            {
                var bformatter = new BinaryFormatter();

                bformatter.Serialize(stream, classList);
            }
        }

        private static void ReadFileObject()
        {
            //deserialize
            using (Stream stream = File.Open(@"students.dat", FileMode.Open))
            {
                var bformatter = new BinaryFormatter();

                List<ClassRoom> list = (List<ClassRoom>)bformatter.Deserialize(stream);

                foreach(ClassRoom @class in list)
                {
                    classList.Add(@class);
                }
            }

            Display();
        }

        private static void SaveFileJson()
        {
            //Chuyen object | list object -> json string
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(classList);

            //Luu vao file
            File.WriteAllText(@"students.json", json);
        }

        private static void ReadFileJson()
        {
            //Doc noi dung tu file
            string json = File.ReadAllText(@"students.json");

            classList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClassRoom>>(json);

            Display();
        }

        private static void ExitProgram()
        {
            Console.WriteLine("Thoat chuong trinh!!!");
        }

        static void ShowMenu()
        {
            Console.WriteLine("1. Nhap N lop hoc");
            Console.WriteLine("2. Hien thi thong tin lop hoc");
            Console.WriteLine("3. Luu students.txt");
            Console.WriteLine("4. Doc students.txt");
            Console.WriteLine("5. Luu students.dat");
            Console.WriteLine("6. Doc students.dat");
            Console.WriteLine("7. Luu students.json");
            Console.WriteLine("8. Doc students.json");
            Console.WriteLine("9. Thoat");
            Console.WriteLine("Chon: ");
        }
    }
}


#Student.cs


using System;
namespace BT1536
{
    [Serializable]
    public class Student
    {
        public string Fullname { get; set; }
        public string Birthday { get; set; }
        public string Email { get; set; }
        public string Address { get; set; }
        public string Gender { get; set; }

        public Student()
        {
        }

        public Student(string fullname, string birthday, string email, string address, string gender)
        {
            Fullname = fullname;
            Birthday = birthday;
            Email = email;
            Address = address;
            Gender = gender;
        }

        public void Input()
        {
            Console.WriteLine("================================");
            Console.WriteLine("Nhap ten: ");
            Fullname = Console.ReadLine();

            Console.WriteLine("Nhap ngay sinh: ");
            Birthday = Console.ReadLine();

            Console.WriteLine("Nhap email: ");
            Email = Console.ReadLine();

            Console.WriteLine("Nhap dia chi: ");
            Address = Console.ReadLine();

            Console.WriteLine("Nhap gioi tinh: ");
            Gender = Console.ReadLine();
        }

        public void Display()
        {
            Console.WriteLine("Ten: {0}, ngay sinh: {1}, email: {2}, dia chi: {3}, " +
                "gioi tinh: {4}", Fullname, Birthday, Email, Address, Gender);
        }

        public string GetFileLine()
        {
            return string.Format("student:{0},{1},{2},{3},{4}\n",
                Fullname, Birthday, Email, Address, Gender);
        }

        public void Parse(string line)
        {
            string[] elements = line.Split(",");
            Fullname = elements[0];
            Birthday = elements[1];
            Email = elements[2];
            Address = elements[3];
            Gender = elements[4];
        }
    }
}


#ClassRoom.cs


using System;
using System.Collections.Generic;

namespace BT1536
{
    [Serializable]
    public class ClassRoom
    {
        public string Name { get; set; }
        public string Address { get; set; }
        public List<Student> StudentList { get; set; }

        public ClassRoom()
        {
            StudentList = new List<Student>();
        }

        public void Input()
        {
            Console.WriteLine("================================");
            Console.WriteLine("Nhap ten: ");
            Name = Console.ReadLine();

            Console.WriteLine("Nhap dia chi: ");
            Address = Console.ReadLine();

            Console.WriteLine("Nhap so sinh vien trong lop: ");
            int N = int.Parse(Console.ReadLine());

            for(int i=0;i<N;i++)
            {
                Student student = new Student();
                student.Input();

                StudentList.Add(student);
            }
        }

        public void Display()
        {
            Console.WriteLine("Ten lop: {0}, dia chi: {1}", Name, Address);
            foreach(Student student in StudentList)
            {
                student.Display();
            }
        }

        public string GetFileLine()
        {
            string content = string.Format("class:{0},{1}\n", Name, Address);
            foreach(Student student in StudentList)
            {
                content += student.GetFileLine();
            }
            return content;
        }

        public void Parse(string line)
        {
            string[] elements = line.Split(",");
            Name = elements[0];
            Address = elements[1];
        }
    }
}




Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó

×