?? stocktransfercheckframe.java
字號:
//清空文本框的內(nèi)容
jTextArea1.setText("");
//清空表格的內(nèi)容
this.showTableData(stockSubLedgerObjects);
//取得面板上的所有控件
Component[] components = contentPane.getComponents();
//創(chuàng)建臨時編輯框控件
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("");
}
}
}
//設置用戶的方法
public void setUser(User user) {
this.user = user;
}
//設置賬套的方法
public void setLedgerDate(String ledgerDate) {
this.ledgerDate = ledgerDate;
}
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
exit();
}
}
//顯示查詢商品調(diào)入單的方法
public void showSearchStockLedger(){
listData1.clear();
//為商品調(diào)入單列表框加入商品調(diào)入單數(shù)據(jù)
for(int i = 0; i < stockLedgers.length; i++){
listData1.addElement(stockLedgers[i][0]);
}
}
//顯示單個商品調(diào)入單的方法
public void showStockLedger(){
//取得當前選擇項的位置
int selectedIndex = jList1.getSelectedIndex();
//當列表框不處于選擇狀態(tài),不顯示數(shù)據(jù)
if(selectedIndex == -1){
return;
}
//顯示商品調(diào)入單的數(shù)據(jù)
jTextField4.setText(stockLedgers[selectedIndex][0]); //票據(jù)編號
jTextField5.setText(stockLedgers[selectedIndex][2]); //關(guān)聯(lián)標識
jTextField6.setText(stockLedgers[selectedIndex][3]); //商品調(diào)出員
jTextField7.setText(stockLedgers[selectedIndex][5]); //商品驗收員
jTextField8.setText(stockLedgers[selectedIndex][4]); //商品調(diào)出倉庫
jTextField9.setText(stockLedgers[selectedIndex][8]); //商品調(diào)入倉庫
jTextField10.setText(stockLedgers[selectedIndex][9]); //調(diào)出日期
jTextField11.setText(stockLedgers[selectedIndex][10]); //驗收日期
jTextField12.setText(onProcesses[Integer.parseInt(stockLedgers[selectedIndex][11])]);
jTextArea1.setText(stockLedgers[selectedIndex][12]);
//顯示商品調(diào)入單明細數(shù)據(jù)
this.showStockSubLedger();
}
//顯示商品調(diào)入單明細數(shù)據(jù)的方法
public void showStockSubLedger(){
//取得當前選擇項的位置
int selectedIndex = jList1.getSelectedIndex();
String orderId = stockLedgers[selectedIndex][0];
stockSubLedgers = stockManagementData.getStockSubLedgerByOrderId(ledgerDate, orderId);
//將數(shù)組數(shù)據(jù)轉(zhuǎn)換為表格數(shù)據(jù)
stockSubLedgerObjects = new Object[stockSubLedgers.length][7];
double total = 0;
for(int i = 0; i < stockSubLedgers.length; i++){
stockSubLedgerObjects[i][0] = new Integer(stockSubLedgers[i][0]);
stockSubLedgerObjects[i][1] = stockSubLedgers[i][1];
stockSubLedgerObjects[i][2] = stockSubLedgers[i][2];
double costPrice = dataMethod.round(Double.parseDouble(stockSubLedgers[i][3]));
int quantity = Integer.parseInt(stockSubLedgers[i][4]);
stockSubLedgerObjects[i][3] = new Double(costPrice);
stockSubLedgerObjects[i][4] = new Integer(quantity);
double amount = dataMethod.round(costPrice * quantity);
stockSubLedgerObjects[i][5] = new Double(amount);
stockSubLedgerObjects[i][6] = dataMethod.transferShortDate(stockSubLedgers[i][5]).toString();
total += amount;
}
//顯示總價
jTextField13.setText(String.valueOf(dataMethod.round(total)));
//顯示表格的內(nèi)容
this.showTableData(stockSubLedgerObjects);
}
//顯示表格內(nèi)容的方法
public void showTableData(Object[][] detail){
//設置表格的標題
sslTableModel.setColumnNames(colNames);
//設置表格的數(shù)據(jù)
sslTableModel.setData(detail);
//使表格不可編輯
sslTableModel.setColumnEditState(1);
jTable1 = new JTable(sslTableModel);
//設置表格的字體
jTable1.setFont(dialog13);
//將數(shù)據(jù)表格加入數(shù)據(jù)滾動框
jScrollPane3.getViewport().add(jTable1, null);
//設置列的寬度
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);
}
//清空單個商品調(diào)入單顯示的方法
public void clearStockLedger(){
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jTextField7.setText("");
jTextField8.setText("");
jTextField9.setText("");
jTextField10.setText("");
jTextField11.setText("");
jTextField12.setText("");
jTextField13.setText("");
jTextArea1.setText("");
stockSubLedgers = new String[0][6];
stockSubLedgerObjects = new Object[0][7];
this.showTableData(stockSubLedgerObjects);
}
//列表1的選擇事件
void jList1_valueChanged(ListSelectionEvent e) {
if(listData1.size() > 0){
this.showStockLedger();
}else{
this.clearStockLedger();
}
}
//查詢方法
public void search(){
//取得查詢選項
int selectedIndex = jComboBox1.getSelectedIndex();
//取得編輯框的變量
String searchValue = jTextField1.getText().trim();
String startDateStr = jTextField2.getText().trim();
String endDateStr = jTextField3.getText().trim();
if (selectedIndex == 0 | selectedIndex == 1 | selectedIndex == 2 |
selectedIndex == 3 | selectedIndex == 4 | selectedIndex == 5) {
if (searchValue.length() == 0) {
JOptionPane.showMessageDialog(null, "請輸入查詢值");
return;
}
switch (selectedIndex) {
case 0:
//根據(jù)商品調(diào)入單編號取得記錄
stockLedgers = stockManagementData.getStockLedgerByStringField(
ledgerDate, "orderId", searchValue, 3);
break;
case 1:
//根據(jù)商品調(diào)出員取得記錄
stockLedgers = stockManagementData.getStockLedgerByStringField(
ledgerDate, "submitUser", searchValue, 3);
break;
case 2:
//根據(jù)商品驗收員取得記錄
stockLedgers = stockManagementData.getStockLedgerByStringField(
ledgerDate, "checkUser", searchValue, 3);
break;
case 3:
//根據(jù)調(diào)出倉庫名字取得記錄,調(diào)出倉庫名字保存在調(diào)入單的commitUser字段
stockLedgers = stockManagementData.getStockLedgerByStringField(
ledgerDate, "commitUser", searchValue, 3);
break;
case 4:
//根據(jù)調(diào)入倉庫名字取得記錄
stockLedgers = stockManagementData.getStockLedgerByStringField(
ledgerDate, "warehouse", searchValue, 3);
break;
case 5:
if(dataMethod.checkInt(searchValue) == 0){
JOptionPane.showMessageDialog(null, "按完成狀態(tài)查詢時,輸入值必須是整數(shù),"
+ "0表示進行,1表示撤消,2表示完成.");
return;
}
//根據(jù)完成狀態(tài)取得記錄
stockLedgers = stockManagementData.getStockLedgerByOnProcess(
ledgerDate, 3, Integer.parseInt(searchValue));
break;
}
}else{
java.sql.Timestamp startDate = dataMethod.transferDate(startDateStr);
java.sql.Timestamp endDate = dataMethod.transferEndDate(endDateStr);
if(startDate == null | endDate == null){
JOptionPane.showMessageDialog(null, "日期輸入錯誤,正確的日期格式是"
+ "yyyy-mm-dd(年-月-日),如2004-1-1");
return;
}
//根據(jù)日期取得記錄
stockLedgers = stockManagementData.getStockLedgerByOrderDate(ledgerDate,
startDate, endDate, 3);
}
this.showSearchStockLedger();
}
//單擊事件
public void actionPerformed(ActionEvent e) {
//取得按鈕的動作字符串
String actionCommand = e.getActionCommand().trim();
int selectedIndex = 0;
String remark = jTextArea1.getText().trim();
int onProcess = 0;
if (actionCommand.equals("signStockLedger") |
actionCommand.equals("cancelStockLedger") |
actionCommand.equals("restoreStockLedger")) {
//檢查打開的賬套是否當前賬套
int result = stockManagementData.isCurrentLedger(ledgerDate);
if(result == 0){
JOptionPane.showMessageDialog(null, ledgerDate + "是往期賬套,不能進行添加、修改和撤消操作.");
return;
}
if(jList1.isSelectionEmpty()){
JOptionPane.showMessageDialog(null, "請選擇商品調(diào)入單.");
return;
}
selectedIndex = jList1.getSelectedIndex();
//檢查商品調(diào)入單是否完成
onProcess = Integer.parseInt(stockLedgers[selectedIndex][11]);
if(onProcess == 2){
JOptionPane.showMessageDialog(null, stockLedgers[selectedIndex][0]
+ "商品調(diào)入單已經(jīng)完成,不可以進行電子簽名、撤消、恢復操作.");
return;
}
}
int result = 0;
if (actionCommand.equals("search")) {
//查詢
search();
}else if(actionCommand.equals("signStockLedger")){
//檢查商品調(diào)入單是否撤消
if(onProcess == 1){
JOptionPane.showMessageDialog(null, stockLedgers[selectedIndex][0]
+ "商品調(diào)入單已經(jīng)撤消,不可以進行電子簽名操作.");
return;
}
//驗收員進行調(diào)入單和調(diào)出單的電子簽名并且更新完成狀態(tài)
result = stockManagementData.signStockLedgerAndSubForFinish(ledgerDate,
"checkUser", user.getUserName(), stockLedgers[selectedIndex][0], 2, remark);
result = stockManagementData.signStockLedgerAndSubForFinish(ledgerDate,
"checkUser", user.getUserName(), stockLedgers[selectedIndex][2], 2, remark);
if(result == 1){
JOptionPane.showMessageDialog(null, "商品調(diào)入單電子簽名成功.");
//更新編輯框的值
jTextField7.setText(user.getUserName());
jTextField12.setText(onProcesses[2]);
//更新數(shù)組的數(shù)據(jù)
stockLedgers[selectedIndex][5] = user.getUserName();
stockLedgers[selectedIndex][11] = "2";
stockLedgers[selectedIndex][12] = remark;
}else{
JOptionPane.showMessageDialog(null, "商品調(diào)入單電子簽名失敗.");
}
}else if(actionCommand.equals("cancelStockLedger")){
//撤消商品調(diào)入單
result = stockManagementData.cancelOrRestoreTransferOrder(ledgerDate,
stockLedgers[selectedIndex][0], stockLedgers[selectedIndex][2], 1, remark);
if(result == 1){
JOptionPane.showMessageDialog(null, "商品調(diào)入單撤消成功.");
//更新完成狀態(tài)編輯框的值
jTextField12.setText(onProcesses[1]);
//更新數(shù)組的數(shù)據(jù)
stockLedgers[selectedIndex][11] = "1";
stockLedgers[selectedIndex][12] = remark;
}else{
JOptionPane.showMessageDialog(null, "商品調(diào)入單撤消失敗.");
}
}else if(actionCommand.equals("restoreStockLedger")){
//恢復商品調(diào)入單
result = stockManagementData.cancelOrRestoreTransferOrder(ledgerDate,
stockLedgers[selectedIndex][0], stockLedgers[selectedIndex][2], 0, remark);
if(result == 1){
JOptionPane.showMessageDialog(null, "商品調(diào)入單恢復成功.");
//更新完成狀態(tài)編輯框的值
jTextField12.setText(onProcesses[0]);
//更新數(shù)組的數(shù)據(jù)
stockLedgers[selectedIndex][11] = "0";
stockLedgers[selectedIndex][12] = remark;
}else{
JOptionPane.showMessageDialog(null, "商品調(diào)入單恢復失敗.");
}
}else if(actionCommand.equals("exit")){
exit();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -