📄 monthdatainputframe.java
字号:
//panelin.removeAll();
gridbag=new GridBagLayout();
panelin.setLayout(gridbag);
System.out.println(inuptown);
System.out.println(inbuilding);
roomid = new String[150];
/*int i=0;
do{
System.out.println(i);
i++;
}while(!uptownname[i].equals(inuptown));*/
System.out.println("the 03-2");
getroom( id, inbuilding);
System.out.println("the 03-3");
water = new String[roomcount];
ele = new String[roomcount];
gas = new String[roomcount];
in_uptown = new String( id);
in_building = new String( inbuilding );
System.out.println("the 1000");
datelabel = new JLabel("输入日期(格式YYYYMM)");
inset = new Insets(5,5,5,5);
c = new GridBagConstraints(2,1,1,1,0,0,10,0,inset,0,0);
gridbag.setConstraints(datelabel,c);
panelin.add(datelabel);
datefield = new JTextField(10);
c = new GridBagConstraints(4,1,2,1,0,0,10,0,inset,0,0);
gridbag.setConstraints(datefield,c);
panelin.add(datefield);
System.out.println("the 03-4");
int x=4;
for( int f=0;f<roomcount; f++)
{
System.out.println("the room id test"+roomid[f]);
}
waterlabel = new JLabel[roomcount];
elelabel = new JLabel[roomcount];
gaslabel = new JLabel[roomcount];
roomlabel = new JLabel[roomcount];
elefield = new JTextField[roomcount];
waterfield = new JTextField[roomcount];
gasfield = new JTextField[roomcount];
for( int j = 0; j<roomcount; j++)
{
System.out.println("the 03--"+j);
roomlabel[j] = new JLabel( roomid[j] );
//System.out.println("the 03--"+j);
waterfield[j] = new JTextField( 10 );
elefield[j] = new JTextField( 10 );
gasfield[j] = new JTextField( 10 );
waterlabel[j] = new JLabel("水表读数");
elelabel[j] = new JLabel("电表读数");
gaslabel[j] = new JLabel("煤气表读数");
//System.out.println("the 03--"+j);
x=j+4;
c = new GridBagConstraints(2,x,1,1,0,0,10,0,inset,0,0);
gridbag.setConstraints(roomlabel[j],c);
panelin.add(roomlabel[j]);
c = new GridBagConstraints(3,x,1,1,0,0,10,0,inset,0,0);
gridbag.setConstraints(waterlabel[j],c);
panelin.add(waterlabel[j]);
c = new GridBagConstraints(4,x,1,1,0,0,10,0,inset,0,0);
gridbag.setConstraints(waterfield[j],c);
panelin.add(waterfield[j]);
c = new GridBagConstraints(5,x,1,1,0,0,10,0,inset,0,0);
gridbag.setConstraints(elelabel[j],c);
panelin.add(elelabel[j]);
c = new GridBagConstraints(6,x,1,1,0,0,10,0,inset,0,0);
gridbag.setConstraints(elefield[j],c);
panelin.add(elefield[j]);
c = new GridBagConstraints(7,x,1,1,0,0,10,0,inset,0,0);
gridbag.setConstraints(gaslabel[j],c);
panelin.add(gaslabel[j]);
c = new GridBagConstraints(8,x,1,1,0,0,10,0,inset,0,0);
gridbag.setConstraints(gasfield[j],c);
panelin.add(gasfield[j]);
}
x+=9;
System.out.println("the 03-5");
button1 = new JButton( "确定" );
button1.setEnabled( true );
button1.addActionListener(//执行报警,数据库插入,三个月前的数据删除
new ActionListener() {
public void actionPerformed( ActionEvent event)
{
date_in = datefield.getText();
for( int k=0; k<roomcount; k++)
{
water[k] = waterfield[k].getText();
ele[k] = elefield[k].getText();
gas[k] = gasfield[k].getText();
}
for( int i=0; i<roomcount;i++)
{
System.out.println(water[i]);
System.out.println(ele[i]);
System.out.println(gas[i]);
System.out.println(roomid[i]);
}
nullvalue=judgenull(water,ele,gas,date_in);
if(nullvalue==0)
{
MonthDataOperate operate = new MonthDataOperate( in_uptown, in_building, roomid, water, ele, gas, date_in, roomcount);
}
else
{
message2="有空值,请输入完整";
JOptionPane.showMessageDialog(null,message2,"Error",JOptionPane.PLAIN_MESSAGE);
}
}
}
);
c = new GridBagConstraints(6,x,1,2,0,0,10,0,inset,0,0);
gridbag.setConstraints(button1,c);
panelin.add(button1);
System.out.println("the 03-6");
button2 = new JButton( "返回" );
button2.addActionListener(
new ActionListener(){
public void actionPerformed( ActionEvent event){
//mainperform();
MonthDataInputFrame.this.setVisible(false);
}
}
);
c = new GridBagConstraints(7,x,1,2,0,0,10,0,inset,0,0);
gridbag.setConstraints(button2,c);
panelin.add(button2);
System.out.println("the 03-7");
/*button3 = new JButton( "重置" );
button3.setEnabled( true );
button3.setToolTipText( "清空输入的内容,以重新输入" );
button3.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent event )
{
for( int i = 0; i<roomcount; i++)
{
///waterfield[i] = new JTextField();
waterfield[i].setText("");
//elefield[i] = new JTextField();
elefield[i].setText("");
//gasfield[i] = new JTextField();
gasfield[i].setText("");
}
}
}
);
c = new GridBagConstraints(7,x,1,2,0,0,10,0,inset,0,0);
gridbag.setConstraints(button3,c);
panelin.add(button3);*/
panelin.setVisible(true);
System.out.println("the 03-8");
setSize(800,550);
setVisible(true);
}
public void getuptown()//获取小区信息
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url1 = "jdbc:odbc:estate";
Connection connection1 = DriverManager.getConnection(url1);
Statement stmt1 = connection1.createStatement();
String sqlUptown = "SELECT district_id,district_name FROM district_info ORDER BY district_id";
ResultSet rs1 = stmt1.executeQuery(sqlUptown);
System.out.println("the 00");
int i= 1;
while( rs1.next() )
{
uptownid[i] = rs1.getString( "district_id" );
uptownname[i] = rs1.getString( "district_name" );
i++;
}
//System.out.println("the 01");
rs1.close();
connection1.close();
}
catch( Exception ex ) {
System.out.println(ex);
MonthDataInputFrame.this.setVisible(false);
}//完成取小区信息
}
public void getbuilding(String uptown)//获取小区内的楼宇信息
{
System.out.println("the 04");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url2 = "jdbc:odbc:estate";
Connection connection2 = DriverManager.getConnection(url2);
Statement stmt2 = connection2.createStatement();
String sqlBuilding = "SELECT building_id FROM building_info WHERE district_id="+uptown+" ORDER BY building_id";
System.out.println("the 041");
ResultSet rs2 = stmt2.executeQuery(sqlBuilding);
int i = 1;
while( rs2.next() )
{
buildingid[i] = rs2.getString( "building_id" );
i++;
}
//System.out.println("the 11");
//panelin.repaint();
rs2.close();
connection2.close();
}
catch( Exception ex )
{
System.out.println( ex );
//MonthDataInputFrame.this.setVisible(false);
}
}
public void getroom( String uptown,String building)//获取楼宇中房间信息
{
System.out.println("getroom begin");
try{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
String url3 = "jdbc:odbc:estate";
Connection connection3 = DriverManager.getConnection( url3 );
Statement stmt3 = connection3.createStatement();
String sqlRoom = "SELECT room_id FROM room_info WHERE district_id="+uptown+" AND building_id="+building+" ORDER BY room_id";
ResultSet rs3 = stmt3.executeQuery( sqlRoom );
int i=0;
while( rs3.next() )
{
roomid[i] = rs3.getString( "room_id" );
i++;
}
roomcount = i;
rs3.close();
connection3.close();
}
catch( Exception ex )
{
System.out.println( ex );
}
System.out.println("getroom out");
}
public int judgenull(String string1[], String string2[], String string3[], String value)
{
int type=0;
System.out.println("type="+type);
for( int i=0;i<roomcount;i++)
{
if(string1[i].equals(""))
{
type=1;
}
if(string2[i].equals(""))
{
type=1;
}
if(string3[i].equals(""))
{
type=1;
}
}
if(value.equals(""))
{
type=1;
}
System.out.println("value"+value+"end");
System.out.println("type="+type);
return(type);
}
public static void main(String args[])
{
MonthDataInputFrame ap = new MonthDataInputFrame(1);
//ap.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -