📄 stockaccountentrysearchframe.java
字号:
contentPane.add(jComboBox1, null); contentPane.add(jComboBox2, null); //设置窗口类的字体和为按钮加入动作接收器 setupFontAndListener(); } //设置窗口类的字体和为按钮加入动作接收器的方法 public void setupFontAndListener(){ Component[] components = contentPane.getComponents(); //创建临时按钮控件 JButton tmpBtn = new JButton(); for(int i = 0; i < components.length; i++){ components[i].setFont(dialog13); if(components[i].getClass().getName().equals("javax.swing.JButton")){ tmpBtn = (JButton)components[i]; tmpBtn.addActionListener(this); } } } //退出方法 public void exit(){ //隐藏窗口 this.setVisible(false); //清空数组的内容 accountEntryLedgers = new String[0][8]; accountEntrySubLedgers = new String[0][5]; accountEntrySubLedgerObjects = new Object[0][5]; //清空列表框的内容 listData1.clear(); //清空文本框的内容 jTextArea1.setText(""); //清空表格的内容 this.showTableData(accountEntrySubLedgerObjects); //取得面板上的所有控件 Component[] components = contentPane.getComponents(); //创建临时编辑框控件 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]; //清空编辑框的内容 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(); } } //显示查询会计分录的方法 public void showSearchAccountEntryLedger(){ listData1.clear(); //为会计分录列表框加入会计分录数据 for(int i = 0; i < accountEntryLedgers.length; i++){ listData1.addElement(accountEntryLedgers[i][0]); } } //显示单个会计分录的方法 public void showAccountEntryLedger(){ //取得当前选择项的位置 int selectedIndex = jList1.getSelectedIndex(); //当列表框不处于选择状态,不显示数据 if(selectedIndex == -1){ return; } //显示会计分录的数据 jTextField4.setText(accountEntryLedgers[selectedIndex][0]); jTextField5.setText(accountEntryLedgers[selectedIndex][1]); jTextField6.setText(accountEntryLedgers[selectedIndex][2]); jTextField7.setText(accountEntryLedgers[selectedIndex][3]); jTextField8.setText(accountEntryLedgers[selectedIndex][4]); jTextField9.setText(accountEntryLedgers[selectedIndex][5]); jTextField10.setText(onProcesses[Integer.parseInt(accountEntryLedgers[selectedIndex][6])]); jTextArea1.setText(accountEntryLedgers[selectedIndex][7]); //显示会计分录明细数据 this.showAccountEntrySubLedger(); } //显示会计分录明细数据的方法 public void showAccountEntrySubLedger(){ //取得当前选择项的位置 int selectedIndex = jList1.getSelectedIndex(); int serialId = Integer.parseInt(accountEntryLedgers[selectedIndex][0]); accountEntrySubLedgers = stockManagementData.getAccountEntrySubLedgerByLinkSerialId(ledgerDate, serialId); //将数组数据转换为表格数据 accountEntrySubLedgerObjects = new Object[accountEntrySubLedgers.length][5]; double total = 0; for(int i = 0; i < accountEntrySubLedgers.length; i++){ accountEntrySubLedgerObjects[i][0] = new Integer(accountEntrySubLedgers[i][0]); accountEntrySubLedgerObjects[i][1] = new Integer(accountEntrySubLedgers[i][1]); int debitCredit = Integer.parseInt(accountEntrySubLedgers[i][2]); accountEntrySubLedgerObjects[i][2] = debitCreditStrs[debitCredit]; accountEntrySubLedgerObjects[i][3] = dataMethod.transferAccountName(accountEntrySubLedgers[i][3]); double amount = dataMethod.round(Double.parseDouble(accountEntrySubLedgers[i][4])); accountEntrySubLedgerObjects[i][4] = new Double(amount); if(debitCredit == 0){ total += amount; }else{ total -= amount; } } //显示借贷平衡数字 jTextField11.setText(String.valueOf(dataMethod.round(total))); //显示表格的内容 this.showTableData(accountEntrySubLedgerObjects); } //显示表格内容的方法 public void showTableData(Object[][] detail){ //设置表格的标题 aeslTableModel.setColumnNames(colNames); //设置表格的数据 aeslTableModel.setData(detail); //设置表格的列编辑状态,所有列不能编辑 aeslTableModel.setColumnEditState(1); jTable1 = new JTable(aeslTableModel); //设置表格的字体 jTable1.setFont(dialog13); //将数据表格加入数据滚动框 jScrollPane3.getViewport().add(jTable1, null); //为表格科目标识列加入下拉列表框 javax.swing.table.TableColumn debitCreditColumn = jTable1.getColumnModel().getColumn(2); JComboBox comboBox = new JComboBox(new String[] {"借","贷"}); debitCreditColumn.setCellEditor(new DefaultCellEditor(comboBox)); //设置列的宽度 jTable1.getColumnModel().getColumn(0).setPreferredWidth(20); jTable1.getColumnModel().getColumn(1).setPreferredWidth(20); jTable1.getColumnModel().getColumn(2).setPreferredWidth(20); jTable1.getColumnModel().getColumn(3).setPreferredWidth(120); jTable1.getColumnModel().getColumn(4).setPreferredWidth(20); } //清空单个会计分录显示的方法 public void clearAccountEntryLedger(){ jTextField4.setText(""); jTextField5.setText(""); jTextField6.setText(""); jTextField7.setText(""); jTextField8.setText(""); jTextField9.setText(""); jTextField10.setText(""); jTextField11.setText(""); jTextArea1.setText(""); accountEntrySubLedgers = new String[0][5]; accountEntrySubLedgerObjects = new Object[0][5]; this.showTableData(accountEntrySubLedgerObjects); } //列表1的选择事件 void jList1_valueChanged(ListSelectionEvent e) { if(listData1.size() > 0){ this.showAccountEntryLedger(); }else{ this.clearAccountEntryLedger(); } } //查询方法 public void search(){ //取得查询选项 int selectedIndex = jComboBox2.getSelectedIndex(); int accountNameSelectedIndex = jComboBox1.getSelectedIndex(); //创建科目查询字符串数组 String[] accountNamesSearch = {"应付账款", "存货", "现金", ""}; String accountNameSearch = accountNamesSearch[accountNameSelectedIndex]; //取得编辑框的变量 String searchValue = jTextField1.getText().trim(); String startDateStr = jTextField2.getText().trim(); String endDateStr = jTextField3.getText().trim(); if (selectedIndex == 0 | selectedIndex == 1 | selectedIndex == 2 | selectedIndex == 3) { if (searchValue.length() == 0) { JOptionPane.showMessageDialog(null, "请输入查询值"); return; } switch (selectedIndex) { case 0: //根据关联标识取得记录 accountEntryLedgers = stockManagementData.getAccountEntryLedgerByStringField( ledgerDate, accountNameSearch, "linkId", searchValue); break; case 1: //根据记账用户取得记录 accountEntryLedgers = stockManagementData.getAccountEntryLedgerByStringField( ledgerDate, accountNameSearch, "filler", searchValue); break; case 2: //根据审核用户取得记录 accountEntryLedgers = stockManagementData.getAccountEntryLedgerByStringField( ledgerDate, accountNameSearch, "auditUser", searchValue); break; case 3: if(dataMethod.checkInt(searchValue) == 0){ JOptionPane.showMessageDialog(null, "按完成状态查询时,输入值必须是整数," + "0表示进行,1表示撤消,2表示完成."); return; } //根据完成状态取得记录 accountEntryLedgers = stockManagementData.getAccountEntryLedgerByOnProcess( ledgerDate, accountNameSearch, 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; } //根据日期取得记录 accountEntryLedgers = stockManagementData.getAccountEntryLedgerByFillDate( ledgerDate, startDate, endDate, accountNameSearch); } this.showSearchAccountEntryLedger(); } //单击事件 public void actionPerformed(ActionEvent e) { //取得按钮的动作字符串 String actionCommand = e.getActionCommand().trim(); if (actionCommand.equals("search")) { //查询 search(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -