- 657.00 KB
- 2022-05-16 18:34:49 发布
- 1、本文档共5页,可阅读全部内容。
- 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,可选择认领,认领后既往收益都归您。
- 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细先通过免费阅读内容等途径辨别内容交易风险。如存在严重挂羊头卖狗肉之情形,可联系本站下载客服投诉处理。
- 文档侵权举报电话:19940600175。
实验报告仓库管理系统实验课程数据库实验实验者1姓名班级学号实验者2姓名班级学号实验时间指导老师43
目录P3要求P4参考资料阅读心得P6概述(设计思路、实现功能、运用技术)P7实现及操作(关键代码解析、运行结果、类方法的介绍)P17存在问题和需要改善的地方P18附录(完整代码包括分布调试代码)43
要求:使用ACCESS、SQLSERVER、ORACLE、MYSQL等作后台数据库,选择ASP、VB、VC、JAVA等作为前台开发工具设计一个小型管理系统。所设计的小型管理系统应包含输入输出、查询、插入、删除等基本功能,功能越强大越好。根据题目的基本需求,设计数据库、编写程序,并写出详细的设计说明书。每班以2人为一组自由分组,由班长将分组情况报到指导教师处;需要提交的文档资料:设计说明书每人一份(包括:参考资料的阅读心得,功能需求说明,设计思路,数据表结构及作用,数据关系图,存储过程代码及相关注释,设计体会);电子文档:可运行的,能实现全部或者主要基本功能的小型系统。课程设计说明书编写规范:a.需求分析:题目要求达到的功能,所提供的原始数据,需要输出的数据及样式等。b.数据库设计:根据要求设计数据库的结构,包括:表、数据完整性、关系、视图。c.开发方案选择:主要是前端开发平台的选择与方案的比较,至少比较两套方案。d.安全性设计:登录用户、数据库用户、数据库角色、命令许可等方面。e.前台应用程序设计:要求至少完成通过前台程序实现对后台数据库的数据查询、插入、删除与更新。涉及到数据的所有操作要求采用存储过程的方式进行。f.附录或参考资料:参考资料来源,阅读心得。43
参考资料阅读心得:参考资料(老师提供):2、教材信息数据库高校的教材管理需要相应的数据库环境,请根据如下系统需求定义数据表结构及关系,并通过编写存储过程来实现其中的两项功能:1)、教材出入库(1)教材入库将教材内部识别号、入库时间,入库数,适用对象等信息输入到教材入库记录表中,并更新在库教材信息表。教材入库后把教材征订单相应项目做教材收到标记。(暂不处理订单中某教材只入库其中一部分的情况,即缺货情况。)(2)教材出库教师或学生或班级或其它人员领用教材,需要把教材内部编号,教材代号,出库时间,出库数量,使用单位(指班级或教师,可多个班级或教师),用途,经办人等信息输入到教材出库记录表中。并同时更新教材信息表中的在库数量。为便于教材信息的录入,可通过班级名称、课程名称或教材名称查询到要出库的教材信息表中相应教材的内部编号。(3)教材信息录入将教材的内部识别号(由本系统自动维护),代号,书名,编著者,出版社,版次,定价,入库时间,入库数,适用对象等信息录入到系统的数据库中。2)、教材查询(1)在库教材查询查询教材在库情况:可按书名、代号等查询,可查询某班级使用的教材及在库数量,可查询某课程使用的教材及在库数量。可查询指定教材的在库数量,价值总额。可查询教材在库的统计信息:在库教材总数、种类总数、价值总额。(2)教材出库查询教材出库信息查询:按教材代号等信息查询教材出库情况,可查询某使用对象(包括班级、教师、部门、其他人员)的教材出库情况。可查询某时间范围内(学期、学年等)的教材出库情况。(3)教材历史查询查询指定书的在库及出入库的历史信息,也可按时间或时间范围查询教材入库情况。便于管理员掌握教材出入库情况。3)、教材订购(1)、生成教材订单根据输入的各专业班级课程教材选用信息、教材出版社信息生成订单。(2)、教材订单状态管理订单状态管理:可标记各订单为有效(款项发出),图书入库后标记订单为到货,图书退回标记为退换货。4)、教材订单查询可查询指定学期教材订单的到货、缺货情况,查询订单未到教材的订货公司信息包括它的银行帐号、地址、联系人、联系方法等,以便与其联系。5)、其他相关数据:学生相关、课程相关、教师相关、班级相关、系部相关43
阅读心得:我们的选题是仓库管理系统,和教材信息数据库大致相同,实现的功能略作添加;我们需要完成的任务:(1).这个实验本质就是设置合理的操作界面,实现对数据库的数据读取、修改、删除、更新等操作;(2).系统的完备性和操作的安全性,是完善软件的关键,其中包括:插入相同信息;数据库中物品数量不足;管理员编号不存在;安全登录;不同角色的对数据库的操作权限;等等问题,都是我们需要解决的基本问题;(3)界面的美化和操作的快捷性和正确性;界面是给客户的第一感触,尽量的新颖并且符合客户要求:(这里我们是学习,争取掌握多一点处理界面的函数,没有系统的规划)如果美化界面是尽量的完善,那么操作的快捷性和正确性是必须要实现的,给客户一个合理的操作是成功的必备条件;(4)分工与合作我们两个人都是java的初级学习者,不断的学习,分别设计不同的界面,相互交流实现效果的的经验;关于数据库的知识和SQL语言的学习,都是我们要重新学习的;(5)文档的处理和制作,也是我们要完成的重要任务,我们也是分工完成;43
概述1.设计思路:(1).仓库管理系统,实现功能:入库登记:商品入库记录;出库登记:库存商品出库;在库商品查询:库存物品查询;出库入库信息查询:按时间,操作管理员查询操作信息;管理员信息管理:管理员的登记,查询,删除;(2).附加实现功能:登录界面:实现管理员员和客户的不同角色登录;界面的转换:分别创建不同的窗口,并及时删除浏览过的窗口;分角色设定使用权限:管理员和客户的使用权限不同;(3).异常处理:操作错误:信息输入错误等;常规错误:仓库物品数量不足等;2.运用技术:(1)界面实现:java语言;(2)数据路操作实现:使用Access2003,运用SQL语言进行操作;43
实现及操作根据分析,一共设计9个类,如下图,其中:数据库操作类:DBAccess:实现连接,查询修改等分步操作;GetDBInfo:实现查询结果集的返回;操作界面类:Enter:登录界面Select:功能选择界面InStoreHouse:物品入库操作界面OutStoreHouse:物品出库操作界面SearchGoods:物品查询界面OutIn:出入库查询界面ManagerInfo:管理员信息管理界面分步实现说明:1.DBAccess类publicStatementgetStatement(StringdbPath)throwsException:返回连接数据库的状态;publicResultSetexecuteQuery(Statementstmt,Stringquery)throwsException:返回查询结果集;publicvoidexecuteUpdate(Statementstmt,Stringquery)throwsSQLException:更新数据库;publicvoidclose()throwsSQLException:关闭数据库的连接;2.GetDBInfo类privateVector>rows;记录查询返回元组privateVectorcolumnHeads;记录查询返回结果的标题//获取表头VolumnHeadspublicVectorgetColumnHeads();//获取表中内容publicVectorgetRows();//更新数据库publicvoidexecuteUpdate(Statementstmt,Stringquery)throwsSQLException;3.Enter类privateJFrameframe;privateJButtonenterButton;privateJButtonresetButton;用于标识登陆角色的单选按钮43
privateJRadioButtonradioButton1;privateJRadioButtonradioButton2;privateJTextFieldnameText;privateJPasswordFieldpasswordText;表示登录身份:publicstaticbooleanisManager=false;实现效果:基本实现:(1)图片载入:JLabellabel4=newJLabel();ImageIconicon=newImageIcon("E:\study\java\workspace\StoreHouse\abc.jpg");label4.setIcon(icon);(2)单选按钮:ButtonGroupgroup=newButtonGroup();radioButton1=newJRadioButton("管理员",false);radioButton2=newJRadioButton("客户",true);group.add(radioButton1);group.add(radioButton2);1.InStoreHouse类基本成员变量:privateJFrameframe;输入信息的11个文本框:privateJTextFieldtext1-11;privateJTextFieldinfoText;privateJButtonokButton;privateJButtonbackButton;设置日期格式:privatestaticfinalStringYYYMMDDHHMMSS="yyyy/MM/ddHH:mm:ss";基本函数://SQL语句生成publicStringgetSQL()//自动生成插入时间publicStringinsertTime()43
//自动生成入库IDpublicStringinHouseID()//清除文本框publicvoidclear()实现效果:基本功能实现:监听器的设定:publicvoidactionPerformed(ActionEvente){Objectsource=e.getSource();if(source==okButton){try{DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Statementstmt=db.getStatement(dbPath);Stringquery=getSQL();db.executeUpdate(stmt,query);query=insertSQL();db.executeUpdate(stmt,query);stmt.close();db.close();infoText.setText("存储成功");clear();}catch(Exceptionex){ex.printStackTrace();}}elseif(source==backButton){frame.dispose();newSelect();}}43
1.OutStoreHouse类基本成员变量:privateJFrameframe;privateJButtonokButton;privateJButtonbackButton;privateJTextFieldtext1;privateJTextFieldtext2;privateJTextFieldtext3;privateJTextFieldtext4;privatestaticfinalStringYYYMMDDHHMMSS="yyyy/MM/ddHH:mm:ss";privateIntegernum;//修改数据里中数量的临时变量基本函数:同InStoreHouse雷同实现效果:基本功能实现:处理物品编号不存在,以及数量不足的问题:publicvoidactionPerformed(ActionEvente){Objectsource=e.getSource();if(source==okButton){try{DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Stringquery=getGoodsSQL();Statementstmt=db.getStatement(dbPath);ResultSetrs=db.executeQuery(stmt,query);if(!(rs.next()))//判断数据库中是否有内容{JOptionPane.showMessageDialog(null,"输入货物编号不存在","提示信息",JOptionPane.INFORMATION_MESSAGE);text3.setText("操作失败");43
clear();}else{//判断仓库物品是否够//这里实验了很多次为什么只有num=放在这里才可以呢if((num=Integer.valueOf(rs.getString(1)).intValue()-Integer.valueOf(text2.getText()).intValue())<0){JOptionPane.showMessageDialog(null,"仓库货物不足","提示信息",JOptionPane.INFORMATION_MESSAGE);clear();text3.setText("操作失败");}else{query=getSendOutSQL();db.executeUpdate(stmt,query);query=updateGoodsSQL(num);db.executeUpdate(stmt,query);text3.setText("操作成功");}}stmt.close();db.close();}catch(Exceptionex){ex.printStackTrace();}}elseif(source==backButton){frame.dispose();newSelect();}}解析:这里应用到数据类型的转变,String到intdouble的转化;还可以应用其他方法:如:rs.getInt(3);直接读取数据库中的int类型;rs.getDouble(4):直接读取double类型1.SearchGoods类基本成员函数:privateJFrameframe;privateJScrollPanejsp;privateJComboBoxnameList;privateJComboBoxtypeList;privateJComboBoxproductList;privateJTextFieldcountText;privateJTextFieldvalueText;privateJButtonokButton;43
privateJTabletable;privateDefaultTableModelmodel;privateJButtonbackButton;privateVectorrows;//表行值privateVectorcolumnHeads;//表列名//查询使用:Stringstr1,str2,str3;基本函数实现相同;实现效果:7.OutIn类基本函数变量:privateJFrameframe;privateJRadioButtoninButton;privateJRadioButtonoutButton;privateJButtonokButton;privateJButtonbackButton;privateJComboBoxcombox1;privateJComboBoxcombox2;privateJTabletable;privateVectorrows;//表行值privateVectorcolumnHeads;//表列名privateDefaultTableModelmodel;privateJScrollPanejsp;privateStringstr1=null,str2=null;//查询使用privatebooleanflag=false;privateinttmp=0;privatestaticfinalStringYYYMMDDHHMMSS="yyyy/MM/dd";实现效果:43
基本实现:时间字符创的分割处理;8.Select类基本成员变量privateJButtonbutton1;privateJButtonbutton2;privateJButtonbutton3;privateJButtonbutton4;privateJButtonbutton5;privateJButtonbutton6;privateJTextFieldText;privateJFrameframe;实现效果:基本实现:界面效果实现:infoLabel.setHorizontalAlignment(SwingConstants.CENTER);infoLabel.setBackground(Color.gray);Text.setBackground(Color.gray);Text.setForeground(Color.cyan);Text.setFont(newFont("宋体",Font.HANGING_BASELINE,20));43
8.ManagerInfo类基本函数:privateJFrameframe;privateJTabbedPanetabbedPane;privateJLabellabel1;privateJLabellabel2;privateJLabellabel3;privateJPanelpanel1;privateJPanelpanel2;privateJPanelpanel3;privateJComboBoxageBox;privateJComboBoxworkAgeBox;privateJComboBoxpostionBox;privateJTextFieldtext21;privateJTextFieldtext22;privateJTextFieldtext23;privateJTextFieldtext24;privateJTextFieldtext25;privateJTextFieldtext26;privateJTextFieldtext27;privateJTextFieldtext28;privateJTextFieldtext31;privateJTextFieldtext32;privateJButtonbutton11;privateJButtonbutton12;privateJButtonbutton21;privateJButtonbutton31;privateJButtonbackButton;privateJTabletable;privateVectorrows;//表行值privateVectorcolumnHeads;//表列名privateDefaultTableModelmodel;privateJScrollPanejsp;privateStringstr1=null,str2=null,str3=null;//查询使用基本功能函数:这里的函数处理和上面的相同,只是在布局上采用了JtablePanle面板,将三个功能加在同一个窗口里;实现效果:43
处理问题:要删除的管理员信息不存在:43
if(source==button31){booleandeleteState=false;try{DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Stringquery="select*fromManagerwhere编号="+"""+text31.getText()+""";Statementstmt=db.getStatement(dbPath);ResultSetrs=db.executeQuery(stmt,query);while(rs.next()){if(rs.getString(1).equals(text31.getText())){query="deletefromManagerwhere编号="+"""+text31.getText()+""";db.executeUpdate(stmt,query);text31.setText("");text32.setText("删除成功");deleteState=true;}}stmt.close();db.close();}catch(Exceptionex){ex.printStackTrace();}if(deleteState==false){text32.setText("输入编号不存在");text31.setText("");}解析:在删除之前,对数据库进行检查,判断管理员编号是否存在;43
存在问题和需要完善的问题43
附录:代码实现43DBAccess.Java文件importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassDBAccess{publicConnectionconn=null;//连接未加密的数据库publicStatementgetStatement(StringdbPath)throwsException{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Stringdburl="jdbc:odbc:driver={MicrosoftAccessDriver(*.mdb)};"+"DBQ="+dbPath;//此为NO-DSN方式//Stringdburl="jdbc:odbc:odbcName";//此为ODBC连接方式conn=DriverManager.getConnection(dburl);returnconn.createStatement();}//连接加密的数据库publicStatementgetStatement(StringdbPath,Stringpassword)throwsException{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Stringdburl="jdbc:odbc:driver={MicrosoftAccessDriver(*.mdb)};"+"pwd="+password+";DBQ="+dbPath;//此为NO-DSN方式//Stringdburl="jdbc:odbc:odbcName";//此为ODBC连接方式conn=DriverManager.getConnection(dburl);returnconn.createStatement();}/*查询数据库*/publicResultSetexecuteQuery(Statementstmt,Stringquery)throwsException{ResultSetrs=stmt.executeQuery(query);returnrs;}/**更新数据库*/publicvoidexecuteUpdate(Statementstmt,Stringquery)throwsSQLException{stmt.executeUpdate(query);}/***关闭链接*/publicvoidclose()throwsSQLException{if(conn!=null)conn.close();}publicstaticvoidmain(Stringargs[])throwsException{DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Stringquery="select*fromManager";Statementstmt=db.getStatement(dbPath);ResultSetrs=db.executeQuery(stmt,query);while(rs.next()){System.out.println(rs.getString(1)+"t"+rs.getString(2)+"t"+rs.getString(3)+"t"+rs.getString(4)+"t"+rs.getString(5)+rs.getString(6)+rs.getString(7));}}}Enter.java文件importjavax.swing.*;43
importjava.awt.event.*;importjava.awt.*;importjava.sql.ResultSet;importjava.sql.Statement;publicclassEnterimplementsActionListener{privateJFrameframe;privateJButtonenterButton;privateJButtonresetButton;privateJRadioButtonradioButton1;privateJRadioButtonradioButton2;privateJTextFieldnameText;privateJPasswordFieldpasswordText;publicstaticbooleanisManager=false;publicEnter(){frame=newJFrame("仓库管理系统登录界面");enterButton=newJButton("登录");resetButton=newJButton("重置");JLabellabel1=newJLabel("用户名:");JLabellabel2=newJLabel("密码:");JLabellabel3=newJLabel("登录方式:");JLabellabel4=newJLabel();JLabellabel5=newJLabel();JLabellabel6=newJLabel();JLabellabel7=newJLabel();ImageIconicon=newImageIcon("E:\study\java\workspace\StoreHouse\abc.jpg");label4.setIcon(icon);label5.setText("华润品牌");label7.setText("追求卓越");label6.setText("中心软件,让您选择无悔的软件,感谢支持晓伟O(∩_∩)O~制作");nameText=newJTextField();passwordText=newJPasswordField();//单选按钮ButtonGroupgroup=newButtonGroup();radioButton1=newJRadioButton("管理员",false);radioButton2=newJRadioButton("客户",true);group.add(radioButton1);group.add(radioButton2);/**字体等格式设置*/label1.setHorizontalAlignment(SwingConstants.CENTER);label2.setHorizontalAlignment(SwingConstants.CENTER);label3.setHorizontalAlignment(SwingConstants.CENTER);label5.setHorizontalAlignment(SwingConstants.CENTER);label6.setHorizontalAlignment(SwingConstants.CENTER);label1.setFont(newFont("宋体",Font.HANGING_BASELINE,30));label2.setFont(newFont("宋体",Font.HANGING_BASELINE,30));label5.setFont(newFont("华文行楷",Font.HANGING_BASELINE,40));label7.setFont(newFont("华文行楷",Font.HANGING_BASELINE,40));label5.setForeground(Color.red);label7.setForeground(Color.red);/**局部布局*/label4.setBounds(0,0,800,90);label5.setBounds(0,100,200,100);label7.setBounds(0,200,200,100);label6.setBounds(0,300,800,100);43
label1.setBounds(220,110,150,60);label2.setBounds(220,180,150,60);nameText.setBounds(400,120,200,40);passwordText.setBounds(400,190,200,40);label3.setBounds(200,250,150,40);radioButton1.setBounds(350,250,100,40);radioButton2.setBounds(350,300,100,40);enterButton.setBounds(460,270,150,40);resetButton.setBounds(620,270,150,40);/**增加监听器*/enterButton.addActionListener(this);resetButton.addActionListener(this);/**整体布局*/Containerctn=frame.getContentPane();ctn.setLayout(null);ctn.add(label1);ctn.add(label2);ctn.add(nameText);ctn.add(passwordText);ctn.add(label3);ctn.add(label4);ctn.add(label5);ctn.add(label6);ctn.add(label7);ctn.add(radioButton1);ctn.add(radioButton2);ctn.add(enterButton);ctn.add(resetButton);frame.setVisible(true);frame.setBounds(400,200,800,400);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}publicvoidactionPerformed(ActionEvente){booleantmp=false;Objectsource=e.getSource();if(source==enterButton){try{DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Stringquery="select*fromHost";Statementstmt=db.getStatement(dbPath);ResultSetrs=db.executeQuery(stmt,query);while(rs.next()){if(nameText.getText().equals(rs.getString(1))&&passwordText.getText().equals(rs.getString(2))){tmp=true;Selectselect=newSelect();this.dispose();break;}}stmt.close();db.close();}catch(Exceptionex){ex.printStackTrace();}if(tmp==false){JOptionPane.showMessageDialog(null,"输入密码或用户名错误","登录信息",JOptionPane.INFORMATION_MESSAGE);nameText.setText("");passwordText.setText("");}}elseif(source==resetButton){nameText.setText("");passwordText.setText("");}elseif(source==radioButton1){43
isManager=true;}elseif(source==radioButton2){isManager=false;}}publicvoiddispose(){this.frame.dispose();}publicstaticbooleanisManager(){returnisManager;}publicstaticvoidmain(Stringargs[]){Entertest=newEnter();}}GetDBInfo.java文件importjava.sql.*;importjava.util.Vector;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.ResultSetMetaData;importjava.sql.SQLException;importjava.sql.Statement;importjavax.swing.JOptionPane;publicclassGetDBInfo{privateVector>rows;privateVectorcolumnHeads;//构造函数publicGetDBInfo(StringDBInfo,StringselStr){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Stringdburl="jdbc:odbc:driver={MicrosoftAccessDriver(*.mdb)};"+"DBQ="+DBInfo;//此为NO-DSN方式Connectionconn=DriverManager.getConnection(dburl);Statementstate=conn.createStatement();ResultSetrs=state.executeQuery(selStr);if(!(rs.next()))//判断数据库中是否有内容{JOptionPane.showMessageDialog(null,"结果集中无记录","无记录",JOptionPane.INFORMATION_MESSAGE);}ResultSetMetaDatarsmd=rs.getMetaData();//获得结果集列属性值rows=newVector();columnHeads=newVector();for(inti=1;i<=rsmd.getColumnCount();i++){columnHeads.addElement(rsmd.getColumnName(i));//添加列名}do{rows.addElement(getNextRow(rs,rsmd));//添加表行值}while(rs.next());rs.close();state.close();}catch(Exceptione){e.printStackTrace();}}//获取表头VolumnHeadspublicVectorgetColumnHeads(){returncolumnHeads;}//获取表中内容publicVectorgetRows(){returnrows;}//取得表行的值方法privateVectorgetNextRow(ResultSetrs,ResultSetMetaDatarsmd)throwsSQLException{VectorcurrentRow=newVector();for(inti=1;i<=rsmd.getColumnCount();i++){currentRow.addElement(rs.getString(i));}returncurrentRow;43
}//更新数据库publicvoidexecuteUpdate(Statementstmt,Stringquery)throwsSQLException{stmt.executeUpdate(query);}publicstaticvoidmain(Stringargs[]){GetDBInfotest=newGetDBInfo("E:\study\java\workspace\StoreHouse\StoreHouse.mdb","select*fromPutIn");System.out.println(test.getRows());System.out.println(test.getColumnHeads());}}InStoreHouse.java文件importjava.awt.event.*;importjava.awt.*;importjava.sql.Statement;importjava.text.SimpleDateFormat;importjava.util.Date;importjavax.swing.*;publicclassInStoreHouseimplementsActionListener{privateJFrameframe;privateJTextFieldtext1;privateJTextFieldtext2;privateJTextFieldtext3;privateJTextFieldtext4;privateJTextFieldtext5;privateJTextFieldtext6;privateJTextFieldtext7;privateJTextFieldtext8;privateJTextFieldtext9;privateJTextFieldtext10;privateJTextFieldtext11;privateJTextFieldinfoText;privateJButtonokButton;privateJButtonbackButton;privatestaticfinalStringYYYMMDDHHMMSS="yyyy/MM/ddHH:mm:ss";publicInStoreHouse(){frame=newJFrame("商品入库登记");text1=newJTextField();text2=newJTextField();text3=newJTextField();text4=newJTextField();text5=newJTextField();text6=newJTextField();text7=newJTextField();text8=newJTextField();text9=newJTextField();text10=newJTextField();text11=newJTextField();infoText=newJTextField();okButton=newJButton("确定");backButton=newJButton("返回主菜单");JLabelinfoLabel=newJLabel("填写信息:");JLabellabel1=newJLabel("编号");JLabellabel2=newJLabel("名称");JLabellabel3=newJLabel("数量");JLabellabel4=newJLabel("价格");JLabellabel5=newJLabel("规格");JLabellabel6=newJLabel("体积");JLabellabel7=newJLabel("重量");JLabellabel8=newJLabel("颜色");JLabellabel9=newJLabel("产地");JLabellabel10=newJLabel("种类");JLabellabel11=newJLabel("管理员编号");//颜色格式设置infoLabel.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));label1.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));label1.setHorizontalAlignment(SwingConstants.CENTER);text1.setBackground(Color.lightGray);label2.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));43
label2.setHorizontalAlignment(SwingConstants.CENTER);text2.setBackground(Color.lightGray);label3.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));label3.setHorizontalAlignment(SwingConstants.CENTER);text3.setBackground(Color.lightGray);label4.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));label4.setHorizontalAlignment(SwingConstants.CENTER);text4.setBackground(Color.lightGray);label5.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));label5.setHorizontalAlignment(SwingConstants.CENTER);text5.setBackground(Color.lightGray);label6.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));label6.setHorizontalAlignment(SwingConstants.CENTER);text6.setBackground(Color.lightGray);label7.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));label7.setHorizontalAlignment(SwingConstants.CENTER);text7.setBackground(Color.lightGray);label8.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));label8.setHorizontalAlignment(SwingConstants.CENTER);text8.setBackground(Color.lightGray);label9.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));label9.setHorizontalAlignment(SwingConstants.CENTER);text9.setBackground(Color.lightGray);label10.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));text10.setBackground(Color.lightGray);label11.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));text11.setBackground(Color.lightGray);//infoLabel.setBounds(10,10,120,30);label1.setBounds(40,40,80,30);text1.setBounds(140,40,140,30);label2.setBounds(360,40,80,30);text2.setBounds(460,40,140,30);label3.setBounds(40,100,80,30);text3.setBounds(140,100,140,30);label4.setBounds(360,100,80,30);text4.setBounds(460,100,140,30);label5.setBounds(40,160,80,30);text5.setBounds(140,160,140,30);label6.setBounds(360,160,80,30);text6.setBounds(460,160,140,30);label7.setBounds(40,220,80,30);text7.setBounds(140,220,140,30);label8.setBounds(360,220,80,30);text8.setBounds(460,220,140,30);label9.setBounds(40,280,80,30);text9.setBounds(140,280,140,30);label10.setBounds(650,40,80,30);text10.setBounds(650,100,140,30);label11.setBounds(650,160,80,30);text11.setBounds(650,220,140,30);infoText.setBounds(360,280,360,30);okButton.setBounds(360,320,150,30);backButton.setBounds(570,320,150,30);okButton.addActionListener(this);backButton.addActionListener(this);//整体布局43
Containerctn=frame.getContentPane();ctn.setLayout(null);ctn.add(infoLabel);ctn.add(label1);ctn.add(text1);ctn.add(label2);ctn.add(text2);ctn.add(label3);ctn.add(text3);ctn.add(label4);ctn.add(text4);ctn.add(label5);ctn.add(text5);ctn.add(label6);ctn.add(text6);ctn.add(label7);ctn.add(text7);ctn.add(label8);ctn.add(text8);ctn.add(label9);ctn.add(text9);ctn.add(label10);ctn.add(text10);ctn.add(label11);ctn.add(text11);ctn.add(infoText);ctn.add(okButton);ctn.add(backButton);frame.setVisible(true);//frame.setResizable(false);frame.setBounds(400,200,800,400);frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);System.out.println(getSQL());}//SQL语句生成publicStringgetSQL(){Stringtem=null;tem="insertintoGoods"+"values"+"("+"""+text1.getText()+"""+","+"""+text2.getText()+"""+","+"""+text10.getText()+"""+","+text3.getText()+","+text4.getText()+","+"""+text5.getText()+"""+","+text6.getText()+","+text7.getText()+","+"""+text8.getText()+"""+","+"""+text9.getText()+"""+","+"""+inHouseID()+"""+")";returntem;}publicStringinsertTime(){Stringtmp=null;DatenowDate=newDate();SimpleDateFormatsf=newSimpleDateFormat(YYYMMDDHHMMSS);tmp=sf.format(nowDate).toString();returntmp;}publicStringinHouseID(){returninsertTime()+text1.getText();}publicStringinsertSQL(){Stringtmp=null;tmp="insertintoPutIn"+"values"+"("+"""+inHouseID()+"""+","+"""+text11.getText()+"""+","+"""+insertTime()+"""+")";returntmp;}publicvoidclear(){text1.setText("");text2.setText("");text3.setText("");text4.setText("");text5.setText("");text6.setText("");text7.setText("");text8.setText("");text9.setText("");text10.setText("");}publicvoidactionPerformed(ActionEvente){43
Objectsource=e.getSource();if(source==okButton){try{DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Statementstmt=db.getStatement(dbPath);Stringquery=getSQL();db.executeUpdate(stmt,query);query=insertSQL();db.executeUpdate(stmt,query);stmt.close();db.close();infoText.setText("存储成功");clear();}catch(Exceptionex){ex.printStackTrace();}}elseif(source==backButton){frame.dispose();newSelect();}}publicstaticvoidmain(Stringargs[]){InStoreHousetest=newInStoreHouse();}}ManagerInfo.java文件importjava.awt.*;importjavax.swing.*;importjavax.swing.table.DefaultTableModel;importjava.awt.event.*;importjava.sql.ResultSet;importjava.sql.Statement;importjava.util.Vector;publicclassManagerInfoimplementsActionListener{privateJFrameframe;privateJTabbedPanetabbedPane;privateJLabellabel1;privateJLabellabel2;privateJLabellabel3;privateJPanelpanel1;privateJPanelpanel2;privateJPanelpanel3;privateJComboBoxageBox;privateJComboBoxworkAgeBox;privateJComboBoxpostionBox;privateJTextFieldtext21;privateJTextFieldtext22;privateJTextFieldtext23;privateJTextFieldtext24;privateJTextFieldtext25;privateJTextFieldtext26;privateJTextFieldtext27;privateJTextFieldtext28;privateJTextFieldtext31;privateJTextFieldtext32;privateJButtonbutton11;privateJButtonbutton12;privateJButtonbutton21;privateJButtonbutton31;privateJButtonbackButton;privateJTabletable;privateVectorrows;//表行值privateVectorcolumnHeads;//表列名privateDefaultTableModelmodel;privateJScrollPanejsp;privateStringstr1=null,str2=null,str3=null;//查询使用publicManagerInfo(){frame=newJFrame("管理员信息查询");tabbedPane=newJTabbedPane();label1=newJLabel();label2=newJLabel();label3=newJLabel();panel1=newJPanel();panel2=newJPanel();panel3=newJPanel();43
panel1.add(label1);panel2.add(label2);panel3.add(label3);tabbedPane.addTab("查询信息",null,panel1,"label1");tabbedPane.addTab("录入信息",panel2);tabbedPane.addTab("删除信息",panel3);/**设计查询信息面板*/JLabellabel11=newJLabel("查询条件:");JLabellabel12=newJLabel("年龄");JLabellabel13=newJLabel("工龄");JLabellabel14=newJLabel("职务");button11=newJButton("全部");button12=newJButton("查询");ageBox=newJComboBox();workAgeBox=newJComboBox();postionBox=newJComboBox();//初始化表格StringDBName="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";GetDBInfogetInfo=newGetDBInfo(DBName,"select*fromManager");rows=getInfo.getRows();columnHeads=getInfo.getColumnHeads();model=newDefaultTableModel(rows,columnHeads);//用来修改表格值table=newJTable(model);table.setRowHeight(25);//设置行高table.setGridColor(Color.yellow);//设置边框颜色jsp=newJScrollPane();jsp.setViewportView(table);table.getTableHeader().setReorderingAllowed(false);//设置列不可移动JPaneltablePanel=newJPanel(newGridLayout(1,1));//这里也要注意,必须把整个表放进去tablePanel.add(jsp);//初始化JComboBoxtry{DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Stringquery="selectDISTINCT职务fromManager";Statementstmt=db.getStatement(dbPath);ResultSetrs=db.executeQuery(stmt,query);intb=0;while(rs.next()){postionBox.insertItemAt(rs.getString(1),b);b++;}stmt.close();db.close();}catch(Exceptionex){ex.printStackTrace();}ageBox.insertItemAt("20~25",0);ageBox.insertItemAt("26~30",1);ageBox.insertItemAt("31~35",2);ageBox.insertItemAt("36~40",3);ageBox.insertItemAt("40~",4);workAgeBox.insertItemAt("1~3",0);workAgeBox.insertItemAt("4~7",1);workAgeBox.insertItemAt("8~15",2);workAgeBox.insertItemAt("16~20",3);workAgeBox.insertItemAt("20~",4);//格式设置label11.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));label12.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));43
label13.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));label14.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));label11.setForeground(Color.blue);button11.setBackground(Color.cyan);button12.setBackground(Color.cyan);//布局label11.setBounds(10,5,120,30);label12.setBounds(140,5,100,30);ageBox.setBounds(180,5,80,30);label13.setBounds(280,5,100,30);workAgeBox.setBounds(320,5,80,30);label14.setBounds(420,5,100,30);postionBox.setBounds(460,5,80,30);button11.setBounds(580,5,80,30);button12.setBounds(680,5,80,30);tablePanel.setBounds(10,50,750,250);//这里一定要是面板panel1.setLayout(null);panel1.add(label11);panel1.add(label12);panel1.add(ageBox);panel1.add(label13);panel1.add(workAgeBox);panel1.add(label14);panel1.add(postionBox);panel1.add(button11);panel1.add(button12);panel1.add(tablePanel);/**录入信息面板*/button21=newJButton("提交");text21=newJTextField();text22=newJTextField();text23=newJTextField();text24=newJTextField();text25=newJTextField();text26=newJTextField();text27=newJTextField();text28=newJTextField();text28.setText("请按规定输入信息");JLabellabel29=newJLabel();JLabellabel21=newJLabel("编号:");JLabellabel22=newJLabel("姓名:");JLabellabel23=newJLabel("年龄:");JLabellabel24=newJLabel("性别:");JLabellabel25=newJLabel("工龄:");JLabellabel26=newJLabel("职务:");JLabellabel27=newJLabel("工资:");JLabellabel28=newJLabel();ImageIconicon=newImageIcon("E:\study\java\workspace\StoreHouse\cde.jpg");label28.setIcon(icon);//布局label21.setBounds(30,10,100,30);text21.setBounds(150,10,200,30);label22.setBounds(30,50,100,30);text22.setBounds(150,50,200,30);label23.setBounds(30,90,100,30);text23.setBounds(150,90,200,30);label24.setBounds(30,130,100,30);text24.setBounds(150,130,200,30);label25.setBounds(30,170,100,30);text25.setBounds(150,170,200,30);label26.setBounds(30,210,100,30);text26.setBounds(150,210,200,30);label27.setBounds(30,250,100,30);text27.setBounds(150,250,200,30);label28.setBounds(380,10,420,180);text28.setBounds(380,210,400,30);button21.setBounds(450,250,250,30);panel2.setLayout(null);panel2.add(label21);panel2.add(text21);panel2.add(label22);panel2.add(text22);panel2.add(label23);panel2.add(text23);panel2.add(label24);panel2.add(text24);43
panel2.add(label25);panel2.add(text25);panel2.add(label26);panel2.add(text26);panel2.add(label27);panel2.add(text27);panel2.add(label28);panel2.add(text28);panel2.add(button21);//字体设置label21.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));label22.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));label23.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));label24.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));label25.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));label26.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));label27.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));label29.setHorizontalAlignment(SwingConstants.CENTER);text21.setBackground(Color.lightGray);text22.setBackground(Color.lightGray);text23.setBackground(Color.lightGray);text24.setBackground(Color.lightGray);text25.setBackground(Color.lightGray);text26.setBackground(Color.lightGray);text27.setBackground(Color.lightGray);text28.setBackground(Color.yellow);button21.setBackground(Color.blue);button21.setForeground(Color.red);/**删除信息面板*/text31=newJTextField();text32=newJTextField();text32.setText("数据宝贵,删除后无法找回");button31=newJButton("删除");JLabellabel31=newJLabel("输入删除管理员编号:");//格式设置label31.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));text31.setBackground(Color.lightGray);text32.setBackground(Color.cyan);//布局label31.setBounds(50,50,300,70);text31.setBounds(350,50,300,50);button31.setBounds(50,150,100,50);text32.setBounds(200,150,300,50);panel3.setLayout(null);panel3.add(label31);panel3.add(text31);panel3.add(text32);panel3.add(button31);/**整体布局*/label1.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));label2.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));label3.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));backButton=newJButton("返回主菜单");//增加监听器button11.addActionListener(this);button12.addActionListener(this);button21.addActionListener(this);button31.addActionListener(this);backButton.addActionListener(this);ageBox.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){intindex=ageBox.getSelectedIndex();43
if(index==0){str1="between20and25";}elseif(index==1){str1="between26and30";}elseif(index==2){str1="between31and35";}elseif(index==3){str1="between36and40";}elseif(index==4){str1=">40";}}});workAgeBox.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){intindex=workAgeBox.getSelectedIndex();if(index==0){str2="between1and3";}elseif(index==1){str2="between4and7";}elseif(index==2){str2="between8and15";}elseif(index==3){str2="between16and20";}elseif(index==4){str2=">20";}}});postionBox.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){JComboBoxsource=(JComboBox)e.getSource();str3=(String)source.getSelectedItem();}});Containerctn=frame.getContentPane();ctn.setLayout(newBorderLayout());ctn.add(tabbedPane,BorderLayout.CENTER);ctn.add(backButton,BorderLayout.SOUTH);frame.setBounds(400,200,800,400);frame.setVisible(true);frame.setResizable(false);frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}publicvoidactionPerformed(ActionEvente){//处理按钮事件Objectsource=e.getSource();if(source==button11){StringDBInfo="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";GetDBInfoDB=newGetDBInfo(DBInfo,"select*fromManager");rows=DB.getRows();columnHeads=DB.getColumnHeads();model=newDefaultTableModel(rows,columnHeads);//用来修改表格值table=newJTable(model);jsp.setViewportView(table);}elseif(source==button12){try{if(str1==null)str1="isnotnull";if(str2==null)str2="isnotnull";if(str3==null)str3="isnotnull";StringDBInfo="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";GetDBInfoDB=new43
GetDBInfo(DBInfo,getSQL1());rows=DB.getRows();columnHeads=DB.getColumnHeads();model=newDefaultTableModel(rows,columnHeads);//用来修改表格值table=newJTable(model);jsp.setViewportView(table);}catch(Exceptionex){ex.printStackTrace();}System.out.println(getSQL1());}elseif(source==button21){try{DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Stringquery=getSQL2();Statementstmt=db.getStatement(dbPath);db.executeUpdate(stmt,query);stmt.close();db.close();text28.setText("存储成功");clear2();}catch(Exceptionex){ex.printStackTrace();}}elseif(source==button31){booleandeleteState=false;try{DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Stringquery="select*fromManagerwhere编号="+"""+text31.getText()+""";Statementstmt=db.getStatement(dbPath);ResultSetrs=db.executeQuery(stmt,query);while(rs.next()){if(rs.getString(1).equals(text31.getText())){query="deletefromManagerwhere编号="+"""+text31.getText()+""";db.executeUpdate(stmt,query);text31.setText("");text32.setText("删除成功");deleteState=true;}}stmt.close();db.close();}catch(Exceptionex){ex.printStackTrace();}if(deleteState==false){text32.setText("输入编号不存在");text31.setText("");}}elseif(source==backButton){frame.dispose();newSelect();}}publicvoiddispose(){this.frame.dispose();}publicvoidclear2(){text21.setText("");text22.setText("");text23.setText("");text24.setText("");text25.setText("");text26.setText("");text27.setText("");}publicStringgetSQL1(){Stringtmp=null;tmp="select*fromManagerwhere"43
+"年龄"+str1+"OR工龄"+str2+"OR职务=""+str3+""";returntmp;}publicStringgetSQL2(){Stringtmp=null;tmp="insertintoManager"+"values"+"("+"""+text21.getText()+"""+","+"""+text22.getText()+"""+","+text23.getText()+","+"""+text24.getText()+"""+","+text25.getText()+","+"""+text26.getText()+"""+","+text27.getText()+")";returntmp;}publicbooleanisExist(Stringstr){booleantmp=false;try{DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Stringquery="select姓名fromManagerInfo";Statementstmt=db.getStatement(dbPath);ResultSetrs=db.executeQuery(stmt,query);while(rs.next()){if(str.equals(rs.getString(1).toString())){tmp=true;break;}}stmt.close();db.close();}catch(Exceptionex){ex.printStackTrace();}returntmp;}publicstaticvoidmain(Stringargs[]){ManagerInfotest=newManagerInfo();}}OutIn文件:importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;importjava.sql.ResultSet;importjava.sql.Statement;importjava.text.SimpleDateFormat;importjava.util.Date;importjava.util.Calendar;importjava.util.StringTokenizer;importjava.util.Vector;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.JComboBox;importjavax.swing.JScrollPane;importjavax.swing.JTable;importjavax.swing.SwingConstants;importjavax.swing.table.AbstractTableModel;importjavax.swing.table.DefaultTableModel;publicclassOutInimplementsActionListener{privateJFrameframe;privateJRadioButtoninButton;privateJRadioButtonoutButton;privateJButtonokButton;privateJButtonbackButton;privateJComboBoxcombox1;privateJComboBoxcombox2;privateJTabletable;privateVectorrows;//表行值privateVectorcolumnHeads;//表列名privateDefaultTableModelmodel;privateJScrollPanejsp;privateStringstr1=null,str2=null;//查询使用privatebooleanflag=false;privateinttmp=0;privatestaticfinalStringYYYMMDDHHMMSS=43
"yyyy/MM/dd";publicOutIn(){frame=newJFrame("入库出库查询");inButton=newJRadioButton("入库查询",true);outButton=newJRadioButton("出库查询",false);okButton=newJButton("查询");backButton=newJButton("返回主菜单");ButtonGroupgroup=newButtonGroup();group.add(inButton);group.add(outButton);JLabellabel1=newJLabel("选择操作:");JLabellabel2=newJLabel("时间");JLabellabel3=newJLabel("管理员");combox1=newJComboBox();combox2=newJComboBox();//初始化JComboBoxcombox1.insertItemAt("当前",0);combox1.insertItemAt("三天内",1);combox1.insertItemAt("半月内",2);combox1.insertItemAt("一个月内",3);combox1.insertItemAt("三个月内",4);combox1.insertItemAt("全部",5);try{DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Stringquery="selectDISTINCT管理员编号fromPutIn";Statementstmt=db.getStatement(dbPath);ResultSetrs=db.executeQuery(stmt,query);intb=0;while(rs.next()){combox2.insertItemAt(rs.getString(1),b);b++;}stmt.close();db.close();}catch(Exceptionex){ex.printStackTrace();}//初始化TableStringDBName="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";GetDBInfogetInfo=newGetDBInfo(DBName,"select*fromPutIn");rows=getInfo.getRows();columnHeads=getInfo.getColumnHeads();model=newDefaultTableModel(rows,columnHeads);//用来修改表格值JTabletable=newJTable(model);table.setRowHeight(25);//设置行高table.setGridColor(Color.yellow);//设置边框颜色jsp=newJScrollPane();jsp.setViewportView(table);table.getTableHeader().setReorderingAllowed(false);//设置列不可移动JPaneltablePanel=newJPanel(newGridLayout(1,1));tablePanel.add(jsp);//格式设置label1.setHorizontalAlignment(SwingConstants.CENTER);label1.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));label2.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));label3.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));label1.setForeground(Color.red);label2.setForeground(Color.blue);label3.setForeground(Color.blue);43
okButton.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));okButton.setForeground(Color.cyan);backButton.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));//布局label1.setBounds(10,10,200,30);inButton.setBounds(160,10,80,30);outButton.setBounds(240,10,80,30);label2.setBounds(340,10,50,30);combox1.setBounds(390,10,80,30);label3.setBounds(500,10,50,30);combox2.setBounds(550,10,80,30);okButton.setBounds(650,10,100,30);tablePanel.setBounds(10,50,760,270);backButton.setBounds(600,320,150,40);//增加监听器inButton.addActionListener(this);outButton.addActionListener(this);backButton.addActionListener(this);okButton.addActionListener(this);combox1.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){Calendardate=Calendar.getInstance();intindex=combox1.getSelectedIndex();if(index==0){date.add(Calendar.DAY_OF_MONTH,0);tmp=0;}elseif(index==1){date.add(Calendar.DAY_OF_MONTH,-3);tmp=3;}elseif(index==2){date.add(Calendar.DAY_OF_MONTH,-15);tmp=15;}elseif(index==3){date.add(Calendar.DAY_OF_MONTH,-30);tmp=30;}elseif(index==4){date.add(Calendar.DAY_OF_MONTH,-90);tmp=90;}elseif(index==5){date.add(Calendar.DAY_OF_MONTH,-360);tmp=360;}SimpleDateFormatformatter=newSimpleDateFormat(YYYMMDDHHMMSS);str1=formatter.format(date.getTime());}});combox2.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){JComboBoxsource=(JComboBox)e.getSource();str2=(String)source.getSelectedItem();if(str2==null)str2="isnotnull";}});//整体布局Containerctn=frame.getContentPane();ctn.setLayout(null);ctn.add(label1);ctn.add(inButton);43
ctn.add(outButton);ctn.add(label2);ctn.add(combox1);ctn.add(label3);ctn.add(combox2);ctn.add(okButton);ctn.add(tablePanel);ctn.add(backButton);frame.setResizable(false);frame.setBounds(400,200,800,400);frame.setVisible(true);frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}publicvoiddispose(){this.frame.dispose();}publicvoidactionPerformed(ActionEvente){Objectsource=e.getSource();if(source==inButton){//改变管理员下拉菜单try{DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Stringquery="selectDISTINCT管理员编号fromPutIn";Statementstmt=db.getStatement(dbPath);ResultSetrs=db.executeQuery(stmt,query);intb=0;while(rs.next()){combox2.insertItemAt(rs.getString(1),b);b++;}stmt.close();db.close();}catch(Exceptionex){ex.printStackTrace();}//flag=true;StringDBName="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";GetDBInfogetInfo=newGetDBInfo(DBName,"select*fromPutIn");rows=getInfo.getRows();columnHeads=getInfo.getColumnHeads();model=newDefaultTableModel(rows,columnHeads);//用来修改表格值JTabletable=newJTable(model);jsp.setViewportView(table);}elseif(source==outButton){//改变管理员编号下拉菜单try{DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Stringquery="selectDISTINCT管理员编号fromSendOut";Statementstmt=db.getStatement(dbPath);ResultSetrs=db.executeQuery(stmt,query);intb=0;while(rs.next()){combox2.insertItemAt(rs.getString(1),b);b++;}stmt.close();db.close();}catch(Exceptionex){ex.printStackTrace();}flag=false;43
StringDBName="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";GetDBInfogetInfo=newGetDBInfo(DBName,"select*fromSendOut");rows=getInfo.getRows();columnHeads=getInfo.getColumnHeads();model=newDefaultTableModel(rows,columnHeads);//用来修改表格值JTabletable=newJTable(model);jsp.setViewportView(table);}elseif(source==okButton){try{StringDBName="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";GetDBInfogetInfo=newGetDBInfo(DBName,getSQL());rows=getInfo.getRows();columnHeads=getInfo.getColumnHeads();model=newDefaultTableModel(rows,columnHeads);//用来修改表格值table=newJTable(model);jsp.setViewportView(table);}catch(Exceptionex){ex.printStackTrace();}}elseif(source==backButton){this.dispose();newSelect();}}publicStringgetTableName(){Stringtable=null;if(flag){table="PutIn";}else{table="SendOut";}returntable;}publicStringgetSQL(){Stringtmp=null;Stringtable=null;if(flag){table="PutIn";}else{table="SendOut";}tmp="select*from"+table+"where管理员编号=""+str2+""";returntmp;}publicstaticvoidmain(Stringargs[]){OutIntest=newOutIn();}}OutStoreHouse.java文件importjava.awt.Color;importjava.awt.Container;importjava.awt.Font;importjava.awt.event.*;importjava.sql.ResultSet;importjava.sql.Statement;importjava.text.SimpleDateFormat;importjava.util.Date;importjavax.swing.*;publicclassOutStoreHouseimplementsActionListener{privateJFrameframe;privateJButtonokButton;privateJButtonbackButton;privateJTextFieldtext1;privateJTextFieldtext2;privateJTextFieldtext3;privateJTextFieldtext4;privatestaticfinalStringYYYMMDDHHMMSS="yyyy/MM/ddHH:mm:ss";43
privateIntegernum;OutStoreHouse(){frame=newJFrame("物品出库管理");text1=newJTextField();text2=newJTextField();text3=newJTextField();text4=newJTextField();okButton=newJButton("确定");backButton=newJButton("返回主菜单");JLabellabel1=newJLabel("物品编号");JLabellabel2=newJLabel("数量");JLabellabel3=newJLabel("信息");JLabellabel4=newJLabel("出库管理员");//格式设置label1.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));label1.setHorizontalAlignment(SwingConstants.CENTER);text1.setBackground(Color.lightGray);label2.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));label2.setHorizontalAlignment(SwingConstants.CENTER);text2.setBackground(Color.lightGray);label3.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));label3.setHorizontalAlignment(SwingConstants.CENTER);text3.setBackground(Color.lightGray);label4.setFont(newFont("仿宋",Font.CENTER_BASELINE,20));label4.setHorizontalAlignment(SwingConstants.CENTER);text4.setBackground(Color.lightGray);okButton.setBackground(Color.red);okButton.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));backButton.setBackground(Color.red);backButton.setFont(newFont("仿宋",Font.CENTER_BASELINE,15));//布局label1.setBounds(50,20,150,40);text1.setBounds(250,20,200,40);label2.setBounds(50,90,150,40);text2.setBounds(250,90,200,40);label4.setBounds(50,160,150,40);text4.setBounds(250,160,200,40);label3.setBounds(50,230,150,40);text3.setBounds(250,230,400,40);okButton.setBounds(300,300,150,40);backButton.setBounds(500,300,150,40);//增加监听器okButton.addActionListener(this);backButton.addActionListener(this);Containerctn=frame.getContentPane();ctn.setLayout(null);ctn.add(label1);ctn.add(label2);ctn.add(label3);ctn.add(label4);ctn.add(text1);ctn.add(text2);ctn.add(text3);ctn.add(text4);ctn.add(okButton);ctn.add(backButton);frame.setVisible(true);frame.setBounds(400,200,800,400);frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);43
}publicvoidactionPerformed(ActionEvente){Objectsource=e.getSource();if(source==okButton){try{DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Stringquery=getGoodsSQL();Statementstmt=db.getStatement(dbPath);ResultSetrs=db.executeQuery(stmt,query);if(!(rs.next()))//判断数据库中是否有内容{JOptionPane.showMessageDialog(null,"输入货物编号不存在","提示信息",JOptionPane.INFORMATION_MESSAGE);text3.setText("操作失败");clear();}else{//判断仓库物品是否够//这里实验了很多次为什么只有num=放在这里才可以呢//?????if((num=Integer.valueOf(rs.getString(1)).intValue()-Integer.valueOf(text2.getText()).intValue())<0){JOptionPane.showMessageDialog(null,"仓库货物不足","提示信息",JOptionPane.INFORMATION_MESSAGE);clear();text3.setText("操作失败");}else{query=getSendOutSQL();db.executeUpdate(stmt,query);query=updateGoodsSQL(num);db.executeUpdate(stmt,query);text3.setText("操作成功");}}stmt.close();db.close();}catch(Exceptionex){ex.printStackTrace();}}elseif(source==backButton){frame.dispose();newSelect();}}//出库时间publicStringoutStoreTime(){Stringtmp=null;DatenowDate=newDate();SimpleDateFormatsf=newSimpleDateFormat(YYYMMDDHHMMSS);tmp=sf.format(nowDate).toString();returntmp;}//自动生成出库编号publicStringoutHouseID(){returnoutStoreTime()+text1.getText();}publicStringgetGoodsSQL(){Stringtmp=null;tmp="select数量fromGoodswhere编号="+"""+text1.getText().toString()+""";returntmp;}//生成修改出库表的SQL语言publicStringgetSendOutSQL(){Stringtmp=null;tmp="insertintoSendOutvalues(""+43
outHouseID()+"",""+text4.getText().toString()+"",""+outStoreTime()+"")";;returntmp;}//修改Goods物品表SQL语言publicStringupdateGoodsSQL(Integernum){Stringtmp=null;tmp="updateGoodsset数量="+num+"where编号=""+text1.getText()+""";returntmp;}//清除Text内容publicvoidclear(){text1.setText("");text2.setText("");text4.setText("");}publicstaticvoidmain(Stringargs[]){OutStoreHousetest=newOutStoreHouse();}}SearchGoods.java文件importjava.awt.*;importjava.awt.event.*;importjava.sql.ResultSet;importjava.sql.Statement;importjava.util.Vector;importjavax.swing.*;importjavax.swing.table.DefaultTableModel;publicclassSearchGoodimplementsActionListener{privateJFrameframe;privateJScrollPanejsp;privateJComboBoxnameList;privateJComboBoxtypeList;privateJComboBoxproductList;privateJTextFieldcountText;privateJTextFieldvalueText;privateJButtonokButton;privateJTabletable;privateDefaultTableModelmodel;privateJButtonbackButton;privateVectorrows;//表行值privateVectorcolumnHeads;//表列名//查询使用Stringstr1,str2,str3;publicSearchGood()throwsException{frame=newJFrame("库存物品查询");nameList=newJComboBox();typeList=newJComboBox();productList=newJComboBox();okButton=newJButton("确定");backButton=newJButton("返回");countText=newJTextField();valueText=newJTextField();JLabellabel=newJLabel("输入查询条件:");JLabellabel3=newJLabel("产地");JLabellabel2=newJLabel("种类");JLabellabel1=newJLabel("名称");JLabellabel4=newJLabel("总金额");JLabellabel5=newJLabel("总数量");label.setHorizontalAlignment(SwingConstants.CENTER);label1.setHorizontalAlignment(SwingConstants.CENTER);label2.setHorizontalAlignment(SwingConstants.CENTER);;label3.setHorizontalAlignment(SwingConstants.CENTER);label4.setHorizontalAlignment(SwingConstants.CENTER);label5.setHorizontalAlignment(SwingConstants.CENTER);backButton.setBackground(Color.blue);//List设置try{DBAccessdb=newDBAccess();43
StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Stringquery="selectDISTINCT种类fromGoods";Statementstmt=db.getStatement(dbPath);ResultSetrs=db.executeQuery(stmt,query);intb=0;while(rs.next()){typeList.insertItemAt(rs.getString(1),b);b++;}query="selectDISTINCT名称fromGoods";rs=db.executeQuery(stmt,query);b=0;while(rs.next()){nameList.insertItemAt(rs.getString(1),b);b++;}query="selectDISTINCT产地fromGoods";rs=db.executeQuery(stmt,query);b=0;while(rs.next()){productList.insertItemAt(rs.getString(1),b);b++;}stmt.close();db.close();}catch(Exceptionex){ex.printStackTrace();}//连接数据库,并获取信息StringDBName="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";GetDBInfogetInfo=newGetDBInfo(DBName,"select*fromGoods");rows=getInfo.getRows();columnHeads=getInfo.getColumnHeads();model=newDefaultTableModel(rows,columnHeads);//用来修改表格值table=newJTable(model);table.setRowHeight(25);//设置行高table.setGridColor(Color.yellow);//设置边框颜色jsp=newJScrollPane();jsp.setViewportView(table);table.getTableHeader().setReorderingAllowed(false);//设置列不可移动/**监听器*/okButton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){try{StringDBInfo="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";GetDBInfoDB=newGetDBInfo(DBInfo,getSQL(str1,str2,str3));rows=DB.getRows();columnHeads=DB.getColumnHeads();model=newDefaultTableModel(rows,columnHeads);//用来修改表格值table=newJTable(model);jsp.setViewportView(table);}catch(Exceptionex){ex.printStackTrace();}//统计数量和总价格try{43
intcountSum=0;doublecountPrice=0.0;DBAccessdb=newDBAccess();StringdbPath="E:\study\java\workspace\StoreHouse\StoreHouse.mdb";Statementstmt=db.getStatement(dbPath);ResultSetrs=db.executeQuery(stmt,getSQL(str1,str2,str3));while(rs.next()){countSum+=rs.getInt(4);countPrice+=rs.getDouble(5);}System.out.println(countSum);countText.setText(String.valueOf(countSum));valueText.setText(String.valueOf(countPrice));stmt.close();db.close();}catch(Exceptionex){System.out.println("chucuole");}}});backButton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){frame.dispose();newSelect();}});nameList.addActionListener(this);typeList.addActionListener(this);productList.addActionListener(this);/**局部布局*/JPanelselectPanel=newJPanel();selectPanel.setLayout(newGridLayout(1,8));selectPanel.add(label);selectPanel.add(label2);selectPanel.add(typeList);selectPanel.add(label1);selectPanel.add(nameList);selectPanel.add(label3);selectPanel.add(productList);selectPanel.add(okButton);JPaneltotalPanel=newJPanel();totalPanel.setLayout(newGridLayout(1,5));totalPanel.add(label4);totalPanel.add(valueText);totalPanel.add(label5);totalPanel.add(countText);totalPanel.add(backButton);Containerctn=frame.getContentPane();ctn.setLayout(newBorderLayout());ctn.add(selectPanel,BorderLayout.NORTH);ctn.add(jsp,BorderLayout.CENTER);ctn.add(totalPanel,BorderLayout.SOUTH);frame.setBounds(400,200,900,400);frame.setVisible(true);frame.setResizable(false);frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}publicStringgetSQL(Stringstr1,Stringstr2,Stringstr3){Stringtmp=null;tmp="select*fromGoodswhere种类=""+str1+""AND名称=""+str2+""AND产地=""+str3+""";returntmp;}publicvoidactionPerformed(ActionEvente){JComboBoxsource=(JComboBox)e.getSource();if(source==typeList){str1=(String)source.getSelectedItem();if(str1==null)str1="isnotnull";43
}elseif(source==nameList){str2=(String)source.getSelectedItem();if(str2==null)str2="isnotnull";}elseif(source==productList){str3=(String)source.getSelectedItem();if(str3==null)str3="isnotnull";}}publicvoiddispose(){this.frame.dispose();}publicstaticvoidmain(Stringargs[])throwsException{SearchGoodtest=newSearchGood();}}Select.java文件:importjavax.swing.event.*;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclassSelectimplementsActionListener{privateJButtonbutton1;privateJButtonbutton2;privateJButtonbutton3;privateJButtonbutton4;privateJButtonbutton5;privateJButtonbutton6;privateJTextFieldText;privateJFrameframe;publicSelect(){frame=newJFrame("选择操作面板");button1=newJButton("入库登记管理");button2=newJButton("库存物品查询");button3=newJButton("出库入库查询");button4=newJButton("出库登记管理");button5=newJButton("管理员信息");button6=newJButton("注销");Text=newJTextField();Text.setText("注意:蓝色按钮项目为管理员专用");JLabeliconLabel=newJLabel();JLabelinfoLabel=newJLabel();ImageIconicon=newImageIcon("E:\study\java\workspace\StoreHouse\bcd.jpg");iconLabel.setIcon(icon);infoLabel.setText("中心软件,让您选择无悔的软件,感谢支持");JLabellabel=newJLabel("选择您的操作:");/**字体等格式设置*/Fontf1=newFont("宋体",Font.PLAIN,40);label.setFont(f1);label.setForeground(Color.blue);Fontf2=newFont("仿宋",Font.PLAIN,20);button1.setBackground(Color.cyan);button1.setFont(f2);button2.setBackground(Color.yellow);button2.setFont(f2);button3.setBackground(Color.yellow);button3.setFont(f2);button4.setBackground(Color.cyan);button4.setFont(f2);button5.setBackground(Color.cyan);button5.setFont(f2);button6.setFont(newFont("华文行楷",Font.ITALIC,30));infoLabel.setHorizontalAlignment(SwingConstants.CENTER);infoLabel.setBackground(Color.gray);Text.setBackground(Color.gray);Text.setForeground(Color.cyan);Text.setFont(newFont("宋体",Font.HANGING_BASELINE,20));/**局部布局*/JPanelpanel1=newJPanel();panel1.setLayout(newGridLayout(1,5));panel1.add(button1);panel1.add(button4);panel1.add(button5);43
panel1.add(button2);panel1.add(button3);JPanelpanel3=newJPanel(newGridLayout(1,2));panel3.add(label);panel3.add(Text);JPanelpanel2=newJPanel();panel2.setLayout(newGridLayout(3,1));panel2.add(panel3);panel2.add(panel1);panel2.add(button6);/**增加监听器*/button1.addActionListener(this);button2.addActionListener(this);button3.addActionListener(this);button4.addActionListener(this);button5.addActionListener(this);button6.addActionListener(this);Text.addActionListener(this);/**整体布局*/Containerctn=frame.getContentPane();ctn.setLayout(newBorderLayout());ctn.add(iconLabel,BorderLayout.NORTH);ctn.add(panel2,BorderLayout.CENTER);ctn.add(infoLabel,BorderLayout.SOUTH);frame.setBounds(400,200,800,400);frame.setVisible(true);frame.setResizable(false);frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}publicvoiddispose(){frame.dispose();}publicvoidsetVisble(booleane){frame.setVisible(e);}publicvoidactionPerformed(ActionEvente){Objectsource=e.getSource();if(source==button1){InStoreHouseinStoreHouse=newInStoreHouse();frame.setVisible(false);}elseif(source==button2){try{SearchGoodsearchGood=newSearchGood();frame.setVisible(false);}catch(Exceptionex){ex.printStackTrace();}}elseif(source==button3){try{OutIninOut=newOutIn();frame.setVisible(false);}catch(Exceptionex){ex.printStackTrace();}}elseif(source==button4){try{OutStoreHouseouStoreHouse=newOutStoreHouse();frame.setVisible(false);}catch(Exceptionex){ex.printStackTrace();}}elseif(source==button5){try{ManagerInfomanagerInfo=newManagerInfo();frame.dispose();}catch(Exceptionex){ex.printStackTrace();}}elseif(source==button6){this.dispose();}}publicstaticvoidmain(Stringargs[]){Selecttest=newSelect();}}43
43