Exemple #1
0
        static DSGiaoDich listGD; // Danh sach cac giao dich
        #endregion

        #region Main
        static void Main(string[] args)
        {
            // khoi tao danh sach tai khoan va giao dich
            listTK = new DSTaiKhoan();
            listGD = new DSGiaoDich();

            // Kiem tra doi so dong lenh
            // de xac dinh dang cu phap dong lenh
            if (args.Length == 0)
            {
                kieuCP = KieuCuPhap.Dang1; // khi khong co doi so nao thi thuc hien theo dang 1
            }
            else if (args.Length == 1 && args[0] == "-h")
            {
                kieuCP = KieuCuPhap.Dang2; // thuoc dang 2
            }
            else
            {
                // In thong bao loi va hien thi huong dan su dung
                Console.WriteLine("Lenh goi chuong trinh cua ban bi sai");
                kieuCP = KieuCuPhap.Dang2;
            }

            // xu ly theo dang cu phap dong lenh
            switch (kieuCP)
            {
            case KieuCuPhap.Dang1:
                // Load du lieu tu file
                XuLyFile.LayDuLieuTuFile(dataPath, listTK, listGD);
                // Hien thi Menu
                XuLyMenu();
                // Luu du lieu xuong file
                if (!XuLyFile.LuuDuLieuRaFile(listTK, listGD, dataPath))
                {
                    Console.WriteLine("LOI trong qua trinh luu du lieu ra file.");
                    Console.ReadLine();
                    File.Delete(dataPath);     // neu luu bi loi thi xoa file
                }
                break;

            case KieuCuPhap.Dang2:
                InHuongDanSuDung();    // In ra huong dan su dung
                Console.ReadKey();     // Cho nguoi sd doc huong dan va bam enter
                Environment.Exit(0);   // roi thoat khoi chuong trinh
                break;
            }
        }
Exemple #2
0
    static void Main(string[] args)
    {
        List <Contact> danhba = new List <Contact>();

        // doc du lieu tu file
        if (File.Exists("contacts.txt"))
        {
            XuLyFile.LayDuLieuTuFile(danhba);
        }

        char r;

        do
        {
            Console.WriteLine("\nMoi nhap thong tin lien lac:");
            Console.Write("Moi nhap ho:");
            string ho = Console.ReadLine();
            Console.Write("Moi nhap ten:");
            string ten = Console.ReadLine();
            Console.Write("Moi nhap dia chi:");
            string diachi = Console.ReadLine();
            Console.Write("Moi nhap so dien thoai:");
            string sdt = Console.ReadLine();

            Contact co = new Contact(ho, ten, diachi, sdt);
            danhba.Add(co);

            Console.Write("Ban co muon tiep tuc nhap hay khong (y/n) ? ");
            r = Console.ReadKey().KeyChar;
        } while (r == 'y');

        Console.WriteLine("\n\nDanh ba da nhap gom:");
        foreach (Contact c in danhba)
        {
            Console.WriteLine("{0} - {1} - {2} - {3}",
                              c.Ho,
                              c.Ten,
                              c.DiaChi,
                              c.SDT);
        }

        XuLyFile.LuuDuLieuRaFile(danhba);
        Console.ReadLine();
    }