⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getmoneypanel.java

📁 银行管理系统,根据实习的要求以及参考现实中的银行数据库系统
💻 JAVA
字号:
package bank;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.*;
import java.util.Calendar;
import java.awt.Color;
import java.awt.SystemColor;

//GET OUT THE MONEY...
public class GetMoneyPanel extends JPanel {
  public GetMoneyPanel() {
    try {
      jbInit();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  public GetMoneyPanel(String accountID,String branchname,String pswd) {
    try {
      jbInit();
      this.accountID=accountID;
      this.branchname=branchname;
      this.pswd=pswd;
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  private String accountID;
  private String branchname;
  private String pswd;
  private void jbInit() throws Exception {
    jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
    this.setLayout(xYLayout1);
    jLabel1.setText("取钱金额:");
    jLabel2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
    jLabel2.setText("结果显示:");
    jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
    jButton1.setText("确定");
    jButton4.setVisible(true);
    jButton1.addActionListener(new GetMoneyPanel_jButton1_actionAdapter(this));
    jTextArea1.setBackground(SystemColor.text);
    jTextArea1.setToolTipText("");
    jTextArea1.setEditable(false);
    jTextArea1.setRows(3);
    jTextArea1.setColumns(8);
    jTextArea1.setLineWrap(true);
    jButton2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
    jButton2.setText("重置");
    jButton3.setVisible(false);
    xYLayout1.setWidth(413);
    xYLayout1.setHeight(311);
    this.setBackground(new Color(190, 241, 183));
    jButton3.setText("透支");
    jButton3.addActionListener(new GetMoneyPanel_jButton3_actionAdapter(this));
    jButton2.addActionListener(new GetMoneyPanel_jButton2_actionAdapter(this));
    jButton4.setText("打印");
    jButton4.addActionListener(new GetMoneyPanel_jButton4_actionAdapter(this));
    this.add(jLabel1, new XYConstraints(26, 48, 80, 44));
    this.add(jTextField1, new XYConstraints(121, 60, 171, 31));
    this.add(jTextArea1, new XYConstraints(30, 133, 272, 107));
    this.add(jLabel2, new XYConstraints(31, 102, 91, 27));
    this.add(jButton1, new XYConstraints(317, 63, 65, 31));
    this.add(jButton2, new XYConstraints(318, 119, 67, 31));
    this.add(jButton3, new XYConstraints(320, 173, 67, 35));
    this.add(jButton4, new XYConstraints(318, 243, 65, 32));
  }

  JLabel jLabel1 = new JLabel();
  XYLayout xYLayout1 = new XYLayout();
  JTextField jTextField1 = new JTextField();
  JTextArea jTextArea1 = new JTextArea();
  JLabel jLabel2 = new JLabel();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  static float getM;
  static  float bal;
  public static java.util.Date dt=new java.util.Date();
  private Connection con;
  JButton jButton3 = new JButton();
  JButton jButton4 = new JButton();
  public void jButton1_actionPerformed(ActionEvent e) {
     getM=Float.parseFloat(jTextField1.getText().trim());
     String sql="select balance from account where account_num like "+"'%"+accountID.trim()+"%'";
      try
    {
      con = bankconnect.getconn();
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery(sql);
      int lable = 0;
      while (rs.next()) {
        bal = Float.parseFloat(rs.getString("balance").trim());
        //  if(bal%100!=0.0&&bal%50!=0.0) {  JOptionPane.showMessageDialog(null,"请输入整100或者整50,谢谢合作!");jTextField1.setText("");}

        if ( (bal - getM) >= 0) { //能够取
            try{
              con.setAutoCommit(false);
              sql = "update account set balance = balance -" + getM +
                  "where account_num like " + "'%" + accountID.trim() +
                  "%'";
              stmt.executeUpdate(sql);
              jTextArea1.setText("现在是:" + dt + ",已经成功取出" + getM + "元,谢谢光临!");
              sql = "insert into message(account_num,message_context,message_time,message_class) values('" +
                  accountID + "','" + jTextArea1.getText() + "','" +
                  TodayTime.getLongDate() + "',1)";
              stmt.executeUpdate(sql); //存取信息。。。
              con.commit();
              con.setAutoCommit(true);
              con.close();
              JOptionPane.showMessageDialog(null, "已经成功取出,谢谢光临!");
               jButton4.setVisible(true);
            }
            catch(Exception exp){
              con.rollback();
              con.close();
              exp.printStackTrace();
            }
        }
        else { //不能取
            jButton3.setVisible(true);
          int lev = 0;
          jTextArea1.setText("你的余额不足!");
          sql = "select customer_lever from customer where  customer_id in (select depositor.customer_id from depositor where account_num in (select account.account_num from account))";
          rs = stmt.executeQuery(sql);
          while (rs.next())
            lev = rs.getInt("customer_lever");
          if (lev > 0) { //判断透支等级,能就透支
            float mo = bal + lev * 100;
            jTextArea1.append("你现在可以透支" + lev * 100 + "元,总共可以取" + mo +
                              "元,确定要取钱吗?");
          }
        }
      }
    }
  catch (SQLException ex) {
    System.out.println("数据库连接错误" + ex.toString());
           }

  }

  public void jButton3_actionPerformed(ActionEvent e) {
     String sql;
    try{
      con = bankconnect.getconn();
     Statement stmt = con.createStatement();
   //  ResultSet rs = stmt.executeQuery(sql);
    try{
      con.setAutoCommit(false);
      sql = "update account set balance=balance-" + getM +
          "where account_num like '%" + accountID.trim() + "%'";
      stmt.executeUpdate(sql);
      //更新信誉度级别????
      sql = "update customer set customer_lever=customer_lever-" +
          (getM - bal) / 100
          + "  where  customer_id in (select depositor.customer_id from depositor,account where depositor.account_num=account.account_num ) ";
      stmt.executeUpdate(sql);
      jTextArea1.append("现在是:" + dt + ",已经成功取出" + getM + "元,请尽快还清款项!谢谢光临!");
      sql = "insert into message(account_num,message_context,message_time,message_class) values('" +
          accountID + "','" + jTextArea1.getText() + "','" +
          TodayTime.getLongDate() + "',2)";
      stmt.executeUpdate(sql); //存取信息。。
      con.commit();
      con.setAutoCommit(true);
      con.close();
      jButton3.setVisible(false);
      jButton4.setVisible(true);
    }
     catch(Exception exp){
              con.rollback();
              con.close();
              exp.printStackTrace();
            }

  }
  catch (SQLException ex)
  {
     System.out.println("数据库连接错误" + ex.toString());
  }

  }

  public void jButton2_actionPerformed(ActionEvent e) {
     jTextField1.setText("");
     jTextArea1.setText("");
     jButton4.setVisible(false);
  }

  public void jButton4_actionPerformed(ActionEvent e) {
    JOptionPane.showMessageDialog(null,"succeed!");
    jButton4.setVisible(false);
  }

  /* public void actionPerformed(ActionEvent e){

    if(e.getSource()==jButton1){
   //取钱操作
         float getM=Float.parseFloat(jTextField1.getText().trim());
         String sql="select balance from account where account_num like "+"'%"+accountID.trim()+"%'";
         try{
           con = bankconnect.getconn();
           Statement stmt = con.createStatement();
           ResultSet rs = stmt.executeQuery(sql);
           int lable = 0;
           java.util.Date dt = new java.util.Date();
           //   Date today=new Date();

           float bal;
           while (rs.next()) {
             bal = Float.parseFloat(rs.getString("balance").trim());
           //  if(bal%100!=0.0&&bal%50!=0.0) {  JOptionPane.showMessageDialog(null,"请输入整100或者整50,谢谢合作!");jTextField1.setText("");}

            if ( (bal - getM) >= 0.000001) { //能够取
               sql = "update account set balance = balance -" + getM +
                   "where account_num like " + "'%" + accountID.trim() + "%'";
               stmt.executeUpdate(sql);
               //??有问题
               jTextArea1.setText("现在是:" + dt + ",已经成功取出" + getM + "元,谢谢光临!");
               //  JOptionPane.showMessageDialog(null,"已经成功取出,谢谢光临!");
             }
             else { //不能取
                int lev=0;
                 jTextArea1.setText("你的余额不足!");
                sql = "select customer_lever from customer where  customer_id in (select depositor.customer_id from depositor where account_num in (select account.account_num from account))";
                rs=stmt.executeQuery(sql);
                while(rs.next())
                   lev=rs.getInt("customer_lever");
                  if( lev > 0) //判断透支等级,能就透支
                  {
                   float mo= bal+lev*100;
                     jTextArea1.append("你现在可以透支"+lev*100+"元,总共可以取"+mo+"元,确定要取钱吗?");
                     if(e.getSource()==jButton3){
                        sql="update account set balance=balance-"+getM+"where account_num like '%"+accountID.trim() + "%'";
                        stmt.executeUpdate(sql);
                        //更新信誉度级别????
                         sql="update customer set customer_lever=customer_lever-"+(getM-bal)/100
                             +"  where  customer_id in (select depositor.customer_id from depositor,account where depositor.account_num=account.account_num ) ";
                         stmt.executeUpdate(sql);
                        jTextArea1.append("现在是:" + dt + ",已经成功取出" + getM + "元,请尽快还清款项!谢谢光临!");
                     }
                  }
                    //不能透支
                  else{
                     jTextArea1.append("非常抱歉!你所在的权限不能取钱!!!");
                   }
                }
               rs.close();
               con.close();
               return;

             }
           }

           catch (SQLException ex) {
             System.out.println("数据库连接错误" + ex.toString());
           }



  }
    else {
  //重置
     jTextField1.setText("");
     jTextArea1.setText("");
    }
  }*/
}

class GetMoneyPanel_jButton4_actionAdapter
    implements ActionListener {
  private GetMoneyPanel adaptee;
  GetMoneyPanel_jButton4_actionAdapter(GetMoneyPanel adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton4_actionPerformed(e);
  }
}

class GetMoneyPanel_jButton2_actionAdapter
    implements ActionListener {
  private GetMoneyPanel adaptee;
  GetMoneyPanel_jButton2_actionAdapter(GetMoneyPanel adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}

class GetMoneyPanel_jButton3_actionAdapter
    implements ActionListener {
  private GetMoneyPanel adaptee;
  GetMoneyPanel_jButton3_actionAdapter(GetMoneyPanel adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton3_actionPerformed(e);
  }
}

class GetMoneyPanel_jButton1_actionAdapter
    implements ActionListener {
  private GetMoneyPanel adaptee;
  GetMoneyPanel_jButton1_actionAdapter(GetMoneyPanel adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -