package view;
import java.awt.List;
import com.handson.common.SystemIn;
import exception.BalanceNotEnoughException;
import exception.LoginException;
import exception.RegisterException;
import biz.FileBank;
import biz.IBank;
import biz.Bank;
import biz.ListBank;
public class TextView {
IBank bank;
long thisid;
public void tools(){
System.out.println("********欢迎********");
System.out.println("******注册请输入1*****");
System.out.println("******登录请输入2*****");
System.out.println("******退出请输入3*****");
int i=SystemIn.readInt();
if(i==1){
reg();
}else if(i==2){
login();
}else if(i==3){
System.exit(0);
}else{
tools();
}
}
private void reg() {
System.out.println("请输入姓名>");
String name=SystemIn.readString();
System.out.println("请输入personId>");
String personId=SystemIn.readString();
System.out.println("请输入类型>");
int type=SystemIn.readInt();
System.out.println("请输入密码>");
String password=SystemIn.readString();
System.out.println("请再输入密码>");
String password2=SystemIn.readString();
try{
long result=bank.reg(password, password2, name, personId, type);
System.out.println(result+"注册成功:");
tools();
}catch(RegisterException e){
System.out.println(e.getMessage());
reg();
}
}
private void oper() {
System.out.println("存款请输入1");
System.out.println("取款请输入2");
System.out.println("查询余额请输入3");
System.out.println("退出请输入4");
System.out.println("返回主菜单请输入5");
int num=SystemIn.readInt();
if(num==1){
System.out.println("请输入存款额度>");
double money=SystemIn.readDouble();
bank.deposit(thisid, money);
oper();
}else if(num==2){
System.out.println("请输入取款额度>");
double money=SystemIn.readDouble();
try{
bank.withdraw(thisid, money);
oper();
}catch(BalanceNotEnoughException e){
System.out.println(e.getMessage());
tools();
}
}else if(num==3){
double balance=bank.selectBalance(thisid);
System.out.print("余额为>"+balance);
oper();
}else if(num==4){
System.exit(0);
}else if(num==5){
tools();
}else{
System.out.println("输入有误!");
oper();
}
}
private void login() {
System.out.println("请输入账号>");
long id=SystemIn.readInt();
System.out.println("请输入密码>");
String password=SystemIn.readString();
try{
long resule=bank.login(id, password);
System.out.println("登陆成功!");
this.thisid=resule;
oper();
}catch(LoginException e){
System.out.println(e.getMessage());
tools();
}
}
public TextView() {
super();
}
public TextView(Bank bank) {
super();
this.bank = bank;
}
public TextView(FileBank bank) {
super();
this.bank = bank;
}
public TextView(ListBank bank) {
super();
this.bank = bank;
}
}
import java.awt.List;
import com.handson.common.SystemIn;
import exception.BalanceNotEnoughException;
import exception.LoginException;
import exception.RegisterException;
import biz.FileBank;
import biz.IBank;
import biz.Bank;
import biz.ListBank;
public class TextView {
IBank bank;
long thisid;
public void tools(){
System.out.println("********欢迎********");
System.out.println("******注册请输入1*****");
System.out.println("******登录请输入2*****");
System.out.println("******退出请输入3*****");
int i=SystemIn.readInt();
if(i==1){
reg();
}else if(i==2){
login();
}else if(i==3){
System.exit(0);
}else{
tools();
}
}
private void reg() {
System.out.println("请输入姓名>");
String name=SystemIn.readString();
System.out.println("请输入personId>");
String personId=SystemIn.readString();
System.out.println("请输入类型>");
int type=SystemIn.readInt();
System.out.println("请输入密码>");
String password=SystemIn.readString();
System.out.println("请再输入密码>");
String password2=SystemIn.readString();
try{
long result=bank.reg(password, password2, name, personId, type);
System.out.println(result+"注册成功:");
tools();
}catch(RegisterException e){
System.out.println(e.getMessage());
reg();
}
}
private void oper() {
System.out.println("存款请输入1");
System.out.println("取款请输入2");
System.out.println("查询余额请输入3");
System.out.println("退出请输入4");
System.out.println("返回主菜单请输入5");
int num=SystemIn.readInt();
if(num==1){
System.out.println("请输入存款额度>");
double money=SystemIn.readDouble();
bank.deposit(thisid, money);
oper();
}else if(num==2){
System.out.println("请输入取款额度>");
double money=SystemIn.readDouble();
try{
bank.withdraw(thisid, money);
oper();
}catch(BalanceNotEnoughException e){
System.out.println(e.getMessage());
tools();
}
}else if(num==3){
double balance=bank.selectBalance(thisid);
System.out.print("余额为>"+balance);
oper();
}else if(num==4){
System.exit(0);
}else if(num==5){
tools();
}else{
System.out.println("输入有误!");
oper();
}
}
private void login() {
System.out.println("请输入账号>");
long id=SystemIn.readInt();
System.out.println("请输入密码>");
String password=SystemIn.readString();
try{
long resule=bank.login(id, password);
System.out.println("登陆成功!");
this.thisid=resule;
oper();
}catch(LoginException e){
System.out.println(e.getMessage());
tools();
}
}
public TextView() {
super();
}
public TextView(Bank bank) {
super();
this.bank = bank;
}
public TextView(FileBank bank) {
super();
this.bank = bank;
}
public TextView(ListBank bank) {
super();
this.bank = bank;
}
}