WithdrawMoney() public method

public WithdrawMoney ( decimal money ) : void
money decimal
return void
コード例 #1
0
        public void Transaction()
        {
            Show("Please insert your card");
            string id = GetInput();

            Show("Please enter your password");
            string pwd = GetInput();

            Account account = bank.FindAccount(id, pwd);

            if (account == null)
            {
                Show("Card invalid or password not corrent");
                return;
            }

            Show("1: display; 2: save; 3: withdraw");
            string op = GetInput();

            if (op == "1")
            {
                Show("Balance: " + account.getMoney());
            }
            else if (op == "2")
            {
                Show("Save money");
                string smoney = GetInput();
                double money  = double.Parse(smoney);

                bool ok = account.SaveMoney(money);
                if (ok)
                {
                    Show("OK");
                }
                else
                {
                    Show("error");
                }

                Show("Balance: " + account.getMoney());
            }
            else if (op == "3")
            {
                Show("Withdraw money");
                string smoney = GetInput();
                double money  = double.Parse(smoney);

                bool ok = account.WithdrawMoney(money);
                if (ok)
                {
                    Show("OK");
                }
                else
                {
                    Show("error");
                }

                Show("Balance: " + account.getMoney());
            }
        }
コード例 #2
0
 protected override bool RunReqiuredOperation(Employee responsibleEmployee, out string outMsg)
 {
     if (Account.WithdrawMoney(MoneyAmount))
     {
         outMsg = "Средства списаны со счета.";
         return(true);
     }
     else
     {
         outMsg = "Не достаточно средств на счете!";
         return(false);
     }
 }
コード例 #3
0
ファイル: ATM.cs プロジェクト: q2git/VS
        private void withdrawMoney()
        {
            try
            {
                double money = double.Parse(GetInput("withdraw"));

                currentAccount.WithdrawMoney(money);

                //if (new Random().Next(3) == 0)
                //    throw new BadCashException("Bad Cash");
                try
                {
                    BadCash.GenerateBadCash();
                }
                catch (BadCashException e)
                {
                    throw new Exception("withdraw money failed", e); //for testing inner exception
                }

                if (BigMoneyFetched != null && money > 10000)
                {
                    BigMoneyFetched(this, new BigMoneyArgs(currentAccount.ID, money));
                }

                bank.UpdateAccount(currentAccount);

                displayAccount();
            }
            catch (Exception e)
            {
                Show("Error: " + e.Message);

                if (e.InnerException != null)
                {
                    Show(string.Format("Error [InnerException]: {0}", e.InnerException.Message));
                }
            }
        }
コード例 #4
0
ファイル: ATM.cs プロジェクト: zc910704/c-sharp-homework
        public void Transaction()
        {
            Show("please insert your card");
            string id = GetInput();

            Show("please enter your password");
            string pwd = GetInput();

            Account account = bank.FindAccount(id, pwd);

            if (account == null)
            {
                Show("card invalid or password not corrent");
                return;
            }

            Show("1: display; 2: save; 3: withdraw");
            string op = GetInput();

            if (op == "1")
            {
                Show("balance: " + account.Money);
            }
            else if (op == "2")
            {
                try
                {
                    Show("save money");
                    string smoney = GetInput();
                    double money  = double.Parse(smoney);
                    try
                    {
                        account.SaveMoney(money);
                        Console.WriteLine("complete");
                    }
                    catch (AccountException e)
                    {
                        if (e.money > 10000)
                        {
                            throw new MyAppException("Money too much");
                        }
                        else
                        {
                            throw new MyAppException("Money amount must bigger than zero");
                        }
                    }
                }
                catch (MyAppException e)
                {
                    Console.WriteLine(e.Message);
                }

                Show("balance: " + account.Money);
            }
            else if (op == "3")
            {
                Show("withdraw money");
                string smoney = GetInput();
                double money  = double.Parse(smoney);
                if (BigMoneyFetched != null && money >= 10000)
                {
                    BigMoneyFetched(this, new BigMoneyArgs(id, money));
                }
                try
                {
                    account.WithdrawMoney(money);
                }
                catch (MyAppException e)
                {
                    Console.WriteLine(e.Message);
                }
                Show("balance: " + account.Money);
            }
        }
コード例 #5
0
ファイル: ATM.cs プロジェクト: fywest/vside_csharp
        //循环处理交易直到用户退出
        public void Transaction()
        {
            Console.Clear();
            bool loop = true;

            Show("\n\n**** 欢迎使用 ATM 服务 " + this.Location + "*****");
            Show("please insert your card");
            string id = GetInput();

            Show("please enter your password");
            string pwd = GetInput();

            Account account = bank.FindAccount(id, pwd);

            if (account == null)
            {
                Show("card invalid or password not correct");
                System.Threading.Thread.Sleep(1000);
                return;
            }
            if (account.Valid == false)
            {
                Show("card invalid 此卡已经冻结,请联系柜台人员");
                System.Threading.Thread.Sleep(2000);
                return;
            }
            do
            {
                Show("1: 查询; 2: 存款; 3: 取款  4:更改密码 5:打印凭条");
                string op = GetInput();

                switch (op)
                {
                case "1":    //  查询
                {
                    //Show("balance: " + account.Money);
                    ((IPrintable)account).IPrint();
                }
                break;

                case "2":    //  存款
                {
                    Show("save money");
                    string smoney = GetInput();
                    double money  = double.Parse(smoney);

                    bool ok = account.SaveMoney(money);
                    if (ok)
                    {
                        Show("save successful");
                    }
                    else
                    {
                        Show("save money fail");
                    }

                    Show("balance: " + account.Money);
                }
                break;

                case "3":    //  取款
                {
                    Show("withdraw money");
                    string smoney = GetInput();
                    double money  = double.Parse(smoney);

                    if (money >= 10000 && account.Money >= 10000)                               //事件发生
                    {
                        BigMoneyFetched(this, new BigMoneyFetchedEventArgs(account.Id, money)); //发生事件
                    }

                    try
                    {
                        bool ok = account.WithdrawMoney(money);

                        if (ok)
                        {
                            try
                            {
                                Cash.GetCash();
                                Show("successful ,please take your cash");
                            }
                            catch (BadCashException e)
                            {
                                throw new CashException("problem in cash", e);
                            }
                        }
                        else
                        {
                            Show("no enough money . withdraw fails");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("出现了异常: {0}", e.Message);
                        Console.WriteLine("内部原因: {0}", e.InnerException.Message);
                        Console.WriteLine("请联系银行工作人员");
                    }

                    Show("balance: " + account.Money);
                }
                break;

                case "4":    //  更改密码
                {
                    Show("please input new password");
                    string pwdnew = GetInput();
                    Show("please input again");
                    string pwdagain = GetInput();
                    if (pwdnew == pwdagain)
                    {
                        account.Pwd = pwdnew;
                        Show("password update succesful");
                    }
                    else
                    {
                        Show("they does not match");
                    }
                }
                break;

                case "5":    //  打印凭条
                {
                    ((IPrintable)account).IPrint();
                }
                break;
                }
                Console.WriteLine("\n");

                Show("\n\n 1: 继续  2: 返回上一级菜单 ");
                string answer = Console.ReadLine();
                if (answer == "1")
                {
                    loop = true;
                }
                else if (answer == "2")
                {
                    loop = false;
                }

                Console.Clear();
            } while (loop);

            return;
        }
コード例 #6
0
        public void Transaction()
        {
            Show("please insert your card");
            string id = GetInput();

            Show("please enter your password");
            string pwd = GetInput();

            Account account = bank.FindAccount(id, pwd);

            if (account == null)
            {
                Show("card invalid or password not corrent");
                return;
            }

            string op = "";

            while (op != "4")
            {
                Show("1: display; 2: save; 3: withdraw; 4: exit");
                op = GetInput();
                string smoney;
                double money;
                bool   ok;

                switch (op)
                {
                case "1":
                    ShowAccountInfo(account);
                    break;

                case "2":
                    Show("save money");
                    smoney = GetInput();
                    money  = double.Parse(smoney);

                    ok = account.SaveMoney(money);
                    if (ok)
                    {
                        ShowAccountInfo(account);
                    }
                    else
                    {
                        Show("eeer");
                    }

                    //Show("balance: " + account.Money);
                    //ShowAccountInfo(account);
                    break;

                case "3":
                    Show("withdraw money");
                    smoney = GetInput();
                    money  = double.Parse(smoney);

                    ok = account.WithdrawMoney(money);
                    //if (ok) Show("ok");
                    //else Show("eeer");

                    if (ok)
                    {
                        ShowAccountInfo(account);
                        // handle a warning event
                        if (money > 10000 && BigMoneyFetched != null)
                        {
                            BigMoneyFetched(this, new BigMoneyFetchedEventArgs(account, money));
                        }
                    }
                    else
                    {
                        Show("eeer");
                    }

                    Random rnd = new Random();
                    if (new Random().Next(3) < 1)
                    {
                        throw new BadCashException("Received bad cash!");
                    }

                    break;

                case "4":
                    break;

                default:
                    Show("Invalid option");
                    break;
                }
            }
        }