package com.sanqing.data;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import com.sanqing.util.DBConnection;
public class HistoryData extends JFrame {
private GridBagConstraints c;
private Insets inset;
private GridBagLayout gridbag;
private String uptown_name[], uptown_id[], building_id[], room_id[],
date[];
private int indate;
private JButton button3, button4;
private JComboBox uptownbox, buildingbox, roombox, datebox;
private JLabel uptownLabel, buildingLabel, roomLabel, dateLabel;
private String inuptownid, inuptownname, inbuilding, inroom;
private String water, gas, sec, ele, lift, light;
private String waters[], gass[], eles[], lifts[], lights[], dates[],
secs[];
private int k, t;
public HistoryData(int tt) { //根据参数执行不同的方法
t = 0;
if (tt == 1) {
uptowndata();
}
if (tt == 2) {
buildingdata();
}
if (tt == 3) {
roomdata();
}
}
public HistoryData(int tt, String uptown, String uptownname) {
System.out.println("init 2");
String id, name;
t = 0;
id = new String(uptown);
name = new String(uptownname);
if (tt == 1) {
uptowndata(id, name);
}
if (tt == 2) {
buildingdata(id, name);
}
if (tt == 3) { //业主费用查询
roomdata(id, name);
}
}
public HistoryData(int tt, String uptown, String uptownname, String building) {
System.out.println("init 3");
String id1, id2, name;
t = 0;
id1 = new String(uptown);
id2 = new String(building);
name = new String(uptownname);
if (tt == 2) {
buildingdata(id1, id2, name);
}
if (tt == 3) {
roomdata(id1, id2, name);
}
}
public HistoryData(int tt, String uptown, String uptownname,
String building, String room) {
System.out.println("init 4");
String id1, id2, id3, name;
id1 = new String(uptown);
id2 = new String(building);
id3 = new String(room);
name = new String(uptownname);
System.out.println("id3 =" + id3);
roomdata(id1, id2, id3, name);
}
public HistoryData(String id, String name) // 查询小区全部记录
{
super("查询小区");
JLabel titleLabel, dateLabel[], waterLabel[], eleLabel[], secLabel[];
JTextField waterField[], eleField[], secField[];
JButton button1, button2;
int y;
Container panelin = getContentPane();
gridbag = new GridBagLayout();
panelin.setLayout(gridbag);
waters = new String[3];
eles = new String[3];
secs = new String[3];
dates = new String[3];
dateLabel = new JLabel[3];
waterLabel = new JLabel[3];
eleLabel = new JLabel[3];
secLabel = new JLabel[3];
waterField = new JTextField[3];
eleField = new JTextField[3];
secField = new JTextField[3];
try {
Connection connection4 = DBConnection.getConnection(); //
Statement stmt4 = connection4.createStatement();
String sqlLastData = "SELECT tot_water_reading, tot_elec_reading, sec_supply_reading, date FROM district_reading WHERE district_id="
+ id;
ResultSet rsLastData = stmt4.executeQuery(sqlLastData);
k = 0;
while (rsLastData.next()) {
waters[k] = rsLastData.getString("tot_water_reading");
eles[k] = rsLastData.getString("tot_elec_reading");
secs[k] = rsLastData.getString("sec_supply_reading");
dates[k] = rsLastData.getString("date");
k++;
}
rsLastData.close();
connection4.close();
}
catch (Exception ex) {
System.out.println(ex);
}
titleLabel = new JLabel(name + "最近三个月的水,电与供水用电读数");
inset = new Insets(5, 5, 5, 5);
c = new GridBagConstraints(2, 1, 3, 1, 0, 0, 10, 0, inset, 0, 0);
gridbag.setConstraints(titleLabel, c);
panelin.add(titleLabel);
System.out.println(dates[0]);
System.out.println(dates[1]);
System.out.println(dates[2]);
System.out.println(k);
y = 4;
for (int j = 0; j < k; j++) {
dateLabel[j] = new JLabel(dates[j]);
c = new GridBagConstraints(2, y, 1, 1, 0, 0, 10, 0, inset, 0, 0);
gridbag.setConstraints(dateLabel[j], c);
panelin.add(dateLabel[j]);
waterLabel[j] = new JLabel("用水");
c = new GridBagConstraints(4, y, 1, 1, 0, 0, 10, 0, inset, 0, 0);
gridbag.setConstraints(waterLabel[j], c);
panelin.add(waterLabel[j]);
waterField[j] = new JTextField(waters[j], 7);
waterField[j].setEditable(false);
c = new GridBagConstraints(6, y, 1, 1, 0, 0, 10, 0, inset, 0, 0);
gridbag.setConstraints(waterField[j], c);
panelin.add(waterField[j]);
eleLabel[j] = new JLabel("用电");
c = new GridBagConstraints(8, y, 1, 1, 0, 0, 10, 0, inset, 0, 0);
gridbag.setConstraints(eleLabel[j], c);
panelin.add(eleLabel[j]);
eleField[j] = new JTextField(eles[j], 7);
eleField[j].setEditable(false);
c = new GridBagConstraints(10, y, 1, 1, 0, 0, 10, 0, inset, 0, 0);
gridbag.setConstraints(eleField[j], c);
panelin.add(eleField[j]);
secLabel[j] = new JLabel("二次供水用电");
c = new GridBagConstraints(12, y, 1, 1, 0, 0, 10, 0, inset, 0, 0);
gridbag.setConstraints(secLabel[j], c);
panelin.add(secLabel[j]);
secField[j] = new JTextField(secs[j], 7);
secField[j].setEditable(false);
c = new GridBagConstraints(14, y, 1, 1, 0, 0, 10, 0, inset, 0, 0);
gridbag.setConstraints(secField[j], c);
panelin.add(secField[j]);
y += 5;
}
y += 4;
button1 = new JButton("继续查询");
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
HistoryData rdif = new HistoryData(1);
HistoryData.this.setVisible(false);
}
});
c = new GridBagConstraints(7, y, 2, 2, 0, 0, 10, 0, inset, 0, 0);
gridbag.setConstraints(button1, c);
panelin.add(button1);
button2 = new JButton("返回");
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
HistoryData.this.setVisible(false);
}
});
c = new GridBagConstraints(10, y, 2, 2, 0, 0, 10, 0, inset, 0, 0);
gridbag.setConstraints(button2, c);
panelin.add(button2);
setSize(800, 300);
setVisible(true);
}
public HistoryData(String id, String name, int date)// 查询特定时期小区记录
{
super("查询小区");
// String water, ele, sec;
System.out.println("init 6");
JLabel titleLabel, dateLabel, waterLabel, eleLabel, secLabel;
JTextField waterField, eleField, secField;
JButton button1, button2;
Container panelin = getContentPane();
gridbag = new GridBagLayout();
panelin.setLayout(gridbag);
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url4 = "jdbc:odbc:estate";
Connection connection4 = DriverManager.getConnection(url4);
Statement stmt4 = connection4.createStatement();
String sqlLastData = "SELECT tot_water_reading, tot_elec_reading, sec_supply_reading FROM district_reading WHERE district_id="
+ id + "AND date=" + date;
ResultSet rsLastData = stmt4.executeQuery(sqlLastData);
while (rsLastData.next()) {
water = rsLastData.getString("tot_water_reading");
ele = rsLastData.getString("tot_elec_reading");
sec = rsLastData.getString("sec_supply_reading");
}
rsLastData.close();
connection4.close();
}
catch (Exception ex) {
System.out.println(ex);
}
titleLabel = new JLabel(name + "在" + date + "的水,电和二次供水用电读数");
inset = new Insets(5, 5, 5, 5);
c = new GridBagConstraints(2, 1, 3, 1, 0, 0, 10, 0, inset, 0, 0);
gridbag.setConstraints(titleLabel, c);
panelin.a