By GokiSoft.com| 19:54 14/10/2021|
C Sharp

Bài tập C Sharp - Chương trình quản lý cán bộ C# - C Sharp BT2478

Đề bài: Một đơn vị sản xuất gồm có các cán bộ là công nhân, kỹ sư,
nhân viên.
• Mỗi cán bộ cần quản lý lý các thuộc tính: Họ tên, ngày sinh, giới tính,
địa chỉ
• Các công nhân cần quản lý: Bậc (công nhân bậc 3/7, bậc 4/7 …)
• Các kỹ sư cần quản lý: Ngành đào tạo
• Các nhân viên phục vụ cần quản lý thông tin: công việc
1. Xây dựng các lớp NhanVien, CongNha
n, KySu kế thừa từ lớp CanBo
2. Xây dựng các hàm để truy nhập (get), thay đổi (set) và hiển thị thông
tin về các thuộc tính của các lớp (nếu cần).
3. Xây dựng lớp QLCB cài đặt các phương thức thực hiện các chức năng
sau:
• Nhập thông tin mới cho cán bộ
• Tìm kiếm theo họ tên
• Hiển thị thông tin cán bộ tìm được
  

Liên kết rút gọn:

https://gokisoft.com/2478

Bình luận

avatar
Đào Mạnh Dũng [C2010L]
2021-10-15 12:13:10


#CanBo.cs


using System;

namespace _2478
{
    internal class CanBo
    {
        public string name, gender, address;
        public DateTime birthday;

        public virtual void Input()
        {
            Console.Write("nhap name : ");
            this.name = Console.ReadLine();
            Console.Write("nhap gender : ");
            this.gender = Console.ReadLine();
            Console.Write("nhap address : ");
            this.address = Console.ReadLine();
            Console.Write("nhap birthday : ");
            this.birthday = lib.Utility.ReadDate();
        }

        public virtual void Display()
        {
            Console.WriteLine(this);
        }
    }
}


#CongNhan.cs


using System;

namespace _2478
{
    internal class CongNhan : CanBo
    {
        public int rank;

        public CongNhan()
        {
        }

        public CongNhan(string name, string gender, string address, DateTime birthday, int rank)
        {
            this.name = name;
            this.gender = gender;
            this.address = address;
            this.birthday = birthday;
            this.rank = rank;
        }

        public override void Input()
        {
            base.Input();
            Console.Write("nhap rank : ");
            this.rank = lib.Utility.ReadInt();
        }

        public override void Display()
        {
            base.Display();
        }

        public override string ToString()
        {
            return "CongNhan{" + "name=" + name + ", gender=" + gender + ", address=" + address + ", birthday=" + birthday + ", rank=" + rank + '}';
        }
    }
}


#KySu.cs


using System;

namespace _2478
{
    internal class KySu : CanBo
    {
        private string industry;

        public KySu()
        {
        }

        public KySu(string name, string gender, string address, DateTime birthday, string industry)
        {
            this.name = name;
            this.gender = gender;
            this.address = address;
            this.birthday = birthday;
            this.industry = industry;
        }
        public override void Input()
        {
            base.Input();
        }
        public override void Display()
        {
            base.Display();
        }
        public override string ToString()
        {
            return "KySu{" + "name=" + name + ", gender=" + gender + ", address=" + address + ", birthday=" + birthday + ", industry=" + industry + '}';
        }
    }
}


#NhanVien.cs


using System;

namespace _2478
{
    internal class NhanVien : CanBo
    {
        public string work;

        public NhanVien()
        {
        }

        public NhanVien(string name, string gender, string address, DateTime birthday, string work)
        {
            this.name = name;
            this.gender = gender;
            this.address = address;
            this.birthday = birthday;
            this.work = work;
        }
        public override void Input()
        {
            base.Input();
            this.work = Console.ReadLine();
        }
        public override void Display()
        {
            base.Display();
        }
        public override string ToString()
        {
            return "NhanVien{" + "name=" + name + ", gender=" + gender + ", address=" + address + ", birthday=" + birthday + ", work=" + work + '}';
        }
    }
}


#QLCB.cs


using lib;
using System;
using System.Collections.Generic;

namespace _2478
{
    internal class QLCB
    {
        private static List<CanBo> canBoList = new List<CanBo>();

        private static void Main(string[] args)
        {
            SwitchCase[] menu = { ShowMenu, Input, Find, exit };
            Utility.Menu(menu);
        }

        private static void exit()
        {
            Environment.Exit(0);
        }

        private static void ShowMenu()
        {
            Console.WriteLine("1. Nhập thông tin mới cho cán bộ\n" +
            "2. Tìm kiếm theo họ tên\n" +
            "3. thoat");
        }

        private static void Input()
        {
            Console.WriteLine("-----");
            CanBo canBo = null;
            Console.WriteLine("chon:\n 1.CongNhan\n" +
                "2.NhanVien\n" +
                "3.KySu");
            switch (Utility.ReadInt())
            {
                case 1:
                    {
                        canBo = new CongNhan();
                        break;
                    }

                case 2:
                    {
                        canBo = new NhanVien();
                        break;
                    }

                case 3:
                    {
                        canBo = new KySu();
                        break;
                    }

                default:
                    {
                        Console.WriteLine("nhap sai!");
                        break;
                    }
            }

            canBo.Input();
            canBoList.Add(canBo);
        }

        private static void Find()
        {
            Console.WriteLine("nhap ten can tim : ");
            string name = Console.ReadLine();
            foreach (var item in canBoList)
            {
                if (item.name.Equals(name))
                {
                    Console.WriteLine("------");
                    item.Display();
                }
            }
        }
    }
}


#Utility.cs


using Newtonsoft.Json;
using System;
using System.IO;

namespace lib
{
    internal delegate void SwitchCase();

    internal class Utility
    {
        public static void Menu(SwitchCase[] menu)
        {
            int choose;
            while (true)
            {
                menu[0]();
                choose = Utility.ReadInt();
                if (choose <= menu.Length)
                {
                    menu[choose]();
                }
                else Console.WriteLine("Dau vao khong hop le! ");
            }
        }

        public static int ReadInt()
        {
            int integer = 0;
            while (true)
            {
                try
                {
                    integer = int.Parse(Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.Write("du lieu dau vao khong hop le, nhap lai : ");
                }
            }
            return integer;
        }

        public static DateTime ReadDate()
        {
            DateTime date;
            while (true)
            {
                try
                {
                    date = ConvertDateTime(Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.Write("du lieu dau vao khong hop le, nhap lai : ");
                }
            }
            return date;
        }

        public static string ConvertDateTime(DateTime myDate)
        {
            return myDate.ToString("dd-MM-yyyy");
        }

        public static DateTime ConvertDateTime(string str)
        {
            return DateTime.ParseExact(str, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
        }

        public static T ReadfileJson<T>(string path)
        {
            return JsonConvert.DeserializeObject<T>(System.IO.File.ReadAllText(path));
        }

        public static void SavefileJson(object obj, string path)
        {
            System.IO.File.WriteAllText(path, JsonConvert.SerializeObject(obj));
            Console.WriteLine("save file json is success!");
        }

        public static void SaveObject(object serialize, string path)
        {
            using (Stream stream = File.Open(path, FileMode.Create))
            {
                new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Serialize(stream, serialize);
                Console.WriteLine("save file object is success!");
            }
        }

        public static object ReadObject(string path)
        {
            using (Stream stream = File.Open(path, FileMode.Open))
            {
                return new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Deserialize(stream);
            }
        }
    }
}


avatar
Hieu Ngo [community,C2009G]
2021-10-14 04:00:30


#Program.cs


using System;
using QLCB.Utlis;
using QLCB.Model;
using System.Collections.Generic;

namespace QLCB
{
    class Program
    {
        public static List<CanBo> list = new List<CanBo>();
        static void Main(string[] args)
        {
            int choose;
            do
            {
                showMenu();
                choose = Utility.ReadInt();

                switch (choose)
                {
                    case 1:
                        Input();
                        break;
                    case 2:
                        SearhByName();
                        break;
                    case 3:
                        ShowInfor();
                        break;
                    case 4:
                        return;
                    default:
                        Console.WriteLine("Nhap sai!!");
                        break;
                }
            } while (choose >= 1 || choose <= 4);
        }

        private static void ShowInfor()
        {
            foreach(CanBo canBo in list)
            {
                canBo.Display();
            }
        }

        private static void SearhByName()
        {
            string nameFind = Console.ReadLine();
            foreach(CanBo canBo in list)
            {
                if(canBo.FullName == nameFind)
                {
                    canBo.Display();
                }
            }
            
        }

        private static void Input()
        {
            
            CanBo canBo;
            int choose;
            Console.WriteLine("1.Ky su");
            Console.WriteLine("2.Nhan vien");
            Console.WriteLine("3.Cong nhan");
            choose = Utility.ReadInt();
            switch(choose)
            {
                case 1:
                    canBo = new KySu();
                    canBo.Input();
                    list.Add(canBo);
                    break;
                case 2:
                    canBo = new NhanVien();
                    canBo.Input();
                    list.Add(canBo);
                    break;
                case 3:
                    canBo = new CongNhan();
                    canBo.Input();
                    list.Add(canBo);
                    break;
            }            
        }

        static void showMenu()
        {
            Console.WriteLine("1. Nhap thong tin moi cho can bo.");
            Console.WriteLine("2. Tim kiem theo ten.");
            Console.WriteLine("3. Hien thi thong tin can bo.");
            Console.WriteLine("4. Exit.");
            Console.WriteLine("Choose:");
        }
    }
}


#Utility.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace QLCB.Utlis
{
    class Utility
    {
        public static int ReadInt()
        {
            int value;
            while(true)
            {
                try
                {
                    value = int.Parse(Console.ReadLine());
                    return value;
                } catch
                {
                    Console.WriteLine("Nhap sai!!");
                }
            }
        }
        public static DateTime ConvertStringToDate (string dateStr)
        {
            DateTime myDate = DateTime.ParseExact(dateStr, "yyyy-MM-dd HH:mm:ss",
                                       System.Globalization.CultureInfo.InvariantCulture);
            return myDate;
        }

        public static string ConvertDateToString (DateTime myDate)
        {
            return myDate.ToString("yyyy-MM-dd HH:mm:ss");
        }
    }
}


#CanBo.cs


using System;
using System.Collections.Generic;
using System.Text;
using QLCB.Utlis;

namespace QLCB.Model
{
    class CanBo
    {
        public string FullName { get; set; }
        public DateTime BirthDate { get; set; }
        public string Gender { get; set; }
        public string Address { get; set; }

        public CanBo() { }
        public CanBo(string fullName, DateTime birthDate, string gender, string address)
        {
            FullName = fullName;
            BirthDate = birthDate;
            Gender = gender;
            Address = address;
        }

        public virtual void Input()
        {
            Console.WriteLine("Nhap ho va ten:");
            FullName = Console.ReadLine();
            Console.WriteLine("Nhap ngay sinh (yyyy - MM - dd HH: mm:ss):");
            BirthDate = Utility.ConvertStringToDate(Console.ReadLine());
            Console.WriteLine("Nhap gioi tinh:");
            Gender = Console.ReadLine();
            Console.WriteLine("Nhap dia chi:");
            Address = Console.ReadLine();
        }

        public virtual void Display()
        {
            Console.WriteLine("Ho va Ten: {0}, Ngay sinh: {1}, Gioi tinh: {2}, Dia chi: {3}", FullName, Utility.ConvertDateToString(BirthDate), Gender, Address);
        }
    }
}


#CongNhan.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace QLCB.Model
{
    class CongNhan : CanBo
    {
        public CongNhan()
        {
        }

        public CongNhan(string fullName, DateTime birthDate, string gender, string address, string level) : base(fullName, birthDate, gender, address)
        {
            Level = level;
        }

        public string Level { get; set; }

        public override void Input()
        {
            base.Input();
            Console.WriteLine("Nhap cap bac:");
            Level = Console.ReadLine();
        }

        public override void Display()
        {
            base.Display();
            Console.Write("Bac: {0}", Level);
            Console.WriteLine();
        }



    }
}


#KySu.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace QLCB.Model
{
    class KySu : CanBo
    {
        public KySu()
        {
        }

        public KySu(string fullName, DateTime birthDate, string gender, string address, string nganh) : base(fullName, birthDate, gender, address)
        {
            NganhDaoTao = nganh;
        }

        public string NganhDaoTao { get; set; }

        public override void Input()
        {
            base.Input();
            Console.WriteLine("Nganh dao tao:");
            NganhDaoTao = Console.ReadLine();

        }

        public override void Display()
        {
            base.Display();
            Console.Write("Nganh dao tao: {0}", NganhDaoTao);
            Console.WriteLine();
        }
    }
}


#NhanVien.cs


using System;
using System.Collections.Generic;
using System.Text;
using QLCB.Utlis;

namespace QLCB.Model
{
    class NhanVien : CanBo
    {
        public NhanVien()
        {
        }

        public NhanVien(string fullName, DateTime birthDate, string gender, string address, string job) : base(fullName, birthDate, gender, address)
        {
            Job = job;
        }

        

        public string Job { get; set; }

        public override void Input()
        {
            base.Input();
            Console.WriteLine("Nhap cong viec:");
            Job = Console.ReadLine();
        }

        public override void Display()
        {
            base.Display();
            Console.Write("Cong viec: {0}", Job);
            Console.WriteLine();
        }
    }
}


avatar
Hoàng Thiện Thanh [community,AAHN-C2009G]
2021-10-13 05:37:22


#Chief.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace OfficerManager.Models
{
    public class Chief : Personel
    {
        public string EducationDept { get; set; }
        public Chief(string Name, DateTime Birthday, string Gender, string Address, string EduDept) : base(Name, Birthday, Gender, Address)
        {
            this.EducationDept = EduDept;
        }
        public Chief()
        {

        }
        public override void Input()
        {
            base.Input();
            Console.WriteLine("Enter Department of Education:");
            EducationDept = Console.ReadLine();
        }

        public override void Display()
        {
            Console.WriteLine("Name: {0}\n" +
                "Birthday: {1}\n" +
                "Gender: {2}\n" +
                "Address: {3}\n" +
                "Education Dept: {4}\n", Name, Birthday.ToString("dd-MMMM-yyyy"), Gender, Address, EducationDept);
        }
    }
}


#Employee.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace OfficerManager.Models
{
    public class Employee : Personel
    {
        public string Job { get; set; }
        public Employee(string Name, DateTime Birthday, string Gender, string Address, string Job) : base(Name, Birthday, Gender, Address)
        {
            this.Job = Job;
        }
        public Employee() { 
        }
        public override void Input()
        {
            base.Input();
            Console.WriteLine("Enter Job:");
            Job = Console.ReadLine();
        }

        public override void Display()
        {
            Console.WriteLine("Name: {0}\n" +
                "Birthday: {1}\n" +
                "Gender: {2}\n" +
                "Address: {3}\n" +
                "Job: {4}\n", Name, Birthday.ToString("dd-MMMM-yyyy"), Gender, Address, Job);
        }
    }
}


#Personel.cs


using OfficerManager.Utils;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace OfficerManager.Models
{
    public class Personel
    {
        public string Name { get; set; }
        public DateTime Birthday { get; set; }
        private string gender;
        public string Gender { 
            get { return gender; } 
            set { 
                while (!Regex.Match(value, @"\b(Male|Female|male|female)\b").Success) 
                {
                    Console.WriteLine("Gender is not either male or female");
                    value = Console.ReadLine();
                }
                this.gender = value;
            } 
        }
        public string Address { get; set; }

        public Personel(string Name, DateTime Birthday, string Gender, string Address)
        {
            this.Name = Name;
            this.Birthday = Birthday;
            this.Gender = Gender;
            this.Address = Address;
        }

        public Personel()
        {
        }

        public virtual void Input()
        {
            Console.WriteLine("Input Name:");
            Name = Utility.ReadLetters();
            Console.WriteLine("Input Birthay:");
            Birthday = Utility.ReadDate();
            Console.WriteLine("Input Gender:");
            Gender = Console.ReadLine();
            Console.WriteLine("Input Address:");
            Address = Console.ReadLine();
        }
        public virtual void Display() {
            Console.WriteLine("Name:{0}\nBirthday:{1}\nGender:{2}\nAddress:{3}", Name, Birthday.ToString("dd-MMMM-yyyy"), Gender, Address);
        }
    }
}


#Worker.cs


using OfficerManager.Utils;
using System;
using System.Collections.Generic;
using System.Text;

namespace OfficerManager.Models
{
    public class Worker : Personel
    {
        private int rank;
        public int Rank { get { return rank; } set { while (value > 7 || value <= 0) {
                    Console.WriteLine("The inputted value must be around 1 - 7");
                    value = Utility.ReadInt();
                }
                this.rank = value;
            } }
        public Worker(string Name, DateTime Birthday, string Gender, string Address, int Rank) : base(Name, Birthday, Gender, Address)
        {
            this.Rank = Rank;
        }
        public Worker()
        {

        }

        public override void Input()
        {
            base.Input();
            Console.WriteLine("Enter Worker Rank:");
            Rank = Utility.ReadInt();
        }

        public override void Display()
        {
            Console.WriteLine("Name: {0}\n" +
                "Birthday: {1}\n" +
                "Gender: {2}\n" +
                "Address: {3}\n" +
                "Rank: {4}/7\n", Name, Birthday.ToString("dd-MMMM-yyyy"), Gender, Address, Rank);
        }
    }
}


#PersonelManager.cs


using OfficerManager.Models;
using OfficerManager.Utils;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace OfficerManager
{
    public class PersonelManager
    {
        public static List<Personel> PersonelList = new List<Personel>();
        public static void ShowMenu()
        {
            int choose;
            do
            {
                Console.WriteLine("1. Input new personel infos\n" +
                    "2. Search personel by name\n" +
                    "3. Show info of all personels\n" +
                    "4. Exit");
                choose = Utility.ReadInt();
                switch (choose)
                {
                    case 1:
                        Input();
                        break;
                    case 2:
                        SearchByName();
                        break;
                    case 3:
                        Display();
                        break;
                    case 4:
                        Console.WriteLine("Exited!");
                        break;
                    default:
                        Console.WriteLine("Wrong Input!");
                        break;
                }

            } while (choose != 4);
        }
        public static void Input()
        {
            Console.WriteLine("Enter the number of personels to input");
            int N = Utility.ReadInt();
            for (int i = 0; i < N; i++)
            {
                Personel p = null;
                Console.WriteLine("Enter Personel type (Employee, Worker, Chief, Default):");
                string PersonelClass = Console.ReadLine();
                while (!Regex.Match(PersonelClass, @"\b(Employee|Worker|Chief|Default)\b").Success)
                {
                    Console.WriteLine("Type doesn't match.");
                    PersonelClass = Console.ReadLine();
                }
                switch (PersonelClass)
                {
                    case "Employee":
                        Console.WriteLine("Enter Employee info:");
                        p = new Employee();
                        p.Input();
                        PersonelList.Add(p);
                        break;
                    case "Worker":
                        Console.WriteLine("Enter Worker info:");
                        p = new Worker();
                        p.Input();
                        PersonelList.Add(p);
                        break;
                    case "Chief":
                        Console.WriteLine("Enter Chief info:");
                        p = new Chief();
                        p.Input();
                        PersonelList.Add(p);
                        break;
                    case "Default":
                        Console.WriteLine("Enter Personel info:");
                        p = new Personel();
                        p.Input();
                        PersonelList.Add(p);
                        break;
                }
            }
        }

        public static void SearchByName()
        {
            if (PersonelList.Count == 0)
            {
                return;
            }
            Console.WriteLine("Enter name to search:");
            string Name = Utility.ReadLetters();
            int count = 0;
            foreach (Personel p in PersonelList){ 
                if (p.Name.Equals(Name))
                {
                    p.Display();
                    count++;
                }
            }
            if (count == 0)
            {
                Console.WriteLine("No results match with name");
            }
        }
        public static void Display()
        {
            if (PersonelList.Count == 0)
            {
                return;
            }
            foreach (Personel p in PersonelList)
            {
                p.Display();
            }
        }
        public static void Main()
        {
            PersonelManager.ShowMenu();
        }
    }
}


#Utility.cs


using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace OfficerManager.Utils
{
    public class Utility
    {
        public static int ReadInt()
        {
            string str = Console.ReadLine();
            bool check()
            {
                try { int.Parse(str); } catch (Exception) { return false; }
                return true;
            }
            while (!check())
            {
                Console.WriteLine("Cannot parse input like a floor numeric value");
                str = Console.ReadLine();
            }
            return int.Parse(str);
        }
        public static DateTime ReadDate()
        {
            string str = Console.ReadLine();
            DateTime date = new DateTime();
            bool check()
            {
                int ERR = 0;
                try { date = DateTime.Parse(str); } catch (Exception) { ERR++; }
                try { if (ERR == 1) date = Convert.ToDateTime(str); } catch (Exception) { ERR++; }
                if (ERR == 2)
                {
                    return false;
                }
                return true;
            }
            while (!check())
            {
                Console.WriteLine("Cannot read DateTime from input");
                str = Console.ReadLine();
            }
            return date;
        }
        public static string ReadLetters()
        {
            string str = Console.ReadLine();
            while (!Regex.Match(str, "^([a-zA-Z]+|[a-zA-Z]+\\s[a-zA-Z]+)*$").Success)
            {
                Console.WriteLine("Input does not only contain letters");
                str = Console.ReadLine();
            }
            return str;
        }
    }
}


avatar
Nam20021608 [community,AAHN-C2009G]
2021-10-12 14:49:39


#Utility.cs


using System;
namespace lap10.libary
{
    class Utility
    {
        public static DateTime ConvertStrignToDateTime()
        {
            String c;
            while (true)
            {
                try
                {
                    c = Console.ReadLine();
                    DateTime myDate = DateTime.ParseExact(c, "yyyy-MM-dd",
                                       System.Globalization.CultureInfo.InvariantCulture);
                    return myDate;
                }
                catch (System.Exception)
                {

                    Console.WriteLine("nhap lai: ");
                }

            }

        }
        public static DateTime ConvertStrignToDateTime(string c)
        {

            c = Console.ReadLine();
            DateTime myDate = DateTime.ParseExact(c, "yyyy-MM-dd",
                               System.Globalization.CultureInfo.InvariantCulture);
            return myDate;

        }

        public static string ConvertDateTimeToString(DateTime dateTime)
        {
            return dateTime.ToString("yyyy-MM-dd");
        }

        public static String Gender()
        {
            Console.WriteLine("1. Nam");
            Console.WriteLine("2. Nu");
            Console.WriteLine("3. Khong ro");
            int d;
            do
            {
                while (true)
                {
                    try
                    {
                        d = int.Parse(Console.ReadLine());
                        switch (d)
                        {
                            case 1:
                                return "Nam";
                                break;
                            case 2:
                                return "Nu";
                                break;
                            case 3:
                                return "Khong biet";
                                break;
                            default:
                                Console.WriteLine("Lua chon lai");
                                break;

                        }
                    }
                    catch (System.Exception)
                    {
                        Console.WriteLine("Nhap lai!!");
                    }
                }
            } while (d != 1 || d != 2 || d != 3);

        }

        public static int Level()
        {
            int a;
            while (true)
            {
                try
                {
                    a = int.Parse(Console.ReadLine());
                    if (a > 7)
                    {
                        Console.WriteLine("cap bac khong hon 7!");
                        a = int.Parse(Console.ReadLine());
                    }
                    return a;
                }
                catch (System.Exception)
                {

                    Console.WriteLine("Nhap lai!!");
                }
            }
        }
        public static int choose()
        {
            int a;
            while (true)
            {
                try
                {
                    a = int.Parse(Console.ReadLine());
                    return a;
                }
                catch (System.Exception)
                {

                    Console.WriteLine("Nhap lai!!");
                }
            }
        }

    }
}


#Canbo.cs


using System;
using lap10.libary;
namespace lap10.Model
{
    class Canbo{
        public String fullName{get;set;}
        public DateTime dob{get;set;}
        public String gender{get;set;}
        public String address{get; set;}

        public Canbo(){}
        public Canbo(String name, String dob , String gendet , String Address){
            this.fullName = name;
            this.dob = Utility.ConvertStrignToDateTime(dob);
            this.gender= gender;
            this.address = Address;
        }

        public virtual void Input(){
            Console.WriteLine("=====NHap du lieu Can bo=====");
            Console.WriteLine("Nhap Ho va Ten : ");
            fullName = Console.ReadLine();
            Console.WriteLine("Nhap ngay sinh: ");
            

            dob = Utility.ConvertStrignToDateTime();
            
            Console.WriteLine("Nhap gioi tinh:  ");
            gender = Utility.Gender();
            Console.WriteLine("Nhap dia chi: ");
            address = Console.ReadLine();
        }

        public virtual void Display(){
            Console.Write("Ho va Ten: {0} , Ngay sinh : {1} , Gioi tinh: {2} , Dia chi: {3}",fullName,dob , gender , address);
        }
    }
}


#CongNhan.cs


using System;
using lap10.libary;
namespace lap10.Model
{
    class CongNhan: Canbo{
        public int level{get;set;}
        public CongNhan(){}
        public CongNhan(String name, String dob , String gendet , String Address,int level ):base( name, dob , gendet , Address){
            this.level = level;
        }
        public override void Input()
        {
            base.Input();
            Console.WriteLine("Nhap cap bac: ");
            level = Utility.Level();
        }
        public override void Display()
        {
            base.Display();
            Console.WriteLine(" , Cap Bac: "+ level+"/7");
        }
    }
}


#KySu.cs


using System;
using lap10.libary;
namespace lap10.Model
{
    class Kisu: Canbo{
        public String work{get;set;}
        public Kisu(){}
        public Kisu(String name, String dob , String gendet , String Address,String job ):base( name, dob , gendet , Address){
            this.work = job;
        }
        public override void Input()
        {
            base.Input();
            Console.WriteLine("Nhap nganh quan ly: ");
            work = Console.ReadLine();
        }
        public override void Display()
        {
            base.Display();
            Console.WriteLine(" , Nganh quan ly: "+ work);
        }
    }
}


#Nhanvien.cs


using System;
using lap10.libary;
namespace lap10.Model
{
    class Nhanvien : Canbo{
        public String job{get;set;}
        public Nhanvien(){}
        public Nhanvien(String name, String dob , String gendet , String Address,String job ):base( name, dob , gendet , Address){
            this.job = job;
        }
        public override void Input()
        {
            base.Input();
            Console.WriteLine("Nhap Cong viec: ");
            job = Console.ReadLine();
        }
        public override void Display()
        {
            base.Display();
            Console.WriteLine(" , Nhan vien phuc vu: "+ job);
        }
    }
}


#QLCB.cs


using System;
using lap10.libary;
using lap10.DataBase;
using System.Collections.Generic;

namespace lap10.Model
{
    class QLCB
    {
        private List<Canbo> listCanbo = new List<Canbo>();
        public QLCB() { }
        public void Menu()
        {
            int choose;
            do
            {
                Console.WriteLine("1. Nhap thong tin moi cho can bo");
                Console.WriteLine("2. Tim kiem theo ho va ten");
                Console.WriteLine("3. Hien thi thong tin cua toan can bo");
                Console.WriteLine("4. Thoat");
                choose = Utility.choose();
                switch (choose)
                {
                    case 1:
                        add();
                        break;
                    case 2:
                        search();
                        break;
                    case 3:
                        View();
                        break;
                    case 4:
                        break;
                    default:
                        Console.WriteLine("Nhap lai !!!");
                        break;
                }
            } while (choose != 4);
        }

        public void add()
        {
            int num;
            do
            {
                Console.WriteLine("===Chon vi tri muon them===");
                Console.WriteLine("1.Nhan vien");
                Console.WriteLine("2.Ki Su");
                Console.WriteLine("3.Cong nhan");
                Console.WriteLine("4.Thoat");
                int d = Utility.choose();
                num = d;
                switch (d)
                {
                    case 1:
                        Nhanvien nv = new Nhanvien();
                        nv.Input();
                        listCanbo.Add(nv);

                        break;
                    case 2:

                        Kisu ks = new Kisu();
                        ks.Input();
                        listCanbo.Add(ks);

                        break;
                    case 3:

                        CongNhan cn = new CongNhan();
                        cn.Input();
                        listCanbo.Add(cn);

                        break;
                    case 4:
                        break;
                    default:
                        Console.WriteLine("Nhap lai !!");
                        break;
                }
            } while (num != 4);
        }
        public void search()
        {
            Console.WriteLine("Nhap ten can bo can tim: ");
            String name = Console.ReadLine();
            for (int i = 0; i < listCanbo.Count; i++)
            {
                if (listCanbo[i].fullName.Equals(name))
                {
                    listCanbo[i].Display();
                }
            }
        }
        public void View()
        {
            if (listCanbo.Count == 0)
            {
                Console.WriteLine("Khong co can bo trong danh sach , vui vong them can bo");
            }
            for (int i = 0; i < listCanbo.Count; i++)
            {
                listCanbo[i].Display();
            }
        }
    }
}


#Program.cs


using System;
using lap10.libary;
using lap10.Model;
using System.Collections.Generic;

namespace lap10
{
    class Program
    {
        static void Main(string[] args)
        {
            QLCB q = new QLCB();
            q.Menu();
        }
    }
}


avatar
Nguyễn Việt Hoàng [community,AAHN-C2009G]
2021-10-12 10:49:00


#Cadres.cs


using Ss10.Ultitis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ss10.B1
{
    class Cadres
    {
        public string FullName { get; set; }
        public DateTime BirthDay { get; set; }
        public string Gender { get; set; }
        public string Address { get; set; }
        public Cadres()
        {

        }
        public Cadres(string fullname, DateTime birthday, string gender, string address)
        {
            this.FullName = fullname;
            this.BirthDay = birthday;
            this.Gender = gender;
            this.Address = address;
        }
        public void Input()
        {
            Console.WriteLine("Enter FullName :");
            FullName = Console.ReadLine();
            Console.WriteLine("Enter BirthDay(dd/MM/yyyy) :");
            BirthDay = Ultility.ConvertStringToDateTime(Console.ReadLine());
            Console.WriteLine("Enter Gender :");
            Gender = Console.ReadLine();
            Console.WriteLine("Enter Address :");
            Address = Console.ReadLine();
        }
        public virtual void Display()
        {
            Console.WriteLine("FullName :{0}, BirthDay :{1}, Gender :{2}, Address :{3}", FullName, BirthDay, Gender, Address);
        }
    }
}


#Engineer.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ss10.B1
{
    class Engineer : Cadres
    {
        public string TrainingIndustry { get; set; }
        public Engineer()
        {

        }
        public Engineer(string fullname, DateTime birthday, string gender, string address, string trainingindustry) : base(fullname,birthday,gender,address)
        {
            this.TrainingIndustry = trainingindustry;
        }
        public void Input()
        {
            base.Input();
            Console.WriteLine("Enter Training Industry :");
            TrainingIndustry = Console.ReadLine();
        }
        public override void Display()
        {
            Console.WriteLine("FullName :{0}, BirthDay :{1}, Gender :{2}, Address :{3}, Training Industry :{4}", base.FullName, base.BirthDay, base.Gender, base.Address, this.TrainingIndustry);
        }
    }
}


#Staff.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ss10.B1
{
    class Staff : Cadres
    {
        public string Work { get; set; }
        public Staff()
        {

        }
        public Staff(string fullname, DateTime birthday, string gender, string address, string work) : base (fullname,birthday,gender,address)
        {
            this.Work = work;
        }
        public void Input()
        {
            base.Input();
            Console.WriteLine("Enter Work :");
            Work = Console.ReadLine();
        }
        public override void Display()
        {
            Console.WriteLine("FullName :{0}, BirthDay :{1}, Gender :{2}, Address :{3}, Work :{4}", base.FullName, base.BirthDay, base.Gender, base.Address,this.Work);
        }
    }
}


#Worker.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ss10.B1
{
    class Worker : Cadres
    {
        public string Step { get; set; }
        public Worker()
        {

        }
        public Worker(string fullname, DateTime birthday, string gender, string address, string step) : base (fullname,birthday,gender,address)
        {
            this.Step = step;
        }
        public void Input()
        {
            base.Input();
            Console.WriteLine("Enter Step : ");
            Step = Console.ReadLine();
        }
        public override void Display()
        {
            
            Console.WriteLine("FullName :{0}, BirthDay :{1}, Gender :{2}, Address :{3}, Step :{4}", base.FullName, base.BirthDay, base.Gender, base.Address, this.Step);
        }
    }
}


#Program.cs


using Ss10.B1;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Ss10
{
    class Program
    {
        public static List<Worker> WorkList = new List<Worker>();
        public static List<Engineer> EngineerList = new List<Engineer>();
        public static List<Staff> StaffList = new List<Staff>();
        public static List<Cadres> CadresList = new List<Cadres>();
        static void ShowMenu()
        {
            Console.WriteLine("1.Add Information Cadres ");
            Console.WriteLine("2.Find by FullName ");
            Console.WriteLine("3.Display Information");

        }
        static void Add()
        {
            string choose;
            Console.WriteLine("Enter Sum Of Cadres :");
            int sum = int.Parse(Console.ReadLine());
            for (int i = 0; i < sum; i++)
            {
                Console.WriteLine("Cadres[" + (i + 1) + "]");
                Console.WriteLine("Please Enter Choose Production Unit(Staff,Engineer,Worker) : ");
                choose = Console.ReadLine();
                List<string> valid = new List<string>() { "Staff", "Engineer", "Worker" };
                while (!valid.Contains(choose, StringComparer.OrdinalIgnoreCase))
                {
                    Console.WriteLine("Please Enter Choose Production Unit(Staff, Engineer, Worker) Again : ");
                    choose = Console.ReadLine();
                }
                if (valid[0].Equals(choose))
                {
                    Staff s = new Staff();
                    s.Input();
                    StaffList.Add(s);
                    CadresList.Add(s);

                }
                else if (valid[1].Equals(choose))
                {
                    Engineer e = new Engineer();
                    e.Input();
                    EngineerList.Add(e);
                    CadresList.Add(e);
                }
                else if (valid[2].Equals(choose))
                {
                    Worker w = new Worker();
                    w.Input();
                    WorkList.Add(w);
                    CadresList.Add(w);
                }
            }
        }
        static void FindByFullName()
        {
            if(CadresList.Count == 0)
            {
                Console.WriteLine("Cadres does not exits");
                return;
            }
            List<Cadres> list = new List<Cadres>();
            Console.WriteLine("Enter Name You Need Find :");
            string find = Console.ReadLine();
            foreach(Cadres c in CadresList)
            {
                if (c.FullName.Equals(find))
                {
                    c.Display();
                    list.Add(c);
                }
                
            }
            if (list.Count == 0 )
            {
                Console.WriteLine("Cannot Find Name You Need !");
            }
        }


        static void Display()
        {
            if (CadresList.Count == 0)
            {
                Console.WriteLine("Cadres does not exits");
                return;
            }
            Console.WriteLine("Cadres :");
            foreach (Cadres c in CadresList)
            {
                c.Display();
            }

        }
        static void ListMenu()
        {
            int choose;

            do
            {
                ShowMenu();
                Console.WriteLine("Please choose value :");
                choose = int.Parse(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        Add();
                        break;
                    case 2:
                        FindByFullName();
                        break;
                    case 3:
                        Display();
                        break;
                    case 4:
                        Console.WriteLine("Exits");
                        return;
                    default:
                        Console.WriteLine("Values must be 1->4");
                        break;
                }
            } while (choose != 4);
        }
        static void Main(string[] args)
        {
            ListMenu();
        }
    }
}