BankAccounts.cs

本文通过示例代码展示了如何使用两个不同的银行账户(VenusBank和JupiterBank)进行资金存取操作,包括存款、取款和显示账户余额。
using System;
using Wrox.ProCSharp;
using Wrox.ProCSharp.VenusBank;
using Wrox.ProCSharp.JupiterBank;
namespace Wrox.ProCSharp
{
   class MainEntryPoint
   {
      static void Main()
      {
         IBankAccount venusAccount = new SaverAccount();
         IBankAccount jupiterAccount = new GoldAccount();
         venusAccount.PayIn(200);
         venusAccount.Withdraw(100);
         Console.WriteLine(venusAccount.ToString());
         jupiterAccount.PayIn(500);
         jupiterAccount.Withdraw(600);
         jupiterAccount.Withdraw(100);
         Console.WriteLine(jupiterAccount.ToString());
      }
   }
}


namespace Wrox.ProCSharp
{
   public interface IBankAccount
   {
      void PayIn(decimal amount);
      bool Withdraw(decimal amount);
      decimal Balance
      {
         get;
      }
   }
}

namespace Wrox.ProCSharp.VenusBank
{
   public class SaverAccount : IBankAccount
   {
      private decimal balance;
      public void PayIn(decimal amount)
      {
         balance += amount;
      }
      public bool Withdraw(decimal amount)
      {
         if (balance >= amount)
         {
            balance -= amount;
            return true;
         }
         Console.WriteLine("Withdrawal attempt failed.");
         return false;
      }
      public decimal Balance
      {
         get
         {
            return balance;
         }
      }
      public override string ToString()
      {
         return String.Format("Venus Bank Saver: Balance = {0,6:C}", balance);
      }
   }
}

namespace Wrox.ProCSharp.JupiterBank
{
   public class GoldAccount : IBankAccount
   {
      private decimal balance;
      public void PayIn(decimal amount)
      {
         balance += amount;
      }
      public bool Withdraw(decimal amount)
      {
         if (balance >= amount)
         {
            balance -= amount;
            return true;
         }
         Console.WriteLine("Withdrawal attempt failed.");
         return false;
      }
      public decimal Balance
      {
         get
         {
            return balance;
         }
      }
      public override string ToString()
      {
         return String.Format("Jupiter Bank Saver: Balance = {0,6:C}", balance);
      }
        }
 
}

转载于:https://www.cnblogs.com/shihao/archive/2012/05/08/2490247.html

#查询历史记录 def Get_history(): # 连接数据库 conn = pyodbc.connect('DRIVER={SQL Server};SERVER=DESKTOP-JM5K5CS;DATABASE=bank;UID=sa;PWD=1') # 获取游标 cursor = conn.cursor() # 创建窗口 window = tk.Tk() window.title('查询历史记录') # 创建标签和输入框 label_account_number = tk.Label(window, text='卡号:') label_account_number.grid(row=0, column=0) entry_account_number = tk.Entry(window) entry_account_number.grid(row=0, column=1) label_password = tk.Label(window, text='密码:') label_password.grid(row=1, column=0) entry_password = tk.Entry(window, show='*') entry_password.grid(row=1, column=1) label_start_date = tk.Label(window, text='交易日期:') label_start_date.grid(row=2, column=0) entry_start_date = tk.Entry(window) entry_start_date.grid(row=2, column=1) label_transaction_type = tk.Label(window, text='交易方式:') label_transaction_type.grid(row=3, column=0) transaction_var = tk.StringVar(value='所有') transaction_radios = [ ('所有', '所有'), ('存款', '存款'), ('取款', '取款'), ('转入', '转入'), ('转出', '转出') ] for i, (text, value) in enumerate(transaction_radios): radio = tk.Radiobutton(window, text=text, variable=transaction_var, value=value) radio.grid(row=i + 4, column=1) label_password = tk.Label(window, text='备注:') label_password.grid(row=4, column=0) entry_password = tk.Entry(window, show='*') entry_password.grid(row=4, column=1) # 创建按钮和文本框 text_history = tk.Text(window) text_history.grid(row=2, column=0, rowspan=6) def get_history(): # 查询数据 account_number = entry_account_number.get() password = entry_password.get() transaction_date = entry_start_date.get() transaction_type = None if transaction_var.get() != '所有': transaction_type = transaction_var.get() # 查询卡号和密码是否匹配 cursor.execute("SELECT * FROM Accounts WHERE account_number = ? AND password = ?",
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值