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

JavaScript

开发平台:

Java

  1. package appjxc.view;
  2. import javax.swing.*;
  3. import java.awt.BorderLayout;
  4. import java.awt.FlowLayout;
  5. import javax.swing.BorderFactory;
  6. import java.awt.Color;
  7. import javax.swing.table.DefaultTableModel;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import appjxc.model.Obj_Stock;
  11. import appjxc.model.obj_medicine;
  12. import java.awt.Font;
  13. import java.util.Calendar;
  14. import java.util.Locale;
  15. public class JF_view_kcpd extends JInternalFrame{//JFrame {
  16.     BorderLayout borderLayout1 = new BorderLayout();
  17.     JScrollPane jScrollPane1 = new JScrollPane();
  18.     JPanel jPanel1 = new JPanel();
  19.     JTable jTable1 = new JTable();
  20.     FlowLayout flowLayout1 = new FlowLayout();
  21.     JButton jBpd = new JButton();
  22.     JButton jBsave = new JButton();
  23.     JButton jBexit = new JButton();
  24.     DefaultTableModel tableModel = null;
  25.     JButton jBquery = new JButton();
  26.     java.util.List liststock = null;
  27.     public JF_view_kcpd() {
  28.         try {
  29.             jbInit();
  30.             buildTable();
  31.         } catch (Exception ex) {
  32.             ex.printStackTrace();
  33.         }
  34.     }
  35.     public void buildTable(){
  36.         String[] tname = {"药品编号","药品名称","药品批号","规格","产地","单位","剂型","有效期至","库存数量","盘点数量"};
  37.         java.util.Vector vname = new java.util.Vector();
  38.         for (int i = 0 ; i < tname.length ; i++){
  39.             vname.addElement(tname[i]);
  40.         }
  41.         tableModel = new DefaultTableModel(vname,0);
  42.         jTable1.setModel(tableModel);
  43.     }
  44.     private void jbInit() throws Exception {
  45.         this.getContentPane().setLayout(borderLayout1);
  46.         jPanel1.setBorder(BorderFactory.createLineBorder(Color.black));
  47.         jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
  48.         jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.
  49.                                                 VERTICAL_SCROLLBAR_ALWAYS);
  50.         jBquery.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  51.         jBquery.setText("查询库存");
  52.         jBquery.addActionListener(new JF_view_kcpd_jBquery_actionAdapter(this));
  53.         jBexit.addActionListener(new JF_view_kcpd_jBexit_actionAdapter(this));
  54.         jBpd.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  55.         jBpd.addActionListener(new JF_view_kcpd_jBpd_actionAdapter(this));
  56.         jBsave.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  57.         jBexit.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  58.         this.setClosable(true);
  59.         this.setTitle("医药进销存管理系统-[库存盘点]");
  60.         this.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
  61.         jBpd.setText("盘点");
  62.         jPanel1.setLayout(flowLayout1);
  63.         this.getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
  64.         jBsave.setVisible(false);
  65.         jBsave.setText("导出Excel");
  66.         jBexit.setText("退出");
  67.         jPanel1.add(jBquery);
  68.         jPanel1.add(jBpd);
  69.         flowLayout1.setAlignment(FlowLayout.RIGHT);
  70.         jPanel1.add(jBsave);
  71.         jPanel1.add(jBexit);
  72.         jScrollPane1.getViewport().add(jTable1);
  73.         setSize(700,500);
  74.         setVisible(true);
  75.        //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
  76.         //SwingUtilities.updateComponentTreeUI(this);
  77.     }
  78.     public void jBquery_actionPerformed(ActionEvent e) {
  79.         if (jTable1.getRowCount() > 0 ) return;
  80.         String queryStr = null;
  81.         //queryStr = "SELECT m.ypbh, m.ypmc, m.ph, m.gg, m.cd, m.dw, m.jx, m.yxq, s.rksl, s.pdsl " +
  82.          //             "FROM Obj_Stock s , obj_medicine m where s.ypbh = m.ypbh";
  83.          //用表关联的方式进行数据统计:从两个一一对应的表中进行组合查询数据( 感觉真酷!!!!)
  84.         queryStr = "FROM Obj_Stock s JOIN s.objmedicine where kcsl > 0";
  85.         java.util.List list = null;
  86.         list = appjxc.dao.AdapterDao.QueryObject(queryStr);
  87.         Object obj[] = null;
  88.         liststock = list;
  89.         for (int i = 0  ; i < list.size() ; i++){
  90.             obj = (Object[])list.get(i);
  91.             Obj_Stock stock = (Obj_Stock)obj[0];//获得关联中的对象
  92.             obj_medicine objmed = (obj_medicine)obj[1];
  93.             java.util.Vector vdata = new java.util.Vector();
  94.             vdata.addElement(objmed.getYpbh());
  95.             vdata.addElement(objmed.getYpmc());
  96.             vdata.addElement(objmed.getPh());
  97.             vdata.addElement(objmed.getGg());
  98.             vdata.addElement(objmed.getCd());
  99.             vdata.addElement(objmed.getDw());
  100.             vdata.addElement(objmed.getJx());
  101.             vdata.addElement(objmed.getYxq());
  102.             vdata.addElement(String.valueOf(stock.getKcsl()));
  103.             tableModel.addRow(vdata);
  104. //            jTable1.setValueAt(String.valueOf(stock.getKcsl()),i,8);
  105. //            jTable1.setValueAt("0",i,9);
  106. //            System.out.println("objmed.getypmc() = " + objmed.getYpmc());
  107.   //          System.out.println("stock.getkcsl() = " + stock.getKcsl());
  108.         }
  109.         jTable1.setRowHeight(20);
  110.         /*java.util.List list = null;
  111.         java.util.List list1 = null;
  112.         java.util.Iterator iterator = null;
  113.         java.util.Iterator iterator1 = null;
  114.         if (jTable1.getRowCount() > 0 ) {
  115.             return;
  116.         }
  117.         queryStr = "from obj_medicine";
  118.         list = appjxc.dao.AdapterDao.QueryObject(queryStr);
  119.         iterator = list.iterator();
  120.         queryStr = "from Obj_Stock";
  121.         list1 = appjxc.dao.AdapterDao.QueryObject(queryStr);
  122.         iterator1 = list1.iterator();
  123.         int i = 0;
  124.         while(iterator.hasNext()){
  125.             obj_medicine objmed = (obj_medicine)iterator.next();
  126.             Obj_Stock stock = (Obj_Stock)iterator1.next();
  127.             java.util.Vector vdata = new java.util.Vector();
  128.             vdata.addElement(objmed.getYpbh());
  129.             vdata.addElement(objmed.getYpmc());
  130.             vdata.addElement(objmed.getPh());
  131.             vdata.addElement(objmed.getGg());
  132.             vdata.addElement(objmed.getCd());
  133.             vdata.addElement(objmed.getDw());
  134.             vdata.addElement(objmed.getJx());
  135.             vdata.addElement(objmed.getYxq());
  136.             tableModel.addRow(vdata);
  137.             jTable1.setValueAt(String.valueOf(stock.getKcsl()),i,8);
  138.             i++;
  139.         }   */
  140.     }
  141.     public void jBexit_actionPerformed(ActionEvent e) {
  142.         javax.swing.DefaultDesktopManager manger = new DefaultDesktopManager();
  143.         int result = JOptionPane.showOptionDialog(null,"是否真的退出药品药品盘点情况?","系统提示",
  144.                                    JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
  145.                                    null,new String[]  {"是","否"},"否");
  146.         if (result == JOptionPane.YES_OPTION) {
  147.             try{
  148.                // UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
  149.                 //SwingUtilities.updateComponentTreeUI(this);
  150.             }catch(Exception ex){
  151.                 ex.printStackTrace();
  152.             }
  153.            manger.closeFrame(this);
  154.         }
  155.     }
  156.     public void jBpd_actionPerformed(ActionEvent e) {
  157.         if (jTable1.getRowCount() <= 0 ) return;
  158.         int result = JOptionPane.showOptionDialog(null,"是否真的存盘药品入库信息情况?","系统提示",
  159.                                    JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
  160.                                    null,new String[]  {"是","否"},"否");
  161.         if (result == JOptionPane.NO_OPTION) return;
  162.         java.util.Calendar calendar = null;
  163.         Locale loc = new Locale("CN");
  164.         calendar = Calendar.getInstance(loc);
  165.         calendar.setTimeInMillis(System.currentTimeMillis());
  166.         int year = calendar.get(Calendar.YEAR);
  167.         int month = calendar.get(Calendar.MONTH) + 1;
  168.         int day = calendar.get(Calendar.DAY_OF_MONTH);
  169.         String rqStr = year + "-" + month + "-" + day;
  170.         java.sql.Date pdrq = java.sql.Date.valueOf(rqStr);
  171.         for (int i = 0 ; i < jTable1.getRowCount() ; i++){
  172.            // if (jTable1.getValueAt(i,9)==null){
  173.          //       JOptionPane.showMessageDialog(null, "盘点数量不允许为空,请录入!!!", "系统提示",
  174.              //                                 JOptionPane.ERROR_MESSAGE);
  175.        //         return;
  176.             //}
  177.             Object[] obj = (Object[])liststock.get(i);
  178.             Obj_Stock stock = null;
  179.             String ypbh = null;
  180.             String sqlStr = null;
  181.             ypbh = jTable1.getValueAt(i,0).toString();
  182.             sqlStr = " from Obj_Stock where ypbh = '" + ypbh + "'";
  183.             java.util.List list = null;
  184.             list = appjxc.dao.AdapterDao.QueryObject(sqlStr);
  185.             stock = (Obj_Stock)list.get(0);
  186.             int kcsl,pdsl;
  187.             try{
  188.                 kcsl = Integer.parseInt(String.valueOf(jTable1.getValueAt(i, 8)));
  189.                 pdsl = Integer.parseInt(String.valueOf(jTable1.getValueAt(i, 9)));
  190.             }catch(java.lang.NumberFormatException format){
  191.                 JOptionPane.showMessageDialog(null,"盘点数量非法,请填写!!!n" + format.getMessage(),"系统提示",JOptionPane.ERROR_MESSAGE);
  192.                 return;
  193.             }
  194.             if (pdsl < 0 ){
  195.             }
  196.             /*if (pdsl > kcsl){
  197.                 JOptionPane.showMessageDialog(null,"盘点数量【" + pdsl + "】不能大于库存数量【" + kcsl + "】,请修改!!!","系统提示",JOptionPane.ERROR_MESSAGE);
  198.                 return;
  199.             }*/
  200.             stock.setKcsl(kcsl);
  201.             stock.setPdsl(pdsl);
  202.             stock.setPdrq(pdrq);
  203.             appjxc.dao.AdapterDao.InsertStock(stock);
  204.         }
  205.         JOptionPane.showMessageDialog(null,"盘点数据存盘成功!!!","系统提示",JOptionPane.OK_OPTION);
  206.     }
  207. }
  208. class JF_view_kcpd_jBpd_actionAdapter implements ActionListener {
  209.     private JF_view_kcpd adaptee;
  210.     JF_view_kcpd_jBpd_actionAdapter(JF_view_kcpd adaptee) {
  211.         this.adaptee = adaptee;
  212.     }
  213.     public void actionPerformed(ActionEvent e) {
  214.         adaptee.jBpd_actionPerformed(e);
  215.     }
  216. }
  217. class JF_view_kcpd_jBexit_actionAdapter implements ActionListener {
  218.     private JF_view_kcpd adaptee;
  219.     JF_view_kcpd_jBexit_actionAdapter(JF_view_kcpd adaptee) {
  220.         this.adaptee = adaptee;
  221.     }
  222.     public void actionPerformed(ActionEvent e) {
  223.         adaptee.jBexit_actionPerformed(e);
  224.     }
  225. }
  226. class JF_view_kcpd_jBquery_actionAdapter implements ActionListener {
  227.     private JF_view_kcpd adaptee;
  228.     JF_view_kcpd_jBquery_actionAdapter(JF_view_kcpd adaptee) {
  229.         this.adaptee = adaptee;
  230.     }
  231.     public void actionPerformed(ActionEvent e) {
  232.         adaptee.jBquery_actionPerformed(e);
  233.     }
  234. }