资源描述
《JAVA程序设计》
课程设计报告
设计题目:商场库存管理系统设计与实现
学院名称: 信息工程学院
专业班级: 13计本2
姓 名: 刘 飞
学 号: 1312210243
目录
一 需求分析。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。3
二 概要设计。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。3
2.1概要设计原则。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。3
2.2.将用户模块需求化。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。3
2.3.最终确定。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。3
三 系统主要功能模块设计。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。4
3..1 登录流程。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。6
3.2.数据库管理。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。8
四 数据库文件。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。10
五程序的主要界面及程序代码。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。15
5.1.用户登录界面。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。15
5.2.商品信息管理界面。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。16
5.2.1.查找界面。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。17
5.2.2添加界面.。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。17
5.2.3删除界面.。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。18
5.2.1修改界面.。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。18
六 总结。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。19
参考资料:.......................................................17
一 需求分析
本系统的主要目的就是实现商品信息管理,使商品信息管理工作更加容易,从而提高工作效率,降低管理成本.
系统中需要对商品价格,数量进行管理,及库存量等。.
二 概要设计
/************************************************************************
概要设计阶段主要是粗略描述整个软件的框架,并从业务的角度描述软件的模块、工作流程等。项目的成功取决于设计的好坏,而概要设计则是整个设计的关键部分。概要设计的主要任务是将用户的需求划分为不同的功能,然后将这些功能细分成模块,并给模块一些规则约束,以达到各个模块之间可以相互交流的目的。概要设计关乎到系统的整体架构,因此想做好一个概要设计,不仅仅要熟悉用户的业务流程,还要具备相当丰富的设计经验。
2.1 概要设计的原则
概要设计是根据系统分析的需求和工作环境的情况对整个软件的总体结构进行大致的设计。概要设计要坚持以下几个原则。
(1)细分原则:软件系统都是由很多不同的模块组成,当设计一套软件时,要先将所有的功能分解。解决复杂问题的方法是将其分解成几个小问题,一个个来解决。
(2)提高代码重用性:在面向对象设计中,首先考虑的就是代码的重用,一个好的设计,将来在升级换代时不需要太大的改动,节省了人力物力。
(3)从上而下层层分析:概要设计要从整体出发,逐个剖析软件的功能,从上而下,先分析系统总的功能,然后一步步细分,直到最小的功能模块。
(4)一致性原则:概要设计要求所有功能模块在定义时使用统一的规范。
(5)提高独立性,减少耦合:各个模块与模块之间尽量减少关联,否则修改一个地方就会引起其他多处的变动,不符合面向对象的原则。一般情况下,对类封装后,只允许对类进行扩展,而不能修改,而封装的类必须具有单一职责,既理论情况下不允许两个类共同完成一个功能。
(6)模块的大小要尽量适中:不是结构算法越复杂的模块越好,模块的大小要根据实际工作目标和其他类的耦合紧密程度来决定。经验表明,一个模块的规模不应过大,模块的总行数应控制在10~100行的范围内,最好为30~60行,这样理解和阅读都较方便。过长的模块往往是分解不充分的表现,会增加阅读理解的难度;但小规模太多也会使模块之间联系变得复杂,增大系统在模块调用时传递信息所花费的开销。
由于概要设计是整个设计的重中之重,牵一发而动全身,所以要努力做一个好的概要设计,才能在今后软件开发过程中不再反复。现在软件行业流行模式化驱动设计,将一些市场上比较成功的模式拿来用在自己的设计中。
2.2 将用户需求模块化
根据概要设计的原则来分析一下本项目的用户需求,并最终转化成用程序语言描述的模块。什么样的需求才是一个模块?模块应该具备如下3个特征。
(1)输入和输出:模块必须能被调用并且正确的返回调用,而且调用都是相对一个对象而言,这是模块独立性的一个体现。
(2)处理功能:模块必须可以对调用的输入数据进行灵活的处理,并为输出准备好处理结果。
(3)程序代码:用来实现模块功能的源代码。
2.3 确定系统最终模块
概要设计中最重要的就是确定此项目包括哪些模块。根据上两节讲述的设计原则和模块特征,将用户需求转化为下面的模块。
/*****************************************************************
三, 系统主要功能模块设计
1.1 登录模块流程
本模块的主要功能是对用户身份进行验证,只有系统的合法用户才能进入系统。在进行系统登录过程中,登录模块将调用数据库里的用户清单,并对账号和密码进行验证,只有输入了正确的账号和密码后,系统登录才会成功。并在输入了错误的或者是不存在的账户和密码时,系统会提示出错信息,指明登录过程中的错误输入或者错误操作,以便用户进行正确的登录。系统登录模块流程如图4.1所示。
1.2库存管理流程
功能:本模块的主要功能是商品信息的查询和更新,库存信息的查询和更新。
查询商品信息:主要功能查询商品的明细信息,和它的库存信息。
添加商品信息:主要功能添加新进的商品。
修改商品信息:主要功能是修改商品的信息,包括他的库存数量。
删除商品信息:主要功能是删除不再销售的商品信息。
输入项、输出项:本模块的数据输入项主要是商品编号。
库存管理流程如图4.4所示
确定登录
商品更改删除
商品查询
添加商品
商品数据库
系统数据流图
四,数据文件(或数据库)设计
表1
表2
五,程序的主要界面、代码实现
1. 用户登录界面:
1.1 输入用户编号和密码后,可以登录,可以关闭窗口,也可以重置
1.2若密码和用户名输入不正确,将显示提示对话框
2 .登录成功后系统
2.1登录成功后将显示提示语句:
2.2并自动进入商场库存管理界面:
2.3查询界面:
2.4删除界面:
2.5添加界面:
2.6修改界面
3.1这是Gread类,用于连接数据库
package work;
import java.sql.*;
public class Gread{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public Gread(){
try{
String driverClassName = "com.mysql.jdbc.Driver";
Class.forName("com.mysql.jdbc.Driver");
//2.连接数据库
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase","root","");
stmt=conn.createStatement();
}catch(Exception ex){
ex.printStackTrace();
}
}
ResultSet executeQuery(String sql){//查询
try{
rs=stmt.executeQuery(sql);
}catch(Exception e){System.out.println(e);}
return rs;
}
void executeUpdate(String sql){//修改
try{
stmt.executeUpdate(sql);
}catch(SQLException e){}
}
void close(){//关闭
try{
stmt.close();
conn.close();
}catch(SQLException e){}
}
}
3.2这是商品库存管理界面类
package work;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.sql.*;
public class Gul extends JFrame implements ActionListener{
BorderLayout BL=new BorderLayout();
JButton jq=new JButton();//查询
JButton ji=new JButton();//插入
JButton jd=new JButton();//删除
JButton jo=new JButton();//编辑
JButton ju=new JButton();//修改
JPanel jp=new JPanel();
JLabel L1=new JLabel();
JLabel L2=new JLabel();
JLabel L3=new JLabel();
JLabel L4=new JLabel();
JLabel L5=new JLabel();
JLabel ts=new JLabel();
JTextField id=new JTextField();
JTextField name=new JTextField();
JTextField number=new JTextField();
JTextField sid=new JTextField();
ResultSet rs=null;
public Gul(){
try{
jbInit();
}catch(Exception a){
a.printStackTrace();
}
}
private void jbInit()throws Exception{
getContentPane().setLayout(BL);
this.setTitle("商场库存管理系统");
jp.setLayout(null);
jp.setBackground(Color.pink);
L1.setText("商品编号:");
L1.setBounds(new Rectangle(8,103,71,30));
L2.setText("数量:");
L2.setBounds(new Rectangle(6,175,42,15));
L3.setText("商品名:");
L3.setBounds(new Rectangle(6,144,42,15));
L4.setText("查询条件:");
L4.setBounds(new Rectangle(4,27,86,22));
L5.setText("商品编号:");
L5.setBounds(new Rectangle(42,52,73,24));
id.setEditable(false);
id.setBounds(new Rectangle(48,109,124,22));
name.setEditable(false);
name.setBounds(new Rectangle(48,143,124,22));
number.setEditable(false);
number.setBounds(new Rectangle(47,174,125,23));
sid.setBounds(new Rectangle(82,55,110,20));
ts.setBounds(new Rectangle(9,281,237,34));
ji.setEnabled(false);
ju.setEnabled(false);
jd.setEnabled(false);
jd.setDoubleBuffered(true);
this.getContentPane().add(jp,java.awt.BorderLayout.CENTER);
jq.setBounds(new Rectangle(216,53,79,23));
ji.setBounds(new Rectangle(20,229,72,23));
ju.setBounds(new Rectangle(133,230,76,23));
jo.setBounds(new Rectangle(217,173,79,23));
jd.setBounds(new Rectangle(245,231,74,23));
jq.setText("查询");
jq.addActionListener(this);
ju.setText("修改");
ju.addActionListener(this);
ji.setText("添加");
ji.addActionListener(this);
jo.setText("编辑");
jo.addActionListener(this);
jd.setText("删除");
jd.addActionListener(this);
jp.add(L1);
jp.add(id);
jp.add(name);
jp.add(number);
jp.add(L5);
jp.add(sid);
jp.add(L4);
jp.add(jq);
jp.add(ji);
jp.add(jo);
jp.add(L3);
jp.add(L2);
jp.add(jd);
jp.add(ju);
jp.add(ts);
this.setSize(500,400);
this.setVisible(true);
}
public static void main(String args[]){
Gul F=new Gul();
}
public void actionPerformed(ActionEvent e){
ts.setText("");
if(e.getSource()==jq){//查询
String s=sid.getText().trim();
String sql="select * from user where id='"+s+"'";
Gread db=new Gread();
rs=db.executeQuery(sql);
try{
while(rs.next()){
id.setText(rs.getString(1));
name.setText(rs.getString(2));
number.setText(rs.getString(3));
}
rs.close();
if(!id.getText().equals(""))
ts.setText("操作成功!");
}catch(SQLException ex){}
}
else if(e.getSource()==jo){//编辑
id.setEditable(true);
name.setEditable(true);
number.setEditable(true);
ji.setEnabled(true);
ju.setEnabled(true);
jd.setEnabled(true);
}
else if(e.getSource()==ji){//添加
String s1=id.getText();
String s2=name.getText();
int s3=Integer.parseInt(number.getText());
String sql="insert into number values("+s1+","+s2+","+s3+")";
System.out.println(sql);
Gread db=new Gread();
db.executeUpdate(sql);
ts.setText("操作成功!");
}
else if(e.getSource()==ju){//修改
String s1=id.getText();
String s2=name.getText();
int s3=Integer.parseInt(number.getText());
String sql="update number set name="+s2+",number="+s3+"where id="+s1+"";
Gread db=new Gread();
db.executeUpdate(sql);
ts.setText("操作成功!");
}
else if(e.getSource()==jd){//删除
String s1=id.getText();
String s2=name.getText();
int s3=Integer.parseInt(number.getText());
String sql="delete number where id="+s1+"and name="+s2+"and numer="+s3;
Gread db=new Gread();
db.executeUpdate(sql);
id.setText("");
name.setText("");
number.setText("");
id.setEditable(false);
name.setEditable(false);
number.setEditable(false);
ts.setText("操作成功!");
}
}
}
}
3.3登录界面类
package work;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import javax.imageio.*;
import java.sql.*;
import java.util.*;
import java.io.*;
class LoginWindowV2 extends JFrame implements ActionListener
{ JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
JPanel p5=new JPanel();
JTextField txtUserName=new JTextField(15); //用户名文本框
JPasswordField txtPwd=new JPasswordField(15);//密码框
JButton ok=new JButton("登录");
JButton cancel=new JButton("关闭");
JButton resert=new JButton("重置");
public LoginWindowV2(){
//字体设置
Font font = new Font("宋体",Font.PLAIN,24);
Font labelFont = new Font("隶书",Font.BOLD,24);
UIManager.put("Button.font",font);
UIManager.put("Label.font",labelFont);
UIManager.put("TextField.font",labelFont);
JpanelBack jpb = new JpanelBack();
Container contentPane=this.getContentPane();//取出内容面板
p2.add(new JLabel("用户编号:"));p2.add(txtUserName); //将组件添加到中间容器
p3.add(new JLabel("密 码:"));p3.add(txtPwd);
p4.add(ok);p4.add(cancel);p4.add(resert);
ok.addActionListener(this);
cancel.addActionListener(this);
resert.addActionListener(this);
txtUserName.addActionListener(this);
txtPwd.addActionListener(this);
jpb.add(p2);
jpb.add(p3);
jpb.add(p4);
contentPane.add(jpb);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);//设置自动关闭窗口
int width = 400,height=300;
setSize(width,height);
Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
setLocation((screen.width-width)/2,(screen.height-height)/2);
setTitle("欢迎你进入XX商场库存系统");
setResizable(false); //不让用户改变窗口大小
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==ok||e.getSource()==txtPwd) //单击确定按钮后
{
String uid = txtUserName.getText().trim();
String upass = txtPwd.getText().trim();
if(checkUser(uid,upass))
{int i=JOptionPane.showConfirmDialog(null,"登录成功,是否立即去查询系统?","是否查询",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if(i==JOptionPane.YES_OPTION)
{
Gul stu = new Gul();
dispose();
stu.setVisible(true);
}
}
else
{ JOptionPane.showMessageDialog(null,"用户编号或密码错误!");
txtUserName.requestFocus(); //设置焦点
txtUserName.setSelectionStart(0); //设置选中文本开始位置
txtUserName.setSelectionEnd(txtUserName.getText().length());
}
}
else if(e.getSource()==cancel) //单击关闭
{ dispose();
System.exit(0);
}
else if(e.getSource()==txtUserName) //在用户编号文本框按回车移动焦点到密码框
{ txtPwd.requestFocus();
}
else if(e.getSource()==resert){
txtUserName.setText("");
txtPwd.setText("");
txtUserName.requestFocus();
}
}
public boolean checkUser(String id ,String password)
{try{
//1.注册驱动
String driverClassName = "com.mysql.jdbc.Driver";
Class.forName("com.mysql.jdbc.Driver");
//2.连接数据库
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase","root","");
String temp_ID=txtUserName.getText();
String temp_pass=txtPwd.getText();
String sql_user="select userID,userPW from shopping where UserID=? and UserPW=?";
PreparedStatement pst=null;
pst=conn.prepareStatement(sql_user);
pst.setString (1,temp_ID); //为绑定变量赋值
pst.setString (2,temp_pass);
ResultSet rst=pst.executeQuery();
if(rst.next())
{
rst.close();
pst.close();
conn.close();
return true;
}
else
return false;
}
catch(Exception sqle){
System.err.println(sqle);
return false;
}
}
public static void main(String[] args)
{
new LoginWindowV2();
}
class JpanelBack extends JPanel {
BufferedImage img =null;
public JpanelBack (){
try {
img = ImageIO.read(new File("12.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(img, 0,0, getWidth(),getHeight(),this);
}
}
}
六,对设计结果的总结
我自己感觉此次课程设计做得挺成功的,通过这一次,我学到了不少实际编程的知识
在这次设计开始的第一天开始,我刚开始很自信自己能顺顺利利编写成功,但这一过程太不顺利。用了两天时间来研究改写那个程序,磕磕绊绊的不断发现错误,并改正它们,功夫不负有心人人,我的程序最后运行成功了。
在这课程设计期间我的同学帮助了我,有些东西是我们一起探讨,一起解决方法的。当然在学习Java和设计程序的过程中还得到了指导老师的辛勤指导,为我解答了不少的疑问。在此表示衷心的感谢!同时,还要感谢帮助过我的同学!
这次课程设计令我感受很多。从拿到题目到研究例题;然后请教同学慢慢研究琢磨;从理论到实践;从失败到成功; 这其中了不少的东西,磨砺了我的意志;同时还巩固了以前所学的知识,学到了不少书本上没有的知识;学到了很多java编程知识,并学会了简单的使用java来开发java程序的一些使用技巧,这次课程设计是对我本学期所学的知识的检验,由此我发现了不少的问题。可以说它给了我一次自我评估的机会。通过设计让我知道了那些方面我还是有欠缺的,促使我花时间弥补。
水平所限,致使程序实现的功能在方法上也许不是很完美,但我以后会多向老师请教,自己也要加强对Java 的学习。努力进一步提高自己的编程水平。
19
展开阅读全文