package Guanliyuan;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;


public class Xiangxi extends JFrame implements ActionListener{

	
	JTextArea area;
	Box box1,baseBox,box2,baseBox2;
	JButton buttonOfBianJi,buttonOfFanHui,buttonOfTi;
	Connection con = null;
	Statement stmt = null;
	ResultSet rs = null;
	String number=null;
	int setEnable =0;
	String information;
/*	
 * 这个详细信息 管理员的界面
 */
	public Xiangxi(String number)
	{
		
		init();
		setVisible(true);
//		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(500, 200, 620, 360);
		setTitle("管理员详细信息界面");
		this.number = number;
		setArea();
		
	}
	public  void setArea()//打开界面就把 数据库中的详细信息写入到area中
	{
		this.connDB();
		try {
			stmt = con.createStatement();
			String sql = "select * from car_information where number='"+number+"'; ";
			rs = stmt.executeQuery(sql);
		} catch (SQLException e2) {
			e2.printStackTrace();
		}
		try {
			if(rs.next())
			{
				information = rs.getString("information");
				area.setText(information);
				area.setEnabled(false);
				
			}
			else
			{
				JOptionPane.showMessageDialog(null,"没有此编号的车辆的详细信息!");
			}
			
		} catch (HeadlessException e2) {
			e2.printStackTrace();
		} catch (SQLException e2) {
			e2.printStackTrace();
		}
	}
	void init()
	{
		JLabel label = new JLabel("车辆的详细信息:");
		area = new JTextArea(10, 10);
		buttonOfBianJi = new JButton("编辑");
		buttonOfBianJi.addActionListener(this);
		buttonOfFanHui = new JButton("返回");
		buttonOfFanHui.addActionListener(this);
		buttonOfTi = new JButton("提交");
		buttonOfTi.addActionListener(this);
		
		box1 = Box.createVerticalBox();
		box1.add(box1.createVerticalStrut(8));
		box1.add(label);
		box1.add(area);
		
		
		box2 = Box.createHorizontalBox();
		box2.add(box2.createHorizontalStrut(8));
		box2.add(buttonOfBianJi);
		box2.add(box2.createHorizontalStrut(8));
		box2.add(buttonOfTi);
		box2.add(box2.createHorizontalStrut(8));
		box2.add(buttonOfFanHui);
		
		
		baseBox = Box.createHorizontalBox();
		baseBox.add(baseBox.createHorizontalStrut(10));
		baseBox.add(box1);
		baseBox.add(baseBox.createHorizontalStrut(10));
		
		baseBox2 = Box.createVerticalBox();
		baseBox2.add(baseBox);
		baseBox2.add(baseBox2.createVerticalStrut(10));
		baseBox2.add(box2);
		baseBox2.add(baseBox2.createVerticalStrut(10));
		
		add(baseBox2);
	}
	
	public void connDB() { // 连接数据库
		try {
			Class.forName("com.mysql.jdbc.Driver");//注册驱动
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {//创建连接
			con = DriverManager.getConnection("jdbc:mysql://localhost:3306/car_rental?characterEncoding=utf-8", "root", "");
			
		} catch (SQLException e) {
			e.printStackTrace();
			
		}
		
	}

	public void closeDB() // 关闭连接
	{
		try {
			stmt.close();
			con.close();
		} 
		catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();
		if(source == buttonOfBianJi)
		{
			area.setEnabled(true);
			setEnable = 1;
			
		}
		else if (source == buttonOfFanHui)
		{
			this.dispose();
			new Guanliyuan(false);
		}
		else if(source == buttonOfTi)
		{
			if(setEnable == 1)
			{
				String areaString = area.getText();
				this.connDB();
				try 
				{
					stmt = con.createStatement();		
					String sqlString ="update car_information set information='"+areaString+"'where number = '"+number+"';";
					stmt.executeUpdate(sqlString);
				} catch (SQLException e1) 
				{
					e1.printStackTrace();
				}
				JOptionPane.showMessageDialog(null, "提交成功!");
				this.closeDB();
				this.dispose();
				new Guanliyuan(true);
			}
			else
			{
				JOptionPane.showMessageDialog(null, "请点击编辑变换成编辑状态!");
			}
			
		}
		
	}

}
最近下载更多
jiayongchao258  LV9 2023年12月28日
求学的熊猫  LV6 2023年12月25日
李朝磊  LV18 2023年12月3日
王东东  LV17 2023年11月30日
sunshine9920  LV12 2023年10月22日
454897461  LV1 2023年6月26日
KAIzx11  LV7 2023年6月24日
fengsk  LV1 2023年6月20日
严凌琳  LV1 2023年6月18日
羊洋杨  LV1 2023年6月15日
最近浏览更多
Miaaaaaa_ 3月17日
暂无贡献等级
jiayongchao258  LV9 2023年12月28日
求学的熊猫  LV6 2023年12月25日
李朝磊  LV18 2023年12月3日
xp95323  LV14 2023年11月27日
hj1172788262  LV5 2023年10月25日
sunshine9920  LV12 2023年10月22日
wersdfs  LV1 2023年9月13日
454897461  LV1 2023年6月26日
KAIzx11  LV7 2023年6月24日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友