加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DM_view.txt 52.72 KB
一键复制 编辑 原始数据 按行查看 历史
Wang_J 提交于 2020-01-03 12:53 . 界面程序
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027
/*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();
}
}
});
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化