Exemple #1
0
        static void Main(string[] args)
        {
            //Danh sách
            DanhSachThietBi  DS_TB = new DanhSachThietBi();
            DanhSachLinhKien DS_LK = new DanhSachLinhKien();
            DanhSachTanSuat  DS_TS = new DanhSachTanSuat();
            //Thực hiện chức năng
            QuanLyThietBi QL = new QuanLyThietBi();
            //Lưu kêt quả
            DanhSachThietBi DS = new DanhSachThietBi();
            float           gia;

            while (true)
            {
                Console.Clear();
                Console.WriteLine("".PadRight(20) + "HE THONG CHUC NANG");
                Console.WriteLine("0.Thoat khoi chuong trinh");
                Console.WriteLine("1.Nhap du lieu bang tay");
                Console.WriteLine("2.Nhap du lieu tu file");
                Console.WriteLine("3.Tim may tinh co gia re nhat, cao nhat.");
                Console.WriteLine("4.Tim may anh co gia cao nhat re nhat.");
                Console.WriteLine("5.Dem so luong may tinh, may anh co gia la x.");
                Console.WriteLine("6.Hien thi ca hai thiet bi theo chieu tang, giam cua gia");
                Console.WriteLine("7.Sap xep may tinh chieu tang, giam cua gia");
                Console.WriteLine("8.Tim thiet bi co gia CPU cao nhat, thap nhat");
                Console.WriteLine("9.Dem so luong CPU duoc nhieu thiet bi su dung nhat");
                Console.WriteLine("10.Dem so luong RAM khong duoc thiet bi nao su dung.");
                Console.WriteLine("11.Dem so luong RAM su dung theo tung loai RAM.");
                Console.WriteLine("12.Xoa mot loai RAM theo gia.");
                Console.WriteLine("13.Xoa tat ca cac thiet bi su dung RAM co gia la x.");
                Console.WriteLine("14.Tim linh kien duoc su dung nhieu nhat");
                Console.Write("\nNhap so thu tu chuc nang can thuc hien: ");
                Menu menu = (Menu)int.Parse(Console.ReadLine());
                Console.Clear();
                switch (menu)
                {
                case Menu.Thoat:
                    return;

                case Menu.Nhap_Tay:
                    Console.WriteLine("1.Nhap du lieu bang tay\n");
                    DS_TB.NhapBangTay();
                    DS_TB.Xuat();
                    break;

                case Menu.Nhap_File:
                    Console.WriteLine("2.Nhap du lieu tu file\n");
                    DS_TB.NhapTuFile();
                    DS_LK.NhapTuFile();
                    DS_TS.KhoiTao(DS_LK);
                    DS_TS.CapNhat_ToanBo(DS_TB);
                    DS_TB.Xuat();
                    break;

                case Menu.Tim_MT_Gia_MinMax:
                    Console.WriteLine("3.Tim may tinh co gia re nhat, cao nhat\n");
                    DS = QL.PhanLoai_ThietBi(DS_TB, (int)PhanLoai.MayTinh);
                    Console.WriteLine("May tinh co gia re nhat la:");
                    QL.Tim_ThietBi_TheoGia(DS, DS.Tim_Min((int)Gia.TongGia), (int)Gia.TongGia).Xuat();
                    Console.WriteLine("May tinh co gia cao nhat la:");
                    QL.Tim_ThietBi_TheoGia(DS, DS.Tim_Max((int)Gia.TongGia), (int)Gia.TongGia).Xuat(); break;

                case Menu.Tim_MA_Gia_MinMax:
                    Console.WriteLine("4.Tim may anh co gia cao nhat re nhat\n");
                    DS = QL.PhanLoai_ThietBi(DS_TB, (int)PhanLoai.MayAnh);
                    Console.WriteLine("May anh co gia re nhat la:");
                    QL.Tim_ThietBi_TheoGia(DS, DS.Tim_Min((int)Gia.TongGia), (int)Gia.TongGia).Xuat();
                    Console.WriteLine("May anh co gia cao nhat la:");
                    QL.Tim_ThietBi_TheoGia(DS, DS.Tim_Max((int)Gia.TongGia), (int)Gia.TongGia).Xuat();
                    break;

                case Menu.Dem_co_Gia_X:
                    Console.WriteLine("5.Dem so luong may tinh, may anh co gia la x\n");
                    Console.WriteLine("Danh sach thiet bi:");
                    DS_TB.Xuat();
                    Console.Write("Nhap gia: x = ");
                    gia = float.Parse(Console.ReadLine());
                    Console.WriteLine("\nDa tim thay co {0} thiet bi co gia la {1}", QL.Tim_ThietBi_TheoGia(DS_TB, gia, (int)Gia.TongGia).Dem(), gia);
                    break;

                case Menu.HienThi_TangGiam_Gia:
                    Console.WriteLine("6.Hien thi ca hai thiet bi theo chieu tang, giam cua gia\n");
                    Console.WriteLine("Danh sach ban dau:");
                    DS_TB.Xuat();
                    Console.Write("Nhan phim bat ky de tiep tuc...");
                    Console.ReadKey();
                    Console.WriteLine("Danh sach theo chieu tang cua gia:");
                    QL.SapXep(DS_TB, (int)ThuTu.Tang);
                    DS_TB.Xuat();
                    Console.Write("Nhan phim bat ky de tiep tuc...");
                    Console.ReadKey();
                    Console.WriteLine("Danh sach theo chieu giam cua gia:");
                    QL.SapXep(DS_TB, (int)ThuTu.Giam);
                    DS_TB.Xuat();
                    break;

                case Menu.SapXep:
                    Console.WriteLine("7.Sap xep may tinh chieu tang, giam cua gia\n");
                    Console.WriteLine("Danh sach may tinh ban dau:");
                    DS = QL.PhanLoai_ThietBi(DS_TB, (int)PhanLoai.MayTinh);
                    DS.Xuat();
                    Console.Write("Nhan phim bat ky de tiep tuc...");
                    Console.ReadKey();
                    Console.WriteLine("Danh sach may tinh theo chieu tang cua gia:");
                    QL.SapXep(DS, (int)ThuTu.Tang);
                    DS.Xuat();
                    Console.Write("Nhan phim bat ky de tiep tuc...");
                    Console.ReadKey();
                    Console.WriteLine("Danh sach may tinh theo chieu giam cua gia:");
                    QL.SapXep(DS, (int)ThuTu.Giam);
                    DS.Xuat();
                    break;

                case Menu.Tim_TB_CPU_MaxMin:
                    Console.WriteLine("8.Tim thiet bi co gia CPU cao nhat, thap nhat\n");
                    Console.WriteLine("Danh sach thiet bi:");
                    DS_TB.Xuat();
                    Console.WriteLine("Thiet bi co gia CPU cao nhat la: ");
                    QL.Tim_ThietBi_TheoGia(DS_TB, DS_TB.Tim_Max((int)Gia.GiaCPU), (int)Gia.GiaCPU).Xuat();
                    Console.WriteLine("Thiet bi co gia CPU thap nhat la: ");
                    QL.Tim_ThietBi_TheoGia(DS_TB, DS_TB.Tim_Min((int)Gia.GiaCPU), (int)Gia.GiaCPU).Xuat();
                    break;

                case Menu.Dem_CPU_SuDung_Nhieu:
                    Console.WriteLine("9.Dem so luong CPU duoc nhieu thiet bi su dung nhat\n");
                    DS_TB.Xuat();
                    Console.WriteLine("Co {0} CPU su dung nhieu nhat", QL.Tim_LinhKien_SuDung_MucDo(DS_TS, (int)LinhKien.CPU, DS_TS.Tim_Max_CPU()).Dem());
                    QL.Tim_LinhKien_SuDung_MucDo(DS_TS, (int)LinhKien.CPU, DS_TS.Tim_Max_CPU()).Xuat();
                    break;

                case Menu.Dem_RAM_Khong_SD:
                    Console.WriteLine("10.Dem so luong RAM khong duoc thiet bi nao su dung\n");
                    DS_TB.Xuat();
                    Console.WriteLine("Co {0} RAM khong duoc su dung", QL.Tim_LinhKien_SuDung_MucDo(DS_TS, (int)LinhKien.RAM, 0).Dem());
                    QL.Tim_LinhKien_SuDung_MucDo(DS_TS, (int)LinhKien.RAM, 0).Xuat();
                    break;

                case Menu.Dem_RAM_TheoLoai:
                    Console.WriteLine("11.Dem so luong RAM su dung theo tung loai RAM\n");
                    QL.HienThi_SL_SuDung_RAM(DS_TS);
                    break;

                case Menu.Xoa_1_Loai_RAM:
                    Console.WriteLine("12.Xoa mot loai RAM theo gia\n");
                    Console.WriteLine("Danh sach linh kien ban dau:");
                    DS_LK.Xuat();
                    Console.Write("Nhap gia RAM: x = ");
                    gia = float.Parse(Console.ReadLine());
                    Console.WriteLine("\nDanh sach linh kien moi:");
                    DS_LK.Xoa_RAM(gia);
                    DS_LK.Xuat();
                    break;

                case Menu.Xoa_TB_RAM_GiaX:
                    Console.WriteLine("13.Xoa tat ca cac thiet bi su dung RAM co gia la x\n");
                    Console.WriteLine("Danh sach thiet bi ban dau:");
                    DS_TB.Xuat();
                    Console.Write("Nhap gia RAM: x = ");
                    gia = float.Parse(Console.ReadLine());
                    Console.WriteLine("\nDanh sach thiet bi moi:");
                    DS_TB.Xoa_ThietBi_RAM_GiaX(gia);
                    DS_TB.Xuat();
                    break;

                case Menu.Tim_LK_SD_Max:
                    Console.WriteLine("14.Tim linh kien duoc su dung nhieu nhat\n");
                    Console.WriteLine("Linh kien duoc su dung nhieu nhat la:");
                    QL.Tim_LinhKien_SuDung_MucDo(DS_TS, (int)LinhKien.TatCa, DS_TS.listPair.Max(t => t.SoLan)).Xuat();
                    break;

                default:
                    break;
                }
                Console.ReadKey();
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            DanhSachThietBi  DSTB = new DanhSachThietBi();
            DanhSachLinhKien DSLK = new DanhSachLinhKien();
            QuanLyThietBi    QL   = new QuanLyThietBi();

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Danh sach chuc nang:");
                Console.WriteLine("Nhap {0} de Thoat chuong trinh", (int)Menu.Thoat);
                Console.WriteLine("Nhap {0} de Nhap du lieu bang tay", (int)Menu.NhapBangTay);
                Console.WriteLine("Nhap {0} de Nhap du lieu tu file", (int)Menu.NhapTuFile);
                Console.WriteLine("Nhap {0} de xuat danh sach   ", (int)Menu.Xuat);
                Console.WriteLine("Nhap {0} de tim may tinh co gia cao nhat, thap nhat", (int)Menu.TimMayTinhCoGiaCaoThap);
                Console.WriteLine("Nhap {0} de tim may anh co gia cao nhat, thap nhat", (int)Menu.TimMayAnhCoGiaCaoThap);
                Console.WriteLine("Nhap {0} de dem so luong may anh, may tinh co gia la x", (int)Menu.DemSoLuongMayTinhMayAnhCoGia);
                Console.WriteLine("Nhap {0} de sap xep 2 thiet bi theo chieu tang, giam gia", (int)Menu.SapXepTangGiamGia);
                Console.WriteLine("Nhap {0} de sap xep may tinh tang, giam gia", (int)Menu.SapXepMayTinhTangGiamGia);
                Console.WriteLine("Nhap {0} de tim thiet bi co gia CPU cao, thap nhat", (int)Menu.TimThietBiCPUMaxMin);
                Console.WriteLine("Nhap {0} de dem so luong CPU duoc nhieu thiet bi su dung nhat", (int)Menu.DemSoLuongRamKhongDuocSD);
                Console.WriteLine("Nhap {0} de dem so luong RAM khong duoc su dung", (int)Menu.DemSoLuongCPUKhongDuocSD);
                Console.WriteLine("Nhap {0} de dem so luong RAM theo loai RAM", (int)Menu.DemSoLuongRAMTheoLoaiRAM);
                Console.WriteLine("Nhap {0} de xoa mot loai RAM theo gia", (int)Menu.XoaRAMTheoGia);
                Console.WriteLine("Nhap {0} de xoa tat ca cac thiet bi su dung RAM gia x", (int)Menu.XoaTatCaThietBiRAM);
                Console.WriteLine("Nhap {0} de tim linh kien duoc su dung nhieu nhat", (int)Menu.TimLKSDMax);


                Menu nhap = (Menu)int.Parse(Console.ReadLine());
                Console.Clear();
                switch (nhap)
                {
                case Menu.Thoat:
                    return;

                case Menu.NhapBangTay:
                {
                    Console.Clear();
                    DSTB.NhapBangTay();
                    DSTB.Xuat();
                }
                break;

                case Menu.NhapTuFile:
                {
                    Console.Clear();
                    DSTB.NhapTuFile();
                    DSLK.NhapTuFile();
                    Console.WriteLine("Da chuyen du lieu vao danh sach!!" + "\n");
                    //DSLK.Xuat();
                    DSTB.Xuat();
                }
                break;

                case Menu.Xuat:
                {
                    Console.Clear();
                    Console.WriteLine("============================================================================");
                    Console.WriteLine("Danh sach Thiet bi:" + "\n" + "============================================================================" + "\n");
                    DSTB.Xuat();
                    Console.WriteLine("============================================================================");
                    Console.WriteLine("Danh sach Linh kien:" + "\n" + "============================================================================" + "\n");
                    DSLK.Xuat();
                }
                break;

                case Menu.TimMayTinhCoGiaCaoThap:
                {
                    Console.Clear();
                    Console.WriteLine("May tinh co gia cao nhat la:" + "\n");
                    QL.TimMTGiaMax(DSTB).Xuat();
                    Console.WriteLine("May tinh co gia thap nhat la:" + "\n");
                    QL.TimMTGiaMin(DSTB).Xuat();
                } break;

                case Menu.TimMayAnhCoGiaCaoThap:
                {
                    Console.Clear();
                    Console.WriteLine("May anh co gia cao nhat la:" + "\n");
                    QL.TimMAGiaMax(DSTB).Xuat();
                    Console.WriteLine("May anh co gia thap nhat la:" + "\n");
                    QL.TimMAGiaMin(DSTB).Xuat();
                } break;

                case Menu.DemSoLuongMayTinhMayAnhCoGia:
                {
                    Console.Clear();
                    float gia;
                    Console.WriteLine("Xin moi nhap gia x:");
                    gia = float.Parse(Console.ReadLine());
                    Console.WriteLine("Tim thay {0} thiet bi co gia la {1}$!", QL.TimTheoGia(DSTB, gia).Dem(), gia);
                } break;

                case Menu.SapXepTangGiamGia:
                {
                    Console.Clear();
                    Console.WriteLine("Hien thi danh sch theo chieu tang: " + "\n");
                    QL.SapXepGiaTang(DSTB).Xuat();
                    Console.WriteLine("Hien thi danh sach theo chieu giam: " + "\n");
                    QL.SapXepGiaGiam(DSTB).Xuat();
                } break;

                case Menu.SapXepMayTinhTangGiamGia:
                {
                    Console.Clear();
                    Console.WriteLine("Hien thi danh sach may tinh theo chieu tang: " + "\n");
                    QL.SapXepMTTangGia(DSTB).Xuat();
                    Console.WriteLine("Hien thi danh sach may tinh theo chieu giam: " + "\n");
                    QL.SapXepMTGiamGia(DSTB).Xuat();
                } break;

                case Menu.TimThietBiCPUMaxMin:
                {
                    Console.Clear();
                    Console.WriteLine("Thiet bi co gia CPU cao nhat la: ");
                    QL.TimThietBiCPUMax(DSTB).Xuat();
                } break;

                case Menu.DemSoLuongRamKhongDuocSD:
                {
                    Console.Clear();
                    Console.WriteLine("============================================================================");
                    Console.WriteLine("Danh sach Thiet bi:" + "\n" + "============================================================================" + "\n");
                    DSTB.Xuat();
                    Console.WriteLine("============================================================================");
                    Console.WriteLine("Danh sach Linh kien:" + "\n" + "============================================================================" + "\n");
                    DSLK.Xuat();
                    Console.WriteLine("============================================================================");
                    QL.HienThiCPUSDMax(DSTB, DSLK);
                    Console.WriteLine("=====");
                    QL.HienThiCPUSDMin(DSTB, DSLK);
                } break;

                case Menu.DemSoLuongCPUKhongDuocSD:
                {
                    Console.Clear();
                    Console.WriteLine("============================================================================");
                    Console.WriteLine("Danh sach Thiet bi:" + "\n" + "============================================================================" + "\n");
                    DSTB.Xuat();
                    Console.WriteLine("============================================================================");
                    Console.WriteLine("Danh sach Linh kien:" + "\n" + "============================================================================" + "\n");
                    DSLK.Xuat();
                    Console.WriteLine("============================================================================");
                    QL.HienThiRAMSDMin(DSTB, DSLK);
                } break;

                case Menu.DemSoLuongRAMTheoLoaiRAM:
                {
                    Console.Clear();
                    QL.HienThiRAMtheoRAM(DSTB, DSLK);
                } break;

                case Menu.XoaRAMTheoGia:
                {
                    Console.Clear();
                    DSLK.Xuat();
                    float gia;
                    Console.WriteLine("Xin moi nhap gia :");
                    gia = float.Parse(Console.ReadLine());
                    DSLK.XoaRAM(gia);
                    DSLK.Xuat();
                } break;

                case Menu.XoaTatCaThietBiRAM:
                {
                    Console.Clear();
                    DSTB.Xuat();
                    float gia;
                    Console.WriteLine("Xin moi nhap gia :");
                    gia = float.Parse(Console.ReadLine());
                    DSTB.XoaThietBiRAMGiaX(gia);
                    DSTB.Xuat();
                } break;

                case Menu.TimLKSDMax:
                {
                    Console.Clear();
                    QL.HienThiLinhKienDSMax(DSTB, DSLK);
                } break;

                default:
                    break;
                }
                Console.ReadLine();
            }
        }