停车场管理系统源码

 

package CarParking;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Timestamp;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;
import javax.swing.*;

public class Add_in extends JFrame {
    public Add_in() {
        JFrame frame = new JFrame("添加入库车辆信息");
        frame.setLayout(null);
        JLabel IDStr = new JLabel("车牌号:");
        IDStr.setBounds(180, 200, 100, 25);
        frame.add(IDStr);
        JTextField carID = new JTextField();
        carID.setBounds(250, 200, 150, 25);
        frame.add(carID);

        JLabel intimeStr = new JLabel("入库时间:");
        intimeStr.setBounds(180, 250, 100, 25);
        frame.add(intimeStr);
        JButton nowTime = new JButton("获取当前时间");
        nowTime.setBounds(250, 250, 150, 25);
        frame.add(nowTime);

        JButton buttonadd = new JButton("添加");
        buttonadd.setBounds(200, 350, 70, 25);
        frame.add(buttonadd);

        JButton buttonreturn = new JButton("返回");
        buttonreturn.setBounds(300, 350, 70, 25);
        frame.add(buttonreturn);

        frame.setBounds(400, 200, 600, 600);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        //返回按钮监听器
        buttonreturn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dispose();
                mainWindow ar = new mainWindow();
            }
        });
        //为添加按钮增加监听器
        buttonadd.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                DB bd = new DB();
                Date date = new Date();
                Timestamp timeStamp = new Timestamp(date.getTime());
                String sql = "insert into car (carid,carin) values (?,?)";
                try {
                    PreparedStatement ps = bd.getConn().prepareStatement(sql);
                    ps.setString(1, carID.getText());
                    ps.setTimestamp(2,timeStamp);
                    ps.executeUpdate();
                    ps.close();
                } catch (SQLException ex) {
                    System.out.println("添加失败!");
                } finally {
                    bd.close();
                }
            }
        });
    }
//    public static void main (String[]args){
//        Add_in f = new Add_in();
//    }
}

package CarParking;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.lang.*;
import java.sql.Timestamp;
import java.util.Date;

import javax.swing.*;

public class Add_out extends JFrame {
    public Add_out() {
        JFrame frame = new JFrame("添加出库车辆信息");
        frame.setLayout(null);
        JLabel IDStr = new JLabel("车牌号:");
        IDStr.setBounds(180, 200, 100, 25);
        frame.add(IDStr);
        JTextField carID = new JTextField();
        carID.setBounds(250, 200, 150, 25);
        frame.add(carID);

        JLabel intimeStr = new JLabel("出库时间:");
        intimeStr.setBounds(180, 250, 100, 25);
        frame.add(intimeStr);
//        JTextField carOut = new JTextField();
//        carID.setBounds(250, 250, 150, 25);
//        frame.add(carOut);
        JButton nowTime = new JButton("获取当前时间");
        nowTime.setBounds(250, 250, 150, 25);
        frame.add(nowTime);

        JLabel jlpayment = new JLabel("费用:");
        jlpayment.setBounds(180, 300, 100, 25);
        frame.add(jlpayment);
        //计算结果显示
        JLabel jpayment= new JLabel();
        frame.add(jpayment);
        jpayment.setBounds(280, 300, 100, 25);

        JButton calulate = new JButton("计算");
        calulate.setBounds(340, 300, 60, 25);
        frame.add(calulate);

        JButton buttonadd = new JButton("添加");
        buttonadd.setBounds(200, 350, 70, 25);
        frame.add(buttonadd);

        JButton buttonreturn = new JButton("返回");
        buttonreturn.setBounds(300, 350, 70, 25);
        frame.add(buttonreturn);

        frame.setBounds(400, 200, 600, 600);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        //返回按钮监听器
        buttonreturn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dispose();
                mainWindow f = new mainWindow();
            }
        });
        //为获取当前时间添加监听器
        nowTime.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                DB bd = new DB();
                Date date = new Date();
                Timestamp timeStamp = new Timestamp(date.getTime());
                String number = carID.getText();
//                String sql = "insert into car (carout) values (?) where carid='"+number+"' and carout =null";
                String sql="update car set carout='"+timeStamp+"' where carid='"+number+"' and carout is null";
                try {
                    PreparedStatement ps = bd.getConn().prepareStatement(sql);
                    System.out.println("获取成功!");
                    ps.executeUpdate();
                    ps.close();
                } catch (SQLException ex) {
                    System.out.println("添加失败!!!");
                } finally {
                    bd.close();
                }
            }
        });
        //为计算按钮添加监听
        calulate.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                DB db = new DB();
                Double payment =0.0;
 
  • 1
    点赞
  • 58
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值