package com.view;
import java.awt.Button;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Label;
import java.awt.MediaTracker;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import com.common.Start;
import com.db.VIPdb;
import com.model.CheckbalanceModel;
import com.model.ExchangeMoneyModel;
import com.model.LoginModel;
import com.model.ModifyPasswordModel;
import com.model.VIPCreditCheckModel;
public class VIPCreditCheckFrame extends Frame {
/**
* 修改密码界面
*
* @author lz
*/
private Frame vipccf;
private Image img;
private MediaTracker tracker;
private Button okButton;
private Button rebackButton;
private Label name;
private Label id;
private Label money;
private TextField nameText;
private TextField idText;
private TextField moneyText;
/*
* 初始化方法
*/
VIPCreditCheckFrame() {
init();
}
/*
* 设置窗口属性
*/
public void init() {
// 实例化
okButton = new Button("确定");
rebackButton = new Button("返回");
name = new Label("您的姓名:");
id = new Label("您的身份证号码:");
money = new Label("贷款金额:");
nameText = new TextField();
idText = new TextField();
moneyText = new TextField();
// 设置属性
vipccf = this;
this.setBounds(500, 150, 400, 500);
this.setLayout(null);
this.setTitle("重庆邮政储蓄银行ATM机");
this.setResizable(false);
this.setUndecorated(true);
tracker = new MediaTracker(this);
img = Toolkit.getDefaultToolkit().getImage("F:\\学习\\java程序设计\\贷款.jpg");
name.setBounds(80, 70, 100, 25);
name.setFont(new Font("宋体", Font.BOLD, 13));
id.setBounds(80, 130, 200, 25);
id.setFont(new Font("宋体", Font.BOLD, 13));
money.setBounds(80, 300, 100, 25);
money.setFont(new Font("宋体", Font.BOLD, 13));
nameText.setBounds(125, 100, 160, 20);
idText.setBounds(125, 160, 160, 20);
moneyText.setBounds(125, 330, 160, 20);
okButton.setBounds(140, 380, 52, 24);
okButton.setFont(new Font("宋体", Font.BOLD, 13));
rebackButton.setBounds(210, 380, 52, 24);
rebackButton.setFont(new Font("宋体", Font.BOLD, 13));
// 添加组件
this.add(okButton);
this.add(rebackButton);
this.add(name);
this.add(id);
this.add(money);
this.add(nameText);
this.add(idText);
this.add(moneyText);
tracker.addImage(img, 1);
show();
// 窗口事件
this.addWindowListener(new WindowListener() {
@Override
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent arg0) {
System.exit(0);
}
@Override
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
});
// id文本事件
idText.addTextListener(new TextListener() {
@Override
public void textValueChanged(TextEvent arg0) {
LoginModel lm = new LoginModel();
String getid = idText.getText();
Boolean b = lm.check(getid);
if (getid.substring(getid.length() - 1, getid.length()).equals(
"X")) {
} else {
if (b == false) {
JOptionPane.showMessageDialog(null, "ID只能为数字,请重新输入");
idText.setText(null);
}
}
}
});
// 贷款金额文本事件
moneyText.addTextListener(new TextListener() {
@Override
public void textValueChanged(TextEvent arg0) {
LoginModel lm = new LoginModel();
if (lm.check(moneyText.getText()) == false) {
JOptionPane.showMessageDialog(null, "金额输入有误,请重新输入");
moneyText.setText(null);
}
}
});
// 确定按钮事件
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
double getMoney;
VIPCreditCheckModel vipccm = new VIPCreditCheckModel();
VIPdb vipdb = new VIPdb();
CheckbalanceModel cbm = new CheckbalanceModel();
double getBanlance = 0.0;
double money;
getBanlance = cbm.checkBalance(Start.username);
int i = 0;
try {
i = vipdb.checkVIP(Start.username);
} catch (SQLException e) {
e.printStackTrace();
}
getMoney = Double.valueOf(moneyText.getText());
money = getBanlance - getMoney;
if (idText.getText().length() != 18) {
JOptionPane.showMessageDialog(null, "ID应该为18位,请重新输入");
idText.setText(null);
} else {
if(getBanlance > 0 ){
JOptionPane.showMessageDialog(null, "您的账户余额为"+getBanlance);
}
if (i == 1) {
if (getBanlance < -5000) {
JOptionPane.showMessageDialog(null,
"您已贷款5000,不能进行更多的贷款");
} else {
if (money > -5000) {
vipccm.credit(Start.username,
nameText.getText(), idText.getText(),
getMoney);
} else {
JOptionPane.showMessageDialog(null,
"青铜会员,最高只能贷款5000");
nameText.setText(null);
idText.setText(null);
moneyText.setText(null);
}
}
}
if (i == 2) {
if (getBanlance <= -10000) {
JOptionPane.showMessageDialog(null,
"您已贷款10000,不能进行更多的贷款");
} else {
if (money > -10000) {
vipccm.credit(Start.username,
nameText.getText(), idText.getText(),
getMoney);
} else {
JOptionPane.showMessageDialog(null,
"白银会员,最高只能贷款10000");
nameText.setText(null);
idText.setText(null);
moneyText.setText(null);
}
}
}
if (i == 3) {
if (getBanlance <= -50000) {
JOptionPane.showMessageDialog(null,
"您已贷款50000,不能进行更多的贷款");
} else {
if (money > -50000) {
vipccm.credit(Start.username,
nameText.getText(), idText.getText(),
getMoney);
} else {
JOptionPane.showMessageDialog(null,
"黄金会员,最高只能贷款50000");
nameText.setText(null);
idText.setText(null);
moneyText.setText(null);
}
}
}
}
}
});
// 返回按钮事件
rebackButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new VIPFrame().setVisible(true);
vipccf.setVisible(false);
}
});
}
public void paint(Graphics g) {
g.drawImage(img, 60, 180, 280, 120, vipccf);
}
}