package PbuliClass;
|
import java.awt.Color;
|
import java.awt.Container;
|
import java.awt.Dimension;
|
import java.awt.Font;
|
import java.awt.Toolkit;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowListener;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import javax.swing.ButtonGroup;
|
import javax.swing.JButton;
|
import javax.swing.JFrame;
|
import javax.swing.JPanel;
|
import javax.swing.JProgressBar;
|
import javax.swing.JRadioButton;
|
|
import ColorAndFont.UIColor;
|
import ColorAndFont.buttonTitle;
|
import DataBase.DatabaseManagement;
|
import Method.GetNowTime;
|
|
|
/**µ¼³ö±í¸ñ°´Å¥*/
|
public class OutButton {
|
|
static String addtime=null;
|
static String dataName=null;
|
JlableModel choose=new JlableModel("µ¼³öÑ¡Ôñ:"); ;//¿ìËÙÑ¡Ôñ
|
JlableModel start=new JlableModel("¿ªÊ¼Ê±¼ä:"); ;//¿ìËÙÑ¡Ôñ
|
JlableModel stop=new JlableModel("½áÊøÊ±¼ä:"); ;//¿ìËÙÑ¡Ôñ
|
JlableModel jl_jingdu=new JlableModel("Íê³É½ø¶ÈÏÔʾ:"); //¿ìËÙÑ¡Ôñ
|
JRadioButton all=null;
|
JRadioButton day=null;
|
JRadioButton week=null;
|
JButton start_button=null;//Ñ¡Ôñ¿ªÊ¼Ê±¼ä
|
JButton stop_button=null;//Ñ¡Ôñ½áÊøÊ±¼ä
|
JButtonModel sure_button=null;//È·¶¨°´Å¥
|
JButtonModel quxiao_button=null;
|
ButtonGroup group=new ButtonGroup();
|
String startTime;//¹ì¼£²éѯ¿ªÊ¼Ê±¼ä
|
String stopTime;//¹ì¼£²éѯ¼¼Êõʱ¼ä
|
String sql;
|
static JProgressBar progressBar=null;
|
|
JPanel mb=null;//ÉêÃ÷Ò»¸öÃæ°å
|
static int size;//Ñ¡ÖеÄÊý¾ÝÌõÊý
|
boolean ok=false;
|
ChooseDialog choosed=null;
|
|
|
public JButtonModel get_ouotport_button() {
|
JButtonModel outport=null;//µ¼³ö±í¸ñ°´Å¥
|
outport=new JButtonModel(buttonTitle.getOutport());
|
outport.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(choosed==null) {
|
choosed=new ChooseDialog();
|
}
|
}
|
});
|
return outport;
|
}
|
|
|
|
public JButton getStart_button() {
|
if(start_button==null) {
|
start_button=new GetDate();
|
start_button.setBackground(UIColor.getNorth_color());
|
}
|
return start_button;
|
}
|
|
public JButton getStop_button() {
|
if(stop_button==null) {
|
stop_button=new GetDate();
|
stop_button.setBackground(UIColor.getNorth_color());
|
}
|
return stop_button;
|
}
|
|
public JButtonModel getSure_button() {
|
if(sure_button==null) {
|
sure_button=new JButtonModel("µ¼ ³ö");
|
sure_button.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
|
progressBar.setValue(0);
|
progressBar.setBackground(Color.pink);
|
|
if(( !all.isSelected() && !day.isSelected() && !week.isSelected())) {
|
stopTime=stop_button.getText();
|
startTime=start_button.getText();
|
if(stopTime.equals(startTime) && !all.isSelected()) {
|
ShowMessage.zidingyi("¿ªÊ¼Ê±¼ä²»ÄܵÈÓÚ½áÊøÊ±¼ä£¡");
|
return;
|
}
|
|
if(getTimeDifference(stopTime,startTime)<0) {
|
ShowMessage.zidingyi("¿ªÊ¼Ê±¼äÐèÒªÔçÓÚ½áÊøÊ±¼ä£¡");
|
return;
|
|
}
|
sql="SELECT * FROM "+getDataName()+" WHERE "+getAddtime()
|
+" > '"+startTime+"' and "+ getAddtime()+" < '"+stopTime+"'";
|
|
size=DatabaseManagement.serch(sql).size();
|
if(size >65535) {
|
double j=size/65535;
|
int maxPageNumber=(int) Math.ceil(j)+1;
|
ShowMessage.zidingyi("ÒÑÑ¡ÖÐ"+size+"ÌõÊý¾Ý,´óÓÚ65535Ìõ£¬½«×Ô¶¯·ÖΪ"+maxPageNumber+"¸ö±í¸ñµ¼³ö¡£");
|
ok=true;
|
}else if(size>0) {
|
ShowMessage.zidingyi("ÒÑÑ¡ÖÐ"+size+"ÌõÊý¾Ý¡£");
|
ok=true;
|
}else if(size==0) {
|
ShowMessage.zidingyi_24("ÒÑÑ¡ÖÐ"+size+"ÌõÊý¾Ý¡£");
|
ok=false;
|
return;
|
}
|
}
|
|
if((all.isSelected() || day.isSelected() || week.isSelected()) || ok) {
|
new ImExport().export(mb,sql);
|
}
|
|
day.setSelected(false);
|
all.setSelected(false);
|
week.setSelected(false);
|
ok=false;
|
|
|
|
}
|
});
|
}
|
return sure_button;
|
}
|
|
|
|
|
/**Ñ¡Ôñµ¼³öʱ¶Ô»°¿ò*/
|
class ChooseDialog extends JFrame implements WindowListener {
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
|
/**»ñÈ¡¶Ô»°¿ò·½·¨
|
* @return */
|
public ChooseDialog() {
|
group.add(getDay());
|
group.add(getWeek());
|
group.add(getAll());
|
Toolkit toolkit = getToolkit();// »ñµÃ´°Ì幤¾ß°ü
|
Dimension screenSize = toolkit.getScreenSize();// »ñÈ¡ÆÁÄ»´óС
|
int width = (int) (screenSize.width* 0.5);// ¼ÆËã´°Ìåпí¶È
|
int height = (int) (screenSize.height * 0.5);// ¼ÆËã´°Ìåпí¶È
|
int x0=width-240;//´°Ìåx0×ø±ê
|
int y0=height-160;//´°Ìåy0×ø±ê
|
Container rq=getContentPane();
|
rq.add(getMb());
|
this.setTitle("Ñ¡Ôñµ¼³öʱ¼ä¶Ô»°¿ò");
|
this.setBounds(x0, y0,480,320);
|
this.setVisible(true);
|
this.setAlwaysOnTop(true);//2023.07.13 zsh ±£³Ö×ÜÊÇÖö¥
|
this.addWindowListener((WindowListener) this);
|
}
|
|
/**¹Ø±Õ¶Ô»°¿ò·½·¨*/
|
public void closeTagDialog() {
|
choosed.dispose();
|
choosed=null;
|
day.setSelected(false);
|
all.setSelected(false);
|
week.setSelected(false);
|
ok=false;
|
|
}
|
|
/**»ñÈ¡Ãæ°å*/
|
public JPanel getMb() {
|
if(mb==null){
|
mb=new JPanel();
|
mb.setLayout(null);
|
mb.setBackground(UIColor.getNorth_color());
|
|
|
start.setBounds(30, 30,80, 25);
|
getStart_button().setBounds(110, 30,180, 25);
|
|
stop.setBounds(30, 75, 80, 25);
|
getStop_button().setBounds(110, 75, 180, 25);
|
|
choose.setBounds(30, 120,140, 25);
|
getAll().setBounds(100, 120, 80, 25);
|
getDay().setBounds(180, 120,80, 25);
|
getWeek().setBounds(260, 120, 80, 25);
|
jl_jingdu.setBounds(30, 165, 100, 25);
|
getProgressBar().setBounds(130, 165, 160,25);
|
getSure_button().setBounds(130, 220,80, 25);
|
getQuxiao_button().setBounds(230, 220, 80, 25);
|
|
mb.add(getStart_button());
|
mb.add(getStop_button());
|
mb.add(start);
|
mb.add(stop);
|
mb.add(choose);
|
mb.add(all);
|
mb.add(day);
|
mb.add(week);
|
mb.add(jl_jingdu);
|
mb.add(progressBar);
|
mb.add(getSure_button() );
|
mb.add(getQuxiao_button());
|
}
|
|
return mb;
|
}
|
|
public JButtonModel getQuxiao_button() {
|
if(quxiao_button==null) {
|
quxiao_button=new JButtonModel("È¡ Ïû");
|
quxiao_button.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
|
day.setSelected(false);
|
all.setSelected(false);
|
week.setSelected(false);
|
closeTagDialog();
|
}
|
});
|
}
|
return quxiao_button;
|
}
|
|
@Override
|
public void windowOpened(WindowEvent e) {
|
// TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
|
|
}
|
|
@Override
|
public void windowClosing(WindowEvent e) {
|
// TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
|
choosed=null;
|
}
|
|
@Override
|
public void windowClosed(WindowEvent e) {
|
// TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
|
|
}
|
|
@Override
|
public void windowIconified(WindowEvent e) {
|
// TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
|
|
}
|
|
@Override
|
public void windowDeiconified(WindowEvent e) {
|
// TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
|
|
}
|
|
@Override
|
public void windowActivated(WindowEvent e) {
|
// TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
|
|
}
|
|
@Override
|
public void windowDeactivated(WindowEvent e) {
|
// TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
|
|
}
|
}
|
|
|
|
|
public static String getAddtime() {
|
return addtime;
|
}
|
|
|
|
public static String getDataName() {
|
return dataName;
|
}
|
|
|
|
public static void setAddtime(String addtime) {
|
OutButton.addtime = addtime;
|
}
|
|
|
|
public static void setDataName(String dataName) {
|
OutButton.dataName = dataName;
|
}
|
|
|
|
public static JProgressBar getProgressBar() {
|
if(progressBar==null) {
|
progressBar=new JProgressBar();
|
progressBar.setStringPainted(true);
|
progressBar.setIndeterminate(true);
|
progressBar.setFont(new Font("΢ÈíÑźÚ", Font.PLAIN, 16));
|
progressBar.setBackground(Color.pink);
|
}
|
return progressBar;
|
}
|
|
|
|
|
public JRadioButton getAll() {
|
if(all==null) {
|
all=new JRadioButton("È«²¿µ¼³ö");
|
all.setBackground(UIColor.getNorth_color());
|
all.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(all.isSelected()) {
|
sql="SELECT * FROM "+getDataName();
|
size=DatabaseManagement.serch(sql).size();
|
if(size >65535) {
|
double j=size/65535;
|
int maxPageNumber=(int) Math.ceil(j)+1;
|
ShowMessage.zidingyi_24("ÒÑÑ¡ÖÐ"+size+"ÌõÊý¾Ý,´óÓÚ65535Ìõ£¬½«×Ô¶¯·ÖΪ"+maxPageNumber+"¸ö±í¸ñµ¼³ö¡£");
|
ok=true;
|
}else if(size >0) {
|
ShowMessage.zidingyi_24("ÒÑÑ¡ÖÐ"+size+"ÌõÊý¾Ý¡£");
|
ok=true;
|
}else if(size==0) {
|
ShowMessage.zidingyi_24("ÒÑÑ¡ÖÐ"+size+"ÌõÊý¾Ý¡£");
|
ok=false;
|
}
|
|
}
|
|
}
|
});
|
}
|
return all;
|
}
|
|
|
|
public JRadioButton getDay() {
|
if(day==null) {
|
day=new JRadioButton("½ñÌì");
|
day.setBackground(UIColor.getNorth_color());
|
day.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(day.isSelected()) {
|
startTime=GetNowTime.getTimeDay(0);
|
stopTime=GetNowTime.getTimeDay(-1);
|
sql="SELECT * FROM "+getDataName()+" WHERE "+getAddtime()
|
+" > '"+stopTime+"' and "+ getAddtime()+" < '"+startTime+"'";
|
size=DatabaseManagement.serch(sql).size();
|
if(size >65535) {
|
double j=size/65535;
|
int maxPageNumber=(int) Math.ceil(j)+1;
|
ShowMessage.zidingyi_24("ÒÑÑ¡ÖÐ"+size+"ÌõÊý¾Ý,´óÓÚ65535Ìõ£¬½«×Ô¶¯·ÖΪ"+maxPageNumber+"¸ö±í¸ñµ¼³ö¡£");
|
ok=true;
|
}else if(size>0){
|
ShowMessage.zidingyi_24("ÒÑÑ¡ÖÐ"+size+"ÌõÊý¾Ý¡£");
|
ok=true;
|
}else if(size==0) {
|
ShowMessage.zidingyi_24("ÒÑÑ¡ÖÐ"+size+"ÌõÊý¾Ý¡£");
|
ok=false;
|
}
|
}
|
}
|
});
|
}
|
return day;
|
}
|
|
|
|
public JRadioButton getWeek() {
|
if(week==null) {
|
week=new JRadioButton("×î½ü7Ìì");
|
week.setBackground(UIColor.getNorth_color());
|
week.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(week.isSelected()) {
|
startTime=GetNowTime.getTimeDay(0);
|
stopTime=GetNowTime.getTimeDay(-7);
|
sql="SELECT * FROM "+getDataName()+" WHERE "+getAddtime()
|
+" > '"+stopTime+"' and "+ getAddtime()+" < '"+startTime+"'";
|
size=DatabaseManagement.serch(sql).size();
|
if(size >65535) {
|
double j=size/65535;
|
int maxPageNumber=(int) Math.ceil(j)+1;
|
ShowMessage.zidingyi_24("ÒÑÑ¡ÖÐ"+size+"ÌõÊý¾Ý,´óÓÚ65535Ìõ£¬½«×Ô¶¯·ÖΪ"+maxPageNumber+"¸ö±í¸ñµ¼³ö¡£");
|
ok=true;
|
}else if(size>0) {
|
ShowMessage.zidingyi_24("ÒÑÑ¡ÖÐ"+size+"ÌõÊý¾Ý¡£");
|
ok=true;
|
}else if(size==0) {
|
ShowMessage.zidingyi_24("ÒÑÑ¡ÖÐ"+size+"ÌõÊý¾Ý¡£");
|
ok=false;
|
}
|
}
|
|
}
|
});
|
}
|
return week;
|
}
|
|
|
|
public static int getSize() {
|
return size;
|
}
|
|
|
public long getTimeDifference(String strTime1,String strTime2) {
|
//¸ñʽÈÕÆÚ¸ñʽ£¬ÔÚ´ËÎÒÓõÄÊÇ"2018-01-24 19:49:50"ÕâÖÖ¸ñʽ
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
long cha=0;
|
try {
|
Date now = df.parse(strTime1);
|
Date date = df.parse(strTime2);
|
cha=(int) (now.getTime()-date.getTime()); //»ñȡʱ¼ä²î
|
} catch (ParseException e) {
|
e.printStackTrace();
|
}
|
return cha;
|
|
}
|
|
|
|
}
|