package com.view;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import util.DBConnection;
public class Update_delete extends JFrame {
/**
* 实现增加会员
*/
private static final long serialVersionUID = 1L;
// 从JFrame继承
JLabel lbl_id = new JLabel("会员号码:");
JLabel lbl_name = new JLabel("会员名:");
JLabel lbl_password = new JLabel("密码:");
JLabel lbl_sex = new JLabel("性别:");
JLabel lbl_birthday = new JLabel("出生日期:");
JLabel lbl_adr = new JLabel("地址:");
JLabel lbl_pho = new JLabel("电话:");
JLabel lbl_date = new JLabel("加入日期:");
JLabel lbl_grade = new JLabel("等级:");
JTextField txt_id = new JTextField();
JTextField txt_name = new JTextField();
JTextField txt_password = new JTextField();
JTextField txt_sex = new JTextField();
JTextField txt_birthday = new JTextField();
JTextField txt_adr = new JTextField();
JTextField txt_pho = new JTextField();
JTextField txt_date = new JTextField();
JTextField txt_grade = new JTextField();
JButton btn_OK = new JButton("修改");
JButton btn_Cancel = new JButton("删除");
int uuid = 0;
public Update_delete(int uid) {
super("修改或者删除用户信息");
System.out.println(uid);
uuid = uid;
JPanel jp = (JPanel) this.getContentPane();
jp.setLayout(new GridLayout(10, 2));
jp.add(lbl_id);
jp.add(txt_id);
jp.add(lbl_name);
jp.add(txt_name);
jp.add(lbl_password);
jp.add(txt_password);
jp.add(lbl_sex);
jp.add(txt_sex);
jp.add(lbl_birthday);
jp.add(txt_birthday);
jp.add(lbl_adr);
jp.add(txt_adr);
jp.add(lbl_pho);
jp.add(txt_pho);
jp.add(lbl_date);
jp.add(txt_date);
jp.add(lbl_grade);
jp.add(txt_grade);
jp.add(btn_OK);
jp.add(btn_Cancel);
//btn_OK.addActionListener(this);
btn_OK.addActionListener(new ActionEventHandler());
btn_Cancel.addActionListener(new ActionEventHandler());
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = DBConnection.getConnection();
String sql = "select * from member where id=?";
ps = conn.prepareStatement(sql);
System.out.println(sql);
ps.setInt(1, uuid);
rs = ps.executeQuery();
if (!rs.next()) {
JOptionPane.showMessageDialog(this, "没有你要查询的会员!");
return;
} else {
txt_id.setText(rs.getString(1));
txt_name.setText(rs.getString(2));
txt_password.setText(rs.getString(3));
txt_sex.setText(rs.getString(4));
txt_birthday.setText(rs.getString(5));
txt_adr.setText(rs.getString(6));
txt_pho.setText(rs.getString(7));
txt_date.setText(rs.getString(8));
txt_grade.setText(rs.getString(9));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBConnection.close(rs, ps, conn);
}
}
class ActionEventHandler implements ActionListener{
//监听者是一个内部类ActionEventHandler
public void actionPerformed(final ActionEvent e){
/* 监听者可以是包容事件源的容器JFrame,直接实现动作事件接口ActionListener
所需要实现的方法actionPerformed(ActionEvent e)*/
if(e.getSource()==btn_OK){//
eventHandle1();
}
else if(e.getSource()==btn_Cancel){//
eventHandle2();
}
//else System.exit(0);
}
}
public void eventHandle1() {
try {
uuid = Integer.parseInt(txt_id.getText().trim());
} catch (NumberFormatException ne) {
JOptionPane.showMessageDialog(this, "会员号不能为空!");
return;
}
String uname = txt_name.getText().trim();
if (uname.equals("")) {
JOptionPane.showMessageDialog(this, "会员名称不能为空!");
return;
}
String upassword = txt_password.getText().trim();
if (upassword.equals("")) {
JOptionPane.showMessageDialog(this, "密码不能为空!");
return;
}
String usex = txt_sex.getText().trim();
if (!usex.equals("男") && !usex.equals("女")) {
JOptionPane.showMessageDialog(this, "性别只能为男或女!");
return;
}
String ubirthday = txt_birthday.getText().trim();
String uadr = txt_adr.getText().trim();
String upho = txt_pho.getText().trim();
String udate = txt_date.getText().trim();
int ugrade = Integer.parseInt(txt_grade.getText().trim());
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = DBConnection.getConnection();
String sql = "update member set id=?,name=?,password=?,sex=?,birthday=?,address=?,phone=?,joion_date=?,grade=? where id=?";
ps = conn.prepareStatement(sql);
ps.setInt(1, uuid);
ps.setString(2, uname);
ps.setString(3, upassword);
ps.setString(4, usex);
ps.setString(5, ubirthday);
ps.setString(6, uadr);
ps.setString(7, upho);
ps.setString(8, udate);
ps.setInt(9, ugrade);
ps.setInt(10, uuid);
ps.executeUpdate();
System.out.println(sql);
JOptionPane.showMessageDialog(this, "会员修改成功!");
} catch (SQLException e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(this, "会员修改失败,请检查会员号码和会员名称!");
// e.printStackTrace();
} finally {
DBConnection.close(rs, ps, conn);
}
}
public void eventHandle2() {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = DBConnection.getConnection();
String sql = "delete from member where id=?";
ps = conn.prepareStatement(sql);
ps.setInt(1, uuid);
ps.executeUpdate();
System.out.println(sql);
JOptionPane.showMessageDialog(this, "会员删除成功!");
} catch (SQLException e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(this, "会员删除失败,请检查会员号码!");
// e.printStackTrace();
} finally {
DBConnection.close(rs, ps, conn);
}
}
}
md.zip_DVD租赁_碟片租赁_租赁管理系统_租赁管理系统 java
版权申诉
147 浏览量
2022-09-14
18:24:58
上传
评论
收藏 5.69MB ZIP 举报
钱亚锋
- 粉丝: 90
- 资源: 1万+
最新资源
- 网络爬虫软件研究与开发pdf
- Java项目-基于SSM+JSP的母婴用品网站的设计与实现(源码+数据库脚本+部署视频+代码讲解视频+全套软件)
- 基于微信小程序的购物商城app设计带Java后端+源代码+文档说明+数据库.zip
- 基于51单片机外设应用设计.DSN后缀PROTEUS仿真仿真源文件及C语言实例源码例程合集(300个).zip
- “Bunnies and Badgers”兔子和獾和是一个基于pygame库开发的射击游戏
- 华为打印机,华为打印机资料
- Java项目-基于SSM+JSP的医院门诊挂号系统的设计与实现(源码+数据库脚本+部署视频+代码讲解视频+全套软件)
- mac os button功能demo
- 如何在Ubuntu上安装软件?
- 华为HCIA-WLAN 3.0 课程视频(20 熟悉命令行.mp4)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0