📄 atmform.cs
字号:
// ATM.cs created with MonoDevelop// User: Estelle at 1:51 PM 5/5/2008//// To change standard headers go to Edit->Preferences->Coding->Standard Headers//using System;using System.Reflection;using System.Collections;using System.Windows.Forms;using System.Drawing;namespace ATM{ public class ATMForm:Form{ /** * This group of constants is used to naming each page. * By the way, In this application, a page means a form which appearances in the ATMForm * that should be showed in the separated form. Put another way, The ATMForm is consists of * a lot of single form, and they are distincted by the PAGE. */ public const string MENU_PAGE="Menu"; public const string OPERATION_PAGE="Operation"; public const string REGISTER_PAGE="Register"; public const string LOGIN_PAGE="Login"; public const string DEPOSIT_PAGE="Deposit"; public const string DRAW_PAGE="Draw"; public const string QUERY_PAGE="Query_The_Balance"; public const string MODIFY_PASSWORD_PAGE="Modify_The_Password"; /** * This group of constants is used to constrainting the length of the special TextBox. */ public const int MAX_NAME_LENGTH=16; public const int MAX_MONEY_AVAIBLE_LENGTH=4; public const int PASSWORD_LENGTH=6; public const int IC_NUMBER_LENGTH=18; public const int CARD_NUMBER_LENGTH=19; /** * This stands for all the banks this system support. */ public static Bank [] Banks=new Bank[]{ new CCB(), new ICBC() }; /** * Record the current customer. */ public Customer customer=null; /** * The menus is used to keeping the order of pages which has been viewed for returning. * The layouts store the collections of Layout to layout the controls for each page. */ private Stack menus; private String curpage; private Hashtable pages; private Hashtable layouts; private Button register; private Button login; private Button exitATM; private Button deposit; private Button draw; private Button queryBalance; private Button modifyPassword; private Label lblType; private ComboBox types; private Label lblID; private TextBox ID; private Label lblName; private TextBox name; private Label lblPassword; private TextBox password; private Label lblRepwd; private TextBox repwd; private Button submit; private Button cancel; private Label lblCardNo; private TextBox cardNo; private Button authenticat; private Label lblAmount; private TextBox amount; private Button confirm; private Label balance; private Label lblOldPWD; private TextBox oldPWD; /** * This is a method to show a form in this instance. * Every page except some special pages such as LOGIN and REGISTER will be * recorded to the Stack. * * The page stands for pagename which value equals one of the _PAGE constants. */ public void showPage(string page){ try{ if ((this.menus.Count>0)&&(this.menus.Peek().Equals(page)))return; this.curpage=page; if (page.Equals(ATMForm.MENU_PAGE)) this.menus.Clear(); if ((!page.Equals(ATMForm.LOGIN_PAGE))&&(!page.Equals(ATMForm.REGISTER_PAGE))) this.menus.Push(page); this.Controls.Clear(); ArrayList comps=(ArrayList)pages[page]; foreach (Object comp in comps){ try{ ((TextBox)comp).Text=""; }catch(Exception e){ Console.Error.WriteLine(e.Message); } this.Controls.Add((Control)comp); } TableLayout ly=(TableLayout)layouts[page]; ly.layout(); }catch(NullReferenceException nre){ Console.Error.WriteLine(nre); } } /** * Show the last page which has been viewed and pop it. */ public void returnPage(){ try{ this.menus.Pop(); this.showPage((string)this.menus.Pop()); }catch(Exception e){ Console.Error.WriteLine(e.Message); this.showPage(ATMForm.MENU_PAGE); } } /** * Get all the useful controls in the current page. */ public ArrayList getControls(string page){ return (ArrayList)pages[page]; } /** * Get the current page name. */ public string getCurrentPage(){ return this.curpage; } /** * if there is a loginned customers, this method will update the balance Label. */ public void updateBalance(){ if (this.customer==null)return ; CustomerBalance cb=new CustomerBalance(); cb.IDNo=this.customer.IDNo; cb=(CustomerBalance)cb.getEntityByID(); this.balance.Text="The Balance is: "+cb.balance.ToString(); } protected override void OnLoad(EventArgs er){ this.Text="ATM"; Size size=new Size(400,300); this.MinimumSize=this.MaximumSize=size; Rectangle rect=Screen.PrimaryScreen.WorkingArea; this.Location=new Point((rect.Width-this.Width)/2,(rect.Height-this.Height)/2); this.register=this.createButton(ATMForm.REGISTER_PAGE,"GotoPage"); this.login=this.createButton(ATMForm.LOGIN_PAGE,"GotoPage"); this.exitATM=this.createButton("Exit The ATM","ExitATM"); this.deposit=this.createButton(ATMForm.DEPOSIT_PAGE,"GotoPage"); this.draw=this.createButton(ATMForm.DRAW_PAGE,"GotoPage"); this.queryBalance=this.createButton(ATMForm.QUERY_PAGE,"GotoPage"); this.modifyPassword=this.createButton(ATMForm.MODIFY_PASSWORD_PAGE,"GotoPage"); this.lblType=this.createLabel("Card Type"); this.types=this.createComboBox("type",ATMForm.Banks); this.lblID=this.createLabel("Identity Card"); this.ID=this.createTextBox("Identity Card",ATMForm.IC_NUMBER_LENGTH,false); this.lblName=this.createLabel("Real Name"); this.name=this.createTextBox("Real Name",ATMForm.MAX_NAME_LENGTH,false); this.lblPassword=this.createLabel("New Password"); this.password=this.createTextBox("Password",ATMForm.PASSWORD_LENGTH,true); this.lblRepwd=this.createLabel("Confirm PWD"); this.repwd=this.createTextBox("Confirm PWD",ATMForm.PASSWORD_LENGTH,true); this.submit=this.createButton("Submit","Submit"); this.cancel=this.createButton("Cancel","Cancel"); this.lblCardNo=this.createLabel("Card Number"); this.cardNo=this.createTextBox("Card Number",ATMForm.CARD_NUMBER_LENGTH,false); this.authenticat=this.createButton("Login","Login"); this.lblAmount=this.createLabel("Amount"); this.amount=this.createTextBox("Amount",ATMForm.MAX_MONEY_AVAIBLE_LENGTH,false); this.confirm=this.createButton("Confirm","Confirm"); this.balance=this.createLabel("The Balance is: (waiting...)"); this.lblOldPWD=this.createLabel("Login Password"); this.oldPWD=this.createTextBox("OldPassword",ATMForm.PASSWORD_LENGTH,true); this.pages=new Hashtable(); this.layouts=new Hashtable(); this.menus=new Stack(); this.assignComponents(); this.showPage(ATMForm.MENU_PAGE); } /** * Divide all the compoents into the correct page and bind a layout per page. */ private void assignComponents(){ ArrayList page; TableLayout tly; TableLayout.CellConstraint tlcc; //Menu Page page=new ArrayList(); tly=new TableLayout(this,6,5); tlcc=new TableLayout.CellConstraint(1,1); tlcc.size=new Size(4,1); tlcc.space=new TableLayout.Space(3,3,3,3); tly.addCellConstraint(tlcc); page.Add(this.register); tlcc=(TableLayout.CellConstraint)tlcc.Clone(); tlcc.location=new Point(1,2); tly.addCellConstraint(tlcc); page.Add(this.login); tlcc=(TableLayout.CellConstraint)tlcc.Clone(); tlcc.location=new Point(1,3); tly.addCellConstraint(tlcc); page.Add(this.exitATM); pages.Add(ATMForm.MENU_PAGE,page); layouts.Add(ATMForm.MENU_PAGE,tly); //Operation Page page=new ArrayList(); tly=new TableLayout(this,6,7); tlcc=(TableLayout.CellConstraint)tlcc.Clone(); tlcc.location=new Point(1,1); tly.addCellConstraint(tlcc); page.Add(this.deposit); tlcc=(TableLayout.CellConstraint)tlcc.Clone(); tlcc.location=new Point(1,2); tly.addCellConstraint(tlcc); page.Add(this.draw); tlcc=(TableLayout.CellConstraint)tlcc.Clone(); tlcc.location=new Point(1,3); tly.addCellConstraint(tlcc); page.Add(this.queryBalance); tlcc=(TableLayout.CellConstraint)tlcc.Clone(); tlcc.location=new Point(1,4); tly.addCellConstraint(tlcc); page.Add(this.modifyPassword); tlcc=(TableLayout.CellConstraint)tlcc.Clone(); tlcc.location=new Point(1,5); tly.addCellConstraint(tlcc); page.Add(this.cancel); pages.Add(ATMForm.OPERATION_PAGE,page); layouts.Add(ATMForm.OPERATION_PAGE,tly); //Register Page page=new ArrayList(); tly=new TableLayout(this,10,8); tlcc=(TableLayout.CellConstraint)tlcc.Clone(); tlcc.location=new Point(1,1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -