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

JavaScript

开发平台:

Java

  1. package appjxc.view;
  2. import javax.swing.*;
  3. import java.awt.BorderLayout;
  4. import java.awt.FlowLayout;
  5. import java.awt.SystemColor;
  6. import javax.swing.border.Border;
  7. import javax.swing.border.TitledBorder;
  8. import java.awt.Font;
  9. import javax.swing.border.BevelBorder;
  10. import java.awt.Color;
  11. import javax.swing.BorderFactory;
  12. import java.awt.Dimension;
  13. import appjxc.model.obj_medicine;
  14. import appjxc.model.Obj_client;
  15. import appjxc.model.Obj_gys;
  16. import javax.swing.table.DefaultTableModel;
  17. import java.awt.event.ItemEvent;
  18. import java.awt.event.ItemListener;
  19. import java.awt.event.ActionEvent;
  20. import java.awt.event.ActionListener;
  21. import java.awt.event.KeyEvent;
  22. import java.awt.event.KeyAdapter;
  23. public class JF_view_query_jbqk extends JInternalFrame {
  24.     BorderLayout borderLayout1 = new BorderLayout();
  25.     JPanel jPanel1 = new JPanel();
  26.     JScrollPane jScrollPane1 = new JScrollPane();
  27.     JTable jTable1 = new JTable();
  28.     FlowLayout flowLayout1 = new FlowLayout();
  29.     JLabel jLabel1 = new JLabel();
  30.     JComboBox jCobj = new JComboBox();
  31.     Border border1 = BorderFactory.createLineBorder(SystemColor.controlText, 2);
  32.     Border border2 = new TitledBorder(border1, "查询参数设置");
  33.     JLabel jLabel2 = new JLabel();
  34.     JComboBox jCid = new JComboBox();
  35.     JComboBox jCysf = new JComboBox();
  36.     JLabel jLabel3 = new JLabel();
  37.     JTextField jTvalue = new JTextField();
  38.     JButton jByes = new JButton();
  39.     JButton jBquit = new JButton();
  40.     Object[] object = {new obj_medicine(),new Obj_client(),new Obj_gys()};
  41.     String[] name = {"ypbh","pym"};
  42.     int _objIndex = 0,_idIndex = 0,_ysfIndex = 0;
  43.     public JF_view_query_jbqk() {
  44.         try {
  45.             jbInit();
  46.         } catch (Exception ex) {
  47.             ex.printStackTrace();
  48.         }
  49.     }
  50.     public static void main(String[] args) {
  51.         JF_view_query_jbqk jf_view_query_jbqk = new JF_view_query_jbqk();
  52.     }
  53.     private void jbInit() throws Exception {
  54.       //  object[1] = {new obj_medicine(),new Obj_client(),new Obj_gys()};
  55.         jCobj.addItem("药品基本信息");
  56.         jCobj.addItem("客户基本信息");
  57.         jCobj.addItem("供应商基本信息");
  58.         jCysf.addItem("like");
  59.         jCysf.addItem(">");
  60.         jCysf.addItem("<");
  61.         jCid.addItem("信息编号");
  62.         jCid.addItem("拼音码");
  63.         border2 = new TitledBorder(border1, "设置查询参数",
  64.                                      TitledBorder.DEFAULT_JUSTIFICATION,
  65.                                      TitledBorder.DEFAULT_POSITION,
  66.                                      new java.awt.Font("新宋体", 0, 12),
  67.                                      Color.red);
  68.         this.getContentPane().setLayout(borderLayout1);
  69.         jCobj.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  70.         jCobj.addItemListener(new JF_view_query_jbqk_jCobj_itemAdapter(this));
  71.         jLabel3.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  72.         jLabel3.setText("数值:");
  73.         jTvalue.setMinimumSize(new Dimension(106, 21));
  74.         jTvalue.setPreferredSize(new Dimension(136, 24));
  75.         jTvalue.setText("");
  76.         jByes.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  77.         jByes.setText("查询");
  78.         jByes.addActionListener(new JF_view_query_jbqk_jByes_actionAdapter(this));
  79.         jBquit.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  80.         jBquit.setText("关闭");
  81.         jLabel1.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  82.         jLabel2.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  83.         jCid.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  84.         jCid.addItemListener(new JF_view_query_jbqk_jCid_itemAdapter(this));
  85.         jCysf.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  86.         flowLayout1.setHgap(8);
  87.         flowLayout1.setVgap(8);
  88.         borderLayout1.setVgap(3);
  89.         this.setClosable(true);
  90.         this.setMaximizable(true);
  91.         jCysf.addItemListener(new JF_view_query_jbqk_jCysf_itemAdapter(this));
  92.         jCobj.setPreferredSize(new Dimension(133, 25));
  93.         jCid.setPreferredSize(new Dimension(95, 25));
  94.         jCysf.setPreferredSize(new Dimension(85, 25));
  95.         jTvalue.addKeyListener(new JF_view_query_jbqk_jTvalue_keyAdapter(this));
  96.         jBquit.addActionListener(new JF_view_query_jbqk_jBquit_actionAdapter(this));
  97.         this.getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
  98.         jPanel1.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  99.         jPanel1.setBorder(border2);
  100.         jLabel2.setText("运算符:");
  101.         jPanel1.add(jCobj);
  102.         jPanel1.add(jLabel1);
  103.         jPanel1.add(jCid);
  104.         jPanel1.add(jLabel2);
  105.         jPanel1.add(jCysf);
  106.         jPanel1.add(jLabel3);
  107.         jPanel1.add(jTvalue);
  108.         jPanel1.add(jByes);
  109.         jPanel1.add(jBquit);
  110.         jLabel1.setText("查询字段:");
  111.         jPanel1.setLayout(flowLayout1);
  112.         this.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
  113.         jScrollPane1.getViewport().add(jTable1);
  114.         this.setSize(850,550);
  115.         this.setVisible(true);
  116.     }
  117.     public void jCobj_itemStateChanged(ItemEvent e) {
  118.         _objIndex = jCobj.getSelectedIndex();
  119.         if (_objIndex == 0) {
  120.             name[0] = "ypbh";
  121.             name[1] = "pym";
  122.         }
  123.         if (_objIndex == 1) {
  124.             name[0] = "khbh";
  125.             name[1] = "pym";
  126.         }
  127.         if (_objIndex == 2) {
  128.             name[0] = "gysbh";
  129.             name[1] = "pym";
  130.         }
  131.         System.out.println(_objIndex);
  132.     }
  133.     public void jByes_actionPerformed(ActionEvent e) {
  134.         if (jTvalue.getText().trim().length() <= 0){
  135.             JOptionPane.showMessageDialog(null,"请输入查询数值!!","提示",JOptionPane.ERROR_MESSAGE);
  136.             jTvalue.requestFocus();
  137.             return;
  138.         }
  139.         DefaultTableModel defaultmodel = null;
  140.         int choose;
  141.         choose = jCobj.getSelectedIndex();
  142.         String queryStr = null,whereStr = null;
  143.         appjxc.constrol.BuildTable buildTable = new appjxc.constrol.BuildTable();
  144.         if (_ysfIndex == 0){
  145.             whereStr = name[_idIndex] + " " +
  146.                        String.valueOf(jCysf.getItemAt(_ysfIndex)) +
  147.                        " '%" + jTvalue.getText().trim() + "%'";
  148.         }else{
  149.             whereStr = name[_idIndex] + " " +
  150.                        String.valueOf(jCysf.getItemAt(_ysfIndex)) +
  151.                        " '" + jTvalue.getText().trim() + "'";
  152.         }
  153.         switch (choose){
  154.                case 0:
  155.                    queryStr = " From  obj_medicine where " + whereStr;
  156.                    defaultmodel = buildTable.getmedicineTableModel(queryStr);
  157.                    break;
  158.                case 1:
  159.                    queryStr = " From  Obj_client where " + whereStr;
  160.                    defaultmodel = buildTable.getClientTableModel(queryStr);
  161.                    break;
  162.               case 2:
  163.                   queryStr = " From  Obj_gys where " + whereStr;
  164.                   defaultmodel = buildTable.getGysTableModel(queryStr);
  165.                   break;
  166.         }
  167.         jTable1.setModel(defaultmodel);
  168.         if (jTable1.getRowCount() <= 0 ){
  169.             JOptionPane.showMessageDialog(null,"没有找到满足条件的数据!!!","系统提示",JOptionPane.ERROR_MESSAGE);
  170.         }
  171.     }
  172.     public void jCid_itemStateChanged(ItemEvent e) {
  173.         System.out.println(_idIndex);
  174.         _idIndex = jCid.getSelectedIndex();
  175.     }
  176.     public void jCysf_itemStateChanged(ItemEvent e) {
  177.         _ysfIndex = jCysf.getSelectedIndex();
  178.     }
  179.     public void jTvalue_keyPressed(KeyEvent e) {
  180.         if (e.getKeyCode() == KeyEvent.VK_ENTER){
  181.             ActionEvent yesevent = new ActionEvent(jByes,0,null);
  182.             this.jByes_actionPerformed(yesevent);
  183.         }
  184.     }
  185.     public void jBquit_actionPerformed(ActionEvent actionEvent) {
  186.         javax.swing.DefaultDesktopManager manger = new DefaultDesktopManager();
  187.         int result = JOptionPane.showOptionDialog(null,"是否真的退出基本信息查询?","系统提示",
  188.                                    JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
  189.                                    null,new String[]  {"是","否"},"否");
  190.         if (result == JOptionPane.YES_OPTION) {
  191.             try{
  192.                 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
  193.                 SwingUtilities.updateComponentTreeUI(this);
  194.             }catch(Exception ex){
  195.                 ex.printStackTrace();
  196.             }
  197.            manger.closeFrame(this);
  198.         }
  199.     }
  200. }
  201. class JF_view_query_jbqk_jBquit_actionAdapter implements ActionListener {
  202.     private JF_view_query_jbqk adaptee;
  203.     JF_view_query_jbqk_jBquit_actionAdapter(JF_view_query_jbqk adaptee) {
  204.         this.adaptee = adaptee;
  205.     }
  206.     public void actionPerformed(ActionEvent actionEvent) {
  207.         adaptee.jBquit_actionPerformed(actionEvent);
  208.     }
  209. }
  210. class JF_view_query_jbqk_jTvalue_keyAdapter extends KeyAdapter {
  211.     private JF_view_query_jbqk adaptee;
  212.     JF_view_query_jbqk_jTvalue_keyAdapter(JF_view_query_jbqk adaptee) {
  213.         this.adaptee = adaptee;
  214.     }
  215.     public void keyPressed(KeyEvent e) {
  216.         adaptee.jTvalue_keyPressed(e);
  217.     }
  218. }
  219. class JF_view_query_jbqk_jCysf_itemAdapter implements ItemListener {
  220.     private JF_view_query_jbqk adaptee;
  221.     JF_view_query_jbqk_jCysf_itemAdapter(JF_view_query_jbqk adaptee) {
  222.         this.adaptee = adaptee;
  223.     }
  224.     public void itemStateChanged(ItemEvent e) {
  225.         adaptee.jCysf_itemStateChanged(e);
  226.     }
  227. }
  228. class JF_view_query_jbqk_jCid_itemAdapter implements ItemListener {
  229.     private JF_view_query_jbqk adaptee;
  230.     JF_view_query_jbqk_jCid_itemAdapter(JF_view_query_jbqk adaptee) {
  231.         this.adaptee = adaptee;
  232.     }
  233.     public void itemStateChanged(ItemEvent e) {
  234.         adaptee.jCid_itemStateChanged(e);
  235.     }
  236. }
  237. class JF_view_query_jbqk_jByes_actionAdapter implements ActionListener {
  238.     private JF_view_query_jbqk adaptee;
  239.     JF_view_query_jbqk_jByes_actionAdapter(JF_view_query_jbqk adaptee) {
  240.         this.adaptee = adaptee;
  241.     }
  242.     public void actionPerformed(ActionEvent e) {
  243.         adaptee.jByes_actionPerformed(e);
  244.     }
  245. }
  246. class JF_view_query_jbqk_jCobj_itemAdapter implements ItemListener {
  247.     private JF_view_query_jbqk adaptee;
  248.     JF_view_query_jbqk_jCobj_itemAdapter(JF_view_query_jbqk adaptee) {
  249.         this.adaptee = adaptee;
  250.     }
  251.     public void itemStateChanged(ItemEvent e) {
  252.         adaptee.jCobj_itemStateChanged(e);
  253.     }
  254. }