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

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