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

JavaScript

开发平台:

Java

  1. package appjxc.view;
  2. import javax.swing.*;
  3. import java.awt.BorderLayout;
  4. import java.awt.*;
  5. import javax.swing.BorderFactory;
  6. import javax.swing.table.DefaultTableModel;
  7. import javax.swing.table.DefaultTableColumnModel;
  8. import javax.swing.table.TableColumnModel;
  9. import java.awt.event.ActionEvent;
  10. import java.awt.event.ActionListener;
  11. import java.util.Locale;
  12. import java.text.DateFormat;
  13. import java.util.List;
  14. import appjxc.dao.AdapterDao;
  15. import java.util.Iterator;
  16. import java.awt.event.ItemListener;
  17. import java.awt.event.ItemEvent;
  18. import appjxc.model.obj_medicine;
  19. import appjxc.model.Obj_client;
  20. import javax.swing.event.TableModelListener;
  21. import appjxc.model.Obj_SellMain;
  22. import appjxc.model.Obj_SellDetaile;
  23. import java.awt.Font;
  24. import java.util.Calendar;
  25. import java.awt.event.KeyEvent;
  26. import java.awt.event.KeyAdapter;
  27. import appjxc.model.Obj_Stock;
  28. public class JF_view_sell extends JInternalFrame implements TableModelListener{
  29.     public static void main(String[] args) {
  30.         JF_view_sell jf_choose_table = new JF_view_sell();
  31.     }
  32.     BorderLayout borderLayout1 = new BorderLayout();
  33.     JPanel jPanel1 = new JPanel();
  34.     JPanel jPanel2 = new JPanel();
  35.     JPanel jPanel3 = new JPanel();
  36.     GridLayout gridLayout1 = new GridLayout();
  37.     JLabel jLabel1 = new JLabel();
  38.     JTextField jTextField1 = new JTextField();
  39.     JLabel jLabel2 = new JLabel();
  40.     JTextField jTextField2 = new JTextField();
  41.     JLabel jLabel3 = new JLabel();
  42.     JTextField jTextField3 = new JTextField();
  43.     JLabel jLabel4 = new JLabel();
  44.     JTextField jTextField4 = new JTextField();
  45.     JLabel jLabel5 = new JLabel();
  46.     JTextField jTextField5 = new JTextField();
  47.     JLabel jLabel6 = new JLabel();
  48.     JTextField jTextField6 = new JTextField();
  49.     JLabel jLabel7 = new JLabel();
  50.     JLabel jLabel8 = new JLabel();
  51.     JTextField jTextField8 = new JTextField();
  52.     JComboBox jComboBox1 = new JComboBox();
  53.     JSplitPane jSplitPane1 = new JSplitPane();
  54.     BorderLayout borderLayout2 = new BorderLayout();
  55.     JPanel jPanel4 = new JPanel();
  56.     JPanel jPanel5 = new JPanel();
  57.     GridLayout gridLayout2 = new GridLayout();
  58.     JLabel jLabel9 = new JLabel();
  59.     JTextField jTxsph = new JTextField();
  60.     JLabel jLabel10 = new JLabel();
  61.     JTextField jTldrq = new JTextField();
  62.     JLabel jLabel11 = new JLabel();
  63.     JLabel jLabel12 = new JLabel();
  64.     JTextField jTjbr = new JTextField();
  65.     FlowLayout flowLayout1 = new FlowLayout();
  66.     JButton jBadd = new JButton();
  67.     JButton jBsave = new JButton();
  68.     JButton jButton3 = new JButton();
  69.     JComboBox jComboBox2 = new JComboBox();
  70.     BorderLayout borderLayout3 = new BorderLayout();
  71.     JScrollPane jScrollPane1 = new JScrollPane();
  72.     JTable jTable1 = new JTable();
  73.     DefaultTableModel tableModel = null;
  74.     JComboBox jcbh = new JComboBox();
  75.     JComboBox jComboBox21 = new JComboBox();
  76.     JButton jBreg = new JButton();
  77.     JButton jBdel = new JButton();
  78.     private Calendar calendar;
  79.     public JF_view_sell() {
  80.         try {
  81.             buildTable();
  82.             jbInit();
  83.         } catch (Exception ex) {
  84.             ex.printStackTrace();
  85.         }
  86.     }
  87.     public void buildTable(){
  88.         String[] tname = {"流水号","药品编号","药品名称","药品批号","规格","产地","单位","零售价","销售数量","销售金额","库存数量"};
  89.         java.util.Vector vname = new java.util.Vector();
  90.         for (int i = 0 ; i < tname.length ; i++){
  91.             vname.addElement(tname[i]);
  92.         }
  93.         tableModel = new DefaultTableModel(vname,0);
  94.         tableModel.addTableModelListener(this);
  95.         jTable1.setModel(tableModel);
  96.         TableColumnModel tcm = jTable1.getColumnModel();
  97.     }
  98.     private void jbInit() throws Exception {
  99.         tableModel.addTableModelListener(this);
  100.         this.getContentPane().setLayout(borderLayout1);
  101.         jPanel1.setLayout(borderLayout2);
  102.         jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT);
  103.         jSplitPane1.setVerifyInputWhenFocusTarget(false);
  104.         jPanel4.setLayout(gridLayout2);
  105.         gridLayout2.setColumns(4);
  106.         gridLayout2.setRows(2);
  107.         jLabel9.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  108.         jLabel9.setHorizontalAlignment(SwingConstants.LEFT);
  109.         jLabel9.setText("销售票号");
  110.         jTxsph.setText("");
  111.         jLabel10.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  112.         jLabel10.setText("录单日期");
  113.         jTldrq.setText("");
  114.         jLabel11.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  115.         jLabel11.setText("销售客户");
  116.         jLabel12.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  117.         jLabel12.setText("经办人");
  118.         jTjbr.setText("");
  119.         jPanel5.setLayout(flowLayout1);
  120.         jBadd.setEnabled(false);
  121.         jBadd.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  122.         jBadd.setText("添加");
  123.         jBadd.addActionListener(new JF_view_sell_jBadd_actionAdapter(this));
  124.         jBsave.setEnabled(false);
  125.         jBsave.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  126.         jBsave.setText("存盘");
  127.         jBsave.addActionListener(new JF_view_sell_jBsave_actionAdapter(this));
  128.         jButton3.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  129.         jButton3.setText("退出");
  130.         jButton3.addActionListener(new JF_view_sell_jButton3_actionAdapter(this));
  131.         jPanel2.setLayout(borderLayout3);
  132.         jPanel2.setBorder(BorderFactory.createLoweredBevelBorder());
  133.         flowLayout1.setAlignment(FlowLayout.RIGHT);
  134.         jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.
  135.                                                   HORIZONTAL_SCROLLBAR_ALWAYS);
  136.         jTable1.setAutoscrolls(false);
  137.         jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
  138.         this.setClosable(true);
  139.         this.setMaximizable(true);
  140.         this.setTitle("医药进销存管理系统-[药品销售]");
  141.         jBreg.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  142.         jBreg.setText("登记");
  143.         jBreg.addActionListener(new JF_view_sell_jBreg_actionAdapter(this));
  144.         jLabel1.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  145.         jComboBox1.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  146.         jLabel4.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  147.         jLabel2.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  148.         jLabel3.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  149.         jLabel6.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  150.         jLabel7.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  151.         jBdel.setEnabled(false);
  152.         jBdel.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  153.         jBdel.setText("删除");
  154.         jBdel.addActionListener(new JF_view_sell_jBdel_actionAdapter(this));
  155.         jLabel8.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  156.         jLabel5.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  157.         jTextField1.setEnabled(false);
  158.         jTextField2.setEnabled(false);
  159.         jTextField3.setEnabled(false);
  160.         jTextField4.addKeyListener(new JF_view_sell_jTextField4_keyAdapter(this));
  161.         jTextField5.setEnabled(false);
  162.         jTextField6.addKeyListener(new JF_view_sell_jTextField6_keyAdapter(this));
  163.         jComboBox2.setFont(new java.awt.Font("新宋体", Font.PLAIN, 12));
  164.         this.getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
  165.         jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);
  166.         jScrollPane1.getViewport().add(jTable1);
  167.         jLabel1.setText("销售品种");
  168.         jPanel3.setBorder(BorderFactory.createLineBorder(Color.black));
  169.         gridLayout1.setColumns(4);
  170.         gridLayout1.setRows(4);
  171.         jPanel3.setLayout(gridLayout1);
  172.         this.getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH);
  173.         jTextField1.setText("");
  174.         jLabel2.setText("销售总数");
  175.         jTextField2.setText("");
  176.         jLabel3.setText("合计金额");
  177.         jTextField3.setText("");
  178.         jLabel4.setText("折扣金额");
  179.         jTextField4.setText("");
  180.         jLabel5.setText("实收金额");
  181.         jTextField5.setText("");
  182.         jLabel6.setText("应收金额");
  183.         jTextField6.setText("");
  184.         jLabel7.setText("收款方式");
  185.         jComboBox1.addItem("现金");
  186.         jComboBox1.addItem("转帐");
  187.         jLabel8.setText("未收金额");
  188.         jTextField8.setText("");
  189.         jPanel3.add(jLabel1);
  190.         jPanel3.add(jTextField1);
  191.         jPanel3.add(jLabel2);
  192.         jPanel3.add(jTextField2);
  193.         jPanel3.add(jLabel3);
  194.         jPanel3.add(jTextField3);
  195.         jPanel3.add(jLabel4);
  196.         jPanel3.add(jTextField4);
  197.         jPanel3.add(jLabel6);
  198.         jPanel3.add(jTextField5);
  199.         jPanel3.add(jLabel5);
  200.         jPanel3.add(jTextField6);
  201.         jPanel3.add(jLabel7);
  202.         jPanel3.add(jComboBox1);
  203.         jPanel3.add(jLabel8);
  204.         jPanel3.add(jTextField8);
  205.         this.getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
  206.         jPanel1.add(jSplitPane1, java.awt.BorderLayout.CENTER);
  207.         jSplitPane1.add(jPanel4, JSplitPane.TOP);
  208.         jPanel4.add(jLabel9);
  209.         jPanel4.add(jTxsph);
  210.         jPanel4.add(jLabel10);
  211.         jPanel4.add(jTldrq);
  212.         jPanel4.add(jLabel11);
  213.         jPanel4.add(jComboBox2);
  214.         jPanel4.add(jLabel12);
  215.         jPanel4.add(jTjbr);
  216.         jSplitPane1.add(jPanel5, JSplitPane.BOTTOM);
  217.         jPanel5.add(jBreg);
  218.         jPanel5.add(jBadd);
  219.         jPanel5.add(jBdel);
  220.         jPanel5.add(jBsave);
  221.         jPanel5.add(jButton3);
  222.         setSize(850,550);
  223.         setVisible(true);
  224.         //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
  225.         UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
  226.         SwingUtilities.updateComponentTreeUI(this);
  227.     }
  228.     public void jBadd_actionPerformed(ActionEvent e) {
  229.         /*-----添加药品详细记录-------*/
  230.        java.util.Vector vdata = new java.util.Vector();
  231.        String lsh = new appjxc.constrol.GenalLsh().getLsh();
  232.        vdata.addElement(lsh);
  233.        tableModel.addRow(vdata);
  234.        jTable1.setModel(tableModel);
  235.        //此处简洁处理为一次读入完成之后,在进行登记添加的时候不进行读取以提高效率
  236.        if (jcbh.getItemCount() <= 0 ) {
  237.            String queryStr = "";
  238.            queryStr = "select m.ypbh from obj_medicine m";
  239.            List list = AdapterDao.QueryObject(queryStr);
  240.            Iterator iterator = list.iterator();
  241.            jcbh.removeAllItems();
  242.            while (iterator.hasNext()) {
  243.                jcbh.addItem(iterator.next());
  244.            }
  245.            jcbh.addItemListener(new JF_view_sell_jcbh_itemAdapter(this));
  246.        }
  247.        TableColumnModel tcm = jTable1.getColumnModel();
  248.        tcm.getColumn(0).setPreferredWidth(140);
  249.        tcm.getColumn(1).setCellEditor(new DefaultCellEditor(jcbh));
  250.        jTable1.setRowHeight(20);
  251.        jTable1.requestFocus();
  252.        jBdel.setEnabled(true);
  253.        jBsave.setEnabled(true);
  254.     }
  255.     public void tableChanged(javax.swing.event.TableModelEvent e){
  256.         int row = e.getFirstRow();
  257.         int col = e.getColumn();
  258.         if (col == 8){ //为销售数量
  259.             Object obj = jTable1.getValueAt(row,col);
  260.             int xssl,kcsl;
  261.             double xsdj,xsje;
  262.             xsdj = Double.parseDouble(String.valueOf(jTable1.getValueAt(row,7)).trim());
  263.             xssl = Integer.parseInt(String.valueOf(obj).trim());
  264.             kcsl = Integer.parseInt(String.valueOf(jTable1.getValueAt(row,10)));
  265.             if (xssl > kcsl){
  266.                 JOptionPane.showMessageDialog(null,"销售数量【" + xssl + "】不能大于库存数量【" + kcsl + "】,请修改!!!","系统提示",JOptionPane.ERROR_MESSAGE);
  267.                 return;
  268.             }
  269.             xsje = xsdj * xssl;
  270.             System.out.println("xssl" +  xssl + ";xsdj" + xsdj + ";xsje" + xsje);
  271.             jTable1.setValueAt(String.valueOf(xsje),row,9);
  272.             jTextField1.setText(String.valueOf(jTable1.getRowCount())); //销售品种数
  273.             int xszs = 0;
  274.             double hjje = 0.00;
  275.             for (int i = 0 ; i < jTable1.getRowCount() ; i++){
  276.                 xszs = xszs + Integer.parseInt(String.valueOf(jTable1.getValueAt(i,8)).trim());
  277.                 hjje = hjje + Double.parseDouble(String.valueOf(jTable1.getValueAt(i,9)).trim());
  278.             }
  279.             jTextField2.setText(String.valueOf(xszs)); //销售总数
  280.             jTextField3.setText(String.valueOf(hjje)); //合计金额
  281.         }
  282. //
  283.     }
  284.     public void jcbh_itemStateChanged(ItemEvent itemEvent) {
  285.             String bh;
  286.             Object obj = jcbh.getSelectedItem();
  287.             if (obj == null)return;
  288.             int row;
  289.             row = jTable1.getSelectedRow();
  290.             if (row < 0 ) return;
  291.             bh = obj.toString();
  292.             String queryStr;
  293.             System.out.println("queryStr = from obj_medicine m where m.ypbh = '" + bh );
  294.             queryStr = "FROM Obj_Stock s JOIN s.objmedicine where s.ypbh = '" + bh + "'";
  295.             List list = AdapterDao.QueryObject(queryStr);
  296.             Object objlist[] = null;
  297.             objlist = (Object[])list.get(0);
  298.             obj_medicine objm = (obj_medicine)objlist[1];
  299.             jTable1.setValueAt(objm.getYpmc(), row, 2);
  300.             jTable1.setValueAt(objm.getPh(), row, 3);
  301.             jTable1.setValueAt(objm.getGg(), row, 4);
  302.             jTable1.setValueAt(objm.getCd(), row, 5);
  303.             jTable1.setValueAt(objm.getDw(), row, 6);
  304.             jTable1.setValueAt(objm.getLsjg(), row, 7);
  305.             Obj_Stock objstock = (Obj_Stock)objlist[0];
  306.             System.out.println(objstock);
  307.              System.out.println(objstock.getKcsl());
  308.             jTable1.setValueAt(String.valueOf(objstock.getKcsl()), row, 10);
  309.            /* java.util.Iterator iterator = null;
  310.             while (iterator.hasNext()) {
  311.                 //obj_medicine objm = (obj_medicine) iterator.next();
  312.                 jTable1.setValueAt(objm.getYpmc(), row, 2);
  313.                 jTable1.setValueAt(objm.getPh(), row, 3);
  314.                 jTable1.setValueAt(objm.getGg(), row, 4);
  315.                 jTable1.setValueAt(objm.getCd(), row, 5);
  316.                 jTable1.setValueAt(objm.getDw(), row, 6);
  317.                 jTable1.setValueAt(objm.getLsjg(), row, 7);
  318.             }
  319.             queryStr = "select b.kcsl from Obj_BuyDetaile b where b.ypbh = '" + bh + "'";
  320.             list = AdapterDao.QueryObject(queryStr);
  321.             Object kcsl = list.get(0);
  322.             System.out.println("kcsl = " + kcsl);
  323.             jTable1.setValueAt(kcsl, row, 10);*/
  324.    }
  325.    public void jCbox_itemStateChanged(ItemEvent e){
  326.        if (jComboBox2.getItemCount() > 0) {
  327.                 int selectindex;
  328.                 selectindex = jComboBox2.getSelectedIndex();
  329.                 System.out.println(jComboBox2.getSelectedIndex());
  330.                 if (jComboBox21.getItemCount() > 0 ){
  331.                     jComboBox21.setSelectedIndex(selectindex);
  332.                 }
  333.                 System.out.println(jComboBox21.getItemCount());
  334.                 //System.out.println(jComboBox21.getSelectedItem());
  335.             }
  336.    }
  337.     public void jButton3_actionPerformed(ActionEvent e) {
  338.         javax.swing.DefaultDesktopManager manger = new DefaultDesktopManager();
  339.         int result = JOptionPane.showOptionDialog(null,"是否真的退出销售信息情况吗?","系统提示",
  340.                                    JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
  341.                                    null,new String[]  {"是","否"},"否");
  342.         if (result == JOptionPane.YES_OPTION) {
  343.             try{
  344.                // UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
  345.                // SwingUtilities.updateComponentTreeUI(this);
  346.             }catch(Exception ex){
  347.                 ex.printStackTrace();
  348.             }
  349.            manger.closeFrame(this);
  350.         }
  351.     }
  352.     public void jBsave_actionPerformed(ActionEvent e) {
  353.         javax.swing.DefaultDesktopManager manger = new DefaultDesktopManager();
  354.         int result = JOptionPane.showOptionDialog(null,"是否真的存盘销售信息情况?","系统提示",
  355.                                    JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
  356.                                    null,new String[]  {"是","否"},"否");
  357.         if (result == JOptionPane.NO_OPTION) return;
  358.         if (jTjbr.getText().trim().length() <= 0){
  359.             JOptionPane.showMessageDialog(null,"经办人不允许为空,请录入!!!","系统提示",JOptionPane.ERROR_MESSAGE);
  360.             jTjbr.requestFocus();
  361.             return;
  362.         }
  363.         if(jTable1.getRowCount() > 1){
  364.             for (int i = 0 ; i < jTable1.getRowCount(); i++) {
  365.                 String ypbh, ypbh1;
  366.                 ypbh = String.valueOf(jTable1.getValueAt(i, 1));
  367.                 System.out.println("ypbh = " + ypbh + "; i = " + i);
  368.                 int j = i + 1;
  369.                 if (j == jTable1.getRowCount()) continue;
  370.                 for (; j < jTable1.getRowCount(); j++) {
  371.                     ypbh1 = String.valueOf(jTable1.getValueAt(j, 1));
  372.                     System.out.println("ypbh1 = " + ypbh1 + "; j = " + j);
  373.                     if(ypbh.equals(ypbh1)){
  374.                         JOptionPane.showMessageDialog(null, "编号【" + ypbh1 + "】重复请从新选择", "系统提示",
  375.                                               JOptionPane.ERROR_MESSAGE);
  376.                         return;
  377.                     }
  378.                 }
  379.             }
  380.         }
  381.         if (jTextField4.getText().trim().length() <= 0){
  382.             JOptionPane.showMessageDialog(null,"折扣金额不允许为空,请录入!!!","系统提示",JOptionPane.ERROR_MESSAGE);
  383.             jTextField4.requestFocus();
  384.             return;
  385.         }
  386.         if (jTextField5.getText().trim().length() <= 0){
  387.             JOptionPane.showMessageDialog(null,"应收金额不允许为空,请录入!!!","系统提示",JOptionPane.ERROR_MESSAGE);
  388.             jTextField5.requestFocus();
  389.             return;
  390.         }
  391.         if (jTextField6.getText().trim().length() <= 0){
  392.             JOptionPane.showMessageDialog(null,"实收金额不允许为空,请录入!!!","系统提示",JOptionPane.ERROR_MESSAGE);
  393.             jTextField6.requestFocus();
  394.             return;
  395.         }
  396.         /*------生成主表更新对象 Obj_SellMain--------*/
  397.         Obj_SellMain objsellmain = new Obj_SellMain();
  398.         objsellmain.setKhbh(String.valueOf(jComboBox21.getSelectedItem()));
  399.         int pzs,xszs;
  400.         Double xsje,xszk,ysje,ssje,wsje;
  401.         try{
  402.             pzs = Integer.parseInt(jTextField1.getText().trim());
  403.             xszs = Integer.parseInt(jTextField2.getText().trim());
  404.             xsje = Double.valueOf(jTextField3.getText().trim());
  405.             xszk = Double.valueOf(jTextField4.getText().trim());
  406.             ysje = Double.valueOf(jTextField5.getText().trim());
  407.             ssje = Double.valueOf(jTextField6.getText().trim());
  408.             wsje = Double.valueOf(jTextField8.getText().trim());
  409.         }catch(java.lang.NumberFormatException format){
  410.            JOptionPane.showMessageDialog(null, "输入的数据格式有误,请重新录入!!n" + format.getMessage(), "系统提示",JOptionPane.ERROR_MESSAGE);
  411.            System.out.println(format.getMessage());
  412.            return;
  413.        }
  414.         objsellmain.setPzs(pzs);
  415.         objsellmain.setXszs(xszs);
  416.         objsellmain.setXsje(xsje);
  417.         objsellmain.setXszk(xszk);
  418.         objsellmain.setYsje(ysje);
  419.         objsellmain.setSsje(ssje);
  420.         objsellmain.setWsje(wsje);
  421.         java.sql.Date xsrq = null;
  422.         try{
  423.             xsrq = java.sql.Date.valueOf(jTldrq.getText().trim());
  424.         }catch(Exception ex){
  425.             ex.printStackTrace();
  426.             return;
  427.         }
  428.         objsellmain.setXsrq(xsrq);
  429.         objsellmain.setSkfs(String.valueOf(jComboBox1.getSelectedItem()));
  430.         objsellmain.setJbr(jTjbr.getText().trim());
  431.         if (wsje.floatValue() <= 0){
  432.             objsellmain.setQssts("T");
  433.         }else{
  434.             objsellmain.setQssts("F");
  435.         }
  436.         objsellmain.setXsdjh(jTxsph.getText().trim());
  437.         if (AdapterDao.InsertSellMain(objsellmain)){
  438.             JOptionPane.showMessageDialog(null,"药品销售情况主表数据录入成功","系统提示",JOptionPane.INFORMATION_MESSAGE);
  439.            }else{
  440.                JOptionPane.showMessageDialog(null,"药品销售情况数据存盘失败","系统提示",JOptionPane.ERROR_MESSAGE);
  441.            }
  442.         /*------生成从表更新对象 Obj_SellDetaile--------*/
  443.         for (int i = 0 ; i < jTable1.getRowCount(); i++){
  444.             Obj_SellDetaile objselldetaile = new Obj_SellDetaile();
  445.             String lsh,ypbh,xsdjh;
  446.             int xssl,kcsl;
  447.             float xsdj,je;
  448.             lsh = String.valueOf(jTable1.getValueAt(i,0));
  449.             ypbh = String.valueOf(jTable1.getValueAt(i,1));
  450.             xsdjh = jTxsph.getText().trim();
  451.             xssl = Integer.parseInt(String.valueOf(jTable1.getValueAt(i,8)));
  452.             kcsl = Integer.parseInt(String.valueOf(jTable1.getValueAt(i,10)));
  453.             if (xssl > kcsl){
  454.                 JOptionPane.showMessageDialog(null,"销售数量【" + xssl + "】不能大于库存数量【" + kcsl + "】,请修改!!!","系统提示",JOptionPane.ERROR_MESSAGE);
  455.                 return;
  456.             }
  457.             xsdj = Float.parseFloat(String.valueOf(jTable1.getValueAt(i,7)));
  458.             je = Float.parseFloat(String.valueOf(jTable1.getValueAt(i,9)));
  459.             objselldetaile.setXslsh(lsh);
  460.             objselldetaile.setYpbh(ypbh);
  461.             //定义主表的关联对象用来保存主表中的ypbh
  462.             appjxc.model.obj_medicine medicne = new obj_medicine();
  463.             medicne.setYpbh(ypbh);
  464.             objselldetaile.setMedicine(medicne);
  465.             objselldetaile.setXsdjh(xsdjh);
  466.             objselldetaile.setXssl(xssl);
  467.             objselldetaile.setXsdj(xsdj);
  468.             objselldetaile.setXsje(je);
  469.             objselldetaile.setXsrq(xsrq);
  470.             objselldetaile.setThsts("F");
  471.             AdapterDao.InsertSellDetaile(objselldetaile);
  472.             //更新盘点数据表Obj_Stock 以便进行查询
  473.             String stockQuery = "from Obj_Stock where ypbh = '" + ypbh + "'";
  474.             java.util.List list = AdapterDao.QueryObject(stockQuery);
  475.             java.util.Iterator iterator = list.iterator();
  476.             appjxc.model.Obj_Stock objstock = (appjxc.model.Obj_Stock)iterator.next();
  477.             objstock.setYpbh(ypbh);
  478.             int kcslnew = 0,xsslnew = 0;
  479.             xsslnew = objstock.getXssl() + xssl;
  480.             kcslnew = objstock.getKcsl() - xssl;
  481.             System.out.println("kcslnew = " + kcslnew + "n xsslnew = " + xsslnew);
  482.             objstock.setXssl(xsslnew);
  483.             objstock.setKcsl(kcslnew);
  484.             AdapterDao.InsertStock(objstock);
  485.         }
  486.         jBreg.setEnabled(true);
  487.         jBadd.setEnabled(false);
  488.         jBdel.setEnabled(false);
  489.         jBsave.setEnabled(false);
  490.         this.jTjbr.setText("");
  491.         this.jTldrq.setText("");
  492.         this.jTxsph.setText("");
  493.         jComboBox2.removeAllItems();
  494.         jComboBox21.removeAllItems();
  495.         this.jTextField1.setText("");
  496.         this.jTextField2.setText("");
  497.         this.jTextField3.setText("");
  498.         this.jTextField4.setText("");
  499.         this.jTextField5.setText("");
  500.         this.jTextField6.setText("");
  501.         this.jTextField8.setText("");
  502.         String[] tname = {"流水号","药品编号","药品名称","药品批号","规格","产地","单位","零售价","销售数量","销售金额","库存数量"};
  503.         java.util.Vector vname = new java.util.Vector();
  504.         for (int i = 0 ; i < tname.length ; i++){
  505.             vname.addElement(tname[i]);
  506.         }
  507.         tableModel = new DefaultTableModel(vname,0);
  508.         tableModel.addTableModelListener(this);
  509.         jTable1.setModel(tableModel);
  510.       }
  511.     public void jBreg_actionPerformed(ActionEvent e) {
  512.         /*-----对销售主表操作------*/
  513.         String xsph;
  514.         xsph = new appjxc.constrol.GenalLsh().getPh();
  515.         jTxsph.setText(xsph);
  516.         jTxsph.setEnabled(false);
  517.         java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-mm-dd");
  518.         Locale loc = new Locale("CN");
  519.         String lsh = null;
  520.         calendar = Calendar.getInstance(loc);
  521.         calendar.setTimeInMillis(System.currentTimeMillis());
  522.         int year = calendar.get(Calendar.YEAR);
  523.         int month = calendar.get(Calendar.MONTH) + 1;
  524.         int day = calendar.get(Calendar.DAY_OF_MONTH);
  525.         //System.out.println("" + year + "" + month +  "" + day);
  526.         jTldrq.setText(year + "-" + month + "-" + day );
  527.         jTldrq.setEnabled(false);
  528.         jComboBox2.requestFocus();
  529.         //此处简洁处理为一次读入完成之后,在进行登记添加的时候不进行读取以提高效率
  530.         if (jComboBox2.getItemCount() <= 0 ){
  531.             String queryClient = "";
  532.             queryClient = "from Obj_client";
  533.             List listClient = AdapterDao.QueryObject(queryClient);
  534.             Iterator iteratorclient = listClient.iterator();
  535.             jComboBox2.removeAllItems();
  536.             jComboBox21.removeAllItems();
  537.             while(iteratorclient.hasNext()){
  538.                 Obj_client object = (Obj_client)iteratorclient.next();
  539.                 jComboBox2.addItem(object.getKhmc());
  540.                 jComboBox21.addItem(object.getKhbh());
  541.             }
  542.             jComboBox2.addItemListener(new JF_view_sell_jCbox_itemAdapter(this));
  543.         }
  544.         jTjbr.requestFocus();
  545.         jBreg.setEnabled(false);
  546.         jBadd.setEnabled(true);
  547.     }
  548.     public void jTextField4_keyPressed(KeyEvent e) {
  549.         if (e.getKeyCode() == KeyEvent.VK_ENTER){
  550.             double zkje,ysje,hjje;
  551.             try{
  552.                 hjje = Double.parseDouble(jTextField3.getText().trim());
  553.                 zkje = Double.parseDouble(jTextField4.getText().trim());
  554.             }catch(java.lang.NumberFormatException format){
  555.                 JOptionPane.showMessageDialog(null,
  556.                                               "输入的数据格式有误,请重新录入!!n" +
  557.                                               format.getMessage(), "系统提示",
  558.                                               JOptionPane.ERROR_MESSAGE);
  559.                 System.out.println(format.getMessage());
  560.                 return;
  561.             }
  562.             ysje = hjje - zkje;
  563.             if (ysje >= 0) {
  564.                 jTextField5.setText(String.valueOf(ysje));
  565.                 jTextField6.requestFocus();
  566.             } else {
  567.                 JOptionPane.showMessageDialog(null, "输入的折扣金额不允许比合计金额大,请从新输入!!!",
  568.                                               "系统提示", JOptionPane.ERROR_MESSAGE);
  569.                 jTextField4.requestFocus();
  570.             }
  571.         }
  572.     }
  573.     public void jTextField6_keyPressed(KeyEvent e) {
  574.         if(e.getKeyCode() == KeyEvent.VK_ENTER){
  575.             double ysje,sjje,wsje;
  576.             try{
  577.                 ysje = Double.parseDouble(jTextField5.getText().trim());
  578.                 sjje = Double.parseDouble(jTextField6.getText().trim());
  579.             }catch(java.lang.NumberFormatException format){
  580.                 JOptionPane.showMessageDialog(null,
  581.                                               "输入的数据格式有误,请重新录入!!n" +
  582.                                               format.getMessage(), "系统提示",
  583.                                               JOptionPane.ERROR_MESSAGE);
  584.                 System.out.println(format.getMessage());
  585.                 return;
  586.             }
  587.             wsje = ysje - sjje;
  588.             if (wsje >= 0){
  589.                 jTextField8.setText(String.valueOf(wsje));
  590.                 jTextField8.setEnabled(false);
  591.             }else{
  592.                 JOptionPane.showMessageDialog(null, "输入的实收金额不允许比应收金额大,请从新输入!!!",
  593.                                               "系统提示", JOptionPane.ERROR_MESSAGE);
  594.                 jTextField6.requestFocus();
  595.             }
  596.         }
  597.     }
  598.     public void jBdel_actionPerformed(ActionEvent e) {
  599.         int row = jTable1.getSelectedRow();
  600.         if (row < 0) return;
  601.         Object ypbh = jTable1.getValueAt(row,1);
  602.         int result = JOptionPane.showOptionDialog(null,"是否真的删除编号为【" + ypbh +  "】的销售明细信息情况?","系统提示",
  603.                                    JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
  604.                                    null,new String[]  {"是","否"},"否");
  605.         if (result == JOptionPane.NO_OPTION) return;
  606.         tableModel.removeRow(row);
  607.     }
  608. }
  609. class JF_view_sell_jBdel_actionAdapter implements ActionListener {
  610.     private JF_view_sell adaptee;
  611.     JF_view_sell_jBdel_actionAdapter(JF_view_sell adaptee) {
  612.         this.adaptee = adaptee;
  613.     }
  614.     public void actionPerformed(ActionEvent e) {
  615.         adaptee.jBdel_actionPerformed(e);
  616.     }
  617. }
  618. class JF_view_sell_jTextField6_keyAdapter extends KeyAdapter {
  619.     private JF_view_sell adaptee;
  620.     JF_view_sell_jTextField6_keyAdapter(JF_view_sell adaptee) {
  621.         this.adaptee = adaptee;
  622.     }
  623.     public void keyPressed(KeyEvent e) {
  624.         adaptee.jTextField6_keyPressed(e);
  625.     }
  626. }
  627. class JF_view_sell_jTextField4_keyAdapter extends KeyAdapter {
  628.     private JF_view_sell adaptee;
  629.     JF_view_sell_jTextField4_keyAdapter(JF_view_sell adaptee) {
  630.         this.adaptee = adaptee;
  631.     }
  632.     public void keyPressed(KeyEvent e) {
  633.         adaptee.jTextField4_keyPressed(e);
  634.     }
  635. }
  636. class JF_view_sell_jBreg_actionAdapter implements ActionListener {
  637.     private JF_view_sell adaptee;
  638.     JF_view_sell_jBreg_actionAdapter(JF_view_sell adaptee) {
  639.         this.adaptee = adaptee;
  640.     }
  641.     public void actionPerformed(ActionEvent e) {
  642.         adaptee.jBreg_actionPerformed(e);
  643.     }
  644. }
  645. class JF_view_sell_jBsave_actionAdapter implements ActionListener {
  646.     private JF_view_sell adaptee;
  647.     JF_view_sell_jBsave_actionAdapter(JF_view_sell adaptee) {
  648.         this.adaptee = adaptee;
  649.     }
  650.     public void actionPerformed(ActionEvent e) {
  651.         adaptee.jBsave_actionPerformed(e);
  652.     }
  653. }
  654. class JF_view_sell_jButton3_actionAdapter implements ActionListener {
  655.     private JF_view_sell adaptee;
  656.     JF_view_sell_jButton3_actionAdapter(JF_view_sell adaptee) {
  657.         this.adaptee = adaptee;
  658.     }
  659.     public void actionPerformed(ActionEvent e) {
  660.         adaptee.jButton3_actionPerformed(e);
  661.     }
  662. }
  663. class JF_view_sell_jCbox_itemAdapter implements ItemListener {
  664.     private JF_view_sell adaptee;
  665.     JF_view_sell_jCbox_itemAdapter(JF_view_sell adaptee) {
  666.         this.adaptee = adaptee;
  667.     }
  668.     public void itemStateChanged(ItemEvent itemEvent) {
  669.         adaptee.jCbox_itemStateChanged(itemEvent);
  670.     }
  671. }
  672. class JF_view_sell_jcbh_itemAdapter implements ItemListener {
  673.     private JF_view_sell adaptee;
  674.     JF_view_sell_jcbh_itemAdapter(JF_view_sell adaptee) {
  675.         this.adaptee = adaptee;
  676.     }
  677.     public void itemStateChanged(ItemEvent itemEvent) {
  678.         adaptee.jcbh_itemStateChanged(itemEvent);
  679.     }
  680. }
  681. class JF_view_sell_jBadd_actionAdapter implements ActionListener {
  682.     private JF_view_sell adaptee;
  683.     JF_view_sell_jBadd_actionAdapter(JF_view_sell adaptee) {
  684.         this.adaptee = adaptee;
  685.     }
  686.     public void actionPerformed(ActionEvent e) {
  687.         adaptee.jBadd_actionPerformed(e);
  688.     }
  689. }