Example #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());
            }
        }
Example #2
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.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);
            }
        }
Example #3
0
        //循环处理交易直到用户退出
        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;
        }
Example #4
0
 /// <summary>
 /// 将当前登录的账户升级为信用账户
 /// </summary>
 /// <param name="credit">信用额度</param>
 public void changeToCredit(decimal credit)
 {
     bank.changeToCreditAccount(account.Id, credit);
     account = bank.FindAccount(account.Id);
 }
Example #5
0
        public static void Main(string[] args)
        {
            Print pr = s => Console.WriteLine(s);


            Bank       bank = new Bank();
            Account    a    = new Account(BankType.ICBC, "1", "1", 100);
            Account    b    = new Account(BankType.ICBC, "2", "2", 2);
            CreditCard c    = new CreditCard(BankType.ICBC, "3", "3", 200, 100, CardType.Platinum);


            bank.OpenAccount(a);
            bank.OpenAccount(b);
            bank.OpenAccount(c);

            //bank.showAccount();
            //((IPrintable)bank).IPrint();



            ATM atm = new ATM(bank, "Beijing City");



            ((IPayment)c).Payment(20); //接口方法处理消费付款
            c.Type = CardType.Golden;  //枚举赋值
            //((IPrintable)c).IPrint();

            b["USD"] = 29;//外币赋值
            ((IPayment)b).Payment(2);
            //((IPrintable)b).IPrint();
            //((IPrintable)a).IPrint();


            //atm.Transaction();//循环处理交易直到用户退出

            //***************************************************************************************************


            atm.BigMoneyFetched += new BigMoneyFetchedHandler(ShowWarning); //注册事件

            string op;

            while (true)
            {
                System.Threading.Thread.Sleep(1000);
                Console.Clear();
                pr("\n\n\n             银行服务系统           \n\n\n");
                pr("1:柜台服务" + "\t" + "2:ATM服务" + "\t" + "3:退出");
                op = Console.ReadLine();
                if (op == "1")
                {
                    bool loop = true;
                    do
                    {
                        pr("请选择办理业务:");
                        pr("1:开户" + "\t" + "2:销户" + "\t" + "3:预览" + "\t" + "4:挂失" + "\t" + "5:解卦" + "\t");

                        string service = Console.ReadLine();
                        switch (service)
                        {
                        case "1":    //  开户
                        {
                            pr("请选择开户银行: ");
                            pr("1:工行" + "\t" + "2:中行" + "\t" + "3:农行" + "\t" + "4:建行" + "\t" + "5:招行");
                            string sbanktype = Console.ReadLine();

                            int      type     = int.Parse(sbanktype);
                            BankType banktype = (BankType)type;

                            pr("请填写开户账号:");
                            string id = Console.ReadLine();
                            if (bank.IsExist(id))
                            {
                                pr("账号已经存在,请重新设定");
                                break;
                            }
                            pr("请输入密码,并确认:");
                            string pwd = Console.ReadLine();
                            pr("请填写存款:");
                            string smoney = Console.ReadLine();
                            double money  = double.Parse(smoney);



                            pr("信用卡用户请输入额度,零为普通用户");
                            string sCredit = Console.ReadLine();
                            double credit  = double.Parse(smoney);

                            if (sCredit == "0")
                            {
                                Account account = new Account(banktype, id, pwd, money);


                                if (account != null)
                                {
                                    bank.OpenAccount(account);
                                    pr("普通账户开户成功");
                                }
                                else
                                {
                                    pr("普通账户开户失败");
                                }
                            }
                            else
                            {
                                CreditCard creditCard = new CreditCard(banktype, id, pwd, money, money, CardType.Silver, credit);
                                if (creditCard != null)
                                {
                                    bank.OpenAccount(creditCard);
                                    pr("信用卡账户开户成功");
                                }
                                else
                                {
                                    pr("信用卡账户开户失败");
                                }
                            }

                            //bank.banktype = banktype;
                        }
                        break;

                        case "2":    //注销
                        {
                            pr("请输入注销账号:");
                            string id = Console.ReadLine();
                            pr("请输入密码,并确认:");
                            string pwd = Console.ReadLine();

                            Account account;

                            account = bank.FindAccount(id, pwd);
                            bool ok = bank.CloseAccount(account);
                            if (ok)
                            {
                                pr("注销成功");
                            }
                            else
                            {
                                pr("注销失败");
                            }
                        }
                        break;

                        case "3":    //预览
                        {
                            ((IPrintable)bank).IPrint();
                        }
                        break;

                        case "4":    //挂失
                        {
                            pr("请输入挂失账号:");
                            string id = Console.ReadLine();
                            pr("请输入密码,并确认:");
                            string pwd = Console.ReadLine();

                            Account account;

                            account = bank.FindAccount(id, pwd);
                            bool ok = bank.Accountdisable(account);
                            if (ok)
                            {
                                pr("挂失成功");
                            }
                            else
                            {
                                pr("挂失失败");
                            }
                        }
                        break;

                        case "5":    //解挂
                        {
                            pr("请输入解挂账号:");
                            string id = Console.ReadLine();
                            pr("请输入密码,并确认:");
                            string pwd = Console.ReadLine();

                            Account account;

                            account = bank.FindAccount(id, pwd);
                            bool ok = bank.AccountEnable(account);
                            if (ok)
                            {
                                pr("解挂成功");
                            }
                            else
                            {
                                pr("解挂失败");
                            }
                        }

                        break;
                        }


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

                        Console.Clear();
                    } while (loop);
                }
                else if (op == "2")
                {
                    atm.Transaction();
                }
                else if (op == "3")
                {
                    break;
                }
            }
        }
Example #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;
                }
            }
        }