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

📄 statisticdialog.java~46~

📁 是适合于使用的管理系统 可以在现实中使用
💻 JAVA~46~
字号:
package mysiloer;

import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.Vector;
import java.sql.ResultSetMetaData;

/**
 * <p>Title: MySiloer</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: yskey</p>
 *
 * @author 杨涛
 * @version 1.0
 */
public class StatisticDialog
    extends JDialog {
  JPanel panel1 = new JPanel();
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JTextField startField = new JTextField();
  JLabel jLabel3 = new JLabel();
  JTextField endField = new JTextField();
  JButton statisticButt = new JButton();
  JButton cancelButt = new JButton();
  GridBagLayout gridBagLayout1 = new GridBagLayout();
  MainFrame frmae = null;
  Connection con = null;
  StatisticPanel sPanel = null;
  public StatisticDialog(JFrame frame, StatisticPanel panel, boolean modal) {
    super(frame, "统计查询对话框", modal);
    try {
      this.sPanel = panel;
      con = panel.dataBase.connection;
      setDefaultCloseOperation(DISPOSE_ON_CLOSE);
      jbInit();
      pack();
    }
    catch (Exception exception) {
      exception.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    panel1.setLayout(gridBagLayout1);
    jLabel1.setText("请输入要统计的时间段:");
    jLabel2.setText("起始时间:");
    startField.setText("");
    jLabel3.setText("终止时间:");
    endField.setText("");
    statisticButt.setText("统计查询");
    statisticButt.addActionListener(new
                                    StatisticDialog_statisticButt_actionAdapter(this));
    cancelButt.setText("取    消");
    cancelButt.addActionListener(new StatisticDialog_cancelButt_actionAdapter(this));
    this.setResizable(false);
    getContentPane().add(panel1);
    panel1.add(jLabel1, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0
                                               , GridBagConstraints.WEST,
                                               GridBagConstraints.NONE,
                                               new Insets(16, 17, 0, 36), 3, 9));
    panel1.add(jLabel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
                                               , GridBagConstraints.WEST,
                                               GridBagConstraints.NONE,
                                               new Insets(17, 17, 0, 0), 0, 0));
    panel1.add(jLabel3, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
                                               , GridBagConstraints.WEST,
                                               GridBagConstraints.NONE,
                                               new Insets(17, 0, 0, 132), 0, 0));
    panel1.add(endField, new GridBagConstraints(2, 1, 1, 1, 1.0, 0.0
                                                , GridBagConstraints.WEST,
                                                GridBagConstraints.HORIZONTAL,
                                                new Insets(14, 62, 0, 16), 112,
                                                0));
    panel1.add(startField, new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0
                                                  , GridBagConstraints.WEST,
                                                  GridBagConstraints.HORIZONTAL,
                                                  new Insets(14, 76, 0, 0), 112,
                                                  0));
    panel1.add(statisticButt, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
        , GridBagConstraints.CENTER, GridBagConstraints.NONE,
        new Insets(45, 12, 42, 14), 8, 6));
    panel1.add(cancelButt, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
                                                  , GridBagConstraints.CENTER,
                                                  GridBagConstraints.NONE,
                                                  new Insets(45, 37, 42, 75), 8,
                                                  6));
  }

  public void cancelButt_actionPerformed(ActionEvent e) {
    this.setVisible(false);
    this.dispose();
  }

  public void statisticButt_actionPerformed(ActionEvent e) {
    try{
      String startTime = startField.getText();
      String endTime = endField.getText();
      String sql = "select * from "+Type.SILOTABLE+" where 入库时间>'"+startTime+"' and 入库时间<'"+endTime+"'";
      Statement sta = con.createStatement();
      ResultSet set = sta.executeQuery(sql);
      while(set.next()){
        ResultSetMetaData meta = set.getMetaData();
      int colCount = meta.getColumnCount();
      int rowCount =  sPanel.tablePanel.tbModel.getRowCount();
      for(int i = 0; i < rowCount; i++){
        parentPanel.tablePanel.tbModel.removeRow(0);
      }
      Vector colNames = new Vector();
      Vector row;
      for(int i = 1; i <= colCount; i++){
        colNames.add(meta.getColumnLabel(i));
      }
      parentPanel.tablePanel.tbModel.setColumnIdentifiers(colNames);
      while(set.next()){
        row = new Vector();
        for(int i = 1; i <= colCount; i++){
          String temp = set.getString(i);

//          if(i == 3 || i == 4){//单价和数量取两位小数
          if(i == 4){
            temp = temp.substring(0, temp.length() -2);
          }

          if(temp.indexOf(" ") >= 0){
            temp = temp.substring(0, temp.indexOf(" "));
          }
          row.add(temp);
//          System.out.print(set.getString(i)+"   ");
        }
//        System.out.println();
        parentPanel.tablePanel.tbModel.addRow(row);
      }//end while

      }
    }
    catch(SQLException ex){

    }
  }
}

class StatisticDialog_statisticButt_actionAdapter
    implements ActionListener {
  private StatisticDialog adaptee;
  StatisticDialog_statisticButt_actionAdapter(StatisticDialog adaptee) {
    this.adaptee = adaptee;
  }

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

class StatisticDialog_cancelButt_actionAdapter
    implements ActionListener {
  private StatisticDialog adaptee;
  StatisticDialog_cancelButt_actionAdapter(StatisticDialog adaptee) {
    this.adaptee = adaptee;
  }

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

⌨️ 快捷键说明

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