JF_view_query_kcmx_rk.java
上传用户:whbcdz
上传日期:2008-08-04
资源大小:7683k
文件大小:14k
源码类别:

JavaScript

开发平台:

Java

  1. package appjxc.view;
  2. import java.awt.*;
  3. import javax.swing.*;
  4. import java.awt.BorderLayout;
  5. import java.awt.Font;
  6. import java.awt.Dimension;
  7. import javax.swing.border.Border;
  8. import java.util.Calendar;
  9. import java.util.Locale;
  10. import javax.swing.event.ChangeEvent;
  11. import javax.swing.event.ChangeListener;
  12. import javax.swing.table.TableColumnModel;
  13. import javax.swing.table.DefaultTableModel;
  14. import java.awt.event.ActionEvent;
  15. import java.awt.event.ActionListener;
  16. import java.awt.event.ItemEvent;
  17. import java.awt.event.ItemListener;
  18. import appjxc.model.Obj_BuyDetaile;
  19. public class JF_view_query_kcmx_rk extends JInternalFrame {
  20.     BorderLayout borderLayout1 = new BorderLayout();
  21.     JPanel jPanel1 = new JPanel();
  22.     GridLayout gridLayout1 = new GridLayout();
  23.     JPanel jPanel2 = new JPanel();
  24.     JPanel jPanel3 = new JPanel();
  25.     FlowLayout flowLayout1 = new FlowLayout();
  26.     JCheckBox jCheckBox1 = new JCheckBox();
  27.     JLabel jLabel1 = new JLabel();
  28.     JComboBox jCid = new JComboBox();
  29.     JComboBox jCysf = new JComboBox();
  30.     JTextField jTvalue = new JTextField();
  31.     JCheckBox jCheckBox2 = new JCheckBox();
  32.     JLabel jLabel2 = new JLabel();
  33.     JLabel jLabel3 = new JLabel();
  34.     JLabel jLabel4 = new JLabel();
  35.     JLabel jLabel6 = new JLabel();
  36.     FlowLayout flowLayout2 = new FlowLayout();
  37.     Border border1 = BorderFactory.createLineBorder(UIManager.getColor(
  38.             "ToolBar.dockingForeground"), 2);
  39.     Border border2 = BorderFactory.createLineBorder(Color.magenta, 1);
  40.     JButton jByes = new JButton();
  41.     JScrollPane jScrollPane1 = new JScrollPane();
  42.     JTable jTable1 = new JTable();
  43.     JFormattedTextField jFormattedTextField1 = new JFormattedTextField();
  44.     JFormattedTextField jFormattedTextField2 = new JFormattedTextField();
  45.     String[] name = {"rkdjh","rksl","rkje"};
  46.     int _idIndex ,_ysfIndex ;
  47.     public JF_view_query_kcmx_rk() {
  48.         _idIndex = 0 ;
  49.         _ysfIndex = 0 ;
  50.         try {
  51.             buildTable();
  52.             jbInit();
  53.         } catch (Exception exception) {
  54.             exception.printStackTrace();
  55.         }
  56.     }
  57.     public void setjSpinner(){
  58.     }
  59.     private void jbInit() throws Exception {
  60.         border2 = BorderFactory.createLineBorder(Color.magenta, 2);
  61.         jFormattedTextField1.setEnabled(false);
  62.         jFormattedTextField2.setEnabled(false);
  63.         border1 = BorderFactory.createLineBorder(Color.red, 1);
  64.         jCheckBox1.setSelected(true);
  65.         jCheckBox2.setSelected(false);
  66.         jCysf.addItem("like");
  67.         jCysf.addItem(">");
  68.         jCysf.addItem("<");
  69.         jCysf.addItem(">=");
  70.         jCysf.addItem("<=");
  71.         jCid.addItem("入库单据号");
  72.         jCid.addItem("入库数量");
  73.         jCid.addItem("入库金额");
  74.         getContentPane().setLayout(borderLayout1);
  75.         jCheckBox2.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  76.         jCheckBox2.setText("入库日期");
  77.         jCheckBox2.addChangeListener(new JF_view_query_kcmx_rk_jCheckBox2_changeAdapter(this));
  78.         jLabel2.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  79.         jLabel2.setText("起始日期:");
  80.         jLabel3.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  81.         jLabel3.setText("终止日期:");
  82.         jLabel4.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  83.         jLabel4.setText("运算符:");
  84.         jLabel6.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  85.         jLabel6.setText("数值:");
  86.         flowLayout1.setHgap(8);
  87.         jPanel3.setLayout(flowLayout2);
  88.         flowLayout2.setHgap(8);
  89.         jCheckBox1.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  90.         jLabel1.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  91.         jCid.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  92.         jCid.setPreferredSize(new Dimension(97, 23));
  93.         jCid.addItemListener(new JF_view_query_kcmx_rk_jCid_itemAdapter(this));
  94.         jPanel2.setBorder(border1);
  95.         jPanel3.setBorder(border2);
  96.         jTvalue.setPreferredSize(new Dimension(156, 24));
  97.         jCysf.setPreferredSize(new Dimension(53, 23));
  98.         jCysf.addItemListener(new JF_view_query_kcmx_rk_jCysf_itemAdapter(this));
  99.         jByes.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  100.         jByes.setText("查询");
  101.         jByes.addActionListener(new JF_view_query_kcmx_rk_jByes_actionAdapter(this));
  102.         jFormattedTextField1.setPreferredSize(new Dimension(139, 24));
  103.         jFormattedTextField2.setPreferredSize(new Dimension(139, 24));
  104.         this.setClosable(true);
  105.         this.getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
  106.         jPanel2.setLayout(flowLayout1);
  107.         jCheckBox1.setText("查询条件");
  108.         jLabel1.setText("选择字段:");
  109.         jPanel1.add(jPanel2);
  110.         jPanel2.add(jCheckBox1);
  111.         jPanel2.add(jLabel1);
  112.         jPanel2.add(jCid);
  113.         jPanel2.add(jLabel4);
  114.         jPanel2.add(jCysf);
  115.         jPanel2.add(jLabel6);
  116.         jPanel2.add(jTvalue);
  117.         jPanel1.add(jPanel3);
  118.         jPanel3.add(jCheckBox2);
  119.         jPanel3.add(jLabel2);
  120.         jPanel3.add(jFormattedTextField1);
  121.         jPanel3.add(jLabel3);
  122.         jPanel3.add(jFormattedTextField2);
  123.         jPanel3.add(jByes);
  124.         this.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
  125.         jScrollPane1.getViewport().add(jTable1);
  126.         gridLayout1.setColumns(1);
  127.         gridLayout1.setRows(2);
  128.         jPanel1.setLayout(gridLayout1);
  129.         this.setSize(750,550);
  130.         this.setVisible(true);
  131.         UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
  132.         SwingUtilities.updateComponentTreeUI(this);
  133.     }
  134.     public void buildTable(){//"药品名称","药品批号","规格","产地","单位",,"零售价","有效期至"
  135.         String[] tname = {"入库单据号","药品编号","进货价格","进货数量","进货金额","进货日期"};
  136.         java.util.Vector vname = new java.util.Vector();
  137.         for (int i = 0 ; i < tname.length ; i++){
  138.             vname.addElement(tname[i]);
  139.         }
  140.         DefaultTableModel tableModel = null;
  141.         tableModel = new DefaultTableModel(vname,0);
  142.         jTable1.setModel(tableModel);
  143.         TableColumnModel tcm = jTable1.getColumnModel();
  144.     }
  145.     public void jCheckBox2_stateChanged(ChangeEvent e) {
  146.         if(jCheckBox2.isSelected()){
  147.             jFormattedTextField1.setEnabled(true);
  148.             jFormattedTextField2.setEnabled(true);
  149.             long nCurrentTime = System.currentTimeMillis();
  150.             java.util.Calendar calendar = java.util.Calendar.getInstance(new
  151.                     Locale("CN"));
  152.             calendar.setTimeInMillis(nCurrentTime);
  153.             int year = calendar.get(Calendar.YEAR);
  154.             int month = calendar.get(Calendar.MONTH) + 1;
  155.             int day = calendar.get(Calendar.DAY_OF_MONTH);
  156.             String mm, dd;
  157.             if (month < 10) {
  158.                 mm = "0" + String.valueOf(month);
  159.             } else {
  160.                 mm = String.valueOf(month);
  161.             }
  162.             if (day < 10) {
  163.                 dd = "0" + String.valueOf(day);
  164.             } else {
  165.                 dd = String.valueOf(day);
  166.             }
  167.           //  System.out.println(year + "-" + mm + "-" + dd);
  168.             java.sql.Date date = java.sql.Date.valueOf(year + "-" + mm + "-" +
  169.                     dd);
  170.             jFormattedTextField1.setText(String.valueOf(date));
  171.             jFormattedTextField2.setText(String.valueOf(date));
  172.         }else{
  173.             jFormattedTextField1.setEnabled(false);
  174.             jFormattedTextField2.setEnabled(false);
  175.             jFormattedTextField1.setText(String.valueOf(""));
  176.              jFormattedTextField2.setText(String.valueOf(""));
  177.         }
  178.     }
  179.     public void jByes_actionPerformed(ActionEvent e) {
  180.         if (jCheckBox1.isSelected()){
  181.            if (jTvalue.getText().trim().length() <= 0){
  182.                JOptionPane.showMessageDialog(null, "请输入查询数值!!", "提示",
  183.                                              JOptionPane.ERROR_MESSAGE);
  184.                jTvalue.requestFocus();
  185.                return;
  186.           }
  187.        }
  188.         String[] tname = {"入库单据号","药品编号","进货价格","进货数量","进货金额","进货日期"};
  189.         java.util.Vector vname = new java.util.Vector();
  190.         for (int i = 0 ; i < tname.length ; i++){
  191.             vname.addElement(tname[i]);
  192.         }
  193.         DefaultTableModel tableModel = null;
  194.         tableModel = new DefaultTableModel(vname,0);
  195.         jTable1.setModel(tableModel);
  196.         String whereStr = null,queryStr = null;
  197.         System.out.println(_ysfIndex);
  198.         if(jCheckBox1.isSelected() && !jCheckBox2.isSelected()){
  199.             if (_ysfIndex == 0){
  200.                whereStr = name[_idIndex] + " " + jCysf.getSelectedItem() + " '%" +
  201.                           jTvalue.getText().trim() + "%'";
  202.             }else{
  203.               whereStr = name[_idIndex] + " " + jCysf.getSelectedItem() + " '" +
  204.                      jTvalue.getText().trim() + "'";
  205.             }
  206.         }else if(jCheckBox1.isSelected()&& jCheckBox2.isSelected()){
  207.             java.sql.Date date1,date2 ;
  208.             try{
  209.                 date1 = java.sql.Date.valueOf(jFormattedTextField1.getText().trim());
  210.                 date2 = java.sql.Date.valueOf(jFormattedTextField2.getText().trim());
  211.                 System.out.println("date1 = " + date1 + "; date2 = " + date2);
  212.                 jFormattedTextField1.setText(String.valueOf(date1));
  213.                 jFormattedTextField2.setText(String.valueOf(date2));
  214.                 if (date1.after(date2)){
  215.                     JOptionPane.showMessageDialog(null,"输入的起始日期不能小于终止日期!!!","系统提示",JOptionPane.ERROR_MESSAGE);
  216.                     return;
  217.                 }
  218.             }catch(java.lang.NumberFormatException formate){
  219.                 JOptionPane.showMessageDialog(null,"输入的日期有误!!!n" + formate.getMessage(),"系统提示",JOptionPane.ERROR_MESSAGE);
  220.                 return;
  221.             }
  222.             if (_ysfIndex == 0){
  223.                whereStr = name[_idIndex] + " " + jCysf.getSelectedItem() + " '%" +
  224.                           jTvalue.getText().trim() + "%' and rkrq >= '" + date1 + "' and rkrq <= '" + date2 + "'";
  225.             }else{
  226.                 whereStr = name[_idIndex] + " " + jCysf.getSelectedItem() + " '" +
  227.                    jTvalue.getText().trim() + "' and rkrq >= '" + date1 + "' and rkrq <= '" + date2 + "'";
  228.             }
  229.         }else if(!jCheckBox1.isSelected() && jCheckBox2.isSelected()){
  230.             java.sql.Date date1,date2 ;
  231.             try{
  232.                 date1 = java.sql.Date.valueOf(jFormattedTextField1.getText().trim());
  233.                 date2 = java.sql.Date.valueOf(jFormattedTextField2.getText().trim());
  234.                 System.out.println("date1 = " + date1 + "; date2 = " + date2);
  235.                 jFormattedTextField1.setText(String.valueOf(date1));
  236.                 jFormattedTextField2.setText(String.valueOf(date2));
  237.                 if (date1.after(date2)){
  238.                     JOptionPane.showMessageDialog(null,"输入的起始日期不能小于终止日期!!!","系统提示",JOptionPane.ERROR_MESSAGE);
  239.                     return;
  240.                 }
  241.             }catch(java.lang.NumberFormatException formate){
  242.                 JOptionPane.showMessageDialog(null,"输入的日期有误!!!n" + formate.getMessage(),"系统提示",JOptionPane.ERROR_MESSAGE);
  243.                 return;
  244.             }
  245.             whereStr = " rkrq >= '" + date1 + "' and rkrq <= '" + date2 + "'";
  246.         }else if(!jCheckBox1.isSelected() && !jCheckBox2.isSelected()){
  247.             return;
  248.         }
  249.         queryStr = " from Obj_BuyDetaile where " + whereStr;
  250.         System.out.println(queryStr);
  251.         java.util.List list = appjxc.dao.AdapterDao.QueryObject(queryStr);
  252.         if (list.size() <= 0){
  253.             JOptionPane.showMessageDialog(null,"没有找到满足条件的数据!!","系统提示",JOptionPane.INFORMATION_MESSAGE);
  254.             return;
  255.         }
  256.         int rowcount = jTable1.getRowCount();
  257.         System.out.println("list.size() = " + list.size());
  258.         java.util.Iterator iterator = list.iterator();
  259.         //DefaultTableModel table = new DefaultTableModel();
  260.         while(iterator.hasNext()){
  261.             Obj_BuyDetaile buy = (Obj_BuyDetaile)iterator.next();
  262.             java.util.Vector vdata = new java.util.Vector();
  263.             vdata.addElement(buy.getRkdjh());
  264.             vdata.addElement(buy.getYpbh());
  265.             vdata.addElement(String.valueOf(buy.getRkdj()));
  266.             vdata.addElement(String.valueOf(buy.getRksl()));
  267.             vdata.addElement(String.valueOf(buy.getRkje()));
  268.             vdata.addElement(buy.getRkrq());
  269.             tableModel.addRow(vdata);
  270.         }
  271.         jTable1.setModel(tableModel);
  272.         jTable1.setRowHeight(20);
  273.     }
  274.     public void jCid_itemStateChanged(ItemEvent e) {
  275.         _idIndex = jCid.getSelectedIndex();
  276.     }
  277.     public void jCysf_itemStateChanged(ItemEvent e) {
  278.         _ysfIndex = jCysf.getSelectedIndex();
  279.     }
  280. }
  281. class JF_view_query_kcmx_rk_jByes_actionAdapter implements ActionListener {
  282.     private JF_view_query_kcmx_rk adaptee;
  283.     JF_view_query_kcmx_rk_jByes_actionAdapter(JF_view_query_kcmx_rk adaptee) {
  284.         this.adaptee = adaptee;
  285.     }
  286.     public void actionPerformed(ActionEvent e) {
  287.         adaptee.jByes_actionPerformed(e);
  288.     }
  289. }
  290. class JF_view_query_kcmx_rk_jCid_itemAdapter implements ItemListener {
  291.     private JF_view_query_kcmx_rk adaptee;
  292.     JF_view_query_kcmx_rk_jCid_itemAdapter(JF_view_query_kcmx_rk adaptee) {
  293.         this.adaptee = adaptee;
  294.     }
  295.     public void itemStateChanged(ItemEvent e) {
  296.         adaptee.jCid_itemStateChanged(e);
  297.     }
  298. }
  299. class JF_view_query_kcmx_rk_jCysf_itemAdapter implements ItemListener {
  300.     private JF_view_query_kcmx_rk adaptee;
  301.     JF_view_query_kcmx_rk_jCysf_itemAdapter(JF_view_query_kcmx_rk adaptee) {
  302.         this.adaptee = adaptee;
  303.     }
  304.     public void itemStateChanged(ItemEvent e) {
  305.         adaptee.jCysf_itemStateChanged(e);
  306.     }
  307. }
  308. class JF_view_query_kcmx_rk_jCheckBox2_changeAdapter implements ChangeListener {
  309.     private JF_view_query_kcmx_rk adaptee;
  310.     JF_view_query_kcmx_rk_jCheckBox2_changeAdapter(JF_view_query_kcmx_rk adaptee) {
  311.         this.adaptee = adaptee;
  312.     }
  313.     public void stateChanged(ChangeEvent e) {
  314.         adaptee.jCheckBox2_stateChanged(e);
  315.     }
  316. }