package evbuy.liyao;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.sql.ResultSet;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class UserCheck extends JFrame {
private JPanel contentPane;
private JTextField txt_user_id;
private JTable table;
private DefaultTableModel mm;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UserCheck frame = new UserCheck();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public UserCheck() {
setTitle("\u7528\u6237\u4FE1\u606F\u7BA1\u7406");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 472, 376);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblid = new JLabel("\u7528\u6237ID");
lblid.setBounds(43, 36, 41, 22);
contentPane.add(lblid);
txt_user_id = new JTextField();
txt_user_id.setBounds(94, 37, 66, 21);
contentPane.add(txt_user_id);
txt_user_id.setColumns(10);
JLabel label = new JLabel("\u90E8\u95E8");
label.setBounds(204, 40, 39, 15);
contentPane.add(label);
JComboBox cmb_dpm_name = new JComboBox();
cmb_dpm_name.setModel(new DefaultComboBoxModel(new String[] {"", "\u603B\u7ECF\u7406", "\u4FE1\u606F\u90E8", "\u4E1A\u52A1\u5458"}));
cmb_dpm_name.setBounds(242, 37, 75, 21);
contentPane.add(cmb_dpm_name);
JButton btn_user_chk = new JButton("\u67E5\u8BE2");
btn_user_chk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String txtUserId=txt_user_id.getText();
String cmbDpmName=cmb_dpm_name.getSelectedItem().toString();
ConnDB c=new ConnDB();
String sql="select user_id,user_pwd,dpm_name from user,department "
+ "where user.user_dpm=department.dpm_id";
if(!txtUserId.equals(""))
{
sql=sql+" and user.user_id like '%"+txtUserId+"%'";
}
if(!cmbDpmName.equals(""))
{
sql=sql+" and department.dpm_name='"+cmbDpmName+"'";
}
ResultSet rs=c.getResult(sql);
try {
mm.setRowCount(0);
table.setModel(mm);
while(rs.next())
{
String userId=rs.getString("user_id").toString();
String userPwd=rs.getString("user_pwd").toString();
String userDpm=rs.getString("dpm_name").toString();
String[] row= {userId,userPwd,userDpm};
mm.addRow(row);
}
table.setModel(mm);
}catch(Exception e)
{
System.out.println(e.toString());
}
}
});
btn_user_chk.setBounds(349, 36, 66, 23);
contentPane.add(btn_user_chk);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(43, 89, 372, 176);
contentPane.add(scrollPane);
table = new JTable();
String[] col= {"用户ID","用户密码","部门名称"};
mm=new DefaultTableModel(col, 0);
table.setModel(mm);
scrollPane.setViewportView(table);
JButton btn_user_add = new JButton("\u6DFB\u52A0");
btn_user_add.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
UserAdd ua=new UserAdd();
ua.setVisible(true);
}
});
btn_user_add.setBounds(41, 293, 66, 23);
contentPane.add(btn_user_add);
JButton btn_user_upd = new JButton("\u4FEE\u6539");
btn_user_upd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(table.getSelectedRow()==-1)
{
JOptionPane.showMessageDialog(null, "请选中修改数据!");
}else {
String userId=String.valueOf(table.getValueAt(table.getSelectedRow(), 0));
String userPwd=String.valueOf(table.getValueAt(table.getSelectedRow(), 1));
String userDpm=String.valueOf(table.getValueAt(table.getSelectedRow(), 2));
UserUpd uu=new UserUpd(userId, userPwd, userDpm);
uu.setVisible(true);
}
}
});
btn_user_upd.setBounds(145, 293, 66, 23);
contentPane.add(btn_user_upd);
JButton btn_user_del = new JButton("\u5220\u9664");
btn_user_del.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(table.getSelectedRow()==-1)
{
JOptionPane.showMessageDialog(null, "请选中要删除的数据!");
}else
{
int i=JOptionPane.showConfirmDialog(null, "是否确认删除?");
if(i==0)
{
String userId=table.getValueAt(table.getSelectedRow(), 0).toString();
ConnDB c=new ConnDB();
String sql="delete from user where user_id='"+userId+"'";
boolean flag=c.executeSql(sql);
if(flag)
{
JOptionPane.showMessageDialog(null, "删除成功!");
mm.removeRow(table.getSelectedRow());
table.setModel(mm);
}else
{
JOptionPane.showMessageDialog(null, "删除失败!");
}
}
}
}
});
btn_user_del.setBounds(251, 293, 66, 23);
contentPane.add(btn_user_del);
JButton btn_exit = new JButton("\u9000\u51FA");
btn_exit.setBounds(349, 293, 66, 23);
contentPane.add(btn_exit);
ConnDB c=new ConnDB();
String sql="select user_id,user_pwd,dpm_name from user,department "
+ "where user.user_dpm=department.dpm_id";
ResultSet rs=c.getResult(sql);
try {
mm.setRowCount(0);
table.setModel(mm);
while(rs.next())
{
String userId=rs.getString("user_id").toString();
String userPwd=rs.getString("user_pwd").toString();
String userDpm=rs.getString("dpm_name").toString();
String[] row= {userId,userPwd,userDpm};
mm.addRow(row);
}
table.setModel(mm);
}catch(Exception e)
{
System.out.println(e.toString());
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
evbuy.zip
共34个文件
class:23个
java:6个
sql:1个
需积分: 5 0 下载量 56 浏览量
2022-11-28
14:08:26
上传
评论
收藏 701KB ZIP 举报
温馨提示
evbuy.zip
资源推荐
资源详情
资源评论
收起资源包目录
evbuy.zip (34个子文件)
evbuy
bin
evbuy
liyao
ConnDB.class 3KB
UserAdd$3.class 670B
MainFrame.class 2KB
Login$3.class 2KB
UserUpd$1.class 798B
UserCheck$5.class 2KB
UserUpd$3.class 735B
UserCheck$4.class 1KB
UserCheck$2.class 3KB
UserCheck$3.class 768B
UserAdd$1.class 730B
UserCheck.class 5KB
UserCheck$1.class 740B
Login$2.class 815B
UserUpd$2.class 2KB
UserAdd.class 3KB
Login$1.class 720B
UserAdd$2.class 2KB
MainFrame$2.class 775B
Login$4.class 916B
MainFrame$1.class 740B
UserUpd.class 3KB
Login.class 2KB
mysql-connector-java-5.1.7-bin.jar 693KB
.settings
org.eclipse.jdt.core.prefs 598B
src
evbuy
liyao
UserCheck.java 6KB
Login.java 3KB
UserAdd.java 3KB
MainFrame.java 3KB
ConnDB.java 2KB
UserUpd.java 4KB
.project 381B
.classpath 376B
evbuy.sql 959B
共 34 条
- 1
资源评论
2201_75510670
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功