📄 loanpanel.java
字号:
package bank;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.Color;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
public class LoanPanel extends JPanel implements ActionListener{
public LoanPanel(String accountID,String branchname,String pswd) {
try {
jbInit();
this.accountID=accountID;
this.branchname=branchname;
this.pswd=pswd;
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
jButton1.setBorder(BorderFactory.createRaisedBevelBorder());
jButton2.setBackground(new Color(59, 208, 200));
jButton2.setBorder(BorderFactory.createRaisedBevelBorder());
jButton1.setBackground(new Color(72, 208, 200));
jRadioButton1.setBackground(UIManager.getColor(
"InternalFrame.activeTitleGradient"));
jRadioButton2.setBackground(UIManager.getColor(
"InternalFrame.activeTitleGradient"));
jRadioButton3.setBackground(UIManager.getColor(
"InternalFrame.activeTitleGradient"));
jRadioButton4.setBackground(UIManager.getColor(
"InternalFrame.activeTitleGradient"));
jButton3.setBackground(new Color(72, 208, 200));
jButton3.setBorder(BorderFactory.createRaisedBevelBorder());
jButton3.setText("确定");
jButton3.addActionListener(new LoanPanel_jButton3_actionAdapter(this));
this.setBackground(new Color(181, 212, 255));
jLabel1.setText("您所能贷款的最高金额为:");
this.setLayout(xYLayout1);
jTextField1.setEnabled(false);
jRadioButton1.setText("1年以下");
jRadioButton2.setText("3年以下");
jRadioButton3.setText("5年以下");
xYLayout1.setWidth(448);
xYLayout1.setHeight(345);
jLabel2.setText("请选择贷款年数");
jRadioButton4.setText("10年以下");
jLabel3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
jLabel3.setForeground(Color.red);
jLabel3.setText("---------------------------------------------------------------------------------------------------");
jLabel4.setText("贷款利率为:");
jTextField2.setEditable(false);
jTextArea1.setEditable(false);
jTextArea1.setColumns(8);
jTextArea1.setLineWrap(true);
jLabel5.setText("合同书:");
jButton1.setText("确定贷款");
jButton1.addActionListener(new LoanPanel_jButton1_actionAdapter(this));
jButton2.setText("重置");
jButton2.addActionListener(new LoanPanel_jButton2_actionAdapter(this));
jLabel6.setText("请输入您要贷款的金额:");
group.add(jRadioButton1);
group.add(jRadioButton2);
group.add(jRadioButton3);
group.add(jRadioButton4);
jButton1.setVisible(false);
jRadioButton1.addActionListener(this);
jRadioButton2.addActionListener(this);
jRadioButton3.addActionListener(this);
jRadioButton4.addActionListener(this);
this.add(jLabel4, new XYConstraints(7, 150, 87, 29));
this.add(jTextField2, new XYConstraints(89, 152, 163, 31));
this.add(jTextArea1, new XYConstraints(12, 205, 296, 137));
this.add(jLabel5, new XYConstraints(10, 183, 75, 20));
this.add(jLabel3, new XYConstraints(6, 141, 477, 3));
this.add(jLabel2, new XYConstraints(3, 70, 177, 33));
this.add(jRadioButton1, new XYConstraints(7, 107, 68, 27));
this.add(jRadioButton3, new XYConstraints(174, 105, -1, -1));
this.add(jRadioButton2, new XYConstraints(93, 107, -1, -1));
this.add(jRadioButton4, new XYConstraints(258, 100, 97, 30));
this.add(jTextField1, new XYConstraints(11, 40, 190, 29));
this.add(jLabel1, new XYConstraints(10, 8, 157, 31));
this.add(jLabel6, new XYConstraints(220, 12, 149, 21));
this.add(jTextField3, new XYConstraints(217, 40, 179, 32));
this.add(jButton3, new XYConstraints(370, 158, 64, 47));
this.add(jButton2, new XYConstraints(368, 212, 66, 47));
this.add(jButton1, new XYConstraints(369, 265, 65, 54));
this.add(jRadioButton4, new XYConstraints(259, 105, 97, 30));
this.add(jRadioButton4, new XYConstraints(258, 100, 97, 30));
}
ButtonGroup group = new ButtonGroup ();
JLabel jLabel1 = new JLabel();
XYLayout xYLayout1 = new XYLayout();
JTextField jTextField1 = new JTextField();
JRadioButton jRadioButton1 = new JRadioButton();
JRadioButton jRadioButton2 = new JRadioButton();
JRadioButton jRadioButton3 = new JRadioButton();
JLabel jLabel2 = new JLabel();
JRadioButton jRadioButton4 = new JRadioButton();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JTextField jTextField2 = new JTextField();
JTextArea jTextArea1 = new JTextArea();
JLabel jLabel5 = new JLabel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
public double lev=0;//利率
private Connection con;
private Statement stmt;
private String accountID;
private String branchname;
private String pswd;
private int lable;
private float context; //权限
public int year; //年限
static float mon;//要取的金额
public static String customerid;
JLabel jLabel6 = new JLabel();
JTextField jTextField3 = new JTextField();
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jRadioButton1){
jTextField2.setText("0.02");
lev=0.02;
year=1;
}
else if (e.getSource()==jRadioButton2){
jTextField2.setText("0.03");
lev=0.03;
year=3;
}
else if(e.getSource()==jRadioButton3){
jTextField2.setText("0.04");
lev=0.04;
year=5;
}
else{
jTextField2.setText("0.05");
lev=0.05;
year=10;
}
}
public void jButton3_actionPerformed(ActionEvent e) {
//生成合同书
if(lev==0){
//提示选择年份
jTextField2.setText("请选择贷款年数!!");
}
else{
try{
lable=0;
con=bankconnect.getconn();
stmt=con.createStatement();
// System.out.println(a);................................
String sql="select * from borrower where loan_number="+accountID;
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) lable=1;
if(!jTextField3.getText().trim().equals("")){
mon=Float.parseFloat(jTextField3.getText().trim());
sql="select distinct customer.customer_lever,customer.customer_id from customer,depositor,account where customer.customer_id ="+
"depositor.customer_id"+" and depositor.account_num ="+accountID;
rs=stmt.executeQuery(sql);
context=0;
while(rs.next())
{
String a=rs.getString("customer_lever");
context=Float.parseFloat(a);/////////////////////////////////////////////
customerid=rs.getString("customer_id");
jTextField1.setText(context*100+"元");
//生成合同书
if(context*100-mon>=0){ //能够贷款
jTextArea1.append("今天是:"+new java.util.Date()+",你要贷款"+mon+"元"+",利率是:"+lev+"你贷款年限是:"+year+"谢谢光临!");
JOptionPane.showMessageDialog(null,"如果确定贷款,请按确定贷款!");
jButton3.setVisible(false);
jButton1.setVisible(true);
}
else{//不能贷款
JOptionPane.showMessageDialog(null,"对不起,你的权限不能贷取这么多的金额!");
jButton1.setVisible(false);
}
}
}
else{
JOptionPane.showMessageDialog(null,"请输入您要贷款的金额!!");
}
}
catch(SQLException ex){
ex.printStackTrace();
}
}
}
public void jButton1_actionPerformed(ActionEvent e) {
//确认贷款,象签字一样,把合同书存在数据库里,贷款处理,如果出现第2次贷款,
//而且也有权限贷款的话,直接先把上次贷款的金额更新再加上第2笔贷款额,更新最新时间
try{
con=bankconnect.getconn();
stmt=con.createStatement();
String message=jTextArea1.getText().trim();
try{
con.setAutoCommit(false);
String today=TodayTime.getDate();
//............................设置事务...........................
try{
con.setAutoCommit(false);
//插入
String sql;
String loantime="";
double amount=0;
System.out.print(lev);
if(lable==0)
{ sql =
"insert into loan(branch_name,loan_number,amount,loan_co,loan_time,loan_lev) values('" +
branchname + "','" + accountID + "','" + mon + "','" + message +
"','" + today + "','" + lev + "')";
stmt.executeUpdate(sql);
sql = "insert into borrower(customer_id,loan_number) values('" +
customerid + "','" + accountID + "')";
stmt.executeUpdate(sql);
}
else {
sql = "select * from loan where loan_number=" + accountID;
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
String a = "";
a = rs.getString("amount");
amount = Double.parseDouble(a);
loantime = rs.getString("loan_time");
}
float year=Float.parseFloat(PayForPanel.gettime(today))-Float.parseFloat(PayForPanel.gettime(loantime));
/// sql="delete ";
sql="update loan set amount="+(amount+amount*year*lev+mon)+" where loan_number="+accountID;
stmt.executeUpdate(sql);
sql="update loan set loan_time="+today+" where loan_number="+accountID;
stmt.executeUpdate(sql);
}
sql = "update customer set customer_lever=customer_lever-" +
mon / 100 + " where customer_id like '%" + customerid + "%'";
stmt.executeUpdate(sql);
con.commit();
con.setAutoCommit(true);
con.close();
JOptionPane.showMessageDialog(null,"操作成功");
jButton3.setVisible(true);
jButton1.setVisible(false);
}
catch(Exception exp){
con.rollback();
con.close();
exp.printStackTrace();
}
//...................................................................
}
catch(Exception exp){
exp.printStackTrace();
con.rollback();
con.close();
}
}
catch(SQLException ex){
ex.printStackTrace();
}
}
public void jButton2_actionPerformed(ActionEvent e) {
//清空屏幕
jTextArea1.setText("");
jTextField2.setText("");
jButton3.setVisible(true);
jButton1.setVisible(false);
}
}
class LoanPanel_jButton2_actionAdapter
implements ActionListener {
private LoanPanel adaptee;
LoanPanel_jButton2_actionAdapter(LoanPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class LoanPanel_jButton1_actionAdapter
implements ActionListener {
private LoanPanel adaptee;
LoanPanel_jButton1_actionAdapter(LoanPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class LoanPanel_jButton3_actionAdapter
implements ActionListener {
private LoanPanel adaptee;
LoanPanel_jButton3_actionAdapter(LoanPanel adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -