📄 xiaoshou.java
字号:
package zh;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.sql.*;
public class Xiaoshou extends JPanel implements ItemListener,ActionListener{
JPanel tablePane,buttonsPane;
JTable table;
DefaultTableModel defaultModel = null;
JScrollPane scroll;
Choice choice;
JButton button,button1;
String chs="";int s1,y;
Object rows[][];StringBuffer name;
Object labels[]={"商品ID","商品名称","商品价格","商品销售量","销售日期"};
Xiaoshou()
{ setBorder(BorderFactory.createTitledBorder("销售管理"));
choice=new Choice();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection Con = DriverManager.getConnection("jdbc:odbc:zz",
"", "");
Statement Stmt = Con.createStatement();
String name2;
ResultSet rs = Stmt.executeQuery("select distinct 销售日期 from xiaoshou");
// int id = 0;
while (rs.next()) {
name2 = rs.getString(1);
choice.add(name2.toString());
// y++;
}
ResultSet rs1=Stmt.executeQuery("select * from xiaoshou");
while (rs1.next()) {
y++;
}
Con.close();
} catch (java.lang.Exception ee) {}
rows=new Object[y][6];
defaultModel = new DefaultTableModel(rows,labels);
table=new JTable(defaultModel);
scroll=new JScrollPane(table);
button=new JButton("打印");
button1=new JButton("7月");
buttonsPane=new JPanel();
tablePane=new JPanel();
tablePane.setLayout(new BorderLayout());
tablePane.add(scroll,BorderLayout.CENTER);
buttonsPane.setLayout(new GridLayout(3,1));
buttonsPane.add(choice);
buttonsPane.add(button1);
buttonsPane.add(button);
setLayout(new BorderLayout());
add(tablePane,BorderLayout.CENTER);
add(buttonsPane,BorderLayout.EAST);
choice.addItemListener(this);
button1.addActionListener(this);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==button1){
int j=0,x=0;
while(x<y){
table.setValueAt(null, x, 0);
table.setValueAt(null, x, 1);
table.setValueAt(null, x, 2);
table.setValueAt(null, x, 3);
table.setValueAt(null, x, 4);
x++;
}
String name1,name2,name3,name4;int name5;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:zz","","");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from xiaoshou where 销售日期 between 20070701 and 20070731");
while(rs.next()){
name1=rs.getString(1);
name2=rs.getString(2);
name3=rs.getString(3);
name4=rs.getString(4);
name5=rs.getInt(5);
table.setValueAt(name1, j, 0);
table.setValueAt(name2, j, 1);
table.setValueAt(name3, j, 2);
table.setValueAt(name4, j, 3);
table.setValueAt(name5, j, 4);
j++;
}
table.revalidate();
con.close();
}catch(java.lang.Exception ee){}
}
else if(e.getSource()==button){
int j=0;
while(j<5){
table.setValueAt(null, j, 0);
table.setValueAt(null, j, 1);
table.setValueAt(null, j, 2);
table.setValueAt(null, j, 3);
table.setValueAt(null, j, 4);
j++;
}
}
}
public void itemStateChanged(ItemEvent e)
{
if(e.getItemSelectable()==choice)
{
chs=choice.getSelectedItem();
int s1 = Integer.parseInt(chs);
// txt.setText("共有"+choic1.getItemCount ( )+"项,你选择的是第"+
// choic1.getSelectedIndex ( )+"项,你的职称是:“"+
// choic1.getSelectedItem ( )+"”");
int j=0,x=0;
while(x<5){
table.setValueAt(null, x, 0);
table.setValueAt(null, x, 1);
table.setValueAt(null, x, 2);
table.setValueAt(null, x, 3);
table.setValueAt(null, x, 4);
x++;
}
System.out.print("505");
// String syh = "'"+s1.trim()+"'";
String name1,name2,name3,name4;int name5;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:zz","","");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from xiaoshou where 销售日期="+s1);
while(rs.next()){
name1=rs.getString(1);
name2=rs.getString(2);
name3=rs.getString(3);
name4=rs.getString(4);
name5=rs.getInt(5);
table.setValueAt(name1, j, 0);System.out.print("58888");
table.setValueAt(name2, j, 1);
table.setValueAt(name3, j, 2);
table.setValueAt(name4, j, 3);
table.setValueAt(name5, j, 4);
j++;
}
}catch(java.lang.Exception ee){}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -