📄 longterminoutdialog.java~9~
字号:
package parkingsystem;
import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.BorderLayout;
import com.borland.dx.sql.dataset.Database;
import com.borland.dx.sql.dataset.ConnectionDescriptor;
import com.borland.dx.dataset.ParameterRow;
import com.borland.dx.dataset.Column;
import com.borland.dx.sql.dataset.QueryDataSet;
import com.borland.dx.sql.dataset.Load;
import com.borland.dx.sql.dataset.QueryDescriptor;
import java.util.*;
import java.text.*;
import com.borland.dx.dataset.MetaDataUpdate;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Timestamp;
/**
* <p>Title: 停车场系统</p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author jok
* @version 1.0
*/
public class LongTermInOutDialog
extends JDialog {
JPanel panel1 = new JPanel();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JLabel jLabel7 = new JLabel();
JLabel jLabel8 = new JLabel();
JLabel jLabel9 = new JLabel();
JLabel jLabel10 = new JLabel();
JButton jButton1 = new JButton();
private int cardID;
private String oper;
String inOrNotType="";
String outOrNotType="";
String carNum;
java.util.Date now;/////////////这个不明白!!!!
Database database1 = new Database();
ParameterRow cardparameter = new ParameterRow();
Column column1 = new Column();
QueryDataSet queryDataSet1 = new QueryDataSet();
QueryDataSet queryDataSet2 = new QueryDataSet();
QueryDataSet queryDataSet3 = new QueryDataSet();
QueryDataSet queryDataSet4 = new QueryDataSet();
Column column2 = new Column();
public LongTermInOutDialog(Frame owner, String title, boolean modal,int cardID,String oper) {
super(owner, title, modal);
this.cardID=cardID;
this.oper=oper;
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
pack();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
// public LongTermInOutDialog() {
// this(new Frame(), "LongTermInOutDialog", false);
// }
private void jbInit() throws Exception {
panel1.setLayout(null);
jLabel3.setText("卡有效期至:");
jLabel3.setBounds(new Rectangle(69, 139, 114, 26));
jLabel4.setText("当 前 时 间:");
jLabel4.setBounds(new Rectangle(69, 193, 114, 26));
jLabel5.setText("操 作 类 型:");
jLabel5.setBounds(new Rectangle(69, 247, 114, 26));
jLabel6.setBounds(new Rectangle(220, 31, 114, 26));
jLabel7.setBounds(new Rectangle(220, 85, 114, 26));
jLabel8.setBounds(new Rectangle(220, 139, 114, 26));
jLabel9.setBounds(new Rectangle(220, 193, 114, 26));
jLabel10.setBounds(new Rectangle(220, 247, 114, 26));
jLabel2.setToolTipText("");
jLabel2.setText("车 牌 号:");
jLabel2.setBounds(new Rectangle(69, 85, 114, 26));
jButton1.setBounds(new Rectangle(139, 308, 111, 32));
jButton1.setText("确 定");
jButton1.addActionListener(new LongTermInOutDialog_jButton1_actionAdapter(this));
database1.setConnection(new ConnectionDescriptor(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=parkingdb",
"sa", "123456", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver"));
column1.setColumnName("CardID");
column1.setDataType(com.borland.dx.dataset.Variant.INT);
column1.setPreferredOrdinal(0);
column1.setServerColumnName("NewColumn1");
column1.setSqlType(0);
queryDataSet1.setQuery(new QueryDescriptor(database1,
"select * from card where CardID=:CardID", cardparameter, true,
Load.ALL));
queryDataSet2.setQuery(new QueryDescriptor(database1,
"select * from event where CardID=:CardID and OutTime is Null",
cardparameter, true, Load.ALL));
queryDataSet3.setQuery(new QueryDescriptor(database1, "select * from event", null, true,
Load.ALL));
queryDataSet4.setMetaDataUpdate(MetaDataUpdate.TABLENAME +
MetaDataUpdate.PRECISION +
MetaDataUpdate.SCALE +
MetaDataUpdate.SEARCHABLE);
queryDataSet4.setQuery(new QueryDescriptor(database1,
"select * from event where CardID=:CardID and OutTime is NULL",
cardparameter, true, Load.ALL));
column2.setColumnName("EventID");
column2.setDataType(com.borland.dx.dataset.Variant.INT);
column2.setRowId(true);
column2.setTableName("event");
column2.setServerColumnName("EVENTID");
column2.setSqlType(4);
panel1.add(jLabel7);
panel1.add(jLabel1);
panel1.add(jLabel2);
panel1.add(jLabel3);
panel1.add(jLabel4);
panel1.add(jLabel5);
panel1.add(jLabel10);
panel1.add(jLabel9);
panel1.add(jLabel8);
panel1.add(jLabel6);
panel1.add(jButton1);
this.getContentPane().add(panel1, null);
jLabel1.setText("卡 号:");
jLabel1.setBounds(new Rectangle(69, 31, 114, 26));
panel1.setBounds(new Rectangle( -1, 0, 384, 358));
this.getContentPane().setLayout(null);
cardparameter.setColumns(new Column[] {column1});
queryDataSet4.setColumns(new Column[] {column2});
jLabel6.setText(cardID+"");
cardparameter.setInt("cardID",cardID);
//
queryDataSet1.open();
carNum=queryDataSet1.getString("carNum");
jLabel7.setText(carNum);
String limitTimeStr=queryDataSet1.getTimestamp("TimeLimit").toString();
StringTokenizer strToken=new StringTokenizer(limitTimeStr," ");
String limitDate=strToken.nextToken();
jLabel8.setText(limitDate);
now=new java.util.Date();
SimpleDateFormat timeFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm");
String timeNow=timeFormat.format(now);
StringTokenizer dateNowStrToken=new StringTokenizer(timeNow,"");
String dateNow=dateNowStrToken.nextToken();
jLabel9.setText(dateNow);
queryDataSet2.open();
if(oper.equals("入场")){
if(queryDataSet2.rowCount()==0){
int comResult=limitDate.compareTo(dateNow);
if(comResult>=0){
inOrNotType="允许进入";
}else {
inOrNotType="拒绝进入";
}
jLabel10.setText(inOrNotType);
}else if(oper.equals("出场")){
if(queryDataSet2.rowCount()!=0){
outOrNotType="允许出车场";
}else {
outOrNotType="拒绝出车场";
}
jLabel10.setText(outOrNotType);
}
queryDataSet2.close();
queryDataSet1.close();
}
}
public void jButton1_actionPerformed(ActionEvent e) {
if (oper.equals("入场")) {
if (inOrNotType.equals("允许进入")) {
queryDataSet3.open();//打开并运行查询
queryDataSet3.insertRow(false);//向查询集中插入一记录行
queryDataSet3.setInt("CardID", cardID);//设置插入记录行的CardID字段值
queryDataSet3.setInt("UserID", LoginFrame.userID);//设置插入记录的UserID值
queryDataSet3.setString("CarNum", carNum);//设置插入记录的CarNum字段值
long lTime = now.getTime();
Timestamp t = new Timestamp(lTime);
queryDataSet3.setTimestamp("InTime", t);//设置插入记录行的InTime字段值
database1.saveChanges(queryDataSet3);//将插入记录写入数据库表
JOptionPane.showMessageDialog(this,"插入记录成功!");
}
queryDataSet3.close();//关闭数据集
}
else if(oper.equals("出场")){
if(outOrNotType.equals("允许出车场")){
cardparameter.setInt("CardID",cardID);//设置查询条件字段值
queryDataSet1.open();//打开并运行查询
long lTime = now.getTime();
Timestamp t = new Timestamp(lTime);
queryDataSet1.setTimestamp("OutTime", t);//修改当前记录的OutTime字段值
database1.saveChanges(queryDataSet4);//保存修改数据
JOptionPane.showMessageDialog(this,"修改记录成功!");
}
queryDataSet1.close();//关闭数据集
}
}
}
class LongTermInOutDialog_jButton1_actionAdapter
implements ActionListener {
private LongTermInOutDialog adaptee;
LongTermInOutDialog_jButton1_actionAdapter(LongTermInOutDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -