www.pudn.com > TestToolsProject.rar > CreateTestReport.java, change:2014-06-11,size:35865b


package com.mervyn.testtools; 
 
import hysun.util.DateChooser; 
 
import java.awt.BorderLayout; 
import java.awt.Toolkit; 
 
import javax.swing.JFileChooser; 
import javax.swing.JOptionPane; 
import javax.swing.JPanel; 
import javax.swing.JFrame; 
import javax.swing.JTable; 
 
import java.awt.Dimension; 
import javax.swing.JLabel; 
import java.awt.Rectangle; 
import java.awt.event.WindowAdapter; 
import java.awt.event.WindowEvent; 
import java.io.File; 
import java.io.IOException; 
import java.io.UnsupportedEncodingException; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.sql.Statement; 
import java.text.SimpleDateFormat; 
import java.util.Date; 
import java.util.Vector; 
 
import javax.swing.JTextField; 
import javax.swing.JButton; 
import javax.swing.event.DocumentEvent; 
import javax.swing.event.DocumentListener; 
import javax.swing.table.AbstractTableModel; 
import javax.swing.table.DefaultTableCellRenderer; 
import javax.swing.JScrollPane; 
 
import jxl.Workbook; 
import jxl.format.Alignment; 
import jxl.format.UnderlineStyle; 
import jxl.write.Border; 
import jxl.write.BorderLineStyle; 
import jxl.write.DateTime; 
import jxl.write.Label; 
import jxl.write.NumberFormat; 
import jxl.write.NumberFormats; 
import jxl.write.WritableCellFormat; 
import jxl.write.WritableFont; 
import jxl.write.WritableSheet; 
import jxl.write.WritableWorkbook; 
import jxl.write.WriteException; 
import jxl.write.biff.RowsExceededException; 
import javax.swing.JCheckBox; 
 
public class CreateTestReport extends JFrame { 
 
	private static final long serialVersionUID = 1L; 
 
	private static boolean checkValue, jLabel6Value, jbuttonValue, 
			FormVisibleValue; 
 
	private JPanel jContentPane = null; 
 
	private JLabel jLabel = null; 
 
	private JTextField jTextField = null; 
 
	private JLabel jLabel1 = null; 
 
	private JTextField jTextField1 = null; 
 
	private JLabel jLabel2 = null; 
 
	private JTextField jTextField2 = null; 
 
	private static final SimpleDateFormat FORMATTER = new SimpleDateFormat( 
			"yyyy-MM-dd"); 
 
	private JButton jButton = null; 
 
	String[] title = { "序列号", "测试点", "工号", "设备类型", "设备型号", "开始测试时间", "结束测试时间", 
			"测试步骤", "测试结果", "结果类型" }; 
 
	Vector<Vector> vector; // @jve:decl-index=0: 
 
	AbstractTableModel tm; 
 
	private JScrollPane jScrollPane1 = null; 
 
	private JButton jButton1 = null; 
 
	private JButton jButton2 = null; 
 
	private JButton jButton3 = null; 
 
	private JButton jButton4 = null; 
 
	private JLabel jLabel3 = null; 
 
	private JCheckBox jCheckBox = null; 
 
	private JCheckBox jCheckBox1 = null; 
 
	private JButton jButton5 = null; 
 
	private JLabel jLabel4 = null; 
 
	private JTextField jTextField3 = null; 
 
	private JTable jTable = null; 
 
	private JButton jButton6 = null; 
	 
	private static String RemoteDatabasePath="",LocalBackUPdatabasePath=""; 
 
	private JCheckBox jCheckBox2 = null; 
	public void SetRemoteDatbasePath() 
	{ 
		TestToolsPing CreateReportObject=new TestToolsPing(); 
		RemoteDatabasePath=CreateReportObject.GetRemoteDatabasePath(); 
		LocalBackUPdatabasePath=CreateReportObject.GetLocalBackUPDatabasePath(); 
	} 
	public String GetRemoteDatbasePath() 
	{ 
		SetRemoteDatbasePath(); 
		return RemoteDatabasePath; 
	} 
 
	void initTable() { 
		JTable table; 
 
		vector = new Vector<Vector>(); 
		tm = new AbstractTableModel() {// 实现表格抽象类的接口 
			public int getColumnCount() { 
				return title.length; 
			} 
 
			public int getRowCount() { 
				return vector.size(); 
			} 
 
			public Object getValueAt(int row, int column) { 
				if (!vector.isEmpty()) { 
					return ((Vector) vector.elementAt(row)).elementAt(column); 
				} else { 
					return null; 
				} 
			} 
 
			public void setValueAt(Object value, int row, int column) { 
			} 
 
			public String getColumnName(int column) { 
				return title[column]; 
			} 
 
			public Class getColumnClass(int n) { 
				return getValueAt(0, n).getClass(); 
			} 
 
			public boolean isCellEditable(int row, int column) { 
				return false; 
			} 
		}; 
		table = new JTable(tm); 
		table.setCellSelectionEnabled(false); 
		// table.setToolTipText("test tool tip"); 
		table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); 
		table.setShowHorizontalLines(true); 
		table.setShowVerticalLines(true); 
		DefaultTableCellRenderer r = new DefaultTableCellRenderer(); 
		r.setHorizontalAlignment(JLabel.CENTER); 
		table.setDefaultRenderer(Object.class, r); 
		table.getColumnModel().getColumn(0).setPreferredWidth(200); 
		// scroll=new JScrollPane(table); 
		jScrollPane1.setViewportView(table); 
		System.out.println("调用构建jTable控件!"); 
		// contentPane.add(scroll,null); 
 
	} 
 
	/** 
	 * This is the default constructor 
	 */ 
	public CreateTestReport() { 
		super(); 
		initialize(); 
		initTable(); 
		SetRemoteDatbasePath(); 
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 
		addWindowListener(new WindowAdapter() { 
			public void windowClosing(WindowEvent e) { 
				System.exit(0); 
			} 
		}); 
	} 
 
	public CreateTestReport(boolean firstvalue, boolean secondvalue, 
			boolean thirdvalue, boolean fourvalue) { 
		super(); 
		initialize(); 
		initTable(); 
		checkValue = firstvalue; 
		jLabel6Value = secondvalue; 
		jbuttonValue = thirdvalue; 
		FormVisibleValue = fourvalue; 
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 
		addWindowListener(new WindowAdapter() { 
			public void windowClosing(WindowEvent e) { 
				System.exit(0); 
			} 
		}); 
	} 
 
	/** 
	 * This method initializes this 
	 *  
	 * @return void 
	 */ 
	private void initialize() { 
		this.setSize(742, 323); 
		this.setContentPane(getJContentPane()); 
		this.setTitle("测试数据导出工具"); 
		int windowWidth = this.getWidth(); // 获得窗口宽 
		int windowHeight = this.getHeight(); // 获得窗口高 
		Toolkit kit = Toolkit.getDefaultToolkit(); // 定义工具包 
		Dimension screenSize = kit.getScreenSize(); // 获取屏幕的尺寸 
		int screenWidth = screenSize.width; // 获取屏幕的宽 
		int screenHeight = screenSize.height; // 获取屏幕的高 
		this.setLocation(screenWidth / 2 - windowWidth / 2, screenHeight / 2 
				- windowHeight / 2);// 设置窗口居中显示 
 
	} 
 
	/** 
	 * This method initializes jContentPane 
	 *  
	 * @return javax.swing.JPanel 
	 */ 
	private JPanel getJContentPane() { 
		if (jContentPane == null) { 
			jLabel4 = new JLabel(); 
			jLabel4.setBounds(new Rectangle(507, 14, 65, 23)); 
			jLabel4.setText("结束时间:"); 
			jLabel3 = new JLabel(); 
			jLabel3.setBounds(new Rectangle(366, 270, 268, 16)); 
			jLabel3.setText(""); 
			jLabel2 = new JLabel(); 
			jLabel2.setBounds(new Rectangle(295, 13, 65, 23)); 
			jLabel2.setText("开始时间:"); 
			jLabel1 = new JLabel(); 
			jLabel1.setBounds(new Rectangle(189, 14, 45, 21)); 
			jLabel1.setText("工号:"); 
			jLabel = new JLabel(); 
			jLabel.setBounds(new Rectangle(14, 14, 57, 20)); 
			jLabel.setText("序列号:"); 
			jContentPane = new JPanel(); 
			jContentPane.setLayout(null); 
			jContentPane.add(jLabel, null); 
			jContentPane.add(getJTextField(), null); 
			jContentPane.add(jLabel1, null); 
			jContentPane.add(getJTextField1(), null); 
			jContentPane.add(jLabel2, null); 
			jContentPane.add(getJTextField2(), null); 
			jContentPane.add(getJButton(), null); 
			jContentPane.add(getJScrollPane1(), null); 
			jContentPane.add(getJButton1(), null); 
			jContentPane.add(getJButton2(), null); 
			jContentPane.add(getJButton3(), null); 
			jContentPane.add(getJButton4(), null); 
			jContentPane.add(jLabel3, null); 
			jContentPane.add(getJCheckBox(), null); 
			jContentPane.add(getJCheckBox1(), null); 
			jContentPane.add(getJButton5(), null); 
			jContentPane.add(jLabel4, null); 
			jContentPane.add(getJTextField3(), null); 
			jContentPane.add(getJButton6(), null); 
			jContentPane.add(getJCheckBox2(), null); 
		} 
		return jContentPane; 
	} 
 
	/** 
	 * This method initializes jTextField 
	 *  
	 * @return javax.swing.JTextField 
	 */ 
	private JTextField getJTextField() { 
		if (jTextField == null) { 
			jTextField = new JTextField(); 
			jTextField.setBounds(new Rectangle(76, 13, 109, 23)); 
			jTextField.getDocument().addDocumentListener( 
					new DocumentListener() { 
						public void insertUpdate(DocumentEvent event) // 插入(包括末尾插入) 
						{ 
							if (jTextField.getText().length() == 12) { 
								boolean EmptyValue = true; 
								String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+LocalBackUPdatabasePath; 
								vector.removeAllElements(); 
								tm.fireTableStructureChanged(); 
								int ResultCount = 0; 
								Connection con; 
								Statement sql; // 声明Statement对象 
								ResultSet rs; 
								try { 
									Class 
											.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
									con = DriverManager.getConnection(url); 
									sql = con.createStatement(); 
									String SelectValue = CreateSelectStr( 
											jTextField.getText().toUpperCase(), jTextField1 
													.getText(), jTextField2 
													.getText(), jTextField3 
													.getText()); 
									rs = sql.executeQuery(SelectValue); 
									while (rs.next()) { 
										Vector<String> result = new Vector<String>(); 
										result.addElement(rs.getString(1)); 
										result.addElement(rs.getString(2)); 
										result.addElement(rs.getString(3)); 
										result.addElement(rs.getString(4)); 
										result.addElement(rs.getString(5)); 
										result.addElement(rs.getString(6)); 
										result.addElement(rs.getString(7)); 
										result.addElement(rs.getString(8)); 
										result.addElement(rs.getString(9)); 
										result.addElement(rs.getString(10)); 
										vector.addElement(result); 
										tm.fireTableStructureChanged(); 
										ResultCount = ResultCount + 1; 
										EmptyValue = true; 
									} 
									if (EmptyValue == false) { 
										JOptionPane.showMessageDialog(null, 
												"查询结果为空!", "错误信息", 
												JOptionPane.ERROR_MESSAGE); 
									} 
									jLabel3.setText("累计查询到的测试记录为:" 
											+ ResultCount + "条!"); 
									rs.close(); 
									con.close(); 
								} catch (ClassNotFoundException e) { 
									System.out.println("" + e); 
								} catch (SQLException el) { 
									JOptionPane 
											.showMessageDialog( 
													null, 
													"数据源错误,具体信息:[Microsoft][ODBC Microsoft Access Driver], \n“(未知)”不是一个有效的路径。请检查服务器(192.168.71.49)是否已经打开!", 
													"连接服务器错误信息", 
													JOptionPane.ERROR_MESSAGE); 
								} 
 
							} 
 
						} 
 
						public void removeUpdate(DocumentEvent event) // 删除 
						{ 
 
						} 
 
						public void changedUpdate(DocumentEvent event) { 
 
						} 
					}); 
		} 
		return jTextField; 
	} 
 
	public String getdate(int value) { 
		String returnvalue = ""; 
		if (value == 1) { 
			final DateChooser dc = new DateChooser(this, true); 
			dc.setLocationRelativeTo(jTextField2); 
			dc.setVisible(true); 
			java.util.Calendar cal = dc.getSelectedDate(); 
			if (cal != null) { 
				returnvalue = FORMATTER.format(cal.getTime()); 
			} 
		} 
		if (value == 2) { 
			final DateChooser dc = new DateChooser(this, true); 
			dc.setLocationRelativeTo(jTextField3); 
			dc.setVisible(true); 
			java.util.Calendar cal = dc.getSelectedDate(); 
			if (cal != null) { 
				returnvalue = FORMATTER.format(cal.getTime()); 
			} 
		} 
		return returnvalue; 
	} 
 
	public WritableSheet CreateExcelSub(String FileValue) throws WriteException { 
		WritableWorkbook book = null; 
		WritableSheet sheet = null; 
		WritableCellFormat cellFormat = new WritableCellFormat(); 
		cellFormat.setAlignment(Alignment.CENTRE); 
		WritableCellFormat integerFormat = new WritableCellFormat( 
				NumberFormats.INTEGER); 
		try { 
			// String url ="jdbc:odbc:driver={Microsoft Access Driver 
			// (*.mdb)};DBQ=//192.168.71.49/AcessDataBase/ponbackup.mdb"; 
			book = Workbook.createWorkbook(new File(FileValue)); 
			sheet = book.createSheet("测试清单", 0); 
			/* 
			 * ResultSet rs = null; Connection con; Statement sql; // 
			 * 声明Statement对象 try { 
			 * Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch 
			 * (ClassNotFoundException e) { System.out.println("" + e); } con = 
			 * DriverManager.getConnection(url); sql = con.createStatement(); rs = 
			 * sql.executeQuery(SelectValue); String SelectValue = 
			 * CreateSelectStr(jTextField.getText(), jTextField1 .getText(), 
			 * jTextField2.getText(),jTextField3.getText()); 
			 */ 
 
			int datacount = 0; 
			int DataCountValue = tm.getRowCount(); 
			Label label = new Label(0, 0, "序列号"); 
			label.setCellFormat(cellFormat); 
			sheet.addCell(label); 
			Label label1 = new Label(1, 0, "日期"); 
			label1.setCellFormat(cellFormat); 
			sheet.addCell(label1); 
			Label label2 = new Label(2, 0, "时间"); 
			label2.setCellFormat(cellFormat); 
			sheet.addCell(label2); 
			sheet.setColumnView(0, 16);// 第一列的宽度 
			sheet.setColumnView(1, 12);// 第二列的宽度 
			sheet.setColumnView(2, 12);// 第三列的宽度 
			for (datacount = 0; datacount < DataCountValue; datacount++) { 
				label = new Label(0, datacount + 1, tm.getValueAt(datacount, 0) 
						.toString()); 
				label.setCellFormat(cellFormat); 
				sheet.addCell(label); 
				String StrTimeValue = tm.getValueAt(datacount, 5).toString(); 
				label1 = new Label(1, datacount + 1, StrTimeValue.substring(0, 
						10)); 
				label1.setCellFormat(cellFormat); 
				sheet.addCell(label1); 
				label2 = new Label(2, datacount + 1, StrTimeValue.substring(11, 
						16)); 
				label2.setCellFormat(cellFormat); 
				sheet.addCell(label2); 
			} 
			/* 
			 * while (rs.next()) { label = new Label(0, datacount, 
			 * rs.getString("BarCode")); label.setCellFormat(cellFormat); 
			 * sheet.addCell(label); String StrTimeValue = 
			 * rs.getString("BeginDate"); label1 = new Label(1, datacount, 
			 * StrTimeValue.substring(0, 10),integerFormat); 
			 * label1.setCellFormat(cellFormat); sheet.addCell(label1); label2 = 
			 * new Label(2, datacount,StrTimeValue.substring(11, 
			 * 16),integerFormat); label2.setCellFormat(cellFormat); 
			 * sheet.addCell(label2); datacount++; 
			 *  } 
			 */ 
			book.write(); 
			book.close(); 
			JOptionPane.showMessageDialog(null, "查询的报表导出成功!!!路径为:" + FileValue, 
					"提示信息", JOptionPane.INFORMATION_MESSAGE); 
		} catch (UnsupportedEncodingException unsupprot) { 
 
		} catch (RowsExceededException e4) { 
			// TODO 自动生成 catch 块 
			e4.printStackTrace(); 
		} catch (WriteException e5) { 
			// TODO 自动生成 catch 块 
			e5.printStackTrace(); 
		} catch (IOException e7) { 
			// TODO 自动生成 catch 块 
			e7.printStackTrace(); 
		} 
 
		return sheet; 
	} 
 
	public WritableSheet CreateExcelSub_All(String FileValue) { 
		WritableWorkbook book = null; 
		WritableSheet sheet = null; 
		try { 
			// String url ="jdbc:odbc:driver={Microsoft Access Driver 
			// (*.mdb)};DBQ=//192.168.71.49/AcessDataBase/ponbackup.mdb"; 
			// ResultSet rs = null; 
			// Connection con; 
			// Statement sql; // 声明Statement对象 
			/* 
			 * try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch 
			 * (ClassNotFoundException e) { System.out.println("" + e); } con = 
			 * DriverManager.getConnection(url); sql = con.createStatement(); 
			 * String SelectValue = CreateSelectStr(jTextField.getText(), 
			 * jTextField1 .getText(), 
			 * jTextField2.getText(),jTextField3.getText()); rs = 
			 * sql.executeQuery(SelectValue); 
			 */ 
			book = Workbook.createWorkbook(new File(FileValue)); 
			sheet = book.createSheet("测试清单", 0); 
 
			WritableCellFormat cellFormat = new WritableCellFormat(); 
			cellFormat.setAlignment(Alignment.CENTRE); 
 
			int DataCount = tm.getRowCount(); 
			int datacount = 0; 
			Label label = new Label(0, 0, "序列号"); 
			label.setCellFormat(cellFormat); 
			sheet.addCell(label); 
			Label label1 = new Label(1, 0, "日期"); 
			label1.setCellFormat(cellFormat); 
			sheet.addCell(label1); 
			Label label2 = new Label(2, 0, "时间"); 
			label2.setCellFormat(cellFormat); 
			sheet.addCell(label2); 
			Label label3 = new Label(3, 0, "测试工号"); 
			label3.setCellFormat(cellFormat); 
			sheet.addCell(label3); 
			Label label4 = new Label(4, 0, "设备型号"); 
			label4.setCellFormat(cellFormat); 
			sheet.addCell(label4); 
			Label label5 = new Label(5, 0, "测试次数"); 
			label5.setCellFormat(cellFormat); 
			sheet.addCell(label5); 
			Label label6 = new Label(6, 0, "测试结果"); 
			label6.setCellFormat(cellFormat); 
			sheet.addCell(label6); 
			sheet.setColumnView(0, 16);// 第一列的宽度 
			sheet.setColumnView(1, 12);// 第二列的宽度 
			sheet.setColumnView(2, 12);// 第三列的宽度 
			sheet.setColumnView(3, 12);// 第四列的宽度 
			sheet.setColumnView(4, 12);// 第五列的宽度 
			sheet.setColumnView(5, 12);// 第六列的宽度 
			sheet.setColumnView(6, 12);// 第七列的宽度 
			for (datacount = 0; datacount < DataCount; datacount++) { 
				label = new Label(0, datacount + 1, tm.getValueAt(datacount, 0) 
						.toString()); 
				label.setCellFormat(cellFormat); 
				sheet.addCell(label); 
				String StrTimeValue = tm.getValueAt(datacount, 5).toString(); 
				label1 = new Label(1, datacount + 1, StrTimeValue.substring(0, 
						10)); 
				label1.setCellFormat(cellFormat); 
				sheet.addCell(label1); 
				label2 = new Label(2, datacount + 1, StrTimeValue.substring(11, 
						16)); 
				label2.setCellFormat(cellFormat); 
				sheet.addCell(label2); 
				label3 = new Label(3, datacount + 1, tm 
						.getValueAt(datacount, 2).toString()); 
				label3.setCellFormat(cellFormat); 
				sheet.addCell(label3); 
				label4 = new Label(4, datacount + 1, tm 
						.getValueAt(datacount, 4).toString()); 
				label4.setCellFormat(cellFormat); 
				sheet.addCell(label4); 
				label5 = new Label(5, datacount + 1, tm 
						.getValueAt(datacount, 7).toString()); 
				label5.setCellFormat(cellFormat); 
				sheet.addCell(label5); 
				label6 = new Label(6, datacount + 1, tm 
						.getValueAt(datacount, 9).toString()); 
				label6.setCellFormat(cellFormat); 
				sheet.addCell(label6); 
			} 
 
			/* 
			 * while (rs.next()) { label = new Label(0, datacount, 
			 * rs.getString("BarCode")); label.setCellFormat(cellFormat); 
			 * sheet.addCell(label); String StrTimeValue = 
			 * rs.getString("BeginDate"); label1 = new Label(1, datacount, 
			 * StrTimeValue.substring(0, 10)); label1.setCellFormat(cellFormat); 
			 * sheet.addCell(label1); label2 = new Label(2, datacount, 
			 * StrTimeValue.substring(11, 16)); 
			 * label2.setCellFormat(cellFormat); sheet.addCell(label2); label3 = 
			 * new Label(3, datacount, rs.getString("UserID")); 
			 * label3.setCellFormat(cellFormat); sheet.addCell(label3); label4 = 
			 * new Label(4, datacount, rs.getString("DevType")); 
			 * label4.setCellFormat(cellFormat); sheet.addCell(label4); label5 = 
			 * new Label(5, datacount, rs.getString("ItemSum")); 
			 * label5.setCellFormat(cellFormat); sheet.addCell(label5); label6 = 
			 * new Label(6, datacount, rs.getString("Error")); 
			 * label6.setCellFormat(cellFormat); sheet.addCell(label6); 
			 * datacount++; 
			 *  } 
			 */ 
			book.write(); 
			book.close(); 
			JOptionPane.showMessageDialog(null, "查询的报表导出成功!!!路径为:" + FileValue, 
					"提示信息", JOptionPane.INFORMATION_MESSAGE); 
		} catch (UnsupportedEncodingException unsupprot) { 
 
		} catch (RowsExceededException e4) { 
			// TODO 自动生成 catch 块 
			e4.printStackTrace(); 
		} catch (WriteException e5) { 
			// TODO 自动生成 catch 块 
			e5.printStackTrace(); 
		} catch (IOException e7) { 
			// TODO 自动生成 catch 块 
			e7.printStackTrace(); 
		} 
 
		return sheet; 
	} 
 
	public String CreateSelectStr(String Code, String ID, String StartTime, 
			String EndTime) { 
		String CreateSelectResultValue = ""; 
		if (!StartTime.equals(EndTime)) { 
			if (Code.equals("") && ID.equals("") && StartTime.equals("") 
					&& EndTime.equals(""))// 0000 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result"; 
			} 
			if (Code.equals("") && ID.equals("") && StartTime.equals("") 
					&& !EndTime.equals(""))// 0001 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where BeginDate<='" 
						+ EndTime + "'"; 
			} 
			if (Code.equals("") && ID.equals("") && !StartTime.equals("") 
					&& EndTime.equals(""))// 0010 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where BeginDate >= '" 
						+ StartTime + "'"; 
			} 
			if (Code.equals("") && !ID.equals("") && StartTime.equals("") 
					&& EndTime.equals(""))// 0100 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where UserID='" 
						+ ID + "'"; 
			} 
			if (!Code.equals("") && ID.equals("") && StartTime.equals("") 
					&& EndTime.equals(""))// 1000 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where BarCode='" 
						+ Code + "'"; 
			} 
			if (Code.equals("") && ID.equals("") && !StartTime.equals("") 
					&& !EndTime.equals(""))// 0011 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where BeginDate >= '" 
						+ StartTime + "' and BeginDate <= '" + EndTime + "'"; 
			} 
			if (Code.equals("") && !ID.equals("") && StartTime.equals("") 
					&& !EndTime.equals(""))// 0101 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where UserID='" 
						+ ID + "' and BeginDate >= '" + EndTime + "'"; 
			} 
			if (Code.equals("") && !ID.equals("") && !StartTime.equals("") 
					&& EndTime.equals(""))// .0110 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where UserID='" 
						+ ID + "' and BeginDate <= '" + StartTime + "'"; 
			} 
			if (!Code.equals("") && ID.equals("") && !StartTime.equals("") 
					&& EndTime.equals(""))// 1010 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where BarCode='" 
						+ Code + "' and BeginDate >= '" + StartTime + "'"; 
			} 
			if (!Code.equals("") && !ID.equals("") && StartTime.equals("") 
					&& EndTime.equals(""))// 1100 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where BarCode='" 
						+ Code + "' and ID= '" + ID + "'"; 
			} 
			if (!Code.equals("") && ID.equals("") && StartTime.equals("") 
					&& !EndTime.equals(""))// 1001 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where BarCode='" 
						+ Code + "' and BeginDate <= '" + EndTime + "'"; 
			} 
			if (Code.equals("") && !ID.equals("") && !StartTime.equals("") 
					&& !EndTime.equals(""))// 0111 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where  UserID= '" 
						+ ID 
						+ "' and BeginDate >='" 
						+ StartTime 
						+ "' and BeginDate<='" + EndTime + "'"; 
			} 
			if (!Code.equals("") && ID.equals("") && !StartTime.equals("") 
					&& !EndTime.equals(""))// 1011 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where BarCode='" 
						+ Code 
						+ "' and BeginDate >= '" 
						+ StartTime 
						+ "' and BeginDate <='" + EndTime + "'"; 
			} 
			if (!Code.equals("") && !ID.equals("") && StartTime.equals("") 
					&& !EndTime.equals(""))// 1101 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where BarCode='" 
						+ Code 
						+ "' and UserID= '" 
						+ ID 
						+ "' and BeginDate <='" 
						+ EndTime + "'"; 
			} 
			if (!Code.equals("") && !ID.equals("") && !StartTime.equals("") 
					&& EndTime.equals(""))// 1110 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where BarCode='" 
						+ Code 
						+ "' and UserID= '" 
						+ ID 
						+ "' and BeginDate >='" 
						+ StartTime + "'"; 
			} 
			if (!Code.equals("") && !ID.equals("") && !StartTime.equals("") 
					&& !EndTime.equals(""))// 1111 
			{ 
				CreateSelectResultValue = "Select * FROM tb_product_result where BarCode='" 
						+ Code 
						+ "' and UserID= '" 
						+ ID 
						+ "' and BeginDate >='" 
						+ StartTime + "' and BeginDate<='" + EndTime + "'"; 
			} 
		} else { 
			CreateSelectResultValue = CreateSelectDayStr(Code, ID, StartTime); 
		} 
 
		return CreateSelectResultValue; 
	} 
 
	public String CreateSelectDayStr(String one, String second, String third) { 
		String StrSelectValue = ""; 
		if (one.equals("") && second.equals("") && third.equals("")) { 
			StrSelectValue = "Select * FROM tb_product_result"; 
		} 
		if (one.equals("") && second.equals("") && !third.equals("")) { 
			StrSelectValue = "Select * FROM tb_product_result where BeginDate like '" 
					+ third + "%'"; 
		} 
		if (one.equals("") && !second.equals("") && third.equals("")) { 
			StrSelectValue = "Select * FROM tb_product_result where UserID='" 
					+ second + "'"; 
		} 
		if (one.equals("") && !second.equals("") && !third.equals("")) { 
			StrSelectValue = "Select * FROM tb_product_result where UserID='" 
					+ second + "' and BeginDate like '" + third + "%'"; 
		} 
		if (!one.equals("") && second.equals("") && third.equals("")) { 
			StrSelectValue = "Select * FROM tb_product_result where BarCode='" 
					+ one + "'"; 
		} 
		if (!one.equals("") && second.equals("") && !third.equals("")) { 
			StrSelectValue = "Select * FROM tb_product_result where BarCode='" 
					+ one + "' and BeginDate like '" + third + "%'"; 
		} 
		if (!one.equals("") && !second.equals("") && third.equals("")) { 
			StrSelectValue = "Select * FROM tb_product_result where BarCode='" 
					+ one + "' and UserID='" + second + "'"; 
		} 
		if (!one.equals("") && !second.equals("") && !third.equals("")) { 
			StrSelectValue = "Select * FROM tb_product_result where BarCode='" 
					+ one + "' and UserID='" + second 
					+ "' and BeginDate like '" + third + "%'"; 
		} 
		return StrSelectValue; 
	} 
 
	/** 
	 * This method initializes jTextField1 
	 *  
	 * @return javax.swing.JTextField 
	 */ 
	private JTextField getJTextField1() { 
		if (jTextField1 == null) { 
			jTextField1 = new JTextField(); 
			jTextField1.setBounds(new Rectangle(238, 13, 54, 23)); 
		} 
		return jTextField1; 
	} 
 
	/** 
	 * This method initializes jTextField2 
	 *  
	 * @return javax.swing.JTextField 
	 */ 
	private JTextField getJTextField2() { 
		if (jTextField2 == null) { 
			jTextField2 = new JTextField(); 
			jTextField2.setBounds(new Rectangle(362, 14, 79, 23)); 
		} 
		return jTextField2; 
	} 
 
	/** 
	 * This method initializes jButton 
	 *  
	 * @return javax.swing.JButton 
	 */ 
	private JButton getJButton() { 
		if (jButton == null) { 
			jButton = new JButton(); 
			jButton.setBounds(new Rectangle(439, 14, 64, 22)); 
			jButton.setText("时间"); 
			jButton.addMouseListener(new java.awt.event.MouseAdapter() { 
				public void mouseClicked(java.awt.event.MouseEvent e) { 
					if (jCheckBox.isSelected() == true) { 
						jTextField2.setText(getdate(1).substring(0, 7) 
								.toString()); 
					} else { 
						jTextField2.setText(getdate(1)); 
					} 
 
				} 
			}); 
		} 
		return jButton; 
	} 
 
	/** 
	 * This method initializes jScrollPane1 
	 *  
	 * @return javax.swing.JScrollPane 
	 */ 
	private JScrollPane getJScrollPane1() { 
		if (jScrollPane1 == null) { 
			jScrollPane1 = new JScrollPane(); 
			jScrollPane1.setBounds(new Rectangle(11, 64, 708, 201)); 
			jScrollPane1.setViewportView(getJTable()); 
		} 
		return jScrollPane1; 
	} 
 
	/** 
	 * This method initializes jButton1 
	 *  
	 * @return javax.swing.JButton 
	 */ 
	private JButton getJButton1() { 
		if (jButton1 == null) { 
			jButton1 = new JButton(); 
			jButton1.setBounds(new Rectangle(425, 41, 73, 19)); 
			jButton1.setText("查询"); 
			jButton1.addMouseListener(new java.awt.event.MouseAdapter() { 
				public void mouseClicked(java.awt.event.MouseEvent e) { 
					vector.removeAllElements(); 
					tm.fireTableStructureChanged(); 
					int ResultCount = 0; 
					Connection con; 
					Statement sql;  
					ResultSet rs; 
					boolean EmptyValue = false; 
					try { 
						Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
						String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+LocalBackUPdatabasePath; 
						con = DriverManager.getConnection(url); 
						sql = con.createStatement(); 
						String CreateSelectStr = CreateSelectStr(jTextField 
								.getText().toUpperCase(), jTextField1.getText(), jTextField2 
								.getText(), jTextField3.getText()); 
						rs = sql.executeQuery(CreateSelectStr); 
						while (rs.next()) { 
							Vector<String> result = new Vector<String>(); 
							result.addElement(rs.getString(1)); 
							result.addElement(rs.getString(2)); 
							result.addElement(rs.getString(3)); 
							result.addElement(rs.getString(4)); 
							result.addElement(rs.getString(5)); 
							result.addElement(rs.getString(6)); 
							result.addElement(rs.getString(7)); 
							result.addElement(rs.getString(8)); 
							result.addElement(rs.getString(9)); 
							result.addElement(rs.getString(10)); 
							vector.addElement(result); 
							tm.fireTableStructureChanged(); 
							 
							ResultCount = ResultCount + 1; 
							EmptyValue = true; 
							 
						} 
						if (EmptyValue == false) { 
							JOptionPane.showMessageDialog(null, "查询结果为空!", 
									"错误信息", JOptionPane.ERROR_MESSAGE); 
						} 
						jLabel3.setText("累计查询到的测试记录为:" + ResultCount + "条!"); 
						rs.close(); 
						con.close(); 
					} catch (ClassNotFoundException e1) { 
						System.out.println("" + e1); 
					} catch (SQLException e2) { 
						e2.printStackTrace(); 
						JOptionPane 
								.showMessageDialog( 
										null, 
										"数据源错误,具体信息:[Microsoft][ODBC Microsoft Access Driver], \n“(未知)”不是一个有效的路径。请检查服务器(192.168.71.49)是否已经打开!", 
										"连接服务器错误信息", JOptionPane.ERROR_MESSAGE); 
					} 
				} 
			}); 
		} 
		return jButton1; 
	} 
 
	/** 
	 * This method initializes jButton2 
	 *  
	 * @return javax.swing.JButton 
	 */ 
	private JButton getJButton2() { 
		if (jButton2 == null) { 
			jButton2 = new JButton(); 
			jButton2.setBounds(new Rectangle(498, 41, 73, 19)); 
			jButton2.setText("重置"); 
			jButton2.addMouseListener(new java.awt.event.MouseAdapter() { 
				public void mouseClicked(java.awt.event.MouseEvent e) { 
					jTextField.setText(""); 
					jTextField1.setText(""); 
					jTextField2.setText(""); 
				} 
			}); 
		} 
		return jButton2; 
	} 
 
	/** 
	 * This method initializes jButton3 
	 *  
	 * @return javax.swing.JButton 
	 */ 
	private JButton getJButton3() { 
		if (jButton3 == null) { 
			jButton3 = new JButton(); 
			jButton3.setBounds(new Rectangle(571, 41, 73, 19)); 
			jButton3.setText("导出"); 
			jButton3.addMouseListener(new java.awt.event.MouseAdapter() { 
				public void mouseClicked(java.awt.event.MouseEvent e) { 
					WritableSheet sheet = null; 
					String selectvalue = ""; 
					File f = null; 
					JFileChooser fileChooser = new JFileChooser(); 
					fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); 
					fileChooser.removeChoosableFileFilter(fileChooser 
							.getAcceptAllFileFilter()); // 移去所有文件过滤器 
					fileChooser 
							.addChoosableFileFilter(new com.mervyn.testsource.MyFileFilter( 
									"xls", "Excel文件")); 
					int returnValue = fileChooser.showSaveDialog(null); 
					if (returnValue == JFileChooser.APPROVE_OPTION) { 
						f = fileChooser.getSelectedFile(); 
						selectvalue = f.getPath() + ".xls"; 
					} 
					try { 
						if (jCheckBox1.isSelected()) { 
							sheet = CreateExcelSub_All(selectvalue); 
						} else { 
							sheet = CreateExcelSub(selectvalue); 
						} 
					} catch (WriteException WRITE) { 
 
					} 
 
				} 
 
			}); 
		} 
		return jButton3; 
	} 
 
	/** 
	 * This method initializes jButton4 
	 *  
	 * @return javax.swing.JButton 
	 */ 
	private JButton getJButton4() { 
		if (jButton4 == null) { 
			jButton4 = new JButton(); 
			jButton4.setBounds(new Rectangle(644, 41, 73, 19)); 
			jButton4.setText("返回"); 
			jButton4.addMouseListener(new java.awt.event.MouseAdapter() { 
				public void mouseClicked(java.awt.event.MouseEvent e) { 
					TestToolsPing TestForm = new TestToolsPing(); 
					TestForm.setVisible(true); 
					setVisible(false); 
				} 
			}); 
		} 
		return jButton4; 
	} 
 
	/** 
	 * This method initializes jCheckBox 
	 *  
	 * @return javax.swing.JCheckBox 
	 */ 
	private JCheckBox getJCheckBox() { 
		if (jCheckBox == null) { 
			jCheckBox = new JCheckBox(); 
			jCheckBox.setBounds(new Rectangle(15, 42, 77, 18)); 
			jCheckBox.setText("按月查询"); 
			jCheckBox.addActionListener(new java.awt.event.ActionListener() { 
				public void actionPerformed(java.awt.event.ActionEvent e) { 
					if (jCheckBox.isSelected() == true 
							&& !jTextField2.getText().equals("")) { 
						jTextField2.setText(jTextField2.getText().subSequence( 
								0, 7).toString()); 
 
					} 
					if (jCheckBox.isSelected() == false) { 
						jTextField2.setText(""); 
					} 
				} 
			}); 
		} 
		return jCheckBox; 
	} 
 
	/** 
	 * This method initializes jCheckBox1 
	 *  
	 * @return javax.swing.JCheckBox 
	 */ 
	private JCheckBox getJCheckBox1() { 
		if (jCheckBox1 == null) { 
			jCheckBox1 = new JCheckBox(); 
			jCheckBox1.setBounds(new Rectangle(101, 42, 103, 18)); 
			jCheckBox1.setText("导出全部数据"); 
		} 
		return jCheckBox1; 
	} 
 
	/** 
	 * This method initializes jButton5 
	 *  
	 * @return javax.swing.JButton 
	 */ 
	private JButton getJButton5() { 
		if (jButton5 == null) { 
			jButton5 = new JButton(); 
			jButton5.setBounds(new Rectangle(340, 42, 67, 14)); 
			jButton5.setText("t"); 
			jButton5.setVisible(false); 
			jButton5.addActionListener(new java.awt.event.ActionListener() { 
				public void actionPerformed(java.awt.event.ActionEvent e) { 
					/*TestToolsPing TestForm = new TestToolsPing(checkValue, 
							jLabel6Value, jbuttonValue, FormVisibleValue); 
					TestForm.setVisible(true); 
					setVisible(false);*/ 
					 
					System.out.println("ddd"+GetRemoteDatbasePath()); 
				} 
			}); 
		} 
		return jButton5; 
	} 
 
	/** 
	 * This method initializes jTextField3 
	 *  
	 * @return javax.swing.JTextField 
	 */ 
	private JTextField getJTextField3() { 
		if (jTextField3 == null) { 
			jTextField3 = new JTextField(); 
			jTextField3.setBounds(new Rectangle(576, 15, 79, 23)); 
		} 
		return jTextField3; 
	} 
 
	/** 
	 * This method initializes jTable 
	 *  
	 * @return javax.swing.JTable 
	 */ 
	private JTable getJTable() { 
		if (jTable == null) { 
			jTable = new JTable(); 
			 
		} 
		return jTable; 
	} 
 
	/** 
	 * This method initializes jButton6 
	 *  
	 * @return javax.swing.JButton 
	 */ 
	private JButton getJButton6() { 
		if (jButton6 == null) { 
			jButton6 = new JButton(); 
			jButton6.setBounds(new Rectangle(655, 15, 61, 22)); 
			jButton6.setText("时间"); 
			jButton6.addActionListener(new java.awt.event.ActionListener() { 
				public void actionPerformed(java.awt.event.ActionEvent e) { 
					jTextField3.setText(getdate(2)); 
				} 
			}); 
		} 
		return jButton6; 
	} 
	/** 
	 * This method initializes jCheckBox2	 
	 * 	 
	 * @return javax.swing.JCheckBox	 
	 */ 
	private JCheckBox getJCheckBox2() { 
		if (jCheckBox2 == null) { 
			jCheckBox2 = new JCheckBox(); 
			jCheckBox2.setBounds(new Rectangle(211, 42, 112, 18)); 
			jCheckBox2.setText("查询当天数据"); 
			jCheckBox2.addActionListener(new java.awt.event.ActionListener() { 
				public void actionPerformed(java.awt.event.ActionEvent e) { 
					if(jCheckBox2.isSelected()) 
					{ 
						SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 
						jTextField2.setText(df.format(new Date())); 
						jTextField3.setText(df.format(new Date())); 
					} 
					else 
					{ 
						jTextField2.setText(""); 
						jTextField3.setText(""); 
					} 
				} 
			}); 
		} 
		return jCheckBox2; 
	} 
 
} // @jve:decl-index=0:visual-constraint="10,10"