基于java的超市管理系统设计与实现

加瓦程序设计师 2024-06-14 13:05:02 阅读 89

摘  要

随着小型超市规模的发展不断扩大,商品数量急剧增加,有关商品的各种信息量也成倍增长,传统的人工记忆方式也慢慢的无法适应形势的变化。随着信息技术的发展,计算机已被广泛的用于社会的各个领域,成为推动社会发展的技术动力。而在计算机应用中,软件的作用十分突出,软件已经发展成为信息技术的核心,主导着信息产品的开发和信息技术市场的进一步的开拓。软件产业已成为社会信息化进程中的一个战略性产业。在软件技术的应用中软件的开发技术尤其是应用型软件产品的开发技术成了重中之重。不断开发适应用户需求、市场需要的新型软件产品。随着社会的发展,软件也在不断的更新换代。

由于有些超市里对商品的进货、售出及商品的基本信息等的一些繁琐处理都是通过手工进行记载并进行处理的,对商品信息的处理工作量特别大,不仅浪费大量的人力物力,而且还很容易出错,更重要的是为了方便顾客,超市需要时时刻刻对商品对各种信息进行统计分析。 一直以来人们使用传统人工的方式管理超市的各项工作, 这种管理方式存在着许多缺点, 如: 效率低、保密性差, 另外时间一长, 将产生大量的冗余文件和数据, 这给查找、统计、更新和维护工作都带来了很大的困难。然而大型的超市管理系统功能过于强大而造成操作繁琐降低了小超市的工作效率。如果有这样一套完整的小型超市管理系统软件,只需点击几下鼠标就可完成所需操作,那样就会大大的提高超市员工的工作效率和管理水平,并能进一步提高超市的工作效率并使超市实施规范化管理。鉴于小型超市管理中存在的诸多问题, 我们在此次课程设计中以小型超市管理系统为研究课题,对此系统进行了全面的设计。

超市管理系统由顾客、员工、管理员界面三部分组成。 超市管理系统应该能够为用户提供充足的信息和快捷的查询手段。一个完整系统的设计,当然就离不开后台环境的支持,在此次设计中,我们主要以MYSQL数据库作为基础,实行此系统的开发。

关键词:Idea;MySQL;数据库;表

第一章 设计目的

《面向对象程序设计》是一门实践性很强的计算机专业基础课程,课程设计是学习完该课程后进行的一次较全面的综合练习。其目的在于通过实践加深学生对面向对象程序设计的理论、方法和基础知识的理解,掌握使用Java语言进行面向对象设计的基本方法,提高运用面向对象知识分析实际问题、解决实际问题的能力。

随着现代科学技术的迅猛发展,计算机技术已经渗透到各个领域,成为各行业必不可少的工具,特别是Internet技术的推广和信息高速公路的建立,使IT产业在市场竞争中越发显示出其独特的优势,步入信息化时代,有巨大的数据信息等待加工处理和传输,这使得对数据库的进一步开发和利用显得尤为迫切。

作为国内市场的一些中小型超市,它们在信息化过程中的步伐要落后于大中型超市,而对于这些企业的资源管理,信息的存储和处理也显得迫切需要,要适应市场竞争,就需要有高效的处理方式和管理方法,因此加快超市的信息化进程是必不可少的。

我国的超市在20世纪90年代初期形成,现在已经成为我国零售业的一种重要形态,为国民经济的发展发挥了重要的作用。随着经济的快速发展,超市的经营管理也变得愈加复杂,早期的售货员站柜台的形式早已不能满足现有销售业的发展,这样就迫切地需要引入新的管理技术。

主要是中小型超市使用者,该消费群体具有以下特征:超市日常管理人工化居多,工作效率较低;超市日常交易额较小,货物流通较小,不愿花高价购进大型超市管理系统。因此,该消费群体对产品的功能性需求并不高,只需满足前台销售系统、后台货物管理即可。

第二章 设计任务与要求

课程设计可选用IDEA、MySQL等作为开发平台以提高开发效率,尽可能熟练掌握其中一种集成开发环境。建议采用UML建模技术进行系统的分析设计,在Visio中画出系统用例图和类图,并将UML图复制到设计报告中。

通过这次设计,要求掌握以下内容:

(1)面向对象技术中的继承与多态(重载和覆盖)机制、各种修饰符的使用

(2)类、包、接口的定义与使用

(3)常用工具类与算法的实现(数组、向量、字符串、链表)

(4)Java的异常处理机制

(5)Java的数据库连接技术

第三章 设计说明

3.1  需求分析

3.1.1功能分析

本平台是基于Java语言的一个超市管理系统,主要功能是为广大的中小型超市提供一些日常的琐碎工作的管理,使得超市管理员能够从琐碎的管理事物中抽身出来,节省不必要的精力,从而可以更高效更好地完成工作。根据超市管理的实际需要,将本系统划分为几个功能模块,分别是普通用户及VIP用户的登录注册操作,对商品信息的管理,对员工信息的管理,对用户购物的操作,对用户退货,用户积分积攒及用户基本查看、兑换等操作。

本系统主要实现以下基本功能:

(1) 注册模块:该模块能实现普通用户、VIP用户在该系统注册账号,成为该超市的用户。

登录模块:该模块能实现普通用户、VIP用户登录系统,从而在系统上进行相应的查看商品、下单、退货等一系列操作。

商品管理模块:主要供管理员管理商品信息,可新增、修改、查询、删除商品信息,并进行节日购物打折设置。购物管理模块: 为购物者提供方便的服务,将商品信息进行整理,展示,用户在登录系统后可查看商品、购买商品、退货的功能,VIP会员除此功能外,可查看个人积分并进行积分兑换。管理员管理模块:管理员可登录系统,对员工信息进行查看、添加、修改、删除操作,对员工进行统一管理。

3.1.2性能要求分析

(1) 系统易操作性:

所开发的系统就做到操作简单,尽量使系统操作不受用户对电脑知识水平的限制。

(2) 系统具有可维护性:

由于系统涉及的信息比较广,数据库中的数据需要定期修改,系统可利用的空间及性能也随之下降,为了使系统更好地运转。

(3) 系统具有开放性:

该系统能够在开放的硬件系结构中运行,并且能与其他系统顺利连接,不会因外部系统的不同面要做在量的修改工作。

3.2 概要设计 

3.2.1功能模块图

图3-1 功能模块图

3.3 详细设计

3.3.1项目代码目录结构

controller:程序控制包,放的是说程序逻辑控制判断类。

dao:数据操作包,数据操作接口及其实现类。

db:数据库连接包,下面是数据库连接获取工具类。

view:系统菜单界面包。

po:实体类包。

main:程序启动包,程序启动需通过此包下面的Main.class里面的main方法。

3.3.2数据表设计

admin(管理员表)

建表语句:CREATE TABLE `admin`  (

  `aid` int(11) NOT NULL,

  `aname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

  `apass` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

  `profit` float NULL DEFAULT NULL,

  PRIMARY KEY (`aid`) USING BTREE

) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

employees(员工表)

建表语句:

  CREATE TABLE `employees`  (

  `eid` int(11) NOT NULL AUTO_INCREMENT,

  `ename` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

  `salary` float NULL DEFAULT NULL,

  `state` int(11) NULL DEFAULT NULL,

  PRIMARY KEY (`eid`) USING BTREE

) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

goods(商品表)

建表语句:

CREATE TABLE `goods`  (

  `goodsid` int(11) NOT NULL AUTO_INCREMENT,

  `goodsname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

  `price` float NULL DEFAULT NULL,

  `goodspoint` int(11) NULL DEFAULT NULL,

  `kindid` int(11) NULL DEFAULT NULL,

  `num` int(11) NULL DEFAULT NULL,

  PRIMARY KEY (`goodsid`) USING BTREE

) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

kinds(商品分类表)

建表语句:

CREATE TABLE `kinds`  (

  `kindid` int(11) NOT NULL AUTO_INCREMENT,

  `kindname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

  PRIMARY KEY (`kindid`) USING BTREE

) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

users(普通用户表)

建表语句:

CREATE TABLE `users`  (

  `uid` int(11) NOT NULL AUTO_INCREMENT,

  `uname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

  `upass` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

  `upoint` int(11) NULL DEFAULT NULL,

  PRIMARY KEY (`uid`) USING BTREE

) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

vip(vip用户表)

建表语句:

CREATE TABLE `vip`  (

  `vipid` int(11) NOT NULL AUTO_INCREMENT,

  `vipname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

  `vippass` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

  `vippoint` int(11) NULL DEFAULT NULL,

  PRIMARY KEY (`vipid`) USING BTREE

) ENGINE = InnoDB AUTO_INCREMENT = 1003 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

3.4主要程序功能流程图

(1)用户注册模块:普通用户注册,如图3-3。会员用户注册,如图3-4。

图3-3 普通用户注册

图3-4 会员用户注册

(2)登录模块:普通用户、管理员用户登录,如图3-5所示。会员用户登录,如图3-6所示。

图3-5 普通用户、管理员登录      

图3-6 会员用户登录

(3)商品管理:商品查看,如图3-7所示。商品新增,如图3-8所示。商品修改,如图3-9所示。商品下架,如图3-10所示。

图3-7 商品查看

图3-8 商品新增

图3-9 商品修改

图3-10 商品下架

(4)员工管理:员工查看,如图3-11所示。员工新增,如图3-12所示。员工修改,如图3-13所示。员工删除,如图3-14所示。

图3-11 员工查看

图3-12 员工新增

图3-13 员工修改

图3-14 员工删除

(5)积分兑换管理:积分查看,如图3-15所示。积分兑换,如图3-16所示。

图3-15 积分查看

图3-16 积分兑换

(6)商品节日打折:商品节日打折录入,如图3-17所示。

图3-17 商品节日打折

第四章 设计成果

4.1主要代码

数据库工具类:

package db;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

public class DB {

   private Connection conn;

   public Statement stmt;

   public DB() {

      try {

         Class.forName("com.mysql.jdbc.Driver");

         String url="jdbc:mysql://localhost:3306/supermarket";

         conn=DriverManager.getConnection(url, "root", "123456");

      } catch (ClassNotFoundException e) {

         // TODO Auto-generated catch block

         e.printStackTrace();

      } catch (SQLException e) {

         // TODO Auto-generated catch block

         e.printStackTrace();

      }

      

   }

   public int update(String sql) {//执行增删改

      // TODO Auto-generated method stub

      System.out.println(sql);

      try {

         this.stmt=conn.createStatement();

         return this.stmt.executeUpdate(sql);

      } catch (SQLException e) {

         // TODO Auto-generated catch block

         e.printStackTrace();

      }

      return -1;

   }

   public ResultSet query(String sql) {//查询

      System.out.println(sql);

      try {

         this.stmt=conn.createStatement();

         return this.stmt.executeQuery(sql);

         

      } catch (SQLException e) {

               e.printStackTrace();

      }

      return null;

   }

   

   public int updatepoint(int vipid) {//获取数据库中会员积分

      String sql;

      ResultSet rs;

      sql="SELECT vippoint FROM vip where vipid="+vipid+"";

      try {

         stmt=conn.createStatement();

         rs=stmt.executeQuery(sql);

         if(rs.next()) {

            int vippoint0=rs.getInt(1);

            return vippoint0;

         }

      } catch (SQLException e) {

         e.printStackTrace();

      }

      return -1;

   }

}

程序控制代码:

package control;

import java.util.ArrayList;

import java.util.Scanner;

import dao.impl.AdminDaoImpl;

import dao.impl.EmployeesDaoImpl;

import dao.impl.GoodsDaoImpl;

import dao.impl.UserDaoImpl;

import dao.impl.VipDaoImpl;

import db.DB;

import po.Admin;

import po.Employees;

import po.Goods;

import po.Users;

import po.Vip;

import view.View;

public class Control {

   private AdminDaoImpl adminDao;

   private UserDaoImpl userDao;

   private VipDaoImpl vipDao;

   private EmployeesDaoImpl employeeDao;

   private GoodsDaoImpl goodsDao;

   private Scanner get;

   private View view;

   private DB db;

   public Control() {

      // TODO Auto-generated constructor stub

      adminDao=new AdminDaoImpl();

      userDao=new UserDaoImpl();

      vipDao=new VipDaoImpl();

      employeeDao=new EmployeesDaoImpl();//曾因为未在此处初始化出现错误

      goodsDao=new GoodsDaoImpl();

      get=new Scanner(System.in);

      view=new View();

      db=new DB();

   }

   public void start() {

      // TODO Auto-generated method stub

      while(true) {

         view.showMenu();

         String t=get.next();

         if("1".equals(t)) {//普通用户注册

            System.out.println("请输入用户名:");

            String uname=get.next();

            System.out.println("请输入密码:");

            String upass=get.next();

            Users user=new Users(uname, upass);

            if(userDao.regUser(user)) {

               System.out.println("注册成功");

               while(true) {

                  view.userMenu1();

                  t=get.next();

                  if("1".equals(t)) {//查看所有商品信息

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     System.out.println("goodsid\t\tgoodsname\tprice\t\tgoodspoint\tkindid\t\tnum");

                     for(Goods g:list) {

                        g.show();

                     }

                  }else if("2".equals(t)) {//购买商品

                     System.out.println("请输入要购买商品的名称");

                     String goodsname=get.next();

                     boolean flag=false;

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     for(Goods g:list) {

                        if(goodsname.equals(g.getGoodsname())) {

                           flag=true;

                           System.out.println("商品所剩数量为:"+g.getNum());

                           System.out.println("请输入要购买商品的数量");

                           int number=get.nextInt();

                           if(number<=g.getNum()) {

                              System.out.println("购买成功");

                           }else {

                              System.out.println("所剩商品不足,购买失败");

                           }

                           int newnum=g.getNum()-number;

                           boolean flag1=goodsDao.updateNum(g.getGoodsid(), newnum);//修改库存

                           if(flag1) {

                              System.out.println("库存更新成功");

                           }else {

                              System.out.println("库存更新失败");

                           }

                           break;

                        }

                     }

                     if(flag==true) { }else {

                        System.out.println("超市中不存在此商品");

                     }

                  }else if("3".equals(t)) {//退货

                     System.out.println("请输入要退商品的名称");

                     String goodsname=get.next();

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     for(Goods g:list) {

                        if(goodsname.equals(g.getGoodsname())) {

                           

                           System.out.println("请输入要退商品的数量");

                           int number=get.nextInt();

                           System.out.println("退货成功");

                           int newnum=g.getNum()+number;

                           boolean flag1=goodsDao.updateNum(g.getGoodsid(), newnum);//修改库存

                           if(flag1) {

                              System.out.println("库存更新成功");

                           }else {

                              System.out.println("库存更新失败");

                           }

                           break;

                        }

                     }

                  }else if("0".equals(t)) {

                     break;

                  }

               }

            }else {

               System.out.println("注册失败");

            }

         }else if("2".equals(t)) {//普通用户登录

            System.out.println("请输入用户名:");

            String uname=get.next();

            System.out.println("请输入密码:");

            String upass=get.next();

            Users user=new Users(uname, upass);

            if(userDao.loginUser(user)) {

               System.out.println("登录成功");

               while(true) {

                  view.userMenu1();

                  t=get.next();

                  if("1".equals(t)) {//查看所有商品信息

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     System.out.println("goodsid\t\tgoodsname\tprice\t\tgoodspoint\tkindid\t\tnum");

                     for(Goods g:list) {

                        g.show();

                     }

                  }else if("2".equals(t)) {//购买商品

                     System.out.println("请输入要购买商品的名称");

                     String goodsname=get.next();

                     boolean flag=false;

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     for(Goods g:list) {

                        if(goodsname.equals(g.getGoodsname())) {

                           flag=true;

                           System.out.println("商品所剩数量为:"+g.getNum());

                           System.out.println("请输入要购买商品的数量");

                           int number=get.nextInt();

                           if(number<=g.getNum()) {

                              System.out.println("购买成功");

                           }else {

                              System.out.println("所剩商品不足,购买失败");

                           }

                           int newnum=g.getNum()-number;

                           boolean flag1=goodsDao.updateNum(g.getGoodsid(), newnum);//修改库存

                           if(flag1) {

                              System.out.println("库存更新成功");

                           }else {

                              System.out.println("库存更新失败");

                           }

                           break;

                        }

                     }

                     if(flag==true) { }else {

                        System.out.println("超市中不存在此商品");

                     }

                  }else if("3".equals(t)) {//退货

                     System.out.println("请输入要退商品的名称");

                     String goodsname=get.next();

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     for(Goods g:list) {

                        if(goodsname.equals(g.getGoodsname())) {

                           

                           System.out.println("请输入要退商品的数量");

                           int number=get.nextInt();

                           System.out.println("退货成功");

                           int newnum=g.getNum()+number;

                           boolean flag1=goodsDao.updateNum(g.getGoodsid(), newnum);//修改库存

                           if(flag1) {

                              System.out.println("库存更新成功");

                           }else {

                              System.out.println("库存更新失败");

                           }

                           break;

                        }

                     }

                  }else if("0".equals(t)) {

                     break;

                  }

               }

            }else {

               System.out.println("用户名或者密码错误");

            }

         }else if("3".equals(t)) {//vip用户注册

            System.out.println("请输入用户名:");

            String vipname=get.next();

            System.out.println("请输入密码:");

            String vippass=get.next();

            Vip vip=new Vip(vipname, vippass);

            if(vipDao.regVip(vip)) {               

               System.out.print("本人的会员编号为:");//查找到对应编号

               vipDao.showid(vipname);

               System.out.println("请输入自己的会员编号:");

               int vipid0=get.nextInt();

               System.out.println("注册成功");

               while(true) {

                  view.vipMenu1();

                  t=get.next();

                  if("1".equals(t)) {//查看所有商品信息

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     System.out.println("goodsid\t\tgoodsname\tprice\t\tgoodspoint\tkindid\t\tnum");

                     for(Goods g:list) {

                        g.show();

                     }

                  }else if("2".equals(t)) {//购买商品

                     System.out.println("请输入要购买商品的名称");

                     String goodsname=get.next();

                     boolean flag=false;

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     for(Goods g:list) {

                        if(goodsname.equals(g.getGoodsname())) {

                           flag=true;

                           System.out.println("商品所剩数量为:"+g.getNum());

                           System.out.println("请输入要购买商品的数量");

                           int number=get.nextInt();

                           if(number<=g.getNum()) {

                              System.out.println("购买成功");

                              int newvippo=number*g.getGoodspoint()+db.updatepoint(vipid0);

                              boolean flag1=vipDao.updateVippoint(vipid0, newvippo);

                              if(flag1) {

                                 System.out.println("会员积分更新成功");

                              }else {

                                 System.out.println("会员积分更新失败");

                              }

                           }else {

                              System.out.println("所剩商品不足,购买失败");

                           }

                           int newnum=g.getNum()-number;

                           boolean flag1=goodsDao.updateNum(g.getGoodsid(), newnum);//修改库存

                           if(flag1) {

                              System.out.println("库存更新成功");

                           }else {

                              System.out.println("库存更新失败");

                           }

                           break;

                        }

                     }

                     if(flag==true) { }else {

                        System.out.println("超市中不存在此商品");

                     }

                  }else if("3".equals(t)) {//退货

                     System.out.println("请输入要退商品的名称");

                     String goodsname=get.next();

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     for(Goods g:list) {

                        if(goodsname.equals(g.getGoodsname())) {

                           

                           System.out.println("请输入要退商品的数量");

                           int number=get.nextInt();

                           System.out.println("退货成功");

                           int newvippo=db.updatepoint(vipid0)-number*g.getGoodspoint();

                           

                           boolean flag0=vipDao.updateVippoint(vipid0, newvippo);//修改会员积分

                           if(flag0) {

                              System.out.println("会员积分更新成功");

                           }else {

                              System.out.println("会员积分更新失败");

                           }

                           int newnum=g.getNum()+number;

                           boolean flag1=goodsDao.updateNum(g.getGoodsid(), newnum);//修改库存

                           if(flag1) {

                              System.out.println("库存更新成功");

                           }else {

                              System.out.println("库存更新失败");

                           }

                           break;

                        }

                     }

                  }else if("4".equals(t)) {//查看自己积分

                     int vippoint=db.updatepoint(vipid0);

                     System.out.println("积分为:"+vippoint);

                  }else if("5".equals(t)) {//积分抵扣兑换

                     System.out.println("请输入要购买商品的名称");

                     String goodsname=get.next();

                     boolean flag=false;

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     for(Goods g:list) {

                        if(goodsname.equals(g.getGoodsname())) {

                           flag=true;

                           System.out.println("商品所剩数量为:"+g.getNum());

                           System.out.println("商品的单价为:"+g.getPrice());

                           System.out.println("请输入要购买商品的数量");

                           int number=get.nextInt();

                           if(number<=g.getNum()) {

                              System.out.println("是否选择积分抵扣(y/n):");//只有商品总价格大于积分/30(积分可抵扣积分/30)时才可抵扣

                              String select=get.next();

                              boolean flag1=false;

                            if(number*g.getPrice()>(vipid0/30) && select.equalsIgnoreCase("y")) {

                              if(select.equalsIgnoreCase("y")) {

                                 System.out.println("购买成功");

                                 int newvippo=number*g.getGoodspoint();//全部抵扣原积分

                                 

                                 flag1=vipDao.updateVippoint(vipid0, newvippo);

                              }else if(select.equalsIgnoreCase("n")) {//不用积分抵扣

                                 System.out.println("购买成功");

                                 flag1=vipDao.updateVippoint1(vipid0, number*g.getGoodspoint());

//                               flag1=vipDao.updateVippoint(vip.getVipid(), newvippo);

                              }else {

                                 System.out.println("购买失败");//输入的不是y或者n

                              }

                              

                              if(flag1) {

                                 System.out.println("会员积分更新成功");

                              }else {

                                 System.out.println("会员积分更新失败");

                              }

                           }else {

                              System.out.println("所剩商品不足,购买失败");

                           }

                           int newnum=g.getNum()-number;

                           boolean flag1=goodsDao.updateNum(g.getGoodsid(), newnum);//修改库存

                           if(flag1) {

                              System.out.println("库存更新成功");

                           }else {

                              System.out.println("库存更新失败");

                           }

                           break;

                        }

                     }

                     if(flag==true) { }else {

                        System.out.println("超市中不存在此商品");

                     }

                  }else if("0".equals(t)) {

                     break;

                  }

               }

            }else {

               System.out.println("注册失败");

            }

         }else if("4".equals(t)) {//vip用户登录

            System.out.println("请输入用户名:");

            String vipname=get.next();

            System.out.println("请输入密码:");

            String vippass=get.next();

            Vip vip=new Vip(vipname, vippass);

            

            

            if(vipDao.loginVip(vip)) {    

               System.out.print("本人的会员编号为:");//查找到对应编号

               vipDao.showid(vipname);

               System.out.println("请输入自己的会员编号:");

               int vipid0=get.nextInt();

               System.out.println("登录成功");

               while(true) {

                  view.vipMenu1();

                  t=get.next();

                  if("1".equals(t)) {//查看所有商品信息

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     System.out.println("goodsid\t\tgoodsname\tprice\t\tgoodspoint\tkindid\t\tnum");

                     for(Goods g:list) {

                        g.show();

                     }

                  }else if("2".equals(t)) {//购买商品

                     System.out.println("请输入要购买商品的名称");

                     String goodsname=get.next();

                     boolean flag=false;

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     for(Goods g:list) {

                        if(goodsname.equals(g.getGoodsname())) {

                           flag=true;

                           System.out.println("商品所剩数量为:"+g.getNum());

                           System.out.println("请输入要购买商品的数量");

                           int number=get.nextInt();

                           if(number<=g.getNum()) {

                              System.out.println("购买成功");

//                            System.out.println("!!!!"+db.updatepoint(vipid0));//验证

                              int newvippo=number*g.getGoodspoint()+db.updatepoint(vipid0);

                              boolean flag1=vipDao.updateVippoint(vipid0, newvippo);

                              if(flag1) {

                                 System.out.println("会员积分更新成功");

                              }else {

                                 System.out.println("会员积分更新失败");

                              }

                           }else {

                              System.out.println("所剩商品不足,购买失败");

                           }

                           int newnum=g.getNum()-number;

                           boolean flag1=goodsDao.updateNum(g.getGoodsid(), newnum);//修改库存

                           if(flag1) {

                              System.out.println("库存更新成功");

                           }else {

                              System.out.println("库存更新失败");

                           }

                           break;

                        }

                     }

                     if(flag==true) { }else {

                        System.out.println("超市中不存在此商品");

                     }

                  }else if("3".equals(t)) {//退货

                     System.out.println("请输入要退商品的名称");

                     String goodsname=get.next();

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     for(Goods g:list) {

                        if(goodsname.equals(g.getGoodsname())) {

                           

                           System.out.println("请输入要退商品的数量");

                           int number=get.nextInt();

                           System.out.println("退货成功");

                           int newvippo=db.updatepoint(vipid0)-number*g.getGoodspoint();

                           

                           boolean flag0=vipDao.updateVippoint(vipid0, newvippo);//修改会员积分

                           if(flag0) {

                              System.out.println("会员积分更新成功");

                           }else {

                              System.out.println("会员积分更新失败");

                           }

                           int newnum=g.getNum()+number;

                           boolean flag1=goodsDao.updateNum(g.getGoodsid(), newnum);//修改库存

                           if(flag1) {

                              System.out.println("库存更新成功");

                           }else {

                              System.out.println("库存更新失败");

                           }

                           break;

                        }

                     }

                  }else if("4".equals(t)) {//查看自己积分

                     int vippoint=db.updatepoint(vipid0);

                     System.out.println("积分为:"+vippoint);

                  }else if("5".equals(t)) {//积分抵扣兑换

                     System.out.println("请输入要购买商品的名称");

                     String goodsname=get.next();

                     boolean flag=false;

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     for(Goods g:list) {

                        if(goodsname.equals(g.getGoodsname())) {

                           flag=true;

                           System.out.println("商品所剩数量为:"+g.getNum());

                           System.out.println("商品的单价为:"+g.getPrice());

                           System.out.println("请输入要购买商品的数量");

                           int number=get.nextInt();

                           if(number<=g.getNum()) {

                              System.out.println("是否选择积分抵扣(y/n):");//只有商品总价格大于积分/30(积分可抵扣积分/30)时才可抵扣

                              String select=get.next();

                              boolean flag1=false;

                              if(select.equalsIgnoreCase("y")) {

                                 System.out.println("购买成功");

                                 int newvippo=number*g.getGoodspoint();//全部抵扣原积分

                                 

                                 flag1=vipDao.updateVippoint(vipid0, newvippo);

                              }else if(select.equalsIgnoreCase("n")) {//不用积分抵扣

                                 System.out.println("购买成功");

                                 flag1=vipDao.updateVippoint1(vipid0, number*g.getGoodspoint());

                              }else {

                                 System.out.println("购买失败");//输入的不是y或者n

                              }

                              

                              if(flag1) {

                                 System.out.println("会员积分更新成功");

                              }else {

                                 System.out.println("会员积分更新失败");

                              }

                           }else {

                              System.out.println("所剩商品不足,购买失败");

                           }

                           int newnum=g.getNum()-number;

                           boolean flag1=goodsDao.updateNum(g.getGoodsid(), newnum);//修改库存

                           if(flag1) {

                              System.out.println("库存更新成功");

                           }else {

                              System.out.println("库存更新失败");

                           }

                           break;

                        }

                     }

                     if(flag==true) { }else {

                        System.out.println("超市中不存在此商品");

                     }

                  }else if("0".equals(t)) {

                     break;

                  }

               }

            }else {

               System.out.println("登录失败");

            }

         }else if("5".equals(t)) {//管理员登录

            System.out.println("请输入管理员名称:");

            String aname=get.next();

            System.out.println("请输入管理员密码:");

            String apass=get.next();

            Admin admin=new Admin(aname, apass);

            if(adminDao.loginAdmin(admin)) {

               System.out.println("登录成功");

               while(true) {

                  view.adminMenu1();

                  t=get.next();

                  if("1".equals(t)) {//查看所有商品

                     ArrayList<Goods> list=goodsDao.selectGoods();

                     System.out.println("goodsid\t\tgoodsname\tprice\t\tgoodspoint\tkindid\t\tnum");

                     for(Goods g:list) {

                        g.show();

                     }

                  }else if("2".equals(t)) {//增加商品

                     System.out.println("请输入商品编号");

                     int goodsid=get.nextInt();

                     if(adminDao.selectGoodsid(goodsid)) {

                        System.out.println("库中有此商品");

                        System.out.println("请输入要增加商品的数量");

                        int num=get.nextInt();

                        

                        if(adminDao.addGoodsNum(goodsid, num)) {

                           System.out.println("增加商品库存成功");

                        }else {

                           System.out.println("增加库存失败");

                        }

                     }else {

                        System.out.println("请输入商品名称");

                        String goodsname=get.next();

                        System.out.println("请输入商品单价");

                        float price=get.nextFloat();

                        System.out.println("请输入商品对应积分");

                        int goodspoint=get.nextInt();

                        System.out.println("请输入商品类型编号");

                        int kindid=get.nextInt();

                        System.out.println("请输入添加商品数量");

                        int num=get.nextInt();

                        Goods goods=new Goods(goodsid, goodsname, price, goodspoint, kindid, num);

                        if(goodsDao.addGoods(goods)) {

                           System.out.println("添加商品成功");

                        }else {

                           System.out.println("添加商品失败");

                        }

                     }

                                    

                  }else if("3".equals(t)) {//下架商品

                     System.out.println("请输入要下架的商品的编号");

                     int goodsid=get.nextInt();

                     if(adminDao.deleteGoods(goodsid)) {

                        System.out.println("下架成功");

                     }else {

                        System.out.println("下架失败");

                     }

                  }else if("4".equals(t)) {//节日价格打折

                     System.out.println("请输入要优惠商品的编号");

                     int goodsid=get.nextInt();

                     System.out.println("请输入要优惠的折扣");

                     float percent=get.nextFloat();

                     if(adminDao.updatePrice(percent, goodsid)) {

                        System.out.println("已优惠");

                     }else {

                        System.out.println("设置商品打折失败");

                     }

                  }else if("5".equals(t)) {//修改商品信息                 

                     System.out.println("是否要修改商品的价格(y/n)");

                     String s=get.next();

                     if(s.equalsIgnoreCase("y")) {

                        System.out.println("请输入商品的编号");

                        int goodsid=get.nextInt();

                        System.out.println("请输入商品新的价格");

                        float price=get.nextFloat();

                        if(adminDao.updatePrice1(goodsid, price)) {

                           System.out.println("修改价格成功");

                        }else {

                           System.out.println("修改失败");

                        }

                     }else {}

                     System.out.println("是否要修改商品的对应积分:");

                     String s1=get.next();

                     if(s1.equalsIgnoreCase("y")) {

                        System.out.println("请输入商品的编号");

                        int goodsid=get.nextInt();

                        System.out.println("请输入商品新的对应积分");

                        int goodspoint=get.nextInt();

                        if(adminDao.updateGoodspoint(goodsid, goodspoint)) {

                           System.out.println("修改积分成功");

                        }else {

                           System.out.println("修改积分失败");

                        }

                     }else {}

                  }else if("6".equals(t)) {//管理员工

                     while(true) {

                        view.employeeMenu1();

                        t=get.next();

                        if("1".equals(t)) {//录入新员工

                           System.out.println("请输入新员工的姓名");

                           String ename=get.next();

                           System.out.println("请输入新员工的工资");

                           float salary=get.nextFloat();

                           System.out.println("请输入新员工的工作状态");

                           int state=get.nextInt();

                           Employees employee=new Employees(ename, salary, state);

                           

                           if(employeeDao.addEmp(employee)) {

                              System.out.println("录入成功");

                           }else {

                              System.out.println("录入失败");

                           }

                        }else if("2".equals(t)) {//删除员工

                           System.out.println("请输入要删除员工的编号");

                           int eid=get.nextInt();

                           if(employeeDao.deleteEmp(eid)) {

                              System.out.println("删除员工成功");

                           }else {

                              System.out.println("删除员工失败");

                           }

                        }else if("3".equals(t)) {//查看员工信息

                           employeeDao.show();

                        }else if("4".equals(t)) {//修改员工状态(0请假,1在职)

                           System.out.println("请输入员工编号");

                           int eid=get.nextInt();

                           System.out.println("请输入要修改员工状态为");

                           int state=get.nextInt();

                           if(employeeDao.updateEmp1(eid, state)) {

                              System.out.println("修改成功");

                           }else {

                              System.out.println("修改失败");

                           }

                        }else if("0".equals(t)) {

                           break;

                        }

                     }

                  }else if("0".equals(t)) {

                     break;

                  }

               }

            }

            

         }else if("0".equals(t)) {

            break;

         }

      }

   }

}

4.2运行结果截图

1.系统主界面

图4-1 系统主界面

2.普通用户注册界面

图4-2 普通用户注册界面

3.普通用户登录界面

图4-3 普通用户登录界面

4.vip用户注册界面

图4-4 vip用户注册界面

5.vip用户登录界面

图4-5 vip用户登录界面

6.用户(普通、vip)登录后的共性操作界面

图4-6 查看所有商品界面

图4-7 查看所有商品界面

图4-8 退货界面

7.用户(vip)登录后的积分操作界面

图4-9 查看自己的积分界面

图4-10 积分兑换界面

8.返回界面

图4-11 反馈界面

9.管理员操作界面

图4-12 管理员登录界面

图4-13 管理员查看所有商品界面

图4-14 管理员增加商品界面

 

 图4-15 管理员下架商品界面

图4-16 管理员节日价格打折界面

图4-17 管理员修改商品界面

图4-18 管理员管理员工菜单界面

图4-19 管理员录入新员工界面

图4-20 管理员删除员工界面

 图4-21 管理员查看员工界面

图4-22 管理员修改员工状态界面

 想要的点赞收藏加关注私信作者交流



声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。