public void Login() // hiển thị đăng nhập và check user password { string username = null; string password = null; while (true) { Console.Clear(); Console.WriteLine("|==================================================|"); Console.WriteLine("|------------------| ĐĂNG NHẬP |-------------------|"); Console.WriteLine("|==================================================|\n"); Console.Write("- Tài khoản : "); username = Console.ReadLine(); Console.Write("- Mật khẩu : "); password = FormatAndValid.Password(); string choice; // kiểm tra kí tự name password if ((FormatAndValid.validate(username) == false) || (FormatAndValid.validate(password) == false)) { Console.WriteLine("Tên đăng nhập hoặc mật khẩu không được chứa kí tự đặc biệt!"); Console.WriteLine("Bạn có muốn thử lại không?(C/K): "); choice = Console.ReadLine().ToUpper(); while (true) { if (choice != "C" && choice != "K") { Console.Write("Chỉ được nhập C hoặc K: "); choice = Console.ReadLine().ToUpper(); continue; } break; } switch (choice) { case "c": continue; case "C": continue; case "K": m.MainMenu(); break; case "k": m.MainMenu(); break; } } // check kết nối user password vs user password sql try { user = userBL.GetUser(username, password); } catch (System.Exception) { Console.Write("Mất kết nối, bạn có muốn đăng nhập lại không?(C/K): "); choice = Console.ReadLine().ToUpper(); while (true) { if (choice != "C" && choice != "K") { Console.Write("Chỉ được nhập C hoặc K: "); choice = Console.ReadLine().ToUpper(); continue; } break; } switch (choice) { case "c": continue; case "C": continue; case "K": m.MainMenu(); break; case "k": m.MainMenu(); break; } } if (user == null) { Console.Write("Tài khoản hoặc mật khẩu không chính xác!\nBạn có muốn thử lại không?(C/K): "); choice = Console.ReadLine().ToUpper(); while (true) { if (choice != "C" && choice != "K") { Console.Write("Chỉ được nhập C hoặc K: "); choice = Console.ReadLine().ToUpper(); continue; } break; } switch (choice) { case "c": continue; case "C": continue; case "K": m.MainMenu(); break; case "k": m.MainMenu(); break; default: continue; } } break; } // nhập đúng user thì chuyển sang trang shop if (user != null) { ms.menuShop(userBL.GetUserInfo(user.user_id)); } }
public void AddFund(User user) // nạp tiền vào tài khoản { Console.Clear(); double values; string password; Console.WriteLine("|========================================|"); Console.WriteLine("|-------| NẠP TIỀN VÀO TÀI KHOẢN |-------|"); Console.WriteLine("|========================================|\n"); Console.Write("Nhập số tiền cần nạp: "); while (true) { bool isDouble = Double.TryParse(Console.ReadLine(), out values); if (!isDouble) { Console.Write("Bạn đã nhập sai!\nHãy nhập lại: "); } else if (values > 9999999999 || values <= 0) { Console.WriteLine("Số tiền vượt quá giới hạn (9.999.999.999 VND/lần) hoặc (số tiền <= 0 VND )!"); Console.Write("Hãy nhập lại: "); } else { break; } } Console.Write("Nhập lại mật khẩu để xác nhận giao dịch: "); password = FormatAndValid.Password(); // check pass đúng thì thành công else thất bại if (userBL.GetUser(user.user_name, password) != null) { userBL.Addfund(user, values); Console.WriteLine("GIAO DỊCH THÀNH CÔNG !\nBấm phím bất kì để tiếp tục !"); Console.ReadKey(); GetUserInfo(user.user_id); } else { Console.WriteLine("GIAO DỊCH KHÔNG THÀNH CÔNG!\nHãy chắc chắn bạn đã nhập đúng mật khẩu !"); Console.Write("Bạn có muốn thực hiện lại giao dịch không ?(C/K): "); string choose; while (true) { choose = Console.ReadLine().ToUpper(); if (choose != "C" && choose != "K") { Console.WriteLine("Bạn đã nhập sai, hãy nhập lại! "); Console.Write("Bạn có muốn tiếp tục không(C/K)?: "); continue; } else { break; } } switch (choose) { case "C": AddFund(user); break; case "K": UserInfoMenu(user); break; } } }