代码拉取完成,页面将自动刷新
同步操作将从 Larkkkkkkk1/仓储管理系统 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*Adminupdate 修改密码*/
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import net.wms.bean.User;
import net.wms.dao.LoginUseImp;
public class Adminupdate extends IndexAdmin{
JLabel uname;
JTextField pwd;
JTextField pass;
User user = new User();
public Adminupdate(String name) {
super(name);
init(name);
}
public void init(String name) {
user.setusername(name);
Font d = new Font("楷体", Font.BOLD, 24);
Font f = new Font("楷体", Font.BOLD, 18);
JLabel usertitle = new JLabel("修改密码");
JLabel username = new JLabel("用 户 名:");
uname = new JLabel();
JLabel userpwd = new JLabel("新 密 码:");
pwd = new JTextField();
JLabel userpass = new JLabel("再输次密码:");
pass = new JTextField();
JButton submit = new JButton("修改");
JButton reset = new JButton("重置");
usertitle.setBounds(250, 60, 100, 40);
usertitle.setFont(d);
username.setBounds(150, 140, 140, 30);
username.setFont(f);
uname.setBounds(270, 140, 150, 30);
uname.setFont(f);
uname.setText(name);
userpwd.setBounds(150, 200, 140, 30);
userpwd.setFont(f);
pwd.setBounds(270, 200, 150, 30);
pwd.setFont(f);
userpass.setBounds(150, 260, 140, 30);
userpass.setFont(f);
pass.setBounds(270, 260, 150, 30);
pass.setFont(f);
submit.setBounds(200, 320, 80, 30);
submit.setFont(f);
reset.setBounds(310, 320, 80, 30);
reset.setFont(f);
index.add(usertitle);
index.add(username);
index.add(uname);
index.add(userpwd);
index.add(pwd);
index.add(pass);
index.add(userpass);
index.add(submit);
index.add(reset);
reset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
pwd.setText("");
pass.setText("");
}
});
submit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
LoginUseImp l = new LoginUseImp();
try {
l.Delete(user, "update users set userpwd='"+pass.getText()+"' where username='"+user.getusername()+"'");
JOptionPane.showMessageDialog(null, "修改成功");
} catch (SQLException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
}
});
}
}
/*添加商品*/
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import net.wms.bean.Goods;
import net.wms.dao.GoodsmanagementImp;
import net.wms.dao.StoragemanagementImp;
public class Goodsadd extends IndexAdmin{
JTextField name;
JTextField style;
JTextField number;
JComboBox id;
Goods goods = new Goods();
public Goodsadd(String name) {
super(name);
init();
}
public void init() {
Font d = new Font("楷体", Font.BOLD, 24);
Font f = new Font("楷体", Font.BOLD, 18);
JLabel goodstitle = new JLabel("添加商品");
JLabel goodsname = new JLabel("商品名:");
name = new JTextField();
JLabel goodsstyle = new JLabel("类 型:");
style = new JTextField();
JLabel goodsnumber = new JLabel("数 量:");
number = new JTextField();
JLabel storageid = new JLabel("仓库号:");
StoragemanagementImp s = new StoragemanagementImp();
try {
s.Query1("select storageID from storage");
id = new JComboBox(StoragemanagementImp.vr);
} catch (SQLException e2) {
// TODO 自动生成的 catch 块
e2.printStackTrace();
}
JButton submit = new JButton("提交");
JButton reset = new JButton("重置");
goodstitle.setBounds(250, 40, 100, 40);
goodstitle.setFont(d);
goodsname.setBounds(160, 120, 80, 30);
goodsname.setFont(f);
name.setBounds(240, 120, 150, 30);
name.setFont(f);
goodsstyle.setBounds(160, 180, 80, 30);
goodsstyle.setFont(f);
style.setBounds(240, 180, 150, 30);
style.setFont(f);
goodsnumber.setBounds(160, 240, 80, 30);
goodsnumber.setFont(f);
number.setBounds(240, 240, 150, 30);
number.setFont(f);
storageid.setBounds(160, 300, 80, 30);
storageid.setFont(f);
id.setBounds(240, 300, 150, 30);
id.setFont(f);
submit.setBounds(190, 360, 80, 30);
submit.setFont(f);
reset.setBounds(300, 360, 80, 30);
reset.setFont(f);
index.add(goodstitle);
index.add(goodsname);
index.add(name);
index.add(goodsstyle);
index.add(style);
index.add(goodsnumber);
index.add(number);
index.add(storageid);
index.add(id);
index.add(submit);
index.add(reset);
reset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
name.setText("");
style.setText("");
number.setText("");
}
});
submit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
if(name.getText().equals("") || style.getText().equals("") || number.getText().equals("")) {
JOptionPane.showMessageDialog(null,"请输入内容");
} else {
goods.setGoodsname(name.getText());
goods.setGoodsstyle(style.getText());
goods.setGoodsnumber(Integer.parseInt(number.getText()));
goods.setStorageID(id.getSelectedItem().toString());
GoodsmanagementImp g = new GoodsmanagementImp();
try {
g.Add(goods, "insert into goods(goodsname,goodsstyle,goodsnumber,storageID)" + "values(?,?,?,?)");
name.setText("");
style.setText("");
number.setText("");
JOptionPane.showMessageDialog(null, "添加成功");
} catch (SQLException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
}
}
});
}
}
/*删除商品*/
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import net.wms.dao.GoodsmanagementImp;
public class Goodsdelete extends IndexAdmin{
int id ;
//声明表格
private JTable table;
public Goodsdelete(String name) {
super(name);
init();
}
public void init() {
Font t = new Font("楷体",Font.BOLD, 24);
final Font f = new Font("楷体",Font.BOLD, 15);
JLabel title = new JLabel("商品信息");
title.setFont(t);
title.setBounds(230, 40, 100, 40);
final Vector c = new Vector();
//添加数据
c.add("编号");
c.add("商品名称");
c.add("商品类型");
c.add("商品数量");
c.add("仓库编号");
final GoodsmanagementImp g = new GoodsmanagementImp();
try {
g.Query("select * from goods");
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//创建表格
table = new JTable(g.vec,c);
table.setFont(f);
table.getTableHeader().setFont(f);
//为表格添加鼠标单击事件
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// 获取表格中的ID
id = (int) table.getValueAt(
table.getSelectedRow(), 0);
System.out.println(id);
super.mouseClicked(e);
}
});
//创建Jscrollpane
final JScrollPane js = new JScrollPane(table);
js.setBounds(100, 120, 400, 200);
//创建删除按钮
final JButton delete = new JButton("删除");
//为按钮创建监听事件
delete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//判断Id是否在列表内
if(id == 0){
JOptionPane.showMessageDialog(null, "删除失败请选择需要删除的记录!");
}else{
try {
//给出提示
//4个参数:1.null 2.提示内容 3.标题 4.按钮类型
int mess = JOptionPane.showConfirmDialog(
null,"确定删除记录?","友情提示:",
JOptionPane.YES_NO_OPTION );
//点击确定按钮之后的事件
//0 == 确定 ,1 == 取消
if(mess == 0){
//调用删除方法
g.Delete("delete from goods where id ="+id);
//提示删除成功
JOptionPane.showMessageDialog(null, "删除成功");
g.Query("select * from goods");
//创建表格
JTable new_table = new JTable(g.vec,c);
new_table.setFont(f);
new_table.getTableHeader().setFont(f);
//创建Jscrollpane
JScrollPane p = new JScrollPane(new_table);
//设置新组建的大小
p.setBounds(100, 120, 400, 200);
//移除旧组件
index.remove(js);
//添加新组件
index.add(p);
//重绘组键
index.repaint();
}
} catch (Exception e2) {
// TODO: handle exception
}
}
}
});
//设置位置及大小
delete.setBounds(250, 350, 80,30);
index.add(title);
index.add(js);
//添加按钮
index.add(delete);
}
}
/*查找商品*/
import java.awt.Font;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import net.wms.dao.GoodsmanagementImp;
public class GoodsSelect extends Index{
private JTable table;
int id ;
public GoodsSelect(String name) {
super(name);
init();
}
public void init() {
Font t = new Font("楷体",Font.BOLD, 24);
final Font f = new Font("楷体",Font.BOLD, 15);
JLabel title = new JLabel("商品信息");
title.setFont(t);
title.setBounds(230, 40, 100, 40);
final Vector c = new Vector();
//添加数据
c.add("编号");
c.add("商品名称");
c.add("商品类型");
c.add("商品数量");
c.add("仓库编号");
final GoodsmanagementImp g = new GoodsmanagementImp();
//创建表格
table = new JTable(g.vec,c);
table.setFont(f);
table.getTableHeader().setFont(f);
//创建Jscrollpane
final JScrollPane js = new JScrollPane(table);
js.setBounds(100, 120, 400, 200);
try {
g.Query("select * from goods");
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
index.add(title);
index.add(js);
}
}
/*商品修改*/
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import net.wms.bean.Goods;
import net.wms.dao.GoodsmanagementImp;
import net.wms.dao.StoragemanagementImp;
public class GoodsUpdate extends IndexAdmin{
int id ;
//声明表格
private JTable table;
JTextField name;
JTextField style;
JTextField number;
JComboBox s_id;
public GoodsUpdate(String name) {
super(name);
init();
}
public void init() {
Font t = new Font("楷体",Font.BOLD, 24);
final Font f = new Font("楷体",Font.BOLD, 15);
JLabel title = new JLabel("商品信息");
JLabel goodsname = new JLabel("商品名称:");
goodsname.setBounds(160, 180, 80, 30);
name = new JTextField();
name.setBounds(240, 180, 150, 30);
JLabel goodsstyle = new JLabel("商品类型:");
goodsstyle.setBounds(160, 230, 80, 30);
style = new JTextField();
style.setBounds(240, 230, 150, 30);
JLabel goodsnumber = new JLabel("商品数量:");
goodsnumber.setBounds(160, 280, 80, 30);
number = new JTextField();
number.setBounds(240, 280, 150, 30);
JLabel storageid = new JLabel("仓库编号:");
storageid.setBounds(160, 330, 80, 30);
StoragemanagementImp s = new StoragemanagementImp();
try {
s.Query1("select storageID from storage");
s_id = new JComboBox(StoragemanagementImp.vr);
} catch (SQLException e3) {
e3.printStackTrace();
}
s_id.setBounds(240, 330, 150, 30);
title.setFont(t);
title.setBounds(230, 10, 100, 30);
final Vector c = new Vector();
//添加数据
c.add("编号");
c.add("商品名称");
c.add("商品类型");
c.add("商品数量");
c.add("仓库编号");
final GoodsmanagementImp g = new GoodsmanagementImp();
try {
g.Query("select * from goods");
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//创建表格
table = new JTable(g.vec,c);
table.setFont(f);
table.getTableHeader().setFont(f);
//为表格添加鼠标单击事件
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// 获取表格中的ID
//获取每条记录所对应的id
id = (int)table.getValueAt(table.getSelectedRow(), 0);
//获取部门名称
String gname = (String)table.getValueAt(table.getSelectedRow(), 1);
//获取部门编号
String gstyle = (String)table.getValueAt(table.getSelectedRow(), 2);
//获取部门描述
String gnumber=table.getValueAt(table.getSelectedRow(), 3).toString();
String sid=table.getValueAt(table.getSelectedRow(), 4).toString();
//将数据设置进文本框
name.setText(gname);
style.setText(gstyle);
number.setText(gnumber);
for(int i=0;i<s_id.getItemCount();i++){
Integer g = (Integer)s_id.getItemAt(i);
if(g == Integer.valueOf(sid)){
s_id.setSelectedIndex(i);
}
}
super.mouseClicked(e);
}
});
//创建Jscrollpane
final JScrollPane js = new JScrollPane(table);
js.setBounds(100, 60, 400, 100);
//创建删除按钮
final JButton update = new JButton("修改");
//为按钮创建监听事件
update.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//判断Id是否在列表内
if(id == 0){
JOptionPane.showMessageDialog(null, "修改失败请选择需要修改的记录!");
}else{
try {
//给出提示
//4个参数:1.null 2.提示内容 3.标题 4.按钮类型
int mess = JOptionPane.showConfirmDialog(
null,"确定修改记录?","友情提示:",
JOptionPane.YES_NO_OPTION );
//点击确定按钮之后的事件
//0 == 确定 ,1 == 取消
if(mess == 0){
//调用删除方法
Goods goods = new Goods();
goods.setGoodsname(name.getText());
goods.setGoodsstyle(style.getText());
goods.setGoodsnumber(Integer.parseInt(number.getText()));
goods.setStorageID(s_id.getSelectedItem().toString());
g.Update(goods,"update goods set goodsname = ?,goodsstyle=?,goodsnumber=?,storageID=? where id = "+ id);
//提示删除成功
JOptionPane.showMessageDialog(null, "修改成功");
name.setText("");
style.setText("");
number.setText("");
g.Query("select * from goods");
//原理:移除原组件,添加新组件
//创建表格
JTable new_table = new JTable(g.vec,c);
new_table.setFont(f);
new_table.getTableHeader().setFont(f);
//创建Jscrollpane
JScrollPane p = new JScrollPane(new_table);
//设置新组建的大小
p.setBounds(100, 60, 400, 100);
//移除旧组件
index.remove(js);
//添加新组件
index.add(p);
//重绘组键
index.repaint();
}
} catch (Exception e2) {
// TODO: handle exception
}
}
}
});
//设置位置及大小
update.setBounds(250, 380, 80,30);
index.add(title);
index.add(goodsname);
index.add(name);
index.add(goodsstyle);
index.add(style);
index.add(goodsnumber);
index.add(number);
index.add(storageid);
index.add(s_id);
index.add(js);
index.add(update);
}
}
/*普通用户界面*/
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class Index {
//声明对象
public JFrame index;
private JMenuBar management;
private JMenu user;
private JMenu goods;
private JMenu storage;
private JMenuItem exit;
private JMenuItem usernews;
private JMenuItem userupdate;
private JMenuItem goodsselect;
private JMenuItem storageselect;
//创建构造函数
public Index(String name) {
indexadmin();
//添加对象
user.add(usernews);
user.add(userupdate);
user.add(exit);
goods.add(goodsselect);
storage.add(storageselect);
management.add(user);
management.add(goods);
management.add(storage);
init(name);
action(name);
}
private void init(String name) {
//初始化矿建index
index = new JFrame("欢迎用户"+name+"使用本系统");
//设置框架大小和位置
index.setBounds(500, 100, 600, 500);
index.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//将菜单栏设置进框架
index.setJMenuBar(management);
index.setLayout(null);
index.setVisible(true);
}
public void indexadmin() {
//初始化对象
Font f = new Font("楷体", Font.BOLD, 15);
management = new JMenuBar();
user = new JMenu(" 用户管理");
user.setFont(f);
goods = new JMenu(" 商品管理");
goods.setFont(f);
storage = new JMenu(" 仓库管理");
storage.setFont(f);
exit = new JMenuItem("更换用户");
exit.setFont(f);
usernews = new JMenuItem("个人信息");
usernews.setFont(f);
userupdate = new JMenuItem("密码修改");
userupdate.setFont(f);
goodsselect = new JMenuItem("商品浏览");
goodsselect.setFont(f);
storageselect = new JMenuItem("仓库浏览");
storageselect.setFont(f);
}
//为所有的菜单条目设置监听事件
private void action(final String name) {
exit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { /切换用户
//界面转换
index.setVisible(false);
Login.main(null);
}
});
usernews.addActionListener(new ActionListener() { //个人信息显示
@Override
public void actionPerformed(ActionEvent e) {
//界面转换
index.setVisible(false);
new Usernews(name);
}
});
userupdate.addActionListener(new ActionListener() { //修改密码
@Override
public void actionPerformed(ActionEvent e) {
//界面转换
index.setVisible(false);
new Userupdate(name);
}
});
goodsselect.addActionListener(new ActionListener() { //商品浏览
@Override
public void actionPerformed(ActionEvent e) {
//界面转换
index.setVisible(false);
new GoodsSelect(name);
}
});
storageselect.addActionListener(new ActionListener() { //仓库浏览
@Override
public void actionPerformed(ActionEvent e) {
//界面转换
index.setVisible(false);
new Storageselect(name);
}
});
}
}
/*管理员界面*/
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class IndexAdmin {
//声明对象
public JFrame index;
private JMenuBar management;
private JMenu user;
private JMenu goods;
private JMenu storage;
private JMenuItem exit;
private JMenuItem useradd;
private JMenuItem userdelete;
private JMenuItem userupdate;
private JMenuItem userselect;
private JMenuItem goodsadd;
private JMenuItem goodsdelete;
private JMenuItem goodsupdate;
private JMenuItem storageadd;
private JMenuItem storagedelete;
private JMenuItem storageupdate;
Font f = new Font("楷体", Font.BOLD, 15);
//构造函数
public IndexAdmin(String name) {
indexadmin();
//菜单的添加
//给用户菜单添加条目
user.add(useradd);
user.add(userselect);
user.add(userdelete);
user.add(userupdate);
user.add(exit);
//给商品菜单添加条目
goods.add(goodsadd);
goods.add(goodsdelete);
goods.add(goodsupdate);
//给仓库菜单添加条目
storage.add(storageadd);
storage.add(storagedelete);
storage.add(storageupdate);
//将菜单添加到菜单栏里
management.add(user);
management.add(goods);
management.add(storage);
init(name);
action(name);
}
private void init(String name) {
//初始化框架
index = new JFrame("欢迎管理员"+name+"使用本系统");
//设置框架大小及位置
index.setBounds(500, 100, 600, 500);
index.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//将菜单栏设置进框架
index.setJMenuBar(management);
//清空框架格式
index.setLayout(null);
//设置可视化
index.setVisible(true);
}
public void indexadmin() {
//对象初始化以及设置字体
management = new JMenuBar();
//菜单初始化
user = new JMenu(" 用户管理");
user.setFont(f);
goods = new JMenu(" 商品管理");
goods.setFont(f);
storage = new JMenu(" 仓库管理");
storage.setFont(f);
//菜单条目初始化
exit = new JMenuItem("更换用户");
exit.setFont(f);
useradd = new JMenuItem("添加用户");
useradd.setFont(f);
userdelete = new JMenuItem("删除用户");
userdelete.setFont(f);
userupdate = new JMenuItem("密码修改");
userupdate.setFont(f);
userselect = new JMenuItem("查询用户");
userselect.setFont(f);
goodsadd = new JMenuItem("商品添加");
goodsadd.setFont(f);
goodsdelete = new JMenuItem("商品删除");
goodsdelete.setFont(f);
goodsupdate = new JMenuItem("商品更新");
goodsupdate.setFont(f);
storageadd = new JMenuItem("仓库添加");
storageadd.setFont(f);
storagedelete = new JMenuItem("仓库删除");
storagedelete.setFont(f);
storageupdate = new JMenuItem("仓库更新");
storageupdate.setFont(f);
}
//给所有的菜单条目设置监听事件
private void action(final String name) {
exit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { //切换用户
//界面转换
//将原来页面设置为不可见
index.setVisible(false);
//调用函数转到登陆页面
Login.main(null);
}
});
useradd.addActionListener(new ActionListener() { //添加用户
@Override
public void actionPerformed(ActionEvent e) {
//界面转换
//将原来页面设置为不可见
index.setVisible(false);
//用构造函数获取新页面
new Useradd(name);
}
});
userselect.addActionListener(new ActionListener() { 修改用户
@Override
public void actionPerformed(ActionEvent e) {
//界面转换
index.setVisible(false);
new Userselect(name);
}
});
userdelete.addActionListener(new ActionListener() { //删除用户
@Override
public void actionPerformed(ActionEvent e) {
//界面转换
index.setVisible(false);
new Userdelete(name);
}
});
userupdate.addActionListener(new ActionListener() { //密码修改
@Override
public void actionPerformed(ActionEvent e) {
//界面转换
index.setVisible(false);
new Adminupdate(name);
}
});
goodsadd.addActionListener(new ActionListener() { //添加商品
@Override
public void actionPerformed(ActionEvent e) {
//界面转换
index.setVisible(false);
new Goodsadd(name);
}
});
goodsdelete.addActionListener(new ActionListener() { //删除商品
@Override
public void actionPerformed(ActionEvent e) {
//界面转换
index.setVisible(false);
new Goodsdelete(name);
}
});
goodsupdate.addActionListener(new ActionListener() { //商品更新
@Override
public void actionPerformed(ActionEvent e) {
//界面转换
index.setVisible(false);
new GoodsUpdate(name);
}
});
storageadd.addActionListener(new ActionListener() { //仓库添加
@Override
public void actionPerformed(ActionEvent e) {
//界面转换
index.setVisible(false);
new Storageadd(name);
}
});
storagedelete.addActionListener(new ActionListener() { //删除仓库
@Override
public void actionPerformed(ActionEvent e) {
//界面转换
index.setVisible(false);
new Storagedelete(name);
}
});
storageupdate.addActionListener(new ActionListener() { //仓库更新
@Override
public void actionPerformed(ActionEvent e) {
//界面转换
index.setVisible(false);
new Storageupdate(name);
}
});
}
}
/*主界面*/
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import net.wms.bean.User;
import net.wms.dao.LoginUseImp;
/**
* 登陆界面
* 1、创建登陆界面,初始化上面的对象
* 2、美化登陆界面,设置各个对象的大小、位置、字体
* 3、给按钮设置监听事件
*
*/
public class Login {
//初始化字体
Font d = new Font("楷体", Font.BOLD, 22);
Font f = new Font("楷体", Font.BOLD, 15);
// 初始化对象
JFrame logingui = new JFrame("用户登录界面");
JLabel userlogin = new JLabel("仓库管理系统用户登录");
JLabel username = new JLabel("用户名:");
JLabel password = new JLabel("密 码:");
JLabel usertyle = new JLabel("用户类型");
JTextField name = new JTextField();
JTextField pwd = new JPasswordField();
JComboBox box = new JComboBox(new String[]{"管理员","普通用户"} );
JButton login = new JButton("登录");
//给User类初始化对象user
User user = new User();
public void LoginGui() {
// 设置对象
logingui.setBounds(450, 200, 550, 350);
//设置退出
logingui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//取消框架格式
logingui.setLayout(null);
//设置位置、大小和字体
userlogin.setBounds(160, 30, 250, 30);
userlogin.setFont(d);
username.setBounds(110, 80, 100, 30);
username.setFont(f);
password.setBounds(110, 120, 100, 30);
password.setFont(f);
usertyle.setBounds(110, 160, 100, 30);
usertyle.setFont(f);
name.setBounds(200, 80, 180, 30);
name.setFont(f);
pwd.setBounds(200, 120, 180, 30);
box.setBounds(200, 160, 100, 30);
box.setFont(f);
login.setBounds(200, 200, 80, 30);
login.setFont(f);
// 添加对象
logingui.add(userlogin);
logingui.add(username);
logingui.add(password);
logingui.add(usertyle);
logingui.add(name);
logingui.add(pwd);
logingui.add(box);
logingui.add(login);
// 窗体可视化
logingui.setVisible(true);
box.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//判断选择选项是否和下拉框数据一致
if(box.getSelectedItem().equals("管理员")){
//设置标志量的值
user.setFlag("2");
}else{
user.setFlag("1");
}
}
});
//给登录按钮设置监听事件
login.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//提取文本框里的用户名和密码
String name_text = name.getText();
String pwd_text = pwd.getText();
//将得到的值存入user对象里面
user.setusername(name_text);
user.setuserpwd(pwd_text);
//给登陆接口实现类初始化对象
LoginUseImp l = new LoginUseImp();
//获取标志量
String state = user.getFlag();
//判断标志量,设置文本框的默认值为管理员
if(state != "1" && state != "2") {
state = "2";
}
//判断文本框值是不是管理员
if(state == "2") {
try {
//执行sql语句,进行数据库添加
boolean flag = l.Query(user, "select * from users where username=? and userpwd=? and flag="+state);
if(flag) {
//文本提示框
JOptionPane.showMessageDialog(null, "登陆成功");
//界面转换,隐藏原来界面
logingui.setVisible(false);
//构造新的界面
new IndexAdmin(name_text);
} else {
//文本提示框
JOptionPane.showMessageDialog(null, "登陆失败,请检查用户名和密码");
//设置用户名框和密码框的值为空
name.setText("");
pwd.setText("");
}
} catch (SQLException e1) {
e1.printStackTrace();
}
//判断是不是普通用户
} else if(state == "1") {
try {
//执行sql语句
boolean flag = l.Query(user, "select * from users where username=? and userpwd=? and flag="+state);
if(flag) {
JOptionPane.showMessageDialog(null, "登陆成功");
logingui.setVisible(false);
new Index(name_text);
} else {
JOptionPane.showMessageDialog(null, "登陆失败,请检查用户名和密码");
name.setText("");
pwd.setText("");
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
});
}
//整个程序执行的入口
public static void main(String[] args) {
Login l = new Login();
l.LoginGui();
}
}
/*添加仓库*/
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import net.wms.bean.Storage;
import net.wms.dao.StoragemanagementImp;
public class Storageadd extends IndexAdmin{
JTextField name;
JTextField style;
JTextField id;
Storage storage = new Storage();
public Storageadd(String name) {
super(name);
init();
}
public void init() {
Font d = new Font("楷体", Font.BOLD, 24);
Font f = new Font("楷体", Font.BOLD, 18);
JLabel storagetitle = new JLabel("仓库添加");
JLabel storagename = new JLabel("仓库名:");
name = new JTextField();
JLabel storagestyle = new JLabel("类 型:");
style = new JTextField();
JLabel storageid = new JLabel("编 号:");
id = new JTextField();
JButton submit = new JButton("提交");
JButton reset = new JButton("重置");
storagetitle.setBounds(230, 60, 100, 40);
storagetitle.setFont(d);
storagename.setBounds(160, 140, 80, 30);
storagename.setFont(f);
name.setBounds(240, 140, 150, 30);
name.setFont(f);
storagestyle.setBounds(160, 200, 80, 30);
storagestyle.setFont(f);
style.setBounds(240, 200, 150, 30);
style.setFont(f);
storageid.setBounds(160, 260, 80, 30);
storageid.setFont(f);
id.setBounds(240, 260, 150, 30);
id.setFont(f);
submit.setBounds(190, 320, 80, 30);
submit.setFont(f);
reset.setBounds(300, 320, 80, 30);
reset.setFont(f);
index.add(storagetitle);
index.add(storagename);
index.add(name);
index.add(storagestyle);
index.add(style);
index.add(storageid);
index.add(id);
index.add(submit);
index.add(reset);
reset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
name.setText("");
style.setText("");
id.setText("");
}
});
submit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
if(name.getText().equals("") || style.getText().equals("") || id.getText().equals("")) {
JOptionPane.showMessageDialog(null,"请输入内容");
} else {
storage.setStoragename(name.getText());
storage.setStoragestyle(style.getText());
storage.setStorageID(Integer.parseInt(id.getText()));
StoragemanagementImp s = new StoragemanagementImp();
try {
s.Add(storage, "insert into storage(storagename,storagestyle,storageID)" + "values(?,?,?)");
name.setText("");
style.setText("");
id.setText("");
JOptionPane.showMessageDialog(null, "添加成功");
} catch (SQLException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
}
}
});
}
}
/*删除仓库*/
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import net.wms.dao.GoodsmanagementImp;
import net.wms.dao.StoragemanagementImp;
public class Storagedelete extends IndexAdmin{
int id ;
//声明表格
private JTable table;
public Storagedelete(String name) {
super(name);
init();
}
public void init() {
Font t = new Font("楷体",Font.BOLD, 24);
final Font f = new Font("楷体",Font.BOLD, 15);
JLabel title = new JLabel("仓库信息");
title.setFont(t);
title.setBounds(130, 40, 100, 40);
final Vector c = new Vector();
//添加数据
c.add("编号");
c.add("仓库名称");
c.add("仓库类型");
c.add("仓库编号");
final StoragemanagementImp s = new StoragemanagementImp();
try {
s.Query("select * from storage");
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//创建表格
table = new JTable(s.vec,c);
table.setFont(f);
table.getTableHeader().setFont(f);
//为表格添加鼠标单击事件
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// 获取表格中的ID
id = (int) table.getValueAt(
table.getSelectedRow(), 0);
System.out.println(id);
super.mouseClicked(e);
}
});
//创建Jscrollpane
final JScrollPane js = new JScrollPane(table);
js.setBounds(100, 120, 400, 200);
//创建删除按钮
final JButton delete = new JButton("删除");
//为按钮创建监听事件
delete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//判断Id是否在列表内
if(id == 0){
JOptionPane.showMessageDialog(null, "删除失败请选择需要删除的记录!");
}else{
try {
//给出提示
//4个参数:1.null 2.提示内容 3.标题 4.按钮类型
int mess = JOptionPane.showConfirmDialog(
null,"确定删除记录?","友情提示:",
JOptionPane.YES_NO_OPTION );
//点击确定按钮之后的事件
//0 == 确定 ,1 == 取消
if(mess == 0){
//调用删除方法
s.Delete("delete from storage where id ="+id);
//提示删除成功
JOptionPane.showMessageDialog(null, "删除成功");
s.Query("select * from storage");
//创建表格
JTable new_table = new JTable(s.vec,c);
new_table.setFont(f);
new_table.getTableHeader().setFont(f);
//创建Jscrollpane
JScrollPane p = new JScrollPane(new_table);
//设置新组建的大小
p.setBounds(100, 120, 400, 200);
//移除旧组件
index.remove(js);
//添加新组件
index.add(p);
//重绘组键
index.repaint();
}
} catch (Exception e2) {
// TODO: handle exception
}
}
}
});
//设置位置及大小
delete.setBounds(250, 350, 80,30);
index.add(title);
index.add(js);
//添加按钮
index.add(delete);
}
}
/*显示仓库信息*/
import java.awt.Font;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import net.wms.dao.StoragemanagementImp;
public class Storageselect extends Index{
int id;
private JTable table;
public Storageselect(String name) {
super(name);
init();
}
@SuppressWarnings("unchecked")
public void init() {
Font t = new Font("楷体",Font.BOLD, 24);
final Font f = new Font("楷体",Font.BOLD, 15);
JLabel title = new JLabel("仓库信息");
title.setFont(t);
title.setBounds(230, 40, 100, 40);
Vector v = new Vector();
v.add("编号");
v.add("仓库名称");
v.add("仓库类型");
v.add("仓库编号");
StoragemanagementImp s = new StoragemanagementImp();
table = new JTable(s.vec,v);
table.setFont(f);
table.getTableHeader().setFont(f);
JScrollPane jp = new JScrollPane(table);
jp.setBounds(100, 120, 400, 200);
try {
s.Query("select * from storage");
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
index.add(title);
index.add(jp);
}
}
/*仓库信息修改*/
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import net.wms.bean.Goods;
import net.wms.bean.Storage;
import net.wms.dao.GoodsmanagementImp;
import net.wms.dao.StoragemanagementImp;
public class Storageupdate extends IndexAdmin{
int id ;
//声明表格
private JTable table;
JTextField name;
JTextField style;
JTextField s_id;
public Storageupdate(String name) {
super(name);
init();
}
public void init() {
Font t = new Font("楷体",Font.BOLD, 24);
final Font f = new Font("楷体",Font.BOLD, 15);
JLabel title = new JLabel("仓库信息");
JLabel storagename = new JLabel("仓库名称:");
storagename.setBounds(160, 220, 80, 30);
storagename.setFont(f);
name = new JTextField();
name.setBounds(240, 220, 150, 30);
name.setFont(f);
JLabel storagestyle = new JLabel("仓库类型:");
storagestyle.setBounds(160, 270, 80, 30);
storagestyle.setFont(f);
style = new JTextField();
style.setBounds(240, 270, 150, 30);
style.setFont(f);
JLabel storageid = new JLabel("仓库编号:");
storageid.setBounds(160, 320, 80, 30);
storageid.setFont(f);
s_id = new JTextField();
s_id.setBounds(240, 320, 150, 30);
s_id.setFont(f);
title.setFont(t);
title.setBounds(230, 30, 100, 30);
final Vector c = new Vector();
//添加数据
c.add("编号");
c.add("仓库名称");
c.add("仓库类型");
c.add("仓库编号");
final StoragemanagementImp s = new StoragemanagementImp();
try {
s.Query("select * from storage");
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//创建表格
table = new JTable(s.vec,c);
table.setFont(f);
table.getTableHeader().setFont(f);
//为表格添加鼠标单击事件
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// 获取表格中的ID
//获取每条记录所对应的id
id = (int)table.getValueAt(table.getSelectedRow(), 0);
//获取部门名称
String sname = (String)table.getValueAt(table.getSelectedRow(), 1);
//获取部门编号
String sstyle =(String)table.getValueAt(table.getSelectedRow(), 2);
//获取部门描述
String sid=(String)table.getValueAt(table.getSelectedRow(), 3).toString();
//将数据设置进文本框
name.setText(sname);
style.setText(sstyle);
s_id.setText(sid);
super.mouseClicked(e);
}
});
//创建Jscrollpane
final JScrollPane js = new JScrollPane(table);
js.setBounds(100, 70, 400, 130);
//创建删除按钮
final JButton update = new JButton("修改");
//为按钮创建监听事件
update.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//判断Id是否在列表内
if(id == 0){
JOptionPane.showMessageDialog(null, "修改失败请选择需要修改的记录!");
}else{
try {
//给出提示
//4个参数:1.null 2.提示内容 3.标题 4.按钮类型
int mess = JOptionPane.showConfirmDialog(
null,"确定修改记录?","友情提示:",
JOptionPane.YES_NO_OPTION );
//点击确定按钮之后的事件
//0 == 确定 ,1 == 取消
if(mess == 0){
//调用删除方法
Storage storage = new Storage();
storage.setStoragename(name.getText());
storage.setStoragestyle(style.getText());
storage.setStorageID(Integer.parseInt(s_id.getText()));
s.Update(storage,"update storage set storagename = ?,storagestyle=?,storageID=? where id = "+ id);
//提示删除成功
JOptionPane.showMessageDialog(null, "修改成功");
s.Query("select * from storage");
//原理:移除原组件,添加新组件
//创建表格
JTable new_table = new JTable(s.vec,c);
new_table.setFont(f);
new_table.getTableHeader().setFont(f);
//创建Jscrollpane
JScrollPane p = new JScrollPane(new_table);
//设置新组建的大小
p.setBounds(100, 70, 400, 130);
//移除旧组件
index.remove(js);
//添加新组件
index.add(p);
//重绘组键
index.repaint();
}
} catch (Exception e2) {
// TODO: handle exception
}
}
}
});
//设置位置及大小
update.setBounds(250, 380, 80,30);
index.add(title);
index.add(storagename);
index.add(name);
index.add(storagestyle);
index.add(style);
index.add(storageid);
index.add(s_id);
index.add(js);
//添加按钮
index.add(update);
}
}
/*添加用户*/
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import net.wms.bean.User;
import net.wms.dao.LoginUseImp;
public class Useradd extends IndexAdmin{
//声明部分对象
JTextField name;
JTextField pwd;
JTextField style;
//为User类初始化对象user
User user = new User();
//构造函数
public Useradd(String name) {
super(name);
init();
}
public void init() {
//初始化字体
Font d = new Font("楷体", Font.BOLD, 24);
Font f = new Font("楷体", Font.BOLD, 18);
//初始化对象
JLabel usertitle = new JLabel("添加用户");
JLabel username = new JLabel("用户名:");
name = new JTextField();
JLabel userpwd = new JLabel("密 码:");
pwd = new JTextField();
JLabel userstyle = new JLabel("类 型:");
style = new JTextField();
JButton submit = new JButton("提交");
JButton reset = new JButton("重置");
//设置对象的位置、大小和字体
usertitle.setBounds(250, 60, 100, 40);
usertitle.setFont(d);
username.setBounds(160, 140, 80, 30);
username.setFont(f);
name.setBounds(240, 140, 150, 30);
name.setFont(f);
userpwd.setBounds(160, 200, 80, 30);
userpwd.setFont(f);
pwd.setBounds(240, 200, 150, 30);
pwd.setFont(f);
userstyle.setBounds(160, 260, 80, 30);
userstyle.setFont(f);
style.setBounds(240, 260, 150, 30);
style.setFont(f);
submit.setBounds(200, 320, 80, 30);
submit.setFont(f);
reset.setBounds(310, 320, 80, 30);
reset.setFont(f);
//将对象添加到对象中
index.add(usertitle);
index.add(username);
index.add(name);
index.add(userpwd);
index.add(pwd);
index.add(style);
index.add(userstyle);
index.add(submit);
index.add(reset);
//为重置按钮设置监听事件
reset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//清空用户名框、密码框、用户类型
name.setText("");
pwd.setText("");
style.setText("");
}
});
//未提交按钮设置监听事件
submit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//判断文本框是否为空
if(name.getText().equals("") || pwd.getText().equals("") || style.getText().equals("")) {
//为空,弹出提示框
JOptionPane.showMessageDialog(null,"请输入内容");
} else {
//不为空
//从文本框中提取数据并存放到user对象中
user.setusername(name.getText());
user.setuserpwd(pwd.getText());
user.setFlag(style.getText());
//为登陆接口实现类初始化对象
LoginUseImp l = new LoginUseImp();
try {
//执行sql语句
l.Add(user, "insert into users(username,userpwd,flag) values(?,?,?)");
//清空文本框
name.setText("");
pwd.setText("");
style.setText("");
//添加成功提示框
JOptionPane.showMessageDialog(null, "添加成功");
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
});
}
}
/*删除用户*/
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import net.wms.bean.User;
import net.wms.dao.LoginUseImp;
public class Userdelete extends IndexAdmin {
//声明部分对象
JLabel name;
JLabel pwd;
JLabel style;
JTextField dname;
//为User类初始化对象
User user = new User();
//构造函数
public Userdelete(String name) {
super(name);
init();
}
public void init() {
//初始化字体
Font d = new Font("楷体", Font.BOLD, 24);
Font f = new Font("楷体", Font.BOLD, 18);
//初始化对象
JLabel userdelete = new JLabel("用户删除");
JLabel deletename = new JLabel("输入用户名:");
dname = new JTextField();
JLabel usertitle = new JLabel("删除的用户信息");
JLabel username = new JLabel("用户名:");
name = new JLabel();
JLabel userpwd = new JLabel("密 码:");
pwd = new JLabel();
JLabel userstyle = new JLabel("类 型:");
style = new JLabel();
JButton submit = new JButton("确定");
JButton delete = new JButton("删除");
//设置对象
userdelete.setBounds(250, 30, 100, 40);
userdelete.setFont(d);
deletename.setBounds(120, 90, 120, 30);
deletename.setFont(f);
dname.setBounds(230, 90, 150, 30);
dname.setFont(f);
usertitle.setBounds(200, 140, 200, 40);
usertitle.setFont(d);
username.setBounds(160, 200, 80, 30);
username.setFont(f);
name.setBounds(240, 200, 150, 30);
name.setFont(f);
userpwd.setBounds(160, 260, 80, 30);
userpwd.setFont(f);
pwd.setBounds(240, 260, 150, 30);
pwd.setFont(f);
userstyle.setBounds(160, 320, 80, 30);
userstyle.setFont(f);
style.setBounds(240, 320, 150, 30);
style.setFont(f);
submit.setBounds(390, 90, 80, 30);
submit.setFont(f);
delete.setBounds(250, 380, 80, 30);
delete.setFont(f);
//添加对象
index.add(userdelete);
index.add(deletename);
index.add(dname);
index.add(submit);
index.add(usertitle);
index.add(username);
index.add(name);
index.add(userpwd);
index.add(pwd);
index.add(style);
index.add(userstyle);
index.add(delete);
//为确定按钮添加监听事件
submit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//从文本框中取得用户名设置进user对象中
user.setusername(dname.getText());
LoginUseImp l = new LoginUseImp();
boolean b;
try {
//执行sql语句
b = l.Query1(user, "select * from users where username= '"+dname.getText()+"'");
if(b){
//将数据库中的值设置进文本框
name.setText(user.getusername());
pwd.setText(user.getuserpwd());
style.setText(user.getFlag());
} else {
//未查找到提示框
JOptionPane.showMessageDialog(null,"未查到该用户");
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
//为删除按钮添加监听事件
delete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//将选中的名字添加进文本框
user.setusername(dname.getText());
LoginUseImp l = new LoginUseImp();
try {
//执行删除的sql语句
l.Delete(user, "delete from users where username='"+dname.getText()+"'");
JOptionPane.showMessageDialog(null, "删除成功");
} catch (SQLException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
}
});
}
}
/*查看所有用户信息*/
import java.awt.Font;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import net.wms.dao.LoginUseImp;
public class Userselect extends IndexAdmin{
//声明对象
int id;
private JTable table;
//构造函数
public Userselect(String name) {
super(name);
init();
}
public void init() {
//初始化字体
Font t = new Font("楷体",Font.BOLD, 24);
final Font f = new Font("楷体",Font.BOLD, 15);
//初始化对象
JLabel title = new JLabel("用户信息");
title.setFont(t);
title.setBounds(240, 40, 100, 40);
//初始化Vector集合
Vector v = new Vector();
//为集合添加字段
v.add("编号");
v.add("用户名");
v.add("用户类型");
LoginUseImp l = new LoginUseImp();
//初始化表格
table = new JTable(l.vec,v);
table.setFont(f);
JScrollPane jp = new JScrollPane(table);
jp.setBounds(100, 120, 400, 200);
try {
l.Select("select * from users");
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
index.add(title);
index.add(jp);
}
}
/*显示用户个人信息*/
package net.wms.view;
import java.awt.Font;
import java.sql.SQLException;
import javax.swing.JLabel;
import net.wms.bean.User;
import net.wms.dao.LoginUseImp;
public class Usernews extends Index{
//声明对象
JLabel uname;
JLabel pwd;
JLabel style;
//为User类初始化user对象
User user = new User();
//构造函数
public Usernews(String name) {
super(name);
init();
//将用户名设置进user对象
user.setusername(name);
LoginUseImp l = new LoginUseImp();
try {
//执行按姓名查找的神奇了语句
l.Query1(user, "select * from users where username= '"+name+"'");
uname.setText(user.getusername());
pwd.setText(user.getuserpwd());
//通过标志量判断普通用户和管理员
if(user.getFlag().equals("1")) {
style.setText("普通用户");
} else {
style.setText("管理员");
}
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
public void init() {
//初始化字体
Font d = new Font("楷体", Font.BOLD, 24);
Font f = new Font("楷体", Font.BOLD, 18);
//初始化对象
JLabel usertitle = new JLabel("个人信息");
JLabel username = new JLabel("用户名:");
uname = new JLabel();
JLabel userpwd = new JLabel("密 码:");
pwd = new JLabel();
JLabel userstyle = new JLabel("类 型:");
style = new JLabel();
//设置对象大小、位置和字体
usertitle.setBounds(230, 60, 200, 40);
usertitle.setFont(d);
username.setBounds(180, 130, 80, 30);
username.setFont(f);
uname.setBounds(260, 130, 150, 30);
uname.setFont(f);
userpwd.setBounds(180, 190, 80, 30);
userpwd.setFont(f);
pwd.setBounds(260, 190, 150, 30);
pwd.setFont(f);
userstyle.setBounds(180, 250, 80, 30);
userstyle.setFont(f);
style.setBounds(260, 250, 150, 30);
style.setFont(f);
//将对象添加进框架
index.add(usertitle);
index.add(username);
index.add(uname);
index.add(userpwd);
index.add(pwd);
index.add(style);
index.add(userstyle);
}
}
/*修改用户密码*/
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import net.wms.bean.User;
import net.wms.dao.LoginUseImp;
public class Userupdate extends Index{
JLabel uname;
JTextField pwd;
JTextField pass;
User user = new User();
public Userupdate(String name) {
super(name);
init(name);
}
public void init(String name) {
user.setusername(name);
Font d = new Font("楷体", Font.BOLD, 24);
Font f = new Font("楷体", Font.BOLD, 18);
JLabel usertitle = new JLabel("修改密码");
JLabel username = new JLabel("用 户 名:");
uname = new JLabel();
JLabel userpwd = new JLabel("新 密 码:");
pwd = new JTextField();
JLabel userpass = new JLabel("再输次密码:");
pass = new JTextField();
JButton submit = new JButton("修改");
JButton reset = new JButton("重置");
usertitle.setBounds(230, 60, 100, 40);
usertitle.setFont(d);
username.setBounds(150, 140, 140, 30);
username.setFont(f);
uname.setBounds(270, 140, 150, 30);
uname.setFont(f);
uname.setText(name);
userpwd.setBounds(150, 200, 140, 30);
userpwd.setFont(f);
pwd.setBounds(270, 200, 150, 30);
pwd.setFont(f);
userpass.setBounds(150, 260, 140, 30);
userpass.setFont(f);
pass.setBounds(270, 260, 150, 30);
pass.setFont(f);
submit.setBounds(190, 320, 80, 30);
submit.setFont(f);
reset.setBounds(300, 320, 80, 30);
reset.setFont(f);
index.add(usertitle);
index.add(username);
index.add(uname);
index.add(userpwd);
index.add(pwd);
index.add(pass);
index.add(userpass);
index.add(submit);
index.add(reset);
reset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
pwd.setText("");
pass.setText("");
}
});
submit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
LoginUseImp l = new LoginUseImp();
try {
l.Delete(user, "update users set userpwd='"+pass.getText()+"' where username='"+user.getusername()+"'");
JOptionPane.showMessageDialog(null, "修改成功");
} catch (SQLException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
}
});
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。