?? goodsquantitycombineframe.java
字號(hào):
stockSubLedgersIn = new String[0][6]; stockSubLedgerObjectsIn = new Object[0][7]; //清空列表框的內(nèi)容 listData1.clear(); //清空文本框的內(nèi)容 jTextArea1.setText(""); //清空表格的內(nèi)容 this.showTableDataOut(stockSubLedgerObjectsOut); //取得面板上的所有控件 Component[] components = contentPane.getComponents(); //創(chuàng)建臨時(shí)編輯框控件 JTextField tmpTextField = new JTextField(); for(int i = 0; i < components.length; i++){ if(components[i].getClass().getName().equals("javax.swing.JTextField")){ tmpTextField = (JTextField)components[i]; //清空編輯框的內(nèi)容 tmpTextField.setText(""); } } } //設(shè)置用戶的方法 public void setUser(User user) { this.user = user; } //設(shè)置賬套的方法 public void setLedgerDate(String ledgerDate) { this.ledgerDate = ledgerDate; } protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { exit(); } } //顯示查詢商品組合單的方法 public void showSearchStockLedger(){ listData1.clear(); //為商品組合單列表框加入商品組合單數(shù)據(jù) for(int i = 0; i < stockLedgers.length; i++){ listData1.addElement(stockLedgers[i][0]); } } //顯示單個(gè)商品組合單的方法 public void showStockLedger(){ //取得當(dāng)前選擇項(xiàng)的位置 int selectedIndex = jList1.getSelectedIndex(); //當(dāng)列表框不處于選擇狀態(tài),不顯示數(shù)據(jù) if(selectedIndex == -1){ return; } //顯示商品組合單的數(shù)據(jù) jTextField4.setText(stockLedgers[selectedIndex][0]); //票據(jù)編號(hào) jTextField5.setText(stockLedgers[selectedIndex][2]); //關(guān)聯(lián)標(biāo)識(shí) jTextField6.setText(stockLedgers[selectedIndex][3]); //組合用戶 jTextField7.setText(stockLedgers[selectedIndex][4]); //組合前倉(cāng)庫(kù) jTextField8.setText(stockLedgers[selectedIndex][8]); //組合后倉(cāng)庫(kù) jTextField9.setText(stockLedgers[selectedIndex][9]); //組合日期 jTextField10.setText(onProcesses[Integer.parseInt(stockLedgers[selectedIndex][11])]); jTextArea1.setText(stockLedgers[selectedIndex][12]); //顯示調(diào)出商品明細(xì)數(shù)據(jù) this.showStockSubLedgerOut(); //顯示調(diào)入商品明細(xì)數(shù)據(jù) this.showStockSubLedgerIn(); } //顯示商品組合單的調(diào)出商品明細(xì)數(shù)據(jù)的方法 public void showStockSubLedgerOut(){ //取得當(dāng)前選擇項(xiàng)的位置 int selectedIndex = jList1.getSelectedIndex(); String orderId = stockLedgers[selectedIndex][2]; stockSubLedgersOut = stockManagementData.getStockSubLedgerByOrderId(ledgerDate, orderId); //將數(shù)組數(shù)據(jù)轉(zhuǎn)換為表格數(shù)據(jù) stockSubLedgerObjectsOut = new Object[stockSubLedgersOut.length][7]; double total = 0; for(int i = 0; i < stockSubLedgersOut.length; i++){ stockSubLedgerObjectsOut[i][0] = new Integer(stockSubLedgersOut[i][0]); stockSubLedgerObjectsOut[i][1] = stockSubLedgersOut[i][1]; stockSubLedgerObjectsOut[i][2] = stockSubLedgersOut[i][2]; double costPrice = dataMethod.round(Double.parseDouble(stockSubLedgersOut[i][3])); int quantity = Integer.parseInt(stockSubLedgersOut[i][4]); stockSubLedgerObjectsOut[i][3] = new Double(costPrice); stockSubLedgerObjectsOut[i][4] = new Integer(quantity); double amount = dataMethod.round(costPrice * quantity); stockSubLedgerObjectsOut[i][5] = new Double(amount); stockSubLedgerObjectsOut[i][6] = dataMethod.transferShortDate(stockSubLedgersOut[i][5]).toString(); total += amount; } //顯示總價(jià) jTextField11.setText(String.valueOf(dataMethod.round(total))); //顯示表格的內(nèi)容 this.showTableDataOut(stockSubLedgerObjectsOut); } //顯示商品組合單的調(diào)入商品明細(xì)數(shù)據(jù)的方法 public void showStockSubLedgerIn(){ //取得當(dāng)前選擇項(xiàng)的位置 int selectedIndex = jList1.getSelectedIndex(); String orderId = stockLedgers[selectedIndex][0]; stockSubLedgersIn = stockManagementData.getStockSubLedgerByOrderId(ledgerDate, orderId); //將數(shù)組數(shù)據(jù)轉(zhuǎn)換為表格數(shù)據(jù) stockSubLedgerObjectsIn = new Object[stockSubLedgersIn.length][7]; for(int i = 0; i < stockSubLedgersIn.length; i++){ stockSubLedgerObjectsIn[i][0] = new Integer(stockSubLedgersIn[i][0]); stockSubLedgerObjectsIn[i][1] = stockSubLedgersIn[i][1]; stockSubLedgerObjectsIn[i][2] = stockSubLedgersIn[i][2]; double costPrice = dataMethod.round(Double.parseDouble(stockSubLedgersIn[i][3])); int quantity = Integer.parseInt(stockSubLedgersIn[i][4]); stockSubLedgerObjectsIn[i][3] = new Double(costPrice); stockSubLedgerObjectsIn[i][4] = new Integer(quantity); double amount = dataMethod.round(costPrice * quantity); stockSubLedgerObjectsIn[i][5] = new Double(amount); stockSubLedgerObjectsIn[i][6] = dataMethod.transferShortDate(stockSubLedgersIn[i][5]).toString(); } //顯示表格的內(nèi)容 this.showTableDataIn(stockSubLedgerObjectsIn); } //轉(zhuǎn)換表格數(shù)據(jù)的方法 public void transferTableData(){ stockSubLedgersOut = new String[stockSubLedgerObjectsOut.length][6]; for(int i = 0; i < stockSubLedgerObjectsOut.length; i++){ stockSubLedgersOut[i][0] = ((Integer)stockSubLedgerObjectsOut[i][0]).toString(); stockSubLedgersOut[i][1] = (String)stockSubLedgerObjectsOut[i][1]; stockSubLedgersOut[i][2] = (String)stockSubLedgerObjectsOut[i][2]; stockSubLedgersOut[i][3] = ((Double)stockSubLedgerObjectsOut[i][3]).toString(); stockSubLedgersOut[i][4] = ((Integer)stockSubLedgerObjectsOut[i][4]).toString(); stockSubLedgersOut[i][5] = stockSubLedgerObjectsOut[i][6].toString(); } stockSubLedgersIn = new String[stockSubLedgerObjectsIn.length][6]; for(int i = 0; i < stockSubLedgerObjectsIn.length; i++){ stockSubLedgersIn[i][0] = ((Integer)stockSubLedgerObjectsIn[i][0]).toString(); stockSubLedgersIn[i][1] = (String)stockSubLedgerObjectsIn[i][1]; stockSubLedgersIn[i][2] = (String)stockSubLedgerObjectsIn[i][2]; stockSubLedgersIn[i][3] = ((Double)stockSubLedgerObjectsIn[i][3]).toString(); stockSubLedgersIn[i][4] = ((Integer)stockSubLedgerObjectsIn[i][4]).toString(); stockSubLedgersIn[i][5] = stockSubLedgerObjectsIn[i][6].toString(); } } //顯示組合調(diào)出商品的表格內(nèi)容的方法 public void showTableDataOut(Object[][] detail){ //設(shè)置表格的標(biāo)題 sslTableModel.setColumnNames(colNames); //設(shè)置表格的數(shù)據(jù) sslTableModel.setData(detail); jTable1 = new JTable(sslTableModel); //設(shè)置表格的字體 jTable1.setFont(dialog13); //將數(shù)據(jù)表格加入數(shù)據(jù)滾動(dòng)框 jScrollPane3.getViewport().add(jTable1, null); //設(shè)置列的寬度 jTable1.getColumnModel().getColumn(0).setPreferredWidth(20); jTable1.getColumnModel().getColumn(1).setPreferredWidth(50); jTable1.getColumnModel().getColumn(2).setPreferredWidth(50); jTable1.getColumnModel().getColumn(3).setPreferredWidth(10); jTable1.getColumnModel().getColumn(4).setPreferredWidth(10); jTable1.getColumnModel().getColumn(5).setPreferredWidth(10); jTable1.getColumnModel().getColumn(6).setPreferredWidth(50); //取得表格的行 ListSelectionModel rowSM = jTable1.getSelectionModel(); //加入行選擇接收器 rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { //當(dāng)多種事件被激發(fā)的時(shí)候,不執(zhí)行接收器后面的代碼 if (e.getValueIsAdjusting()) return; jTable1_valueChanged(e); } }); } //顯示組合調(diào)入商品的表格內(nèi)容的方法 public void showTableDataIn(Object[][] detail){ //設(shè)置表格的標(biāo)題 sslTableMode2.setColumnNames(colNames); //設(shè)置表格的數(shù)據(jù) sslTableMode2.setData(detail); jTable2 = new JTable(sslTableMode2); //設(shè)置表格的字體 jTable2.setFont(dialog13); //將數(shù)據(jù)表格加入數(shù)據(jù)滾動(dòng)框 jScrollPane4.getViewport().add(jTable2, null); //設(shè)置列的寬度 jTable2.getColumnModel().getColumn(0).setPreferredWidth(20); jTable2.getColumnModel().getColumn(1).setPreferredWidth(50); jTable2.getColumnModel().getColumn(2).setPreferredWidth(50); jTable2.getColumnModel().getColumn(3).setPreferredWidth(10); jTable2.getColumnModel().getColumn(4).setPreferredWidth(10); jTable2.getColumnModel().getColumn(5).setPreferredWidth(10); jTable2.getColumnModel().getColumn(6).setPreferredWidth(50); sslTableMode2.addTableModelListener(new TableModelListener(){ public void tableChanged(TableModelEvent e) { jTable2_valueChanged(e); } }); } //重新計(jì)算調(diào)出商品金額 public void recountGoodsOutAmount(){ double costPrice = 0; int quantity = 0; double amount = 0; double total = 0; for(int i = 0; i < stockSubLedgerObjectsOut.length; i++){ costPrice = dataMethod.round(((Double)stockSubLedgerObjectsOut[i][3]).doubleValue()); quantity = ((Integer)stockSubLedgerObjectsOut[i][4]).intValue(); amount = dataMethod.round(costPrice * quantity); stockSubLedgerObjectsOut[i][5] = new Double(amount); total += amount; } jTextField11.setText(String.valueOf(dataMethod.round(total))); } //重新計(jì)算調(diào)入商品金額 public void recountGoodsInAmount(){ double costPrice = 0; int quantity = 0; double amount = 0; for(int i = 0; i < stockSubLedgerObjectsIn.length; i++){ costPrice = dataMethod.round(((Double)stockSubLedgerObjectsIn[i][3]).doubleValue()); quantity = ((Integer)stockSubLedgerObjectsIn[i][4]).intValue(); amount = dataMethod.round(costPrice * quantity); stockSubLedgerObjectsIn[i][5] = new Double(amount); } } //檢查組合商品與被組合商品的金額是否相等 public int checkGoodsInAndOutAmount(){ this.recountGoodsOutAmount(); this.recountGoodsInAmount(); double amountOut = - ((Double)stockSubLedgerObjectsIn[0][5]).doubleValue(); double amountIn = Double.parseDouble(jTextField11.getText()); if(amountOut != amountIn){ JOptionPane.showMessageDialog(null, "組合前與組合后的商品的金額不相等."); return 0; } return 1; } //檢查明細(xì)賬日期的方法 public int checkStockSubLedgerDate(){ java.sql.Date date = null; for(int i = 0; i < stockSubLedgerObjectsOut.length; i++){ date = dataMethod.transferShortDate((String)stockSubLedgerObjectsOut[i][6]); if(date == null){ JOptionPane.showMessageDialog(null, "組合前的商品列表的第" + (i+1) + "行日期輸入錯(cuò)誤,正確的日期格式是" + "yyyy-mm-dd(年-月-日),如2004-1-1"); return 0; } } for(int i = 0; i < stockSubLedgerObjectsIn.length; i++){ date = dataMethod.transferShortDate((String)stockSubLedgerObjectsIn[i][6]); if(date == null){ JOptionPane.showMessageDialog(null, "組合后的商品的第" + (i+1) + "行日期輸入錯(cuò)誤,正確的日期格式是" + "yyyy-mm-dd(年-月-日),如2004-1-1"); return 0; } } return 1; } //檢查明細(xì)賬的商品條形碼方法 public int checkStockSubLedgerGoodsBarCode(){ int result = 0; for(int i = 0; i < stockSubLedgerObjectsOut.length; i++){ result = stockManagementData.checkGoodsBarCode((String)stockSubLedgerObjectsOut[i][2]); if(result == 0){ JOptionPane.showMessageDialog(null, "組合前的商品列表的第" + (i + 1) + "行的商品條形碼在商品數(shù)據(jù)庫(kù)中" + "不存在,請(qǐng)打開商品數(shù)據(jù)管理窗口添加."); return 0; } } for(int i = 0; i < stockSubLedgerObjectsIn.length; i++){ result = stockManagementData.checkGoodsBarCode((String)stockSubLedgerObjectsIn[i][2]); if(result == 0){ JOptionPane.showMessageDialog(null, "組合后的商品的第" + (i + 1) + "行的商品條形碼在商品數(shù)據(jù)庫(kù)中" + "不存在,請(qǐng)打開商品數(shù)據(jù)管理窗口添加."); return 0; } } return 1; } //檢查明細(xì)賬數(shù)量的方法 public int checkStockSubLedgerQuantity(){ int quantity = 0; for(int i = 0; i < stockSubLedgerObjectsOut.length; i++){ quantity = ((Integer)stockSubLedgerObjectsOut[i][4]).intValue(); if(quantity >= 0){ JOptionPane.showMessageDialog(null, "組合前的商品列表的第" + (i + 1) + "行的數(shù)量輸入錯(cuò)誤,該數(shù)量必須是負(fù)數(shù)."); return 0; } } for(int i = 0; i < stockSubLedgerObjectsIn.length; i++){ quantity = ((Integer)stockSubLedgerObjectsIn[i][4]).intValue(); if(quantity <= 0){ JOptionPane.showMessageDialog(null, "組合后的商品的第" + (i + 1) + "行的數(shù)量輸入錯(cuò)誤,該數(shù)量必須是正數(shù)."); return 0; } } return 1; } //清空單個(gè)商品組合單顯示的方法 public void clearStockLedger(){ jTextField4.setText(""); jTextField5.setText(""); jTextField6.setText(""); jTextField7.setText(""); jTextField8.setText(""); jTextField9.setText(""); jTextField10.setText(""); jTextField11.setText(""); jTextArea1.setText(""); stockSubLedgersOut = new String[0][6]; stockSubLedgerObjectsOut = new Object[0][7]; stockSubLedgersIn = new String[0][6]; stockSubLedgerObjectsIn = new Object[0][7]; this.showTableDataOut(stockSubLedgerObjectsOut); this.showTableDataIn(stockSubLedgerObjectsIn); } //檢查按鈕的狀態(tài) public void checkBtn(boolean isManipulated){ if(isManipulated){ jButton2.setEnabled(false);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -