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

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. import java.awt.Dimension;
  16. import appjxc.model.Obj_BuyDetaile;
  17. import appjxc.model.Obj_SellDetaile;
  18. import java.awt.event.MouseEvent;
  19. import java.awt.event.MouseAdapter;
  20. import java.awt.event.KeyEvent;
  21. import java.awt.event.KeyAdapter;
  22. public class JF_view_xstk extends JInternalFrame {//implements javax.swing.event.TableModelListener{//JFrame {
  23.     BorderLayout borderLayout1 = new BorderLayout();
  24.     JScrollPane jScrollPane1 = new JScrollPane();
  25.     JPanel jPanel1 = new JPanel();
  26.     JTable jTable1 = new JTable();
  27.     FlowLayout flowLayout1 = new FlowLayout();
  28.     JButton jBth = new JButton();
  29.     JButton jBexit = new JButton();
  30.     DefaultTableModel tableModel = null;
  31.     DefaultTableModel tableMode2 = null;
  32.     JButton jBquery = new JButton();
  33.     JLabel jLabel1 = new JLabel();
  34.     JTextField jTdjh = new JTextField();
  35.     JSplitPane jSplitPane1 = new JSplitPane();
  36.     JScrollPane jScrollPane2 = new JScrollPane();
  37.     JTable jTable2 = new JTable();
  38.     Obj_SellDetaile selldetaile[] = null;
  39.     public JF_view_xstk() {
  40.         try {
  41.             jbInit();
  42.             buildTable();
  43.         } catch (Exception ex) {
  44.             ex.printStackTrace();
  45.         }
  46.     }
  47.     public static void main(String[] args) {
  48.         JF_view_xstk jf_view_kcpd = new JF_view_xstk();
  49.     }
  50.     public void buildTable(){
  51.         String[] tname = {"药品编号","药品名称","药品批号","规格","产地","单位","剂型","有效期至"};
  52.         String[] tname1 = {"销售流水号","药品编号","销售价格","销售数量","销售金额","销售日期","退库数量","退库金额","退库日期","经办人"};
  53.         java.util.Vector vname = new java.util.Vector();
  54.         java.util.Vector vname1 = new java.util.Vector();
  55.         for (int i = 0 ; i < tname.length ; i++){
  56.             vname.addElement(tname[i]);
  57.         }
  58.         for (int i = 0 ; i < tname1.length ; i++){
  59.             vname1.addElement(tname1[i]);
  60.         }
  61.         tableModel = new DefaultTableModel(vname,0);
  62.         tableMode2 = new DefaultTableModel(vname1,0);
  63.         jTable1.setModel(tableModel);
  64.         jTable2.setModel(tableMode2);
  65.     }
  66.     private void jbInit() throws Exception {
  67.         this.getContentPane().setLayout(borderLayout1);
  68.         jPanel1.setBorder(BorderFactory.createLineBorder(Color.black));
  69.         jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
  70.         jTable1.addMouseListener(new JF_view_xstk_jTable1_mouseAdapter(this));
  71.         jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.
  72.                                                 VERTICAL_SCROLLBAR_ALWAYS);
  73.         jBquery.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  74.         jBquery.setText("查询");
  75.         jBquery.addActionListener(new JF_view_xstk_jBquery_actionAdapter(this));
  76.         jBexit.addActionListener(new JF_view_xstk_jBexit_actionAdapter(this));
  77.         jBth.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  78.         jBth.addActionListener(new JF_view_xstk_jBpd_actionAdapter(this));
  79.         jBexit.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  80.         this.setClosable(true);
  81.         this.setTitle("医药进销存管理系统-[销售退货]");
  82.         jLabel1.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  83.         jLabel1.setText("销售单据号:");
  84.         jTdjh.setPreferredSize(new Dimension(226, 27));
  85.         jTdjh.setText("");
  86.         jTdjh.addKeyListener(new JF_view_xstk_jTdjh_keyAdapter(this));
  87.         flowLayout1.setHgap(10);
  88.         jBth.setText("退货");
  89.         jPanel1.setLayout(flowLayout1);
  90.         jBexit.setText("退出");
  91.         jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT);
  92.         jPanel1.add(jLabel1);
  93.         jPanel1.add(jTdjh);
  94.         jPanel1.add(jBquery);
  95.         jPanel1.add(jBth);
  96.         jPanel1.add(jBexit);
  97.         this.getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);
  98.         jScrollPane1.getViewport().add(jTable1);
  99.         jSplitPane1.add(jScrollPane1, JSplitPane.TOP);
  100.         jSplitPane1.add(jScrollPane2, JSplitPane.BOTTOM);
  101.         jScrollPane2.getViewport().add(jTable2);
  102.         this.getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
  103.         setSize(700,500);
  104.         setVisible(true);
  105.         UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
  106.         SwingUtilities.updateComponentTreeUI(this);
  107.         jSplitPane1.setDividerLocation(110);
  108.     }
  109.     public void jBquery_actionPerformed(ActionEvent e) {
  110.         if (jTdjh.getText().trim().length() <= 0 ){
  111.             JOptionPane.showMessageDialog(null,"销售单据号不允许为空,请输入!!!","系统提示",JOptionPane.ERROR_MESSAGE);
  112.             jTdjh.requestFocus();
  113.             return;
  114.         }
  115.         String[] tname = {"药品编号","药品名称","药品批号","规格","产地","单位","剂型","有效期至"};
  116.         String[] tname1 = {"销售流水号","药品编号","销售价格","销售数量","销售金额","销售日期","退库数量","退库金额","退库日期","经办人"};
  117.         java.util.Vector vname = new java.util.Vector();
  118.         java.util.Vector vname1 = new java.util.Vector();
  119.         for (int i = 0 ; i < tname.length ; i++){
  120.             vname.addElement(tname[i]);
  121.         }
  122.         for (int i = 0 ; i < tname1.length ; i++){
  123.             vname1.addElement(tname1[i]);
  124.         }
  125.         tableModel = new DefaultTableModel(vname,0);
  126.         tableMode2 = new DefaultTableModel(vname1,0);
  127.         jTable1.setModel(tableModel);
  128.         jTable2.setModel(tableMode2);
  129.         String djh = null,queryStr = null;
  130.         djh = jTdjh.getText().trim();
  131.          //用表关联的方式进行数据统计:从两个多(t_selldetaile)对一(t_medicinel)的表中进行组合查询数据( 感觉真酷!!!!)
  132.         queryStr = "FROM Obj_SellDetaile s JOIN s.medicine where s.thsts = 'F' and s.xsdjh = '" + djh + "'";
  133.         java.util.List list = null;
  134.         list = appjxc.dao.AdapterDao.QueryObject(queryStr);
  135.         if (list.size() <= 0 ){
  136.             JOptionPane.showMessageDialog(null,"销售单据号码不存在,请从新输入!!!","系统提示",JOptionPane.ERROR_MESSAGE);
  137.             jTdjh.requestFocus();
  138.             return;
  139.         }
  140.         System.out.println(list.size());
  141.         Object obj[] = null;
  142.         selldetaile = new Obj_SellDetaile[list.size()];
  143.         //jTable1.setModel(tableModel);
  144.         for (int i = 0  ; i < list.size() ; i++){
  145.             obj = (Object[])list.get(i);
  146.             selldetaile[i] = (Obj_SellDetaile)obj[0];//获得关联中的对象
  147.             obj_medicine objmed = (obj_medicine)obj[1];
  148.             java.util.Vector vdata = new java.util.Vector();
  149.             vdata.addElement(objmed.getYpbh());
  150.             vdata.addElement(objmed.getYpmc());
  151.             vdata.addElement(objmed.getPh());
  152.             vdata.addElement(objmed.getGg());
  153.             vdata.addElement(objmed.getCd());
  154.             vdata.addElement(objmed.getDw());
  155.             vdata.addElement(objmed.getJx());
  156.             vdata.addElement(objmed.getYxq());
  157.             tableModel.addRow(vdata);
  158.         }
  159.         jTable1.setModel(tableModel);
  160.         jTable1.setRowHeight(20);
  161.     }
  162.     public void jBexit_actionPerformed(ActionEvent e) {
  163.         javax.swing.DefaultDesktopManager manger = new DefaultDesktopManager();
  164.         int result = JOptionPane.showOptionDialog(null,"是否真的退出药品销售退货情况?","系统提示",
  165.                                    JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
  166.                                    null,new String[]  {"是","否"},"否");
  167.         if (result == JOptionPane.YES_OPTION) {
  168.             try{
  169.              // UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
  170.                // SwingUtilities.updateComponentTreeUI(this);
  171.             }catch(Exception ex){
  172.                 ex.printStackTrace();
  173.             }
  174.            manger.closeFrame(this);
  175.         }
  176.     }
  177.     public void jBth_actionPerformed(ActionEvent e) {
  178.         if (jTable2.getRowCount() <= 0 ) return;
  179.         int result = JOptionPane.showOptionDialog(null,"是否存盘药品销售退货情况?","系统提示",
  180.                                    JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
  181.                                    null,new String[]  {"是","否"},"否");
  182.         if (result == JOptionPane.NO_OPTION) return;
  183.         java.util.Calendar calendar = null;
  184.         Locale loc = new Locale("CN");
  185.         calendar = Calendar.getInstance(loc);
  186.         calendar.setTimeInMillis(System.currentTimeMillis());
  187.         int year = calendar.get(Calendar.YEAR);
  188.         int month = calendar.get(Calendar.MONTH) + 1;
  189.         int day = calendar.get(Calendar.DAY_OF_MONTH);
  190.         String rqStr = year + "-" + month + "-" + day;
  191.         java.sql.Date thrq = java.sql.Date.valueOf(rqStr);
  192.         //  "销售价格","销售数量","销售金额","销售日期","退库金额","退库日期","经办人"
  193.         for (int i = 0 ; i < jTable2.getRowCount() ; i++){
  194.             if (jTable1.getValueAt(i,6)==null){
  195.                 JOptionPane.showMessageDialog(null, "退库金额不允许为空,请录入!!!", "系统提示",
  196.                                               JOptionPane.ERROR_MESSAGE);
  197.                 return;
  198.             }
  199.             //"销售流水号","药品编号","销售价格","销售数量","销售金额","销售日期","退库数量","退库金额","退库日期","经办人"
  200.             float xsje,thje;
  201.             xsje = Float.parseFloat(String.valueOf(jTable2.getValueAt(i,4)));
  202.             thje = Float.parseFloat(String.valueOf(jTable2.getValueAt(i,7)));
  203.             if (thje != xsje){
  204.                 JOptionPane.showMessageDialog(null,"退还金额【" + thje + "】必须等于销售金额【" + xsje + "】,请修改!!!","系统提示",JOptionPane.ERROR_MESSAGE);
  205.                 return;
  206.             }
  207.             appjxc.model.Obj_SellDetaileTh selldetaileTh = new appjxc.model.Obj_SellDetaileTh();
  208.             selldetaileTh.setXslsh(jTable2.getValueAt(i,0).toString());
  209.             selldetaileTh.setYpbh(jTable2.getValueAt(i,1).toString());
  210.             selldetaileTh.setJbr("经办人");
  211.             selldetaileTh.setThrq(thrq);
  212.             selldetaileTh.setThsl(Integer.parseInt(jTable2.getValueAt(i,6).toString()));
  213.             selldetaileTh.setThje(Float.parseFloat(String.valueOf(thje)));
  214.             selldetaileTh.setThje(thje);
  215.             appjxc.dao.AdapterDao.InsertObj_SellDetaileTh(selldetaileTh);
  216.             //更新退货明晰表状态
  217.             Obj_SellDetaile sell = selldetaile[i];
  218.             sell.setThsts("T");
  219.             appjxc.dao.AdapterDao.InsertSellDetaile(sell);
  220.             //更新盘点数据表中的库存数量
  221.             String strSql = null;
  222.             strSql = "from Obj_Stock where ypbh = '" + jTable2.getValueAt(i,1).toString() + "'";
  223.             java.util.List stockList =  appjxc.dao.AdapterDao.QueryObject(strSql);
  224.             Obj_Stock stock = (Obj_Stock)stockList.get(0);
  225.             stock.setKcsl(stock.getKcsl() + selldetaileTh.getThsl());
  226.             appjxc.dao.AdapterDao.InsertStock(stock);
  227.         }
  228.         JOptionPane.showMessageDialog(null,"销售退货数据存盘成功!!!","系统提示",JOptionPane.OK_OPTION);
  229.         //jTdjh.setText("");
  230.         ActionEvent frase = new ActionEvent(jBquery,0,null);
  231.         this.jBquery_actionPerformed(frase);
  232.     }
  233.    /* public void tableChanged(javax.swing.event.TableModelEvent event){
  234.         if (event.getColumn() == 6) {
  235.             int row = event.getFirstRow();
  236.             int tksl;
  237.             float tkje, xsjg;
  238.             tksl = Integer.parseInt(String.valueOf(jTable2.getValueAt(row, 6)));
  239.             xsjg = Float.parseFloat(String.valueOf(jTable2.getValueAt(row, 2)));
  240.             tkje = tksl * xsjg;
  241.             jTable2.setValueAt(String.valueOf(tkje), row, 7);
  242.         }
  243.     }*/
  244.     public void jTable1_mouseClicked(MouseEvent e) {
  245.         if (jTable1.getRowCount() <= 0 ) return;
  246.         java.util.Calendar calendar = null;
  247.         Locale loc = new Locale("CN");
  248.         calendar = Calendar.getInstance(loc);
  249.         calendar.setTimeInMillis(System.currentTimeMillis());
  250.         int year = calendar.get(Calendar.YEAR);
  251.         int month = calendar.get(Calendar.MONTH) + 1;
  252.         int day = calendar.get(Calendar.DAY_OF_MONTH);
  253.         String rqStr = year + "-" + month + "-" + day;
  254.         java.sql.Date thrq = java.sql.Date.valueOf(rqStr);
  255.         int row = jTable1.getSelectedRow();
  256.         Obj_SellDetaile sell = selldetaile[row];
  257.         String hm = null,hm1 = null;
  258.         hm = String.valueOf(jTable1.getValueAt(row,0));
  259.         System.out.println("hm = " + hm);
  260.         if (jTable2.getRowCount() > 0 ){
  261.             for (int i= 0 ; i < jTable2.getRowCount(); i++){
  262.                 hm1 = String.valueOf(jTable2.getValueAt(i,1));
  263.                 System.out.println("hm1 = " + hm1);
  264.                 if (hm.equals(hm1)) return;
  265.             }
  266.         }
  267.         java.util.Vector vdata = new java.util.Vector();
  268.         vdata.addElement(sell.getXslsh());
  269.         vdata.addElement(sell.getYpbh());
  270.         vdata.addElement(String.valueOf(sell.getXsdj()));
  271.         vdata.addElement(String.valueOf(sell.getXssl()));
  272.         vdata.addElement(String.valueOf(sell.getXsje()));
  273.         vdata.addElement(sell.getXsrq());
  274.         vdata.addElement(String.valueOf(sell.getXssl()));
  275.         vdata.addElement(String.valueOf(sell.getXsje()));
  276.         vdata.addElement(thrq);
  277.         tableMode2.addRow(vdata);
  278.         jTable2.setRowHeight(20);
  279.     }
  280.     public void jTdjh_keyPressed(KeyEvent e) {
  281.         if(e.getKeyCode() == KeyEvent.VK_ENTER){
  282.             ActionEvent query = new ActionEvent(jBquery,0,null);
  283.             this.jBquery_actionPerformed(query);
  284.         }
  285.     }
  286. }
  287. class JF_view_xstk_jBpd_actionAdapter implements ActionListener {
  288.     private JF_view_xstk adaptee;
  289.     JF_view_xstk_jBpd_actionAdapter(JF_view_xstk adaptee) {
  290.         this.adaptee = adaptee;
  291.     }
  292.     public void actionPerformed(ActionEvent e) {
  293.         adaptee.jBth_actionPerformed(e);
  294.     }
  295. }
  296. class JF_view_xstk_jBexit_actionAdapter implements ActionListener {
  297.     private JF_view_xstk adaptee;
  298.     JF_view_xstk_jBexit_actionAdapter(JF_view_xstk adaptee) {
  299.         this.adaptee = adaptee;
  300.     }
  301.     public void actionPerformed(ActionEvent e) {
  302.         adaptee.jBexit_actionPerformed(e);
  303.     }
  304. }
  305. class JF_view_xstk_jTable1_mouseAdapter extends MouseAdapter {
  306.     private JF_view_xstk adaptee;
  307.     JF_view_xstk_jTable1_mouseAdapter(JF_view_xstk adaptee) {
  308.         this.adaptee = adaptee;
  309.     }
  310.     public void mouseClicked(MouseEvent e) {
  311.         adaptee.jTable1_mouseClicked(e);
  312.     }
  313. }
  314. class JF_view_xstk_jBquery_actionAdapter implements ActionListener {
  315.     private JF_view_xstk adaptee;
  316.     JF_view_xstk_jBquery_actionAdapter(JF_view_xstk adaptee) {
  317.         this.adaptee = adaptee;
  318.     }
  319.     public void actionPerformed(ActionEvent e) {
  320.         adaptee.jBquery_actionPerformed(e);
  321.     }
  322. }
  323. class JF_view_xstk_jTdjh_keyAdapter extends KeyAdapter {
  324.     private JF_view_xstk adaptee;
  325.     JF_view_xstk_jTdjh_keyAdapter(JF_view_xstk adaptee) {
  326.         this.adaptee = adaptee;
  327.     }
  328.     public void keyPressed(KeyEvent e) {
  329.         adaptee.jTdjh_keyPressed(e);
  330.     }
  331. }