Пример #1
0
        /*
         * Tiến hành chuyển khoản, mặc định là ngân hàng.
         * 1. Yêu cầu nhập số tài khoản cần chuyển.
         *      1.1 Xác minh thông tin tài khoản và hiển thị người cẩn chuyển.
         * 2.Nhập số tiền cần chuyển
         *      2.1 Kiểm tra số dư tài khoản.
         * 3.Nhập nội dung chuyển tiền.
         *      3.1 Xác nhận nội dung chuyển tiền.
         * 4. Thực hiện chuyển tiền.
         *      4.1  Mở transaction. Mở block try catch
         *      4.2 Trừ tiền người gửi.
         *           4.2.1. Lấy thông tin tài khoản gửi tiền một lần nữa. Đảm bảo thông tin là mới nhất.
         *           4.2.2 Kiểm tra lại một lần nữa số dư xem có đủ tiền để chuyển không.
         *                 4.2.2.1 Nếu không đủ thì rollback.
         *                 4.2.2.2 Nếu đủ thì trả tiền và update văn bằng 'accounts'.
         *      4.3 Cộng tiền người nhận.
         *           4.3.1 Lấy thông tin tài khoản nhận, đảm bảo tài khoản không bị khóa hoặc inactive
         *                 4.3.1.1. Nếu ok thì update số tiền cho người nhận.
         *                 4.3.1.2. Nếu không ok thì rollback.
         *      4.4. Lưu lịch sử giao dịch.
         *      4.5. Kiểm tra lại trạng thái của 3 câu lệnh trên.
         *           4.5.1. Nếu cả 3 cùng thành công thì commit transaction.
         *           4.5.2. Nếu bất kỳ một câu lệnh nào bị lỗi thì rollback.
         *     4.x. Đóng, commit transaction.
         */

        public void Deposit()
        {
            Console.WriteLine("Deposit.");
            Console.WriteLine("---------------------------------");
            Console.WriteLine("Please enter amount to deposit: ");
            var amount = Utility.GetDecimalNumber();

            Console.WriteLine("Please enter message content: ");
            var content            = Console.ReadLine();
            var historyTransaction = new YYTransaction()
            {
                Id                    = Guid.NewGuid().ToString(),
                Type                  = YYTransaction.TransactionType.DEPOSIT,
                Amount                = amount,
                Content               = content,
                SenderAccountNumber   = Program.currentLoggedInYyAccount.AccountNumber,
                ReceiverAccountNumber = Program.currentLoggedInYyAccount.AccountNumber,
                Status                = YYTransaction.ActiveStatus.DONE
            };

            if (model.UpdateBalance(Program.currentLoggedInYyAccount, historyTransaction))
            {
                Console.WriteLine("Transaction success!");
            }
            else
            {
                Console.WriteLine("Transaction fails, please try again!");
            }
            Program.currentLoggedInYyAccount = model.GetByAccountNumber(Program.currentLoggedInYyAccount.AccountNumber);
            Console.WriteLine("Current balance: " + Program.currentLoggedInYyAccount.Balance);
        }
        public void Transfer()
        {
            Console.WriteLine("Vui lòng nhập số tài khoản người nhận.");
            var receiverAccountNumber = Console.ReadLine();
            var checkAc = model.GetByAccountNumber(receiverAccountNumber);

            Console.WriteLine("Full Name: " + checkAc.FullName);
            Console.WriteLine("Vui lòng nhập số tiền cần chuyển: ");
            var amount = Utility.GetDecimalNumber();

            Console.WriteLine("Vui lòng nhập nội dung tin nhắn: ");
            var content            = Console.ReadLine();
            var historyTransaction = new YYTransaction()
            {
                Id                    = Guid.NewGuid().ToString(),
                Type                  = YYTransaction.TransactionType.TRANSFER,
                Amount                = amount,
                Content               = content,
                SenderAccountNumber   = Program.currentLoggedInYyAccount.AccountNumber,
                ReceiverAccountNumber = receiverAccountNumber,
                Status                = YYTransaction.ActiveStatus.DONE
            };

            if (model.UpdateTranfers(Program.currentLoggedInYyAccount.AccountNumber, receiverAccountNumber, historyTransaction))
            {
                Console.WriteLine("Giao dịch thành công!");
            }
            else
            {
                Console.WriteLine("Giao dịch thất bại, vui lòng kiểm tra lại.!");
            }
        }
        public void GetListTransaction()
        {
            Console.Clear();
            StringBuilder builder = new StringBuilder();
            YYAccount     account = null;
            var           list    =
                TransactionModel.TransactionHistory(Program.currentLoggedInYyAccount.AccountNumber);

            builder.Append("Transaction history.");
            builder.AppendLine();
            builder.AppendFormat("{0,-40} {1,-10} {2,-15} {3,-30} {4,-30} {5,-25} {6,-15}", "Transaction ID",
                                 "Type", "Amount", "Content", "From", "To", "Created date");
            builder.AppendLine();
            foreach (var transaction in list)
            {
                if (transaction.Type == YYTransaction.TransactionType.DEPOSIT)
                {
                    builder.AppendFormat("{0,-40} {1,-10} {2,-15} {3,-30} {4,-30} {5,-25} {6,-15}",
                                         transaction.Id, "Deposit", transaction.Amount, transaction.Content, "You", "You",
                                         transaction.CreatedAt);
                    builder.AppendLine();
                }
                else if (transaction.Type == YYTransaction.TransactionType.WITHDRAW)
                {
                    builder.AppendFormat("{0,-40} {1,-10} {2,-15} {3,-30} {4,-30} {5,-25} {6,-15}",
                                         transaction.Id, "Withdraw", transaction.Amount, transaction.Content, "You", "You",
                                         transaction.CreatedAt);
                    builder.AppendLine();
                }
                else
                {
                    if (Program.currentLoggedInYyAccount.AccountNumber == transaction.SenderAccountNumber)
                    {
                        account = AccountModel.GetByAccountNumber(transaction.ReceiverAccountNumber);
                        builder.AppendFormat("{0,-40} {1,-10} {2,-15} {3,-30} {4,-30} {5,-25} {6,-15}",
                                             transaction.Id, "Transfer", transaction.Amount, transaction.Content, "You", account.FullName,
                                             transaction.CreatedAt);
                    }
                    else
                    {
                        account = AccountModel.GetByAccountNumber(transaction.SenderAccountNumber);
                        builder.AppendFormat("{0,-40} {1,-10} {2,-15} {3,-30} {4,-30} {5,-25} {6,-15}",
                                             transaction.Id, "Transfer", transaction.Amount, transaction.Content, account.FullName, "You",
                                             transaction.CreatedAt);
                    }

                    builder.AppendLine();
                }
            }

            Console.WriteLine(builder);
        }
Пример #4
0
        /*
         * Tiến hành chuyển khoản, mặc định là trong ngân hàng.
         * 1. Yêu cầu nhập số tài khoản cần chuyển.(số tài khoản của người nhận.)
         *     1.1. Xác minh thông tin tài khoản và hiển thị tên người cần chuyển.
         * 2. Nhập số tiền cần chuyển.
         *     2.1. Kiểm tra số dư tài khoản.
         * 3. Nhập nội dung chuyển tiền.
         *     3.1 Xác nhận nội dung chuyển tiền.
         * 4. Thực hiện chuyển tiền.
         *     4.1. Mở transaction. Mở block try catch.
         *     4.2. Trừ tiền người gửi.
         *         4.2.1. Lấy thông tin tài khoản gửi tiền một lần nữa. Đảm bảo thông tin là mới nhất.
         *         4.2.2. Kiểm tra lại một lần nữa số dư xem có đủ tiền để chuyển không.
         *             4.2.2.1. Nếu không đủ thì rollback.
         *             4.2.2.2. Nếu đủ thì trừ tiền và update vào bảng `accounts`.
         *     4.3. Cộng tiền người nhận.
         *         4.3.1. Lấy thông tin tài khoản nhận, đảm bảo tài khoản không bị khoá hoặc inactive.
         *         4.3.1.1. Nếu ok thì update số tiền cho người nhận.
         *         4.3.1.2. Nếu không ok thì rollback.
         *     4.4. Lưu lịch sử giao dịch.
         *     4.5. Kiểm tra lại trạng thái của 3 câu lệnh trên.
         *         4.5.1. Nếu cả 3 cùng thành công thì commit transaction.
         *         4.5.2. Nếu bất kỳ một câu lệnh nào bị lỗi thì rollback.
         *     4.x. Đóng, commit transaction.
         */
        public void Transfer()
        {
            Console.WriteLine("Enter the account number to transfer: ");
            var accountNumber   = Console.ReadLine();
            var receiverAccount = model.GetByAccountNumber(accountNumber);

            if (receiverAccount == null)
            {
                Console.WriteLine("Invalid account information");
                return;
            }

            Console.WriteLine("Name of person to transfer: " + receiverAccount.Name);
            Console.WriteLine("Enter amount to transfer: ");
            var amount = Utillty.GetDecimalNumber();

            Console.WriteLine("Please enter message content: ");
            var content = Console.ReadLine();
//            Program.currentLoggedIn = model.GetAccountByUserName(Program.currentLoggedIn.Username);
            var historyTransaction = new YYTransaction()
            {
                Id                    = Guid.NewGuid().ToString(),
                Type                  = YYTransaction.TransactionType.TRANSFER,
                Amount                = amount,
                Content               = content,
                SenderAccountNumber   = Program.currentLoggedInYyAccount.AccountNumber,
                ReceiverAccountNumber = accountNumber,
                Status                = YYTransaction.ActiveStatus.DONE
            };

            if (model.Transfer(Program.currentLoggedInYyAccount, historyTransaction))
            {
                Console.WriteLine("Transaction success!");
            }
            else
            {
                Console.WriteLine("Transaction fails, please try again!");
            }

            Program.currentLoggedInYyAccount = model.GetByAccountNumber(Program.currentLoggedInYyAccount.AccountNumber);
            Console.WriteLine("Current balance: " + Program.currentLoggedInYyAccount.Balance);
        }
Пример #5
0
        /* * Tiến hành chuyển khoản, mặc định là trong ngân hàng.
         * 1. Yêu cầu nhập số tài khoản cần chuyển.
         *     1.1. Xác minh thông tin tài khoản và hiển thị tên người cần chuyển.
         * 2. Nhập số tiền cần chuyển.
         *     2.1. Kiểm tra số dư tài khoản.
         * 3. Nhập nội dung chuyển tiền.
         *     3.1 Xác nhận nội dung chuyển tiền.
         * 4. Thực hiện chuyển tiền.
         *     4.1. Mở transaction. Mở block try catch.
         *     4.2. Trừ tiền người gửi.
         *         4.2.1. Lấy thông tin tài khoản gửi tiền một lần nữa. Đảm bảo thông tin là mới nhất.
         *         4.2.2. Kiểm tra lại một lần nữa số dư xem có đủ tiền để chuyển không.
         *             4.2.2.1. Nếu không đủ thì rollback.
         *             4.2.2.2. Nếu đủ thì trừ tiền và update vào bảng `accounts`.
         *     4.3. Cộng tiền người nhận.
         *         4.3.1. Lấy thông tin tài khoản nhận, đảm bảo tài khoản không bị khoá hoặc inactive.
         *         4.3.1.1. Nếu ok thì update số tiền cho người nhận.
         *         4.3.1.2. Nếu không ok thì rollback.
         *     4.4. Lưu lịch sử giao dịch.
         *     4.5. Kiểm tra lại trạng thái của 3 câu lệnh trên.
         *         4.5.1. Nếu cả 3 cùng thành công thì commit transaction.
         *         4.5.2. Nếu bất kỳ một câu lệnh nào bị lỗi thì rollback.
         *     4.x. Đóng, commit transaction.
         */
        public void Transfer()
        {
            Console.WriteLine("------------------Transerf Information-------------------");
            var accountNumber = "8ae77d16-4ef7-4e3b-8620-89a794030923";
            var account       = model.GetByAccountNumber(accountNumber);

            if (account == null)
            {
                Console.WriteLine("Invalid account info ");
                return;
            }

            Console.WriteLine("You are doing transaction with account :" + account.FullName);
            Console.WriteLine("enter amout to transfer");
            var amount = Utility.GetDecimalNumber();

            if (amount > account.Balance)

            {
                Console.WriteLine("Amout not enough to perfom transaction:");
                return;
            }

            amount += account.Balance;

            Console.WriteLine("Please enter message conten:");
            var content = Console.ReadLine();

            Console.WriteLine("Are you sure you want to make a transaction with your account ? (y/n)");
            var choice = Console.ReadLine();

            if (choice.Equals("n"))
            {
                return;
            }

            var historyTransaction = new YYTransaction()
            {
                Id                    = Guid.NewGuid().ToString(),
                Type                  = 4,
                Content               = content,
                Amount                = amount,
                SenderAccountNumber   = Program.currentLoggedInYyAccount.AccountNumber,
                ReceiverAccountNumber = account.AccountNumber,
                Status                = 2,
            };

            if (model.TransferAmount(Program.currentLoggedInYyAccount, historyTransaction))
            {
                Console.WriteLine("Transaction success!");
            }
            else
            {
                Console.WriteLine("Transaction fails, please try again!");
            }


            Program.currentLoggedInYyAccount = model.GetByUsername(Program.currentLoggedInYyAccount.Username);
            Console.WriteLine("Current balance: " + Program.currentLoggedInYyAccount.Balance);
            Console.WriteLine("Press enter to continue!");
            Console.ReadLine();
        }
Пример #6
0
        public void Login()
        {
            Console.WriteLine("Please enter Acount Number: ");
            string anumber = Console.ReadLine();

            Console.WriteLine("Please enter password: "******"Username or password false!");
            }
            else
            {
                {
                    while (true)
                    {
                        Console.WriteLine("-----------Welcome to SHB--------------");
                        Console.WriteLine("1, Account Information.");
                        Console.WriteLine("2, The amount in the account");
                        Console.WriteLine("3, Deposit into account.");
                        Console.WriteLine("4, Transfers.");
                        Console.WriteLine("5, Withdrawal");
                        Console.WriteLine("6, Transaction history.");
                        Console.WriteLine("7, Change history.");
                        Console.WriteLine("8, Log out.");
                        Console.WriteLine("---------------------------------------");
                        Console.WriteLine("Please enter choice: ");
                        int choice = Int32.Parse(Console.ReadLine());

                        switch (choice)
                        {
                        case 1:
                            DbConnection.Instance().CloseConnection();
                            Console.WriteLine("You choice acount information.");
                            YYAccount ac          = new YYAccount();
                            var       infoAccount = _model.GetByAccountNumber(anumber);
                            Console.WriteLine("Account Number: " + infoAccount.AccountNumber +
                                              ", User Name: " + infoAccount.UserName +
                                              ", Balance: " + infoAccount.Balance +
                                              ", Identity Card: " + infoAccount.IdentityCard +
                                              ", Full Name: " + infoAccount.FullName +
                                              "\n, Email: " + infoAccount.Email +
                                              ", Phone Number: " + infoAccount.PhoneNumber +
                                              ", Address: " + infoAccount.Address +
                                              ", Gender: " + infoAccount.Gender1()
                                              + ", Status: " + infoAccount.Status1());
                            Console.WriteLine("Do you want to change information(y/n): ");
                            string conts = Console.ReadLine();
                            switch (conts)
                            {
                            case "y":
                                ChangeAccount(anumber);
                                break;

                            case "n":
                                break;
                            }
                            break;

                        case 2:
                            Console.WriteLine("You choice the amount in the account");
                            DbConnection.Instance().CloseConnection();
                            var amount = _model.GetByAccountNumber(anumber);
                            Console.WriteLine("Account balance available is: " + amount.Balance);
                            break;

                        case 3:
                            Console.WriteLine("You choice deposit into account.");
                            DbConnection.Instance().CloseConnection();
                            DepositBalance(anumber);
                            break;

                        case 4:
                            Console.WriteLine("You choice transfers.");
                            DbConnection.Instance().CloseConnection();
                            Trasaction(anumber);
                            break;

                        case 5:
                            Console.WriteLine("You choice withdrawal");
                            DbConnection.Instance().CloseConnection();
                            WithdrawalBalance(anumber);
                            break;

                        case 6:
                            Console.WriteLine("You choice transaction history.");
                            DbConnection.Instance().CloseConnection();
                            Console.WriteLine("You choice transaction history.");
                            Console.WriteLine("{0,-10}{1,-20}{2,-20}{3,-10}{4,-20}{5,-30},{6,-20}", "Id", "Account Number",
                                              "Type", "Amount", "", "Trading account number", "Created Date");
                            List <YYTransactionHistory> list = _history.queryHistory(anumber);
                            foreach (var th in list)
                            {
                                Console.WriteLine("{0,-10}{1,-20}{2,-20}{3,-10}{4,-20}{5,-30},{6, -20}",
                                                  th.Id, th.AccountNumber, th.Type1(), th.Amount, "(VNĐ)", th.TradingAcountNumber1(), th.CreatedDate);
                            }
                            break;

                        case 7:
                            Console.WriteLine("You choice change history.");
                            DbConnection.Instance().CloseConnection();
                            Console.WriteLine("{0,-60}{1,-40}", "Account Number", "Content");
                            List <YYChangeHistory> list1 = _change.queryChange(anumber);
                            foreach (var ch in list1)
                            {
                                Console.WriteLine("{0,-60}{1,-40}", ch.AccountNumber, ch.Content);
                            }
                            break;

                        case 8:
                            Console.WriteLine("Log out.");
                            DbConnection.Instance().CloseConnection();
                            break;

                        default:
                            Console.WriteLine("You enter fails. Please enter again!");
                            break;
                        }

                        if (choice == 8)
                        {
                            break;
                        }
                    }
                }
            }
        }