📄 shoukuantongji.java
字号:
package wuYeGuanLi;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
import java.io.*;
import java.util.*;
public class ShouKuanTongJi
extends JFrame
implements ActionListener {
private JLabel date1;
private JLabel date2;
private JLabel building;
private JLabel shouFeiXiangMu;
private JLabel yeZhu;
private JLabel shouKuanRen;
private JLabel money;
private JTextField date11;
private JTextField date22;
private JComboBox building1;
private JComboBox shouFeiXiangMu1;
private JComboBox yeZhu1;
private JTextField shouKuanRen1;
private JTextArea money1;
private JButton queryButton;
private Connection con;
private Statement stmt;
private ResultSet rs;
public static void main(String[] args) {
ShouKuanTongJi dd = new ShouKuanTongJi();
dd.setVisible(true);
}
public ShouKuanTongJi() {
setTitle("收款统计");
setSize(400, 300);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
//获取屏幕大小
setLocation( (screen.width - 400) / 2, (screen.height - 400) / 2);
//界面默认在屏幕中间显示
this.getContentPane().setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
date1 = new JLabel("开始日期");
UIManager.put("Button.font",
new java.awt.Font("黑体", java.awt.Font.PLAIN, 12));
//date1.setFont("黑体");
date2 = new JLabel("结束日期");
building = new JLabel("大 楼");
shouFeiXiangMu = new JLabel("收费项目");
yeZhu = new JLabel("业 主");
shouKuanRen = new JLabel("收款 人");
money = new JLabel("收款合计");
Calendar rightNow = Calendar.getInstance();
date11 = new JTextField(12);
date11.setText("");
date22 = new JTextField(12);
date22.setText("");
building1 = new JComboBox();
//building1.setText("");
shouFeiXiangMu1 = new JComboBox();
//shouFeiXiangMu1.setText("");
yeZhu1 = new JComboBox();
//yeZhu1.setText("");
shouKuanRen1 = new JTextField(12);
shouKuanRen1.setText("");
money1 = new JTextArea(1, 12);
//money1.setText("");
try {
con = QueryDB.getConnection("wang", "");
stmt = con.createStatement();
String query = "SELECT 姓名 FROM yeZhu";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
yeZhu1.addItem(rs.getString(1));
}
query = "SELECT 楼号 FROM yeZhu";
rs = stmt.executeQuery(query);
while (rs.next()) {
building1.addItem(rs.getString(1));
}
query = "SELECT 服务项目 FROM sevNam";
rs = stmt.executeQuery(query);
while (rs.next()) {
shouFeiXiangMu1.addItem(rs.getString(1));
}
}
catch (Exception e) {
//result.setText("Error " + e);
}
gbc.fill = GridBagConstraints.NONE;
gbc.weightx = 1;
gbc.weighty = 1;
add(date1, gbc, 0, 0, 1, 1);
add(date2, gbc, 0, 1, 1, 1);
add(building, gbc, 0, 2, 1, 1);
add(shouFeiXiangMu, gbc, 0, 4, 1, 1);
add(yeZhu, gbc, 0, 3, 1, 1);
//add(shouKuanRen,gbc,0,5,1,1);
add(money, gbc, 0, 6, 1, 1);
add(date11, gbc, 1, 0, 1, 1);
add(date22, gbc, 1, 1, 1, 1);
add(building1, gbc, 1, 2, 1, 1);
add(shouFeiXiangMu1, gbc, 1, 4, 1, 1);
add(yeZhu1, gbc, 1, 3, 1, 1);
//add(shouKuanRen1,gbc,1,5,1,1);
add(money1, gbc, 1, 6, 1, 1);
queryButton = new JButton("查询");
queryButton.addActionListener(this);
add(queryButton, gbc, 1, 7, 1, 1);
}
private void add(Component c, GridBagConstraints gbc,
int x, int y, int w, int h) {
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = w;
gbc.gridheight = h;
getContentPane().add(c, gbc);
}
/**
* actionPerformed
*
* @param e ActionEvent
*/
public void actionPerformed(ActionEvent e) {
if (e.getSource() == queryButton) {
String beginDate = date11.getText();
String endDate = date22.getText();
int tempBeginDate = Integer.parseInt(beginDate);
//System.out.println(tempBeginDate);
int tempEndDate = Integer.parseInt(endDate);
//System.out.println(tempEndDate);
int bbc = tempEndDate - tempBeginDate + 1;
//System.out.println(bbc);
int temp[] = new int[bbc];
int tempInt[] = new int[bbc];
String stm[] = new String[bbc];
int sum = 0;
String a = (String) building1.getSelectedItem();
String b = (String) yeZhu1.getSelectedItem();
String c = (String) shouFeiXiangMu1.getSelectedItem();
try {
for (int i = 0; i < bbc; i++) {
temp[i] = tempBeginDate;
//System.out.println(tempBeginDate);
stm[i] = "SELECT " + c + " FROM yueHeJi,yeZhu "
+ "WHERE yueHeJi.月份 = " + temp[i]
+ " AND yueHeJi.业主代码 = yeZhu.业主代码"
+ " AND yeZhu.姓名 = '" + b
+ "' AND yeZhu.楼号 = '" + a
+ "'";
ResultSet rs = stmt.executeQuery(stm[i]);
while (rs.next()) {
String ss = rs.getString(1);
//System.out.println(ss);
tempInt[i] = Integer.parseInt(ss);
//System.out.println(tempInt[i]);
//System.out.println(temp[0]);
//System.out.println(temp[1]);
//System.out.println(temp[i]);
sum = sum + tempInt[i];
//System.out.println(sum);
tempBeginDate++;
}
}
rs.close();
}
catch (Exception ee) {
}
String d = Integer.toString(sum);
money1.setText(d);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -