⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 billinframe.java

📁 Jbuilder编写的纱线制衣厂的仓库管理系统(学习java时做的一个系统)源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            jTextField4.setText(LogOn.EID);
            //将storageRemain()方法得到的结果以字符串显示在剩余库存栏
            jTextField2.setText(String.valueOf(storageRemain()));
            try
            {
                //在数据库总查找纱线资料
                ResultSet rs = lookUpYarn_ID(jTextField3.getText());
                //j是对ResultSet进行遍历时用的变量
                String[] findColumnName = {"纱线ID", "色号", "色名", "品种规格", "客户",
                                          "客户色号"};
                tableDisplay(rs, findColumnName);
                rs.close();
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
            //设置表格的纱线ID填写栏的编辑器为组合框,并且设置组合框的基本信息
            Vector comboBoxItem = new Vector();
            try//从数据库查找组合框的基本信息
            {
                ResultSet rs = jf.executeQuery("select YID from Yarn");
                while(rs.next())
                {
                    comboBoxItem.addElement(rs.getString(1));
                }
                rs.close();
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
            yarnIDJComboBox = new JComboBox(comboBoxItem);
            yarnIDJComboBox.setEditable(true);
            //yarnIDJComboBox.getEditor().addActionListener(new BillPane_yarnIDJComboBoxEditor_ActionListener(this));
            //yarnIDJComboBox.addFocusListener(new BillPane_yarnIDJComboBoxFocus_FocusListener(this));
            //yarnIDJComboBox.addItemListener(new BillPane_yarnIDJComboBoxItem_ItemListener(this));
            //设置明细表的纱线ID编辑器为JComboBox
            jTable2.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(yarnIDJComboBox));
            //加入表格的第二栏的单元改变监听
            jTable2.getColumnModel().getColumn(1).getCellEditor().addCellEditorListener(new BillInFrame_yarnIDJComboBoxCell_CellListener(this));
            //jTable2.getColumnModel().getColumn(5).setCellEditor(new DefaultCellEditor(new JCheckBox()));
            jTable2.getColumnModel().getColumn(4).setCellEditor(new DefaultCellEditor(new JTextField()));
            jTable2.getColumnModel().getColumn(6).setCellEditor(new DefaultCellEditor(new JTextField()));
            jTable2.getColumnModel().getColumn(7).setCellEditor(new DefaultCellEditor(new JTextField()));
            jTable2.getColumnModel().getColumn(6).getCellEditor().addCellEditorListener(new BillInFrame_yarnMWJTextFieldCell_CellListener(this));
            jTable2.getColumnModel().getColumn(7).getCellEditor().addCellEditorListener(new BillInFrame_yarnMWJTextFieldCell_CellListener(this));
            jTextField7.setText("0.0");
            jTextField8.setText("0.0");

    }

    //查找剩余库存方法,需要把输入查询仓库条件的JComboBox作参数
        private float storageRemain()
        {
            float temp = 0; //临时变量temp存储在数据库查找的最大容量
            //查找库存的剩余库存并显示在剩余容量栏
            try {
                ResultSet rs = st.executeQuery(
                        "select Mcontent from Storage where SID ='" +
                        (String) jComboBox1.getSelectedItem() + "'");
                rs.next();
                temp = rs.getFloat(1);
                rs.close();
                //查找入库仓库栏的默认仓库的总货物重量
                rs = st.executeQuery("select SUM(YWeight) from Goods where SID ='" +
                                     (String) jComboBox1.getSelectedItem() + "'");
                rs.next();
                //System.out.print(rs.getFloat(1));
                temp = temp - (float) rs.getFloat(1); //将最大容量减去库存容量得到剩余容量
                rs.close();
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
            }
            return temp;
        }

        //按纱线ID号对纱线进行查找的方法,需要输入查询条件
            private ResultSet lookUpYarn_ID(String condition)
            {
                ResultSet rs = null;
                try {
                    rs = st.executeQuery(
                            "select YID,YColorID,YColorName,YVariety,Client,CColor from YarnIn where YID like '" +
                            condition + "%'");
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                return rs;
            }

    //将数据集结果写进表格的方法
    private void tableDisplay(ResultSet rs,String[] columnName)
    {
        //将数据库得到的结果放进rowData中
        try {
            Vector rowData = new Vector();
            if(rs.next())
            do
                {
                    //临时Object数组对象,保存ResultSet读取的单行数据
                    Object[] temp = new Object[rs.getMetaData().getColumnCount()];
                    for (int i = 0; i < rs.getMetaData().getColumnCount();
                                 i++)
                    {
                        temp[i] = rs.getString(i + 1);
                    }
                    rowData.addElement(temp);
                }
            while(rs.next());
            //为纱线查询框设置TableModel
            YarnTableModel yarnInModel = new YarnTableModel(
            rowData,
            columnName);
            jTable1.setModel(yarnInModel);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
    //新增明细按钮的动作监听
     public void jButton4_actionPerformed(ActionEvent e)
     {
         ((YarnTableModel)jTable2.getModel()).addTableItem();
     }

     public void jComboBox1_itemStateChanged(ItemEvent e)
        {
            jTextField2.setText(String.valueOf(storageRemain()));
    }

    //查询文本框文本更改的监听方法
   public void jTextField5_ChangedUpdate(DocumentEvent e)
  {
      String[] columnName = {"纱线ID", "色号", "色名", "品种规格", "客户", "客户色号"};
      tableDisplay(lookUpYarn_ID(jTextField5.getText()),columnName);
  }
  //查询文本框文本插入的监听方法
  public void jTextField5_insertUpdate(DocumentEvent e)
  {
      String[] columnName = {"纱线ID", "色号", "色名", "品种规格", "客户", "客户色号"};
      tableDisplay(lookUpYarn_ID(jTextField5.getText()),columnName);
  }
  //查询文本框文本移除的监听方法
  public void jTextField5_removeUpdate(DocumentEvent e)
  {
      String[] columnName = {"纱线ID", "色号", "色名", "品种规格", "客户", "客户色号"};
      tableDisplay(lookUpYarn_ID(jTextField5.getText()),columnName);
  }

  //双击事件监听实现方法
      public void tableDoubleClick(MouseEvent e)
      {
          int rowCount;
          Object[] signalrowData = new Object[8];
          rowCount = jTable1.getSelectedRow();
          signalrowData[1] = jTable1.getValueAt(rowCount,0);
          signalrowData[2] = jTable1.getValueAt(rowCount,1);
          signalrowData[3] = jTable1.getValueAt(rowCount,3);
          signalrowData[5] = false;
          signalrowData[6] = 0.0;
            signalrowData[7] = 0.0;
          YarnTableModel temp = (YarnTableModel)jTable2.getModel();
          temp.setLastNonFillRow(signalrowData);
    }
    //纱线组合框ID的动作监听方法实线
    public void yarnIDJComboBoxEditor(ActionEvent e)
    {
        if(jTable2.getSelectedRow()>-1)
        {
            try
            {
                ResultSet rs = jf.executeQuery(
                        "select YColorID,YVariety from Yarn where YID = '" +
                        jTable2.getValueAt(jTable2.getSelectedRow(),1) + "'");
                if (rs.next())
                {

                    jTable2.setValueAt(rs.getString(1), jTable2.getSelectedRow(),
                                       2);
                    jTable2.setValueAt(rs.getString(2), jTable2.getSelectedRow(),
                                       3);
                    ((YarnTableModel)jTable2.getModel()).addTableItem();
                }
                else
                {
                    jTable2.setValueAt("", jTable2.getSelectedRow(), 2);
                    jTable2.setValueAt("", jTable2.getSelectedRow(), 3);
                }

            } catch (Exception ex)
            {
                ex.printStackTrace();
            }
        }

    }



   //纱线表格的YID组合框的单元改变监听方法实现
  public void yarnIDJComboBoxEditingStopped(ChangeEvent e)
 {
     if(jTable2.getSelectedRow()>-1)
     {
         try
         {
             ResultSet rs = jf.executeQuery(
                     "select YColorID,YVariety from Yarn where YID = '" +
                     jTable2.getValueAt(jTable2.getSelectedRow(),1) + "'");
             if (rs.next())
             {

                 jTable2.setValueAt(rs.getString(1), jTable2.getSelectedRow(),
                                    2);
                 jTable2.setValueAt(rs.getString(2), jTable2.getSelectedRow(),
                                    3);
                 ((YarnTableModel)jTable2.getModel()).addTableItem();

             }
             else
             {
                 jTable2.setValueAt("", jTable2.getSelectedRow(), 2);
                 jTable2.setValueAt("", jTable2.getSelectedRow(), 3);
             }

         } catch (Exception ex)
         {
             ex.printStackTrace();
         }
     }
 }
 public void yarnIDJComboBoxEditingCanceled(ChangeEvent e)
 {

 }
 //明细表的金额和重量编辑框的编辑完成监听方法
 public void yarnMWJTextFieldCellEditingStopped(ChangeEvent e)
 {
     if (e.getSource() == jTable2.getColumnModel().getColumn(6).getCellEditor())
     {
         float sum = tableColumnSum(jTable2,6);
         jTextField7.setText(String.valueOf(sum));
     }
     if (e.getSource() == jTable2.getColumnModel().getColumn(7).getCellEditor())
     {
         float sum = tableColumnSum(jTable2,7);
         jTextField8.setText(String.valueOf(sum));
     }
 }
 //统计表格列总和,参数为表格JTable和列Column的索引
 public float tableColumnSum(JTable table,int columnIndex)
 {
     float sum = 0;
     for (int i = 0; i < table.getRowCount(); i++)
     {
         try
         {
             float t = Float.valueOf(Float.valueOf((String) table.getValueAt(i,
                     columnIndex)));
             sum = sum + t;
         }
         catch (Exception ex)
         {
             sum = sum;
         }
     }
     return sum;
 }



 public void yarnMWJTextFieldCellEditingCanceled(ChangeEvent e)
  {

 }

    public void jButton5_actionPerformed(ActionEvent e) {
        //返回表格选择了的行的索引
                int[] sRows = jTable2.getSelectedRows();
                YarnTableModel temp = (YarnTableModel)jTable2.getModel();
                temp.deleteRows(sRows);
                //重新计算总金额和总重量,并更新文本框
                jTextField7.setText(String.valueOf(tableColumnSum(jTable2,6)));
        jTextField8.setText(String.valueOf(tableColumnSum(jTable2,7)));
    }
    //查找最大单号加1并且填进单号的填写栏,即新建单据令单号加1

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -