基于java小型超市管理系统(含源文件)
- 格式:doc
- 大小:31.72 KB
- 文档页数:52
基于Java的超市信息管理系统开发与设计实验报告基于Java的超市信息系统的开发与设计上海工程技术大学 10级信管专业2012-2013大学生创新实验报告Java的超市信息系统开发与设计郭文豪031510224 荣攀 031510223 王宗敏031510132 石坚伟 031510130 蔡奕明教师所在学院管理学院实验完成学期 2012~2013学年第一学期基于Java的超市信息系统的开发与设计上海工程技术大学 10级信管专业2012-2013目录摘要 (3)实验目的 (4)1 超市管理系统的分析与设计 (5)1.1 市场对于超市管理信息系统的需求分析 (5)1.2 超市管理系统开发的技术支持 1.2.1 Java简介1.2.2 C#语言 2 Access 数据库 33.1 系统结构ERP3.2 Access (9)3.3 (10)4 (11) (11) (13)系统主页菜单栏功能介绍 (13)4.2.2 系统主页页标签功能及按钮功能介绍 (14)5 Java代码的部分展示 (17)6 实验心得体会 (19)7 参考文献 .......................................22 - 2 -基于Java的超市信息系统的开发与设计上海工程技术大学 10级信管专业2012-2013 摘要科技日异月新,突飞猛进,将科学的管理方式应用于超市管理过程,而形成的,便是超市管理信息系统,在超市管理信息系统中可以便于人员对超市的各项模块进行管理,员工管理、会员系统管理、商品库存系统管理,合理的系统能够有助于超市顺利的运营,理更能提升超市的营业水平。
本系统基于Java语言,以及Access结合两者,通过Java程序窗口对Access 但近几年我国超市经营规模日趋扩大,而且许多超市正小型超市在业务还要时刻更新产品的销售信息,不断添实现超市庞大商品的控制和传输,从而方便应该是可以帮助销售部门提高工作效率,帮助超市工作人员利用计算机,极为方便的对超市的有关数据进行管理、输入、输出、查找等有关操作,使杂乱的超市数据能够具体化、直观化、合理化等,例如美萍超市管理系统。
JAVA语言课程设计报告题目:小型超市管理系统设计者:专业班级:学号:指导教师:2010 年12 月12 日计算机学院目录一、系统需求分析 .................................................................................................................................... - 1 -1.1系统名称: .................................................................................................................................. - 1 -1.2系统介绍: .................................................................................................................................. - 1 -1.3开发背景 ...................................................................................................................................... - 1 -1.4.系统面向的用户群体................................................................................................................... - 1 -1.5开发环境 ...................................................................................................................................... - 1 -二、系统总体设计 .................................................................................................................................... - 2 -2.1系统功能结构图........................................................................................................................... - 2 -三、系统详细设计 .................................................................................................................................... - 2 -3.1数据库实体E-R图设计 .............................................................................................................. - 2 -3.2数据库表的设计........................................................................................................................... - 4 -3.3物理设计文档............................................................................................................................... - 6 -3.4详细设计 .................................................................................................................................... - 10 -四、系统总结 .......................................................................................................................................... - 20 -五、系统设计心得体会........................................................................................................................... - 21 -六、参考文献 .......................................................................................................................................... - 21 -一、系统需求分析1.1系统名称:小型超市管理系统1.2系统介绍:界面设计简洁、友好、美观大方操作简单、快捷方便数据存储安全、可靠信息分类清晰、准确强大的查询功能、保证数据查询的灵活性提供销售排行,为管理员提供真实的数据信息提供灵活、方便的权限设置功能,使整个系统的管理分工明确对用户的输入的数据,系统进行严格的数据检验,尽可能排人为错误1.3开发背景随着现代科学技术的迅猛发展,计算机技术已经渗透到各个领域,成为各行业必不可少的工具,特别是Internet技术的推广和信息高速公路的建立,使IT产业在市场竞争中越发显示出其独特的优势,步入信息化时代,有巨大的数据信息等待加工处理和传输,这使得对数据库的进一步开发和利用显得尤为迫切。
基于Java Web的小型超市订单管理系统是一种常见的毕业设计项目,其主要功能包括订单管理、商品管理、用户管理等模块。
下面是该项目中可能需要实现的一些详细功能:
用户管理模块:包括用户注册、登录、修改个人信息等功能,可以使用Java Servlet 和JSP技术实现。
商品管理模块:通过网页界面展示超市的商品信息,包括商品名称、价格、库存量等,并提供添加、删除、修改商品信息的功能。
可以使用Java Bean和数据库连接技术实现。
订单管理模块:包括查看历史订单、创建新订单、取消订单等功能。
可以使用Java Servlet和JSP技术实现,并与数据库进行交互。
支付功能:可以使用第三方支付平台接口实现在线支付功能。
后台管理模块:管理员可以登录后台系统,对用户、订单、商品等信息进行操作和管理。
可以使用Java Servlet和JSP技术实现,并与数据库进行交互。
基于Java Web的小型超市订单管理系统涉及到前端页面设计、后台逻辑实现、数据库设计等多个方面,需要充分考虑用户体验、安全性、可靠性等因素,并使用合适的工具和技术进行开发。
在实现过程中,还需遵循软件开发规范,保证代码的可读性和可维护性,以便日后的项目开发和维护。
基于Java的超市管理系统//看完删去此处红字内容//第四章总结部分“指导老师×××”(红字标出)自己修改姓名:_______________学院:_______________指导老师:_______________专业:_______________摘要随着零售业的快速发展,超市商品数量急剧增加,相关商品的各种信息也成倍增长。
传统的人工管理方式已经逐渐不能适应当今零售业的需求。
信息技术的广泛普及为各个行业提供了更加高效便捷的管理方式。
本文针对超市商品的管理问题,在分析超市业务流程的基础上,设计了一套超市管理系统,实现对超市商品的进货、库存、销售等更方面的管理,以便于超市节约成本,提高效率,减少差错,扩大收益。
一个完整的软件系统必然离不开后台环境的支持,在此次设计中,我们主要以MySQL 数据库为基础,以Java语言为开发语言,使用Eclipse开发工具实行此系统的开发工作。
关键词:超市管理;Java;MySQL数据库;面向对象编程;第一章绪论 (4)1.1超市管理系统的开发背景 (4)1.2系统设计的目的与意义 (4)1.3 系统功能特点 (4)第二章系统开发的理论基础 (5)2.1 Java语言及其优势 (5)2.2 MySQL数据库简介 (5)2.3 开发工具Eclipse (5)第三章超市管理系统分析与实现 (6)3.1 超市基本业务流程与需求分析 (6)3.2 系统模块设计 (7)第四章总结 (9)参考文献 (10)第一章绪论1.1超市管理系统的开发背景随着现代科学技术的迅猛发展,计算机技术已经渗透到各个领域,成为各行业必不可少的工具,信息全球化的时代已经来临,超市的竞争也进入到了一个全新的领域,竞争已不再是规模的竞争,而是技术的竞争、管理的竞争、人才的竞争。
技术的提升和管理的升级是超市业的竞争核心。
零售领域目前呈多元发展趋势,多种业态:超市、仓储店、便利店、特许加盟店、专卖店、货仓等相互并存。
毕业设计说明书题目:超市账单管理系统超市账单管理系统摘要:随着科学技术的不断发展,计算机越来越普及,随之各种软件也相应而出。
许许多多的企业也用上了相应的软件,来加快自身的发展。
由于超市行业的不断壮大,也需要一套软件来相应的软件来管理。
在这种情况下超市账单管理系统也应运而生。
超市账单管理系统主要是对超市账单、供应商、用户的简单管理。
本系统主要用java语言进行开发,mysql数据库和Eclipse开发工具;主要用的核心技术是Servlet,用来处理用户的请求和页面之间的跳转,JDBC(Java Data Base Connectivity)连接数据库实现处理与数据库的交互。
主要用的美工技术是div+css,javaScript处理页面显示效果。
本系统能更快,更方便的管理好整个工作流程中的各个模块,使工作效率达到最优化。
关键词:java;Servlet;div+css;javaScript;mysql;超市账单管理系统;Title:Supermarket Bill Management SystemAbstract: Along with the science and technology unceasing development, the computer more and more popular, with a variety of software is out. Many companies also use the corresponding software, to accelerate the development of oneself. As a result of Supermarket has grown, also need a set of software to the software to management. In this case the supermarket bill management system also emerge as the times require. Supermarket bill management system is mainly the easy management of supermarket bills, suppliers, users. This system is mainly the use of Java language development, database mysql and Eclipse development tools; the main core technology is Servlet, It used to handle user requests and jump between pages. JDBC(Java Data Base Connectivity)used to handle the interaction with the database .Mainly using artist technical is div+css,javaScript, handling page display effect. This system can be faster, more convenient management of the whole working process of each module, so that the work efficiency is optimized.Keywords: java ,Servlet,div+css,javaScript,mysql,Supermarket bill management system目录摘要 (I)Abstract (II)1 正文 (1)1.1研究背景分析 (1)1.2 超市账单管理系统的概述 (2)1.3所需软、硬件技术准备 (2)1.4可行性分析 (3)1.4.1 技术可行性 (3)1.4.2 经济可行性 (3)1.4.3 社会可行性 (3)2 需求分析 (4)2.1 需求分析的任务及主要内容 (4)2.2.1 具体业务的需求 (4)2.2 层次图 (4)2.3数据流图 (5)3 概要设计 (5)3.1 系统分析 (5)3.1.1 系统的总体分析 (6)3.2 数据库的设计与实现 (6)3.2.1 数据库系统分析 (7)3.2.2 数据库物理实现 (7)4 详细设计 (9)4.1 Servlet的详细应用 (9)4.2 特定模块的详细介绍 (9)4.2.1 登陆模块 (9)4.2.2 账单管理模块 (15)4.2.2 供应商管理模块 (21)4.2.3 用户管理模块 (26)5 系统测试 (33)结语 (34)注释 (34)参考文献 (35)致谢 (37)附录1 (38)1 正文1.1研究背景分析超级市场是以顾客自选方式经营的大型综合性零售商场,又称自选商场。
.毕业设计(论文)基于jsp(java)超市管理系统的设计和开发姓名系别、专业导师姓名、职称完成时间目录摘要 (Ⅴ)ABSTRACT (Ⅵ)1前言 (7)1.1社会背景 (7)1.2超市管理形式: (8)1.3建立超市管理系统的必要性 (8)2相关技术知识概要 (10)2.1 前台开发工具 (10)2.1.1开发语言 (10)2.1.2 开发平台 (10)2.1.3 JSP技术 (10)2.1.4 servlet (13)2.2 SQL SERVER 2000 简介 (15)3系统分析与设计 (18)3.1需求分析 (18)3.2系统可行性分析 (18)3.2.1 技术可行性 (13)3.2.2 经济可行性 (20)3.2.3 操作可行性 (20)3.3系统数据库流程图 (20)3.4数据字典 (20)3.5系统功能模块划分 (22)4系统实现 (23)4.1数据库表的设计 (26)4.2界面设计的实现 (26)4.3系统开发环境 (26)5结语............................... 错误!未定义书签。
致谢........................... 错误!未定义书签。
参考文献 .. (30)超市进销存管理系统摘要随着网络技术的发展、计算机应用水平的提高的扩大,原来系统的时效性、数据的正确性、操作的方便性上都存在不足,已影响到系统的正常使用。
经过考察比较,决定利用科技的力量对超市订购与销售管理系统进行重新设计。
使系统能利用软件开发技术的成果,方便商品销售的管理。
本文主要是介绍超市进销存管理信息系统的环境、功能作用、所用到的语言、设计的方案等各方面的内容。
主要是让使用者了解此系统,使他们能更好的运用本系统,使此系统发挥出应有的作用。
本文主要对超市订购与销售管理系统的设计与开发过程进行了全面的介绍并对各子系统中的程序设计、操作流程、功能实现等进行了详细的解释。
该管理信息系统通过sqlserver2000建立后台的数据库,利用jsp开发工具,实现了超市销售管理等各项基本功能。
java实现水果超市管理系统这篇文章主要为大家详细介绍了java实现水果超市管理系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。
废话不多说,直接上源码:首先建立水果类的界面:public class Fruit {//定义IDprivate String id;//定义名称private String name;//定义价格private int price;//定义单位private String unit;//定义数量private int number;public Fruit(String id, String name, int price, String unit) {super();this.id = id; = name;this.price = price;this.unit = unit;}public Fruit() {super();// TODO Auto-generated constructor stub}public String getId() {return id;}public void setId(String id) {this.id = id;}public String getName() {return name;}public void setName(String name) { = name;}public int getPrice() {return price;}public void setPrice(int price) {this.price = price;}public String getUnit() {return unit;}public void setUnit(String unit) {this.unit = unit;}public int getNumber() {return number;}public void setNumber(int number) {this.number = number;}//获取价格public int getMoney(){return price * number;}}水果超市的界面:import java.io.IOException;import java.util.Scanner;public class FruitTest {public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in);Shopper shopper = new Shopper();Manager manager = new Manager();while(true){System.out.println( " 欢迎光临水果系统");System.out.println("请输入你的角色:(1.顾客2.管理员3.退出)"); int choice = sc.nextInt();switch(choice){case 1://顾客shopper.shop();break;case 2://管理员manager.manager();break;case 3:System.exit(0);default:System.out.println("你的输入有误!");}}}}顾客类:import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.Scanner;public class Shopper {public void shop() throws IOException {Scanner sc = new Scanner(System.in);ArrayList<Fruit> list = new ArrayList<Fruit>();check(list);while (true) {System.out.println(" 欢迎光临水果系统");System.out.println("请输入你的操作:(1.查看水果2.购买水果3.结账 4.退出)"); int choice = sc.nextInt();switch (choice) {case 1:// 查看水果print(list);break;case 2:// 购买水果buy(list);break;case 3:// 结账checkOut(list);break;case 4:// 退出return;default:System.out.println("你输入的操作有误!");}}}//结账private void checkOut(ArrayList<Fruit> list) {int sum = 0;for (int i = 0; i < list.size(); i++) {Fruit f = list.get(i);sum += f.getMoney();}if(sum>200){int newSum = (int) (sum * 0.9);System.out.println("金额:" + sum+ "元, 优惠价格:"+ newSum+"元"); }else{System.out.println("金额:" + sum+"元");}//结完账后,将数量清0for (int i = 0; i < list.size(); i++) {Fruit f = list.get(i);f.setNumber(0);}}// 购买水果public void buy(ArrayList<Fruit> list) throws IOException {Scanner sc1 = new Scanner(System.in);Scanner sc2 = new Scanner(System.in);print(list);while (true) {System.out.println("购买超过200元,享受九折优惠!");System.out.println("请输入想要购买的水果的ID:(如果不想购买,请输入-1退出)"); String id = sc1.nextLine();if ("-1".equals(id)) {System.out.println("购买已结束,请去结账");return;} else {boolean flag = false;for (int i = 0; i < list.size(); i++) {Fruit f = list.get(i);if(f.getId().equals(id)) {System.out.println("请输入购买" + f.getName() + "数量:");int num = sc2.nextInt();f.setNumber(num);flag = true;}}if(!flag){System.out.println("你输入的水果ID不正确,请重新输入");}}}}// 查看水果public void check(ArrayList<Fruit> list) throws IOException {BufferedReader br = new BufferedReader(new FileReader("fruit.txt"));String line;while ((line = br.readLine()) != null) {String[] str = line.split(" ");Fruit f = new Fruit(str[0], str[1], Integer.parseInt(str[2]),str[3]);list.add(f);}br.close();}public void print(ArrayList<Fruit> list) {System.out.println("ID\t水果\t价格\t单位");for (int i = 0; i < list.size(); i++) {Fruit f = list.get(i);System.out.println(f.getId() + "\t" + f.getName() + "\t"+ f.getPrice() + "\t" + f.getUnit());}}}管理员类:import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.util.ArrayList;import java.util.Scanner;public class Manager {public void manager() throws IOException {if (load()) {Scanner sc = new Scanner(System.in);while (true) {ArrayList<Fruit> list = new ArrayList<Fruit>();check(list);System.out.println("请输入您的操作:(1.查看水果种类 2.增加水果种类3.修改水果种类4.删除水果种类5退出)");int choice = sc.nextInt();switch (choice) {case 1:// 查看水果种类print(list);break;case 2:// 增加水果种类addFruit(list);break;case 3:// 修改水果种类reverse(list);break;case 4:// 删除水果种类remove(list);break;case 5:// 退出return;default:System.out.println("你输入的操作有误!");break;}}} else {return;}}public void remove(ArrayList<Fruit> list) throws IOException { Scanner sc = new Scanner(System.in);print(list);System.out.println("请输入要删除的水果ID: ");String id = sc.nextLine();for (int i = 0; i < list.size(); i++) {Fruit f = list.get(i);if(f.getId().equals(id)){list.remove(i);write(list);System.out.println("删除成功");return;}}System.out.println("找不到要删除的水果ID!");}//修改水果public void reverse(ArrayList<Fruit> list) throws IOException { Scanner sc1 = new Scanner(System.in);Scanner sc2 = new Scanner(System.in);print(list);System.out.println("请输入要修改的水果ID: ");String id = sc1.nextLine();for (int i = 0; i < list.size(); i++) {Fruit f = list.get(i);if(f.getId().equals(id)){System.out.println("请输入水果的名称: ");String name = sc1.nextLine();System.out.println("请输入水果的价格: ");int price = sc2.nextInt();System.out.println("请输入水果的单位: ");String unit = sc1.nextLine();f.setName(name);f.setPrice(price);f.setUnit(unit);write(list);System.out.println("修改成功");return;}}System.out.println("找不到要修改的水果ID!");}//增加水果public void addFruit(ArrayList<Fruit> list) throws IOException { Scanner sc1 = new Scanner(System.in);Scanner sc2 = new Scanner(System.in);print(list);System.out.println("请输入要增加水果的ID: ");String id = sc1.nextLine();for (int i = 0; i < list.size(); i++) {Fruit f = list.get(i);if(f.getId().equals(id)){System.out.println("水果ID名重复!");return;}}System.out.println("请输入水果的名字: ");String name = sc1.nextLine();System.out.println("请输入水果的价格: ");int price = sc2.nextInt();System.out.println("请输入水果的单位: ");String unit = sc1.nextLine();Fruit f = new Fruit(id, name, price, unit);list.add(f);write(list);System.out.println("增加成功");}//写入新加的种类private void write(ArrayList<Fruit> list) throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter("fruit.txt"));for (int i = 0; i < list.size(); i++) {Fruit f = list.get(i);bw.write(f.getId()+" " + f.getName() + " " + f.getPrice() + " " + f.getUnit()); bw.newLine();}bw.close();}public void print(ArrayList<Fruit> list) {System.out.println("ID\t水果\t价格\t单位");for (int i = 0; i < list.size(); i++) {Fruit f = list.get(i);System.out.println(f.getId() + "\t" + f.getName() + "\t"+ f.getPrice() + "\t" + f.getUnit());}}// 查看水果public void check(ArrayList<Fruit> list) throws IOException { BufferedReader br = new BufferedReader(new FileReader("fruit.txt")); String line;while ((line = br.readLine()) != null) {String[] str = line.split(" ");Fruit f = new Fruit(str[0], str[1], Integer.parseInt(str[2]),str[3]);list.add(f);}br.close();}// 登陆系统public boolean load() throws FileNotFoundException, IOException { Scanner sc = new Scanner(System.in);System.out.println("请输入用户名:");String username = sc.nextLine();System.out.println("请输入密码:");String password = sc.nextLine();BufferedReader br = new BufferedReader(new FileReader("admin.txt"));String line = br.readLine();String[] str = line.split(",");if (str[0].equals(username) && str[1].equals(password)) {System.out.println("欢迎您进入水果管理系统:" + username);return true;} else {System.out.println("你的用户名或密码输入不正确,无法进入管理系统");return false;}}}以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我哦!。
版权所有人:李蒙学士后java 第一单元,超市收银系统,代码首先分为4个包9个类一个源文件源文件内容:HOST= localhostPORT=8888Clientjiemian类的内容:import java.text.SimpleDateFormat; import java.util.ArrayList;import java.util.Date;import java.util.Scanner;import publiClass.Datas;import publiClass.SysConstants;import datas.Shangpin;import ;public class ClientJiemian {//控制台输入对象private static Scanner input = new Scanner(System.in);//客户端业务对象private static ClientYehu clientyehu =new ClientYehu();public static void main(String[] args) {System.out.println("********************************************* *****************************************************");System.out.println("\t\t\t\t\t欢送使用青鸟超市管理系统");do {System.out.println("1. 登陆\n2. 退出系统");System.out.println("=============================================请选择1/2==============================================");String a = input.next();if (a.equalsIgnoreCase("1")) {createLoginView();break;} else if (a.equalsIgnoreCase("2")) {System.out.println("系统退出成功!");break;} elseSystem.out.println("您选择有误!请重新选择");} while (true);}//实现客户端登陆视图的生成public static void createLoginView(){do {System.out.println("请输入用户名:");String name = input.next();System.out.println("请输入密码:");String password = input.next();Datas datas = clientyehu.doLogin(name, password);//判断是管理员还是收银员if (datas.getFlag().equals(SysConstants.SYS_ADMIN)) {createAdminView();break;} else if (datas.getFlag().equals(SysConstants.SYS_USER)) { createUserView();break;} else {System.out.println("用户名或密码有误,请重新输入");}} while (true);}//实现客户端超市库存管理系统视图的生成private static void createAdminView() {System.out.println("***********************************欢送登陆青鸟超市库存管理系统*******************************************");do {System.out.println("请选择进行的操作:1. 商品入库\t2. 商品出库\t3. 新增商品\t4. 查看全部商品\t5. 按编号查询商品\t6. 退出");String option = input.next();// 商品入库if (option.equals("1")) {String id = null;int num = 0;System.out.print("请输入商品编号:");id = input.next();if (clientyehu.doFind(id).getFlag().equals(SysConstants.SYS_ERROR)) {System.out.println("没有此商品,请选择3:新增商品!");look(clientyehu.doFindAll());} else {System.out.print("请输入入库数量:");num = input.nextInt();if (num > 0) {if (clientyehu.doRuku(id, num).getFlag().equals(SysConstants.SYS_SUCCESS)) {System.out.println("入库成功!");look(clientyehu.doFindAll());}} else {System.out.println("入库失败!数量必须大于0");}}}else if (option.equals("2")) {String id = null;int num = 0;do {System.out.print("请输入商品编号:");id = input.next();Datas data = clientyehu.doFind(id);if (data.getFlag().equals(SysConstants.SYS_ERROR)) {System.out.println("没有此商品!");} else {System.out.print("请输入出库数量:");num = input.nextInt();if (num > 0) {Datas datas = clientyehu.doChuku(id, num);if(datas.getFlag().equals(SysConstants.SYS_LACK)) {System.out.println("库存缺乏,请核实,出库失败");perlook(data);break;} else {System.out.println("出库成功!");look(clientyehu.doFindAll());break;}} else {System.out.println("出库失败!数量必须大于0");break;}}} while (true);}/*** 新增商品*/else if (option.equals("3")) {do {System.out.print("请输入编号");String id = input.next();if (clientyehu.doFind(id).getFlag().equals(SysConstants.SYS_SUCCESS)) {System.out.println("此商品编号已存在!");} else {System.out.print("请输入商品名称:");String name = input.next();System.out.print("请输入商品价格:");double d = input.nextDouble();System.out.print("请输入商品单位:");String w = input.next();System.out.print("请输入商品数量:");Shangpin shangpin = new Shangpin(id, name, d, w, input.nextInt());clientyehu.doAdd(shangpin);System.out.println("新增商品成功!");look(clientyehu.doFindAll());break;}} while (true);}// 查看全部商品else if (option.equals("4")) {look(clientyehu.doFindAll());}// 编号查询商品else if (option.equals("5")) {System.out.print("请输入商品编号:");String id = input.next();Datas data = clientyehu.doFind(id);if (data.getFlag().equals(SysConstants.SYS_SUCCESS))perlook(data);else {System.out.println("对不起,没有此商品!");}}// 退出系统else if (option.equals("6")) {System.out.println("系统退出成功!");return;}else {System.out.println("您输入有误!");}} while (true);}//实现客户端超市收银管理系统视图的生成private static void createUserView() {System.out.println("***********************************欢送登陆青鸟超市收银系统*******************************************");do {System.out.println("请选择进行的操作: 1. 扫描商品\t2. 修改数量\t3. 结账\t4. 退出");String option = input.next();if (option.equals("1")) {System.out.print("请输入商品编号:");String id = input.next();if (clientyehu.doFind(id).getFlag().equals(SysConstants.SYS_SUCCESS)) {System.out.println("扫描成功");show(clientyehu.doScan(id));} else {System.out.println("对不起,没有此商品,扫描失败!");show(clientyehu.doResult());}}// 修改商品else if (option.equals("2")) {if (clientyehu.doResult().getFlag().equals(SysConstants.SYS_ERROR)) {System.out.println("您还没有扫描商品!");continue;}do {System.out.print("请输入要修改的商品编号:");String id = input.next();if (hasGoods(id)) {System.out.print("请输入修改数量:");Datas datas = null;if (input.hasNextInt()) {int a = input.nextInt();if (a > 1) {datas = clientyehu.doUpDate(id, a);if (datas.getFlag().equals(SysConstants.SYS_LACK)) {System.out.println("数量缺乏!请确认!!");perlook(clientyehu.doFind(id));continue;} else {System.out.println("修改成功!");show(clientyehu.doResult());break;}} else {System.out.println("数量必须大于0!");continue;}} else {input.next();System.out.println("请输入正确格式!");continue;}}System.out.println("对不起,还没有扫描此商品!");} while (true);}// 结账else if (option.equals("3")) {createover();} else if (option.equals("4")) {return;} else {System.out.println("您输入有误,请确认!");}} while (true);}private static void createover() {double price = sum(clientyehu.doResult());if (price != 0) {System.out.println("总金额为: " + price);System.out.println("请选择: 1. 普通结账\t2. 会员结账");String a = input.next();if (a.equals("1")) {System.out.print("请输入金额:");int money = 0;do {Scanner input = new Scanner(System.in);if (input.hasNextInt()) {money = input.nextInt();if (money < 0) {System.out.print("请输入正确金额:");}if (money < price) {System.out.print("金额缺乏!请确认:");}if (money >= price) {createResult(money, price);break;}} else {System.out.print("请输入正确格式:");}} while (true);}else if (a.equals("2")) {System.out.print("请输入您的会员卡号:");String vip = input.next();if (vip.equals("2021")) {System.out.print("会员卡号正确,请输入您要支付的金额:");int money = 0;do {Scanner input = new Scanner(System.in);if (input.hasNextInt()) {money = input.nextInt();if (money < 0) {System.out.println("请输入正确金额:");}if (money < price) {System.out.println("金额缺乏!请确认:");}if (money >= price) {createvipResult(money, price);break;}} else {System.out.print("请输入正确格式:");}} while (true);} else {System.out.println("对不起,会员卡号错误!");createover();}} else {System.out.println("您输入有误!");}} else {System.out.println("您还没有扫描商品");}}private static void perlook(Datas data) {System.out.println("------------------------------------------------------------------------------------------------");System.out.println("商品编号\t\t商品名称\t\t商品单价\t\t单位\t\t数量");System.out gpin().getSerialNumber() + "\t\t"+ data.getShangpin().getName() + "\t" +data.getShangpin().getPrice()+ "\t\t" + data.getShangpin().getUnit() + "\t\t"+ data.getShangpin().getStock());System.out.println("------------------------------------------------------------------------------------------------");}private static void look(Datas doFindAll) {System.out.println("------------------------------------------------------------------------------------------------");ArrayList<Shangpin> list = (ArrayList<Shangpin>)doFindAll.getSumArray();System.out.println("商品编号\t\t商品名称\t\t商品单价\t\t单位\t\t数量");for (Shangpin goods : list) {System.out.println(goods.getSerialNumber() + "\t\t" + goods.getName() + "\t"+ goods.getPrice() + "\t\t"+ goods.getUnit() + "\t\t"+ goods.getStock());}System.out.println("------------------------------------------------------------------------------------------------");}private static void createResult(int money, double price) { System.out.println("******************************************************* ********************************************");System.out.println("\t\t\t\t青鸟超市");System.out.println("收银员:1001\t小票号:" + ticket());display();System.out.println("总数量:" +clientyehu.doResult().getBuyArray().size()+ "\t\t应收: " + price);System.out.println("实收: " + money + "\t\t找零: " + (money - price));System.out.println(date());System.out.println("此小票是您退换货及核对积分的凭证,请妥善保存!");System.out.println("======================================================= ===========================================");clientyehu.doClear();}private static String date() {Date date = new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd/hh/mm/ss");String dat = sdf.format(date);return dat;}private static void display() {ArrayList<Shangpin> list = clientyehu.doResult().getBuyArray();System.out.println("序\t\t商品名称\t\t\t\t数量\t\t单位\t\t金额");System.out.println("------------------------------------------------------------------------------------------------");for (int i = 0; i < list.size(); i++) {System.out.println(i + 1 + "\t\t"+ "["et(i).getSerialNumber() + "]"+ list.get(i).getName() + list.get(i).getUnit() + "\t\t"+ list.get(i).getStock() + "\t\t" +list.get(i).getPrice()+ "\t\t" + list.get(i).getStock() *list.get(i).getPrice());}System.out.println("------------------------------------------------------------------------------------------------");}private static String ticket() {Date date = new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmm");String ticket = sdf.format(date) + (int) (Math.random() * 1000);return ticket;}private static void createvipResult(double money, double price) { System.out.println("******************************************************* ********************************************");System.out.println("\t\t\t青鸟超市");System.out.println("收银员:1001\t小票号:" + ticket());display();System.out.println("总数量:" +clientyehu.doResult().getBuyArray().size()+ "\t\t应收: " + price);System.out.println("实收: " + money + "\t\t找零: " + (money - price));System.out.println("本次累计积分成功\t 卡号:2021");System.out.println("当前积分+本次消费积分+消费后积分");System.out.println("2000+" + price + "=" + (2000 + price));System.out.println(date());System.out.println("此小票是您退换货及核对积分的凭证,请妥善保存!");System.out.println("======================================================= =========================================");clientyehu.doClear();}private static double sum(Datas doResult) {if (doResult.getFlag().equals(SysConstants.SYS_SUCCESS)) { ArrayList<Shangpin> list = doResult.getBuyArray();double sum = 0;for (int i = 0; i < list.size(); i++) {sum += list.get(i).getPrice() * list.get(i).getStock();}return sum;} elsereturn 0;}private static boolean hasGoods(String id) {if(clientyehu.doResult().getFlag().equals(SysConstants.SYS_SUCCESS)) { ArrayList<Shangpin> list =clientyehu.doResult().getBuyArray();for (int i = 0; i < list.size(); i++) {if (list.get(i).getSerialNumber().equals(id)) {return true;}}}return false;}private static void show(Datas doScan) {if (doScan.getFlag().equals(SysConstants.SYS_SUCCESS)) { ArrayList<Shangpin> list = doScan.getBuyArray();System.out.println("商品名称\t\t\t\t数量\t\t单价\t\t金额");System.out.println("-----------------------------------------------------------------------------------------------");for (int i = 0; i < list.size(); i++) {System.out.println("["+ list.get(i).getSerialNumber() + "]"+ list.get(i).getName() + list.get(i).getUnit()+ "\t\t" + list.get(i).getStock() + "\t\t"+ list.get(i).getPrice() + "\t\t"+ list.get(i).getPrice() *list.get(i).getStock());}System.out.println("------------------------------------------------------------------------------------------------");}}}Clientyehu类的内容import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import .Socket;import .UnknownHostException;import publiClass.Datas;import publiClass.SysConstants;import publiClass.Tools;import datas.Shangpin;import datas.Yuangong;//用socket实现它与效劳器的交互public class ClientYehu {//创立socket实例Socket socket =new Socket();//创立输入流对象ObjectInputStream objectInputStream =null;//创立输出流对象ObjectOutputStream objectOutputStream =null;private void initSocket(){//实例化socket关联对象String hostname = Tools.getVlaue(SysConstants.SYS_HOSTNAME);int port =Integer.parseInt(Tools.getVlaue(SysConstants.SYS_LISTENERPORT));try {socket = new Socket(hostname,port);//??????objectInputStream =newObjectInputStream(socket.getInputStream());objectOutputStream=newObjectOutputStream(socket.getOutputStream());} catch (UnknownHostException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public void closeSocket(){//关闭socket关联对象try {objectInputStream.close();objectOutputStream.close();socket.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public Datas doLogin(String acountNumber,String password){//登陆方法:通过Socket调用效劳器的登陆效劳try {initSocket();Yuangong yuangong=new Yuangong();yuangong.setName(acountNumber);yuangong.setPassword(password);//设置Datas参数属性Datas datas =new Datas();datas.setYuangong(yuangong);datas.setFlag(SysConstants.SYS_LOGIN);//读和写objectOutputStream.writeObject(datas);d atas=( Datas)objectInputStream.readObject();return datas;} catch (IOException e) {// TODO Auto-generated catch blockce();} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally {closeSocket();}return null;}//增加库存public Datas doRuku(String serialNumber, int stock) { initSocket();Datas datas = new Datas();Shangpin shangpin = new Shangpin();shangpin.setSerialNumber(serialNumber);shangpin.setStock(stock);datas.setShangpin(shangpin);datas.setFlag(SysConstants.SYS_RUKU);objectOutputStream.writeObject(datas);d atas=( Datas)objectInputStream.readObject();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (ClassNotFoundException e) {// TODO Auto-generated catch blockrace();} finally {closeSocket();}return datas;}//减少库存public Datas doChuku(String serialNumber, int stock) { initSocket();Datas datas = new Datas();Shangpin shangpin = new Shangpin();shangpin.setSerialNumber(serialNumber);shangpin.setStock(stock);datas.setShangpin(shangpin);datas.setFlag(SysConstants.SYS_RUKU);try {objectOutputStream.writeObject(datas);d atas=( Datas)objectInputStream.readObject();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {closeSocket();}return datas;}//添加新商品功能public Datas doAdd(Shangpin shangpin){initSocket();Datas datas = new Datas();datas.setFlag(SysConstants.SYS_ADD);datas.setShangpin(shangpin);//读和写objectOutputStream.writeObject(datas);datas=( Datas)objectInputStream.readObject();}catch (ClassNotFoundException e) {e.printStackTrace();}catch (IOException e) {e.printStackTrace();}finally{closeSocket();}return null;}//查询商品方法public Datas doFind(String serialNumber) {initSocket();Shangpin shangpin = new Shangpin();shangpin.setSerialNumber(serialNumber);Datas datas = new Datas();datas.setShangpin(shangpin);datas.setFlag(SysConstants.SYS_FIND);try {objectOutputStream.writeObject(datas);datas=( Datas)objectInputStream.readObject();} catch (IOException e) {} catch (ClassNotFoundException e) {e.printStackTrace();} finally {closeSocket();}return datas;}//查看所有商品public Datas doFindAll() {initSocket();Datas datas = new Datas();datas.setFlag(SysConstants.SYS_FINDALL);try {objectOutputStream.writeObject(datas);datas=( Datas)objectInputStream.readObject();} catch (IOException e) {e.printStackTrace();} catch (ClassNotFoundException e) {e.printStackTrace();} finally {closeSocket();}return datas;}//扫描商品public Datas doScan(String serialNumber) {initSocket();Datas datas = new Datas();Shangpin shangpin = new Shangpin();shangpin.setSerialNumber(serialNumber);datas.setShangpin(shangpin);datas.setFlag(SysConstants.SYS_SCAN);try {objectOutputStream.writeObject(datas);datas=( Datas)objectInputStream.readObject();} catch (IOException e) {} catch (ClassNotFoundException e) {e.printStackTrace();} finally {closeSocket();}return datas;}//商品数量修改public Datas doUpDate(String serialNumber, int stock) { initSocket();Datas datas = new Datas();Shangpin shangpin= new Shangpin();shangpin.setSerialNumber(serialNumber);shangpin.setStock(stock);datas.setShangpin(shangpin);datas.setFlag(SysConstants.SYS_UPDATA);try {objectOutputStream.writeObject(datas);datas=( Datas)objectInputStream.readObject();} catch (IOException e) {e.printStackTrace();} catch (ClassNotFoundException e) {e.printStackTrace();} finally {closeSocket();}return datas;}//商品结账public Datas doResult() {initSocket();Datas datas = new Datas();datas.setFlag(SysConstants.SYS_RESULT);try {objectOutputStream.writeObject(datas);datas=( Datas)objectInputStream.readObject();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {closeSocket();}return datas;}//商品清空public Datas doClear(){initSocket();Datas datas = new Datas();datas.setFlag(SysConstants.SYS_CLEAR);try {objectOutputStream.writeObject(datas);datas=( Datas)objectInputStream.readObject();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {closeSocket();}return datas;}}Shangpin类的内容import java.io.Serializable;public class Shangpin implements Serializable {//名称private String name;//编号private String serialNumber;//价格private double price;//库存private int stock;//单位private String unit;public Shangpin(){}public Shangpin(String _serialNumber,String _name,double _price,String _unit,int _stock){=_name;this.serialNumber=_serialNumber;this.price= _price;this.stock=_stock;this.unit=_unit;}public String getUnit() {return unit;}public void setUnit(String unit) {this.unit = unit;}public String getName() {return name;}public void setName(String name) { = name;}public String getSerialNumber() {return serialNumber;}public void setSerialNumber(String serialNumber2) { this.serialNumber = serialNumber2;}public double getPrice() {return price;}public void setPrice(double d) {if (d>0){this.price = d;}else {System.out.println("输入不合法,请重新输入");}}public int getStock() {return stock;}public void setStock(int stock) {this.stock = stock;}}Yuangong类的内容import java.io.Serializable;public class Yuangong implements Serializable{//账号private String name;//密码private String password;public String getName() {return name;}public void setName(String name) { = name;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public Yuangong(){}public Yuangong(String _acountNumber,String _password){ =_acountNumber;this.password=_password;}}Datas类的内容import java.io.Serializable;import java.util.ArrayList;import datas.Shangpin;import datas.Yuangong;public class Datas implements Serializable{//传递标示private String flag;private Shangpin shangpin;private Yuangong yuangong;private ArrayList<Shangpin> sumArray;private ArrayList<Shangpin> buyArray;public ArrayList<Shangpin> getSumArray() {return sumArray;}public void setSumArray(ArrayList<Shangpin> sumArray) { this.sumArray = sumArray;}public ArrayList<Shangpin> getBuyArray() {return buyArray;}public void setBuyArray(ArrayList<Shangpin> buyArray) { this.buyArray = buyArray;}public String getFlag() {return flag;}public void setFlag(String flag) {this.flag = flag;}public Shangpin getShangpin() {return shangpin;}public void setShangpin(Shangpin shangpin) {this.shangpin = shangpin;}public Yuangong getYuangong() {return yuangong;}public void setYuangong(Yuangong yuangong) {this.yuangong = yuangong;}}SysConstants类的内容public class SysConstants {public static final String SYS_PROPERTYNAME ="sys.properties"; public static final String SYS_LISTENERPORT ="PORT";public static final String SYS_HOSTNAME ="HOST";public static final String SYS_SUCCESS ="SUCCESS";public static final String SYS_ERROR ="ERROR";public static final String SYS_LOGIN ="LOGIN";//添加一个管理员常量public static final String SYS_ADMIN="ADMIN";//添加一个收银常量public static final String SYS_USER = "USER";;//查询商品public static final String SYS_FIND ="FIND";//查询所有public static final String SYS_FINDALL ="FINDALL"; //添加一个入库常量public static final String SYS_RUKU ="RUKU";//添加一个出库常量public static final String SYS_CHUKU ="CHUKU";//添加一个添加常量public static final String SYS_ADD="ADD";//商品扫描public static final String SYS_SCAN="SCAN";//修改商品数量public static final String SYS_UPDATA="UPDATA";//删除商品public static final String SYS_DELETE ="DELETE";//商品结账public static final String SYS_RESULT = "RESULL"; //商品清空public static final String SYS_CLEAR = "CLEAR"; public static final String SYS_LACK = "LACK";}Tools类的内容import java.io.IOException;import java.util.Properties;public class Tools {private static Properties p= new Properties(); //读取properties配置文件信息static {//加载资源文件try {p.load(Tools.class.getClassLoader().getResourceAsStream(SysConsta nts.SYS_PROPERTYNAME));} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}//通过关键字取值public static String getVlaue(String key){return p.getProperty(key);}}Serverservice类的内容import java.util.ArrayList;import ;import ;import publiClass.Datas;import publiClass.SysConstants;import datas.Shangpin;import datas.Yuangong;public class Serversevice {private static Yuangong user;private static Yuangong admin;private static ArrayList<Shangpin> sumlist = newArrayList<Shangpin>();private static ArrayList<Shangpin> buylist = newArrayList<Shangpin>();//初始化员工和商品对象集合static {user = new Yuangong("user", "1234");admin = new Yuangong("admin", "1234");sumlist.add(new Shangpin("10001","苹果",4.5,"1kg",100));sumlist.add(new Shangpin("10002","桃子",2.98,"1kg",100));sumlist.add(new Shangpin("10003","牛奶",4,"100ml",100));}// 用户登录public Datas login(Datas datas) {if(datas.getYuangong().getName().equals(admin.getName())&& datas.getYuangong().getPassword().equals(admin.getPassword()))datas.setFlag(SysConstants.SYS_ADMIN);else if(datas.getYuangong().getName().equals(user.getName())&&datas.getYuangong().getPassword().equals(user.getPassword()))datas.setFlag(SysConstants.SYS_USER);elsedatas.setFlag(SysConstants.SYS_ERROR);return datas;}// 商品入库public Datas up(Datas datas) {for (int i = 0; i < sumlist.size(); i++) {if(datas.getShangpin().getSerialNumber().equals(sumlist.get(i).getSeria lNumber())) {sumlist.get(i).setStock(sumlist.get(i).getStock() +datas.getShangpin().getStock());datas.setSumArray(sumlist);datas.setFlag(SysConstants.SYS_SUCCESS);return datas;}}datas.setFlag(SysConstants.SYS_ERROR);return datas;}// 商品出库public Datas down(Datas datas) {for (int i = 0; i < sumlist.size(); i++) {if(datas.getShangpin().getSerialNumber().equals(sumlist.get(i).getSeria lNumber())) {if (sumlist.get(i).getStock() >=datas.getShangpin().getStock()) {sumlist.get(i).setStock(sumlist.get(i).getStock()。
榆林学院[超市库存管理系统]专业:[计算机科学与技术] 班级:[ 13级计本1班] 学生姓名:[ 李治生]学号:[1312210142]一、需求分析 (3)二、概要设计 (3)三、详细设计 (4)1、数据库设计 (4)用户登录界面: (6)进入主界面: (9)四、软件测试 (39)五、总结 (40)六、附录: (41)一、需求分析本系统主要是用来帮助小型超市进行库存管理系统,能够有效的帮助小型超市进行库存管理!其中包括增删改查等基本的应用。
极大的提高了超市的库存管理效率,节省了大量的时间。
*********************************************************** ***********************************************************二、概要设计1、本系统的每一个功能模块都包含了多个功能。
整个系统主要完成对超市商品的日常管理,包括进货管理,库存管理和供应商管理等方面。
在功能上系统可以完成对相关信息的浏览、查询、添加、删除、修改等功能。
本课题的核心之一是销售管理、库存管理和进货管理三者之间的联系,同时系统有完整的用户管理功能。
本系统采用java语言和SQL Server 2008作为开发工具。
这种系统优势在于系统比较简单,但功能强大,扩展性能也比较好,完全能够处理一般超市的日常任务2、整体分为3个模块(货物,供应商,记录)每个模块之间相互关联,都有自己的增删改查!3、程序流程图如下:开始登陆界面N密码正确Y主界面货物管理供应商管理查询记录进货计划OVER三、详细设计1、数据库设计Goods表:Lzs(用户登录名,密码):Recond表():记录表Supplier(供应商表):用户登录界面:设计代码如下:package source;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;@SuppressWarnings("serial")public class loginframe extends JFrame implements ActionListener { JTextField 用户名;JPasswordField 密码;JButton 登录,重置;Box baseBox,box1,box2,box3;//盒式布局ImagePanel p;//用于插入图片的面板JSplitPane split;//拆分窗格Font f;//设置字体JLabel userName,psw;Function wMain;Connection con;Statement sql;ResultSet rs;String dbdriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";String dburl = "jdbc:sqlserver://localhost:1433;DatabaseName=LZS";String user = "sa";String pass = "123";public loginframe(){setLayout(new FlowLayout());init();setBounds(130,80,960,600);setVisible(true);setResizable(false);try{Class.forName(dbdriver);}catch(ClassNotFoundException classnotfound){System.out.println("未能找到SQLServerDriver,请检查是否已加载SQLServer驱动");}}void init(){f = new Font("幼圆",Font.BOLD,18);p = new ImagePanel(new ImageIcon("E:/Java文件/SuperMarket/picture/1.jpg").getImage());登录= new JButton("登录");登录.addActionListener(this);重置= new JButton("重置");重置.addActionListener(this);用户名= new JTextField(16);用户名.setFont(f);密码= new JPasswordField(16);userName = new JLabel("用户名:");userName.setFont(f);psw = new JLabel("密码:");psw.setFont(f);box1 = Box.createVerticalBox();box1.add(userName);box1.add(Box.createVerticalStrut(20));box1.add(psw);box2 = Box.createVerticalBox();box2.add(Box.createVerticalStrut(240));box2.add(用户名);box2.add(Box.createVerticalStrut(20));box2.add(密码);box2.add(Box.createVerticalStrut(20));box3 = Box.createHorizontalBox();box3.add(登录);box3.add(Box.createHorizontalStrut(20));box3.add(重置);box2.add(box3);box2.add(Box.createVerticalStrut(200));baseBox = Box.createHorizontalBox();baseBox.add(box1);baseBox.add(Box.createHorizontalStrut(15));baseBox.add(box2);//baseBox.add(登录);split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,false,p,baseBox);split.setDividerLocation(0.5);add(split,BorderLayout.PAGE_START);}public void actionPerformed(ActionEvent e){if(e.getSource() == 登录){String Uname = 用户名.getText().trim();char[]psw = 密码.getPassword();String passWord = new String(psw);try{con =DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=LZS","sa","123");System.out.println("数据库连接成功!");sql=con.createStatement();String string = "SELECT * FROM lzs WHERE Uname= '"+Uname+"' AND mima = '"+passWord+"'";rs = sql.executeQuery(string);if(rs.next()){wMain = new Function();wMain.setTitle("超市库存管理系统");wMain.setVisible(true);this.dispose();// wMain.pack();}else{JOptionPane.showMessageDialog(this, "您输入的用密码不正确","警告对话框",JOptionPane.WARNING_MESSAGE);密码.setText(null);密码.requestFocus();}con.close();}catch(SQLException ee){ee.printStackTrace();}}else if(e.getSource() == 重置){用户名.setText("");密码.setText("");}}}进入主界面:第一菜单(货物):第二菜单(供应商):第三菜单(记录):设计代码如下:package source;import java.awt.*;import java.awt.event.*;import javax.swing.*;@SuppressWarnings("serial")public class Function extends JFrame implements ActionListener{ Font f;//菜单栏JMenuBar menubar;//菜单条JMenu 货物,供应商,记录; //菜单JMenuItem 货物管理,退出,供应商管理,查询记录,进货计划;//菜单项//Box box;JLabel label;ImagePanel p;//用于插入图片的面板//构造函数Function(){setLayout(new FlowLayout());init();setTitle("超市库存管理系统");setLocation(20,30);setSize(1200,800);setBounds(130,80,960,600);setVisible(true);setResizable(false);}void init(){menubar = new JMenuBar();f = new Font("华文行楷",Font.BOLD,50);Font f2 = new Font("宋体",0,12);p = new ImagePanel(new ImageIcon("E:Java文件/SuperMarket/picture/2.jpg").getImage());//库房货物管理菜单货物= new JMenu("货物");货物.setFont(f2);货物管理= new JMenuItem("货物管理");货物管理.setFont(f2);货物管理.addActionListener(this);退出= new JMenuItem("退出");退出.setFont(f2);退出.addActionListener(this);货物.add(货物管理);货物.add(退出);menubar.add(货物);//货物供应商菜单供应商= new JMenu("供应商");供应商.setFont(f2);供应商管理= new JMenuItem("供应商管理");供应商管理.setFont(f2);供应商管理.addActionListener(this);供应商.add(供应商管理);menubar.add(供应商);//货物进货、入库和出库记录查询菜单记录= new JMenu("记录");记录.setFont(f2);查询记录= new JMenuItem("查询记录");查询记录.setFont(f2);查询记录.addActionListener(this);进货计划= new JMenuItem("进货计划");进货计划.setFont(f2);进货计划.addActionListener(this);记录.add(查询记录);记录.add(进货计划);menubar.add(记录);label = new JLabel("欢迎进入超市库存管理系统");label.setFont(f);p.add(label);label.setBounds(300,400,800,200);add(p,BorderLayout.CENTER);setJMenuBar(menubar);}public void actionPerformed(ActionEvent e){if(e.getSource()==供应商管理){SupplierManage smTable = new SupplierManage();smTable.setVisible(true);smTable.pack();}else if(e.getSource()==货物管理){goods goTable = new goods();goTable.setVisible(true);goTable.pack();}else if(e.getSource()==查询记录){record reTable = new record();reTable.setVisible(true);reTable.pack();}else if(e.getSource() ==进货计划){plan plTable = new plan();plTable.setVisible(true);plTable.pack();}else if(e.getSource()==退出){this.dispose();}}}进入第一菜单(货物管理):在此菜单下,可进行货物的增删改查操作,设计代码如下:package source;import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.*;import javax.swing.table.DefaultTableModel;@SuppressWarnings("serial")public class goods extends JFrame implements ActionListener{JTable table;JLabel label;JTextField inputText;String []name = {"货物号","货物名","进货价","售价","折扣价","余量","余量预警值","供应商"};String []strings = new String[8];JButton 添加,修改,删除,退出,确认修改;JPanel p;JLabel []labels = new JLabel[8];JTextField []fields = new JTextField[8];Box baseBox,box1,box2;ImagePanel pp;//用于插入图片的面板JSplitPane split;//拆分窗格DefaultTableModel deModel = null;Connection con;Statement sql;ResultSet rs;String dbdriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";String dburl = "jdbc:sqlserver://localhost:1433;DatabaseName=LZS";String user = "sa";String pass = "123";goods(){setLayout(new BorderLayout());init();// Toolkit tk = Toolkit.getDefaultToolkit();// Image img = tk.getImage("E:Java文件/SuperMarket/picture/2.jpg");// setIconImage(img);setTitle("货物管理");setBounds(130,80,960,600);;//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setResizable(false);try{Class.forName(dbdriver);}catch(ClassNotFoundException classnotfound){classnotfound.printStackTrace();}}void init(){pp = new ImagePanel(new ImageIcon("E:/Java文件/SuperMarket/picture/2.jpg").getImage());添加= new JButton("添加");修改= new JButton("修改");删除= new JButton("删除");退出= new JButton("退出");确认修改= new JButton("确认修改");label = new JLabel("请输入想要删除或修改的货物名:");inputText = new JTextField(8);添加.addActionListener(this);修改.addActionListener(this);删除.addActionListener(this);退出.addActionListener(this);确认修改.addActionListener(this);p = new JPanel();p.add(label);p.add(inputText);p.add(添加);p.add(修改);p.add(删除);p.add(退出);p.add(确认修改);add(p,BorderLayout.SOUTH);labels[0] = new JLabel("货物号");labels[1] = new JLabel("货物名");labels[2] = new JLabel("进货价");labels[3] = new JLabel("售价");labels[4] = new JLabel("折扣价");labels[5] = new JLabel("余量");labels[6] = new JLabel("余量预警值");labels[7] = new JLabel("供应商");for(int i = 0;i<8;i++){fields[i] = new JTextField(20);}//用盒式容器装要录入的数据和标签box1 = Box.createVerticalBox();box1.add(Box.createVerticalStrut(15));for(int i = 0;i<8;i++){box1.add(labels[i]);box1.add(Box.createVerticalStrut(35));}box2 = Box.createVerticalBox();box2.add(Box.createVerticalStrut(10));for(int i = 0;i<8;i++){box2.add(fields[i]);box2.add(Box.createVerticalStrut(14));}baseBox = Box.createHorizontalBox();baseBox.add(box1);baseBox.add(Box.createHorizontalStrut(15));baseBox.add(box2);//添加表格add(baseBox,BorderLayout.EAST);deModel = new DefaultTableModel(name,0);table = new JTable(deModel);table.setCellSelectionEnabled(false);table.setEnabled(false);table.setShowHorizontalLines(true);table.setShowVerticalLines(true);//add(new JScrollPane(table),BorderLayout.CENTER);split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,false,newJScrollPane(table),baseBox);split.setDividerLocation(0.5);add(split,BorderLayout.CENTER);String sqlString = "select * from goods";try{//连接数据库con = DriverManager.getConnection(dburl, user, pass);sql = con.createStatement();JOptionPane.showMessageDialog(this, "数据库连接成功!","消息对话框",RMATION_MESSAGE);rs = sql.executeQuery(sqlString);while(rs.next()){for(int i = 0;i<8;i++){strings[i]=rs.getString(i+1);//把查询的结果填入表格中}deModel.addRow(strings);deModel.fireTableStructureChanged();//更新中的数据}}catch(SQLException ee){ee.printStackTrace();}}public void actionPerformed(ActionEvent e){if(e.getSource() == 添加){String sqlString = "INSERT INTO goods VALUES('"+fields[0].getText()+"','"+fields[1].getText()+"','"+fields[2].getText()+"','"+fields[3].getText()+"','" +fields[4].getText()+"','"+fields[5].getText()+"','"+fields[6].getText()+"','"+fields[7].getText()+"')";try{sql.execute(sqlString);JOptionPane.showMessageDialog(this, "操作成功!","消息对话框",RMATION_MESSAGE);//更新表格中的数据for(int i = deModel.getRowCount()-1;i>=0;i--){deModel.removeRow(i);deModel.fireTableStructureChanged();}rs = sql.executeQuery("select * from goods");while(rs.next()){for(int j = 0;j<8;j++){strings[j]=rs.getString(j+1);}deModel.addRow(strings);deModel.fireTableStructureChanged();//更新中的数据}}catch(SQLException ee){ee.printStackTrace();}for(int i = 0;i<8;i++){fields[i].setText("");}fields[0].requestFocus();//设置光标的位置,在第一个文本框上面}else if(e.getSource() == 修改){try{rs = sql.executeQuery("select * from goods");while(rs.next()){for(int i = 0;i<8;i++){strings[i]=rs.getString(i+1);}if(strings[1].trim().compareTo(inputText.getText().trim())==0){for(int i = 0;i<8;i++){fields[i].setText(strings[i]);}}}fields[0].setEditable(false);fields[1].setEditable(false);}catch(SQLException ee){ee.printStackTrace();}}else if(e.getSource() == 确认修改){String sqlString = "UPDATE goods SET shangpinhao ='"+fields[0].getText()+"',shangpinming='"+fields[1].getText()+"',jinhuojia='"+fields[2].getText()+"',s houji='"+fields[3].getText()+"',zhekoujia='"+fields[4].getText()+"',yuliang='"+fields[5].getText()+"',y uliangyujingzhi='"+fields[6].getText()+"',gongyingshang='"+fields[7].getText()+"'where shangpinming ='"+inputText.getText()+"'";try{sql.execute(sqlString);JOptionPane.showMessageDialog(this, "操作成功!","消息对话框",RMATION_MESSAGE);//更新表格中的数据for(int i = deModel.getRowCount()-1;i>=0;i--){deModel.removeRow(i);deModel.fireTableStructureChanged();}rs = sql.executeQuery("select * from goods");while(rs.next()){for(int j = 0;j<8;j++){strings[j]=rs.getString(j+1);}deModel.addRow(strings);deModel.fireTableStructureChanged();//更新中的数据}}catch(SQLException ee){ee.printStackTrace();}for(int i = 0;i<8;i++){fields[i].setText("");}fields[0].setEditable(true);fields[1].setEditable(true);inputText.setText("");fields[0].requestFocus();//设置光标的位置,在第一个文本框上面}else if(e.getSource() == 删除){String sqlString = "DELETE FROM goods WHERE shangpinming = '"+inputText.getText().trim()+"'";try{sql.execute(sqlString);//将表格中的内容清空for(int i = deModel.getRowCount()-1;i>=0;i--){deModel.removeRow(i);deModel.fireTableStructureChanged();}rs = sql.executeQuery("select * from goods");while(rs.next()){for(int i = 0;i<8;i++){strings[i]=rs.getString(i+1);//把查询的结果填入表格中}deModel.addRow(strings);deModel.fireTableStructureChanged();//更新中的数据}JOptionPane.showMessageDialog(this, "操作成功!","消息对话框",RMATION_MESSAGE);inputText.setText("");}catch(SQLException ee){ee.printStackTrace();}}else if(e.getSource()==退出){this.dispose();}}}进入第二菜单(供应商管理界面):在此界面下可进行供应商的增删改查操作:设计代码如下:package source;import java.awt.*;import java.awt.event.*;import java.sql.*;import javax.swing.*;import javax.swing.table.DefaultTableModel;import java.util.Date;@SuppressWarnings("serial")public class SupplierManage extends JFrame implements ActionListener{ JTable table;JLabel label;JTextField inputText;String []name = {"添加时间","供应商","联系电话","地址","邮箱","备注"};String []strings = new String[6];JButton 修改,删除,添加,退出,确认修改;JPanel p;JLabel []labels = new JLabel[5];JTextField []fields = new JTextField[5];Box baseBox,box1,box2;JSplitPane split;//拆分窗格DefaultTableModel deModel = null;Connection con;Statement sql;ResultSet rs;Date date;String dbdriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";String dburl = "jdbc:sqlserver://localhost:1433;DatabaseName=LZS";String user = "sa";String pass = "123";SupplierManage(){setLayout(new BorderLayout());init();Toolkit tk = Toolkit.getDefaultToolkit();Image img = tk.getImage("C:/Documents and Settings/Administrator/workspace/招聘_求职管理系统/picture/003.jpg");setIconImage(img);setTitle("供应商管理");setBounds(130,80,960,600);;setResizable(false);try{Class.forName(dbdriver);}catch(ClassNotFoundException classnotfound){classnotfound.printStackTrace();}}void init(){修改= new JButton("修改");删除= new JButton("删除");添加= new JButton("添加");退出= new JButton("退出");确认修改= new JButton("确认修改");label = new JLabel("请输入想要删除或修改的供应商:");inputText = new JTextField(6);修改.addActionListener(this);删除.addActionListener(this);添加.addActionListener(this);退出.addActionListener(this);确认修改.addActionListener(this);p = new JPanel();p.add(label);p.add(inputText);p.add(修改);p.add(删除);p.add(添加);p.add(退出);p.add(确认修改);add(p,BorderLayout.SOUTH);//labels[0] = new JLabel("添加时间");labels[0] = new JLabel("供应商");labels[1] = new JLabel("联系电话");labels[2] = new JLabel("地址");labels[3] = new JLabel("邮箱");labels[4] = new JLabel("备注");for(int i = 0;i<5;i++){fields[i] = new JTextField(20);}//用盒式容器装要录入的数据和标签box1 = Box.createVerticalBox();box1.add(Box.createVerticalStrut(15));for(int i = 0;i<5;i++){box1.add(labels[i]);box1.add(Box.createVerticalStrut(70));}box2 = Box.createVerticalBox();box2.add(Box.createVerticalStrut(10));for(int i = 0;i<5;i++){box2.add(fields[i]);box2.add(Box.createVerticalStrut(60));}baseBox = Box.createHorizontalBox();baseBox.add(box1);baseBox.add(Box.createHorizontalStrut(15));baseBox.add(box2);//添加表格add(baseBox,BorderLayout.EAST);deModel = new DefaultTableModel(name,0);table = new JTable(deModel);table.setCellSelectionEnabled(false);table.setEnabled(false);table.setShowHorizontalLines(true);table.setShowVerticalLines(true);//add(new JScrollPane(table),BorderLayout.CENTER);split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,false,new JScrollPane(table),baseBox);split.setDividerLocation(0.5);add(split,BorderLayout.CENTER);String sqlString = "select * from supplier";try{//连接数据库con = DriverManager.getConnection(dburl,user,pass);System.out.println("数据库连接成功!");sql=con.createStatement();rs = sql.executeQuery(sqlString);while(rs.next()){for(int i = 0;i<6;i++){strings[i]=rs.getString(i+1);//把查询的结果填入表格中}deModel.addRow(strings);deModel.fireTableStructureChanged();//更新中的数据}}catch(SQLException ee){ee.printStackTrace();}}public void actionPerformed(ActionEvent e){if(e.getSource()==修改){try{rs = sql.executeQuery("select * from supplier");while(rs.next()){for(int i = 0;i<6;i++){strings[i]=rs.getString(i+1);}if(strings[1].trim().compareTo(inputText.getText().trim())==0){for(int i = 0;i<5;i++){fields[i].setText(strings[i+1]);}}}fields[0].setEditable(false);}catch(SQLException ee){ee.printStackTrace();}}else if(e.getSource() == 确认修改){String sqlString = "UPDATE supplier SET gongyingshang ='"+fields[0].getText()+"',lianxidianhua='"+fields[1].getText()+"',dizhi='"+fields[2].getText()+"',youxi ang='"+fields[3].getText()+"',beizhu='"+fields[4].getText()+"'where gongyingshang='"+inputText.getText()+"'";try{sql.execute(sqlString);JOptionPane.showMessageDialog(this, "操作成功!","消息对话框",RMATION_MESSAGE);//更新表格中的数据for(int i = deModel.getRowCount()-1;i>=0;i--){deModel.removeRow(i);deModel.fireTableStructureChanged();}rs = sql.executeQuery("select * from supplier");while(rs.next()){for(int j = 0;j<6;j++){strings[j]=rs.getString(j+1);}deModel.addRow(strings);deModel.fireTableStructureChanged();//更新中的数据}fields[0].setEditable(true);}catch(SQLException ee){ee.printStackTrace();}for(int i = 0;i<5;i++){fields[i].setText("");}inputText.setText("");fields[0].requestFocus();//设置光标的位置,在第一个文本框上面}else if(e.getSource() == 删除){String sqlString = "DELETE FROM supplier WHERE gongyingshang ='"+inputText.getText()+"'";try{sql.execute(sqlString);//将表格中的内容清空for(int i = deModel.getRowCount()-1;i>=0;i--){deModel.removeRow(i);deModel.fireTableStructureChanged();}rs = sql.executeQuery("select * from supplier");while(rs.next()){for(int i = 0;i<6;i++){strings[i]=rs.getString(i+1);//把查询的结果填入表格中}deModel.addRow(strings);deModel.fireTableStructureChanged();//更新中的数据}JOptionPane.showMessageDialog(this, "操作成功!","消息对话框",RMATION_MESSAGE);inputText.setText("");}catch(SQLException ee){ee.printStackTrace();}}else if(e.getSource() == 添加){date=new Date();String sqlString = "INSERT INTO supplier VALUES('"+date+"','"+fields[0].getText()+"','"+fields[1].getText()+"','"+fields[2].getText()+"','"+fields[3].get Text()+"','"+fields[4].getText()+"')";try{sql.execute(sqlString);JOptionPane.showMessageDialog(this, "操作成功!","消息对话框",RMATION_MESSAGE);//更新表格中的数据for(int i = deModel.getRowCount()-1;i>=0;i--){deModel.removeRow(i);deModel.fireTableStructureChanged();}rs = sql.executeQuery("select * from supplier");while(rs.next()){for(int j = 0;j<6;j++){strings[j]=rs.getString(j+1);}deModel.addRow(strings);deModel.fireTableStructureChanged();//更新中的数据}}catch(SQLException ee){ee.printStackTrace();}for(int i = 0;i<5;i++){fields[i].setText("");}inputText.setText("");fields[0].requestFocus();//设置光标的位置,在第一个文本框上面}else if(e.getSource()==退出){this.dispose();}}}进入第三菜单(记录界面):在此界面下可进行对货物进货的记录的增删改查:库存记录设计代码如下:package source;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.table.DefaultTableModel;import java.sql.*;@SuppressWarnings("serial")public class plan extends JFrame implements ActionListener{JButton 添加,删除,退出;JTable table;//表JLabel label;//JTextField inputText;DefaultTableModel deModel = null;JSplitPane split;//拆分窗格JTextField []text = new JTextField[2];//用于填写签约信息的文本框String []name = {"日期","商品名","供应商","操作","数量"};String strings[] = new String[5];JPanel p1,p3;//二个面板JLabel []labels = new JLabel[5];JComboBox choice1,choice2,choice3,inputText;Connection con;Statement sql;ResultSet rs;String dbdriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";String dburl = "jdbc:sqlserver://localhost:1433;DatabaseName=LZS"; String user = "sa";String pass = "123";Box baseBox,box1,box2;//盒式布局plan() {setLayout(new BorderLayout());init();Toolkit tk = Toolkit.getDefaultToolkit();Image img = tk.getImage("e:/java文件/SuperMarket/picture/1.jpg");setIconImage(img);setTitle("进货计划");setBounds(130,80,960,600);;setResizable(false);try{Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");}catch(ClassNotFoundException classnotfound){classnotfound.printStackTrace();}}void init(){添加= new JButton("添加");删除= new JButton("删除");退出= new JButton("退出");添加.addActionListener(this);删除.addActionListener(this);退出.addActionListener(this);choice1=new JComboBox();choice2=new JComboBox();choice3=new JComboBox();inputText=new JComboBox();label = new JLabel("请输入想要删除的日期:"); //inputText = new JTextField(6);p1 = new JPanel();p1.add(label);p1.add(inputText);p1.add(添加);p1.add(删除);p1.add(退出);add(p1,BorderLayout.SOUTH);labels[0] = new JLabel("日期");labels[1] = new JLabel("商品名");labels[2] = new JLabel("供应商");labels[3] = new JLabel("操作");labels[4] = new JLabel("数量");for(int i = 0;i<2;i++){text[i] = new JTextField(20);}choice3.addItem("计划");choice3.addItem("已预定");//用盒式容器装要录入的数据和标签box1 = Box.createVerticalBox();box1.add(Box.createVerticalStrut(20));for(int i = 0;i<5;i++){box1.add(labels[i]);box1.add(Box.createVerticalStrut(70));}box2 = Box.createVerticalBox();box2.add(Box.createVerticalStrut(20));box2.add(text[0]);box2.add(Box.createVerticalStrut(60));box2.add(choice1);box2.add(Box.createVerticalStrut(60));box2.add(choice2);box2.add(Box.createVerticalStrut(60));box2.add(choice3);box2.add(Box.createVerticalStrut(60));box2.add(text[1]);box2.add(Box.createVerticalStrut(60));baseBox = Box.createHorizontalBox();baseBox.add(box1);baseBox.add(Box.createHorizontalStrut(15));baseBox.add(box2);add(baseBox,BorderLayout.EAST);//添加表格//添加表格deModel = new DefaultTableModel(name,0);table = new JTable(deModel);table.setCellSelectionEnabled(true);table.setEnabled(true);table.setShowHorizontalLines(true);table.setShowVerticalLines(true);split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,false,newJScrollPane(table),baseBox);split.setDividerLocation(0.5);add(split,BorderLayout.CENTER);String sqlString = "select * from record";try{//连接数据库con = DriverManager.getConnection(dburl,user,pass);sql = con.createStatement();JOptionPane.showMessageDialog(this, "数据库连接成功!","消息对话框",RMATION_MESSAGE);rs = sql.executeQuery(sqlString);while(rs.next()){for(int i = 0;i<5;i++){strings[i]=rs.getString(i+1);//把查询的结果填入表格中}if(strings[3].trim().compareTo("计划")==0||strings[3].trim().compareTo("已预定")==0){inputText.addItem(strings[0]);deModel.addRow(strings);deModel.fireTableStructureChanged();}//更新中的数据}rs = sql.executeQuery("select * from goods");while(rs.next()){for(int i = 0;i<5;i++){strings[i]=rs.getString(i+1);//把查询的结果填入表格中}choice1.addItem(strings[1]);}rs = sql.executeQuery("select * from supplier");while(rs.next()){for(int i = 0;i<5;i++){strings[i]=rs.getString(i+1);//把查询的结果填入表格中}choice2.addItem(strings[1]);}}catch(SQLException ee){ee.printStackTrace();}}public void actionPerformed(ActionEvent e){if(e.getSource()==添加){String sqlString = "INSERT INTO record VALUES('"+text[0].getText()+"','"+choice1.getSelectedItem().toString()+"','"+choice2.getSelectedItem().to String()+"','"+choice3.getSelectedItem().toString()+"','"+text[1].getText()+"')";try{sql.execute(sqlString);//将表格中的内容清空for(int i = deModel.getRowCount()-1;i>=0;i--){deModel.removeRow(i);deModel.fireTableStructureChanged();}rs = sql.executeQuery("select * from record");while(rs.next()){for(int i = 0;i<5;i++){strings[i]=rs.getString(i+1);//把查询的结果填入表格中}if(strings[3].trim().compareTo("计划")==0||strings[3].trim().compareTo("已预定")==0){deModel.addRow(strings);deModel.fireTableStructureChanged();}//更新中的数据}JOptionPane.showMessageDialog(this, "操作成功!","消息对话框",RMATION_MESSAGE);}catch(SQLException ee){ee.printStackTrace();}for(int i = 0;i<2;i++){text[i].setText("");}}。
摘要由于超市行业的竞争越来越强,超市规模的发展不断扩大,商品数量和种类急剧增加,有关商品的信息量也随之增长。
超市随时都需要对商品各种信息进行统计分析。
超市销售管理系统是基于J2EE的技术架构,使用JSP构建动态网页和Servlet 组件,使用Tomcat作为web服务器, 用JDBC连接的MySql数据库作为存储对象,在设计和完成的过程中加深对数据库查询方法的理解,也进一步的了解MVC的设计模式。
系统主要实现的功能:管理员信息的管理、销售管理、员工管理、供应商管理。
通过上述功能实现对进货、销售及员工等基本的信息采集和处理,辅助提高超市的决策水平;使用该系统,可以提升超市的管理水平和运作效率,降低经营成本,提高管理人员的效益,增强超市扩张力。
关键词: J2EE;Servlet;JSP;MySql;销售管理AbstractWith the competition between supermarkets becoming stronger and stronger, supermarkets themselves becoming larger and larger, and the quantity as well as the varieties of merchandise increasing sharply, the quantity of information about merchandise is becoming larger, too. The supermarket needs to be ready to make statistical analysis of all the information about the merchandise all the time.This system is based on the technological architecture of Java 2 Platform Enterprise Edition, use of JSP Construction of dynamic pages and Servlet as its components,using Tomcat as a web server, using the MySql database as a storage object and visiting to the database are through module JDBC link, in the design and complete the process of deepening the understanding of the database query methods, but also a better understanding of the MVC design pattern.The system compromises the following modules: user right management, sales management, staff management and supplier management, hence managing the recording and inquiring of the information about purchases, sales and employees. Supermarkets may make better decisions by collecting and processing some basic information. Through this system, the management and operational efficiency can be improved, the operating cost can be reduced, the efficiency of the staff members can be promoted and the supermarket’s expandability can become stronger.Key words: J2EE;Servlet;JSP;MySql;sales management目录1 绪论 (1)2 开发环境及开发工具的介绍 (1)2.1 关于WEB (1)2.2 J2EE的优势 (2)2.3 J SP语言和HTML语言 (2)2.4 关于Servlet (3)2.5 M ySql数据库 (4)2.5.1 MySql的优势 (4)2.6 T omcat服务器 (5)2.6.1 Tomcat 服务器简介 (5)2.6.2 TomCat的优势 (5)3 需求分析和可行性分析 (7)3.1 系统用户及其功能分析 (7)3.2 系统的模块划分 (7)3.3 系统运行环境 (8)3.4 技术可行性 (8)3.5 操作可行性 (8)4 系统总体设计 (9)4.1 设计思想 (9)4.2 系统功能模块图 (10)4.3 实体关系图 (10)4.4 数据库设计 (14)4.5 系统的用例图 (18)4.6 系统登录时序图 (21)5 系统的详细设计 (21)5.1 系统模块的划分 (21)5.2 模块流程和具体实现 (21)5.2.1 用户登录模块 (22)5.2.2 商品的销售管理模块 (24)5.2.3 员工管理模块 (27)5.2.4 供应商管理模块 (29)5.2.5 管理员信息管理模块 (31)6 系统测试 (34)6.1 模块测试 (34)结束语 (35)致谢 (37)参考文献 (38)附录部分源代码 (39)1绪论随着现代科学技术的迅猛发展,计算机技术已经渗透到商业领域,成为各行业必不可少的工具,特别是Internet技术的推广和信息高速公路的建立,使IT产业在市场竞争中越发显示出其独特的优势。
基于Java的超市信息管理系统开发与设计实验报告基于Java的超市信息系统的开发与设计上海工程技术大学 10级信管专业2012-2013大学生创新实验报告Java的超市信息系统开发与设计郭文豪031510224 荣攀 031510223 王宗敏031510132 石坚伟 031510130 蔡奕明教师所在学院管理学院实验完成学期 2012~2013学年第一学期基于Java的超市信息系统的开发与设计上海工程技术大学 10级信管专业2012-2013目录摘要 (3)实验目的 (4)1 超市管理系统的分析与设计 (5)1.1 市场对于超市管理信息系统的需求分析 (5)1.2 超市管理系统开发的技术支持 1.2.1 Java简介1.2.2 C#语言 2 Access 数据库 33.1 系统结构ERP3.2 Access (9)3.3 (10)4 (11) (11) (13)系统主页菜单栏功能介绍 (13)4.2.2 系统主页页标签功能及按钮功能介绍 (14)5 Java代码的部分展示 (17)6 实验心得体会 (19)7 参考文献 .......................................22 - 2 -基于Java的超市信息系统的开发与设计上海工程技术大学 10级信管专业2012-2013 摘要科技日异月新,突飞猛进,将科学的管理方式应用于超市管理过程,而形成的,便是超市管理信息系统,在超市管理信息系统中可以便于人员对超市的各项模块进行管理,员工管理、会员系统管理、商品库存系统管理,合理的系统能够有助于超市顺利的运营,理更能提升超市的营业水平。
本系统基于Java语言,以及Access结合两者,通过Java程序窗口对Access 但近几年我国超市经营规模日趋扩大,而且许多超市正小型超市在业务还要时刻更新产品的销售信息,不断添实现超市庞大商品的控制和传输,从而方便应该是可以帮助销售部门提高工作效率,帮助超市工作人员利用计算机,极为方便的对超市的有关数据进行管理、输入、输出、查找等有关操作,使杂乱的超市数据能够具体化、直观化、合理化等,例如美萍超市管理系统。
J a v a超市管理系统(总31页) -CAL-FENGHAI.-(YICAI)-Company One1-CAL-本页仅作为文档封面,使用请直接删除沈阳工程学院课程设计设计题目:面向对象程序设计课程设计小超市管理系统课程设计任务书课程设计题目:面向对象程序设计课程设计小超市管理系统目录摘要..................................................................................................................... 错误!未定义书签。
第1章绪论 .. (1)第2章系统功能介绍 (2)系统功能总框图 (2)本系统模块功能介绍 (2)登录功能介绍 (2)商品销售功能介绍 (3)权限管理功能介绍 (3)销售管理功能介绍 (4)商品管理功能介绍 (4)组内任务分工 (5)第3章数据库设计 (6)数据库需求分析 (6)数据库概念结构设计 (6)数据库表的设计 (7)第4章系统功能实现 (8)登录功能实现 (8)销售界面功能介绍 (11)搜索商品的信息 (11)购买商品 (11)模块的核心代码 (12)权限管理功能介绍 (18)添加用户功能介绍 (18)修改用户功能介绍 (19)删除用户功能介绍 (19)显示用户信息与刷新按钮介绍 (20)用户管理的实现代码 (20)销售管理功能介绍 (27)编号查询功能 (27)账单查询功能 (27)销售管理模块的核心代码 (28)商品管理功能介绍 (31)查询信息 (31)添加信息及提交添加 (32)删除信息及提交删除 (32)修改信息及提交修改 (33)关于 (33)模块的核心代码 (34)总结 (39)致谢 (40)参考文献 (41)第1章绪论随着人们生活水平的不断提高,购物已成为一种时尚。
每天都有大量的消费者在各大商场中留下消费信息,所以作为商场的管理人员就需要有一个自动化、智能化的管理系统来完成这些信息的处理。
第1章JavaBean部分1.1 数据库连接(DataBase.java)package common;import java.sql.*;import javax.naming.*;import javax.sql.*;import java.util.*;public class DataBase {private String dbUrl ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ManagermentDB";private String dbUser = "ren";private String dbPwd = "ren";//定义数据库的连接public DataBase() throws Exception{Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");}//加载数据库的驱动public Connection getConnection()throws Exception{return java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);}//建立数据库的连接public void closeConnection(Connection con){try{if(con!=null) con.close();}catch(Exception e){e.printStackTrace();}}public void closePrepStmt(PreparedStatement prepStmt){try{if(prepStmt!=null) prepStmt.close();}catch(Exception e){e.printStackTrace();}}public void closeResultSet(ResultSet rs){//关闭当前记录集if(rs!=null) rs.close();}catch(Exception e){e.printStackTrace();}}public static void close( ResultSet rs, Statement st, Connection conn )//关闭数据库的连接{try{if( rs!=null ) rs.close();}catch( SQLException ex ) { };try{if( st!=null ) st.close();}catch( SQLException ex ) { };try{if( conn!=null ) conn.close(); }catch( SQLException ex ) { };}}1.2 人事管理部门1.2.1员工实体的定义(Employees.java)package employees;public class Employees implements Comparable{private String EmpId;private String DepId;private String EmpName;private String Sex;private String Nationality;private String Birth;private String Marital;private String Original;private String Id_Card;private String Mobile;private String Memo;//员工实体的属性Employees(String EmpId,String DepId,String EmpName ,String Sex,String Nationality,String Birth,String Academic,String Marital,String Original,String Id_Card,String Mobile,StringMemo){ //初始化操作this.EmpId = EmpId;this.DepId = DepId;this.EmpName = EmpName;this.Sex = Sex;this.Nationality = Nationality;this.Birth = Birth;this.Academic = Academic ;this.Marital = Marital;this.Original = Original;this.Id_Card = Id_Card;this.Mobile = Mobile ;this.Memo = Memo;}//对每一个属性赋值和取值操作public void setEmpId(String newEmpId){this.EmpId = newEmpId;}public String getEmpId(){return EmpId;}public void setDepId(String newDepId){this.DepId = newDepId;}public String getDepId(){return DepId;}this.EmpName = newEmpName;}public String getEmpName(){return EmpName;}public void setSex(String newSex){this.Sex = newSex;}public String getSex(){return Sex;}public void setNationality(String newNationality){ this.Nationality = newNationality;}public String getNationality(){return Nationality;}public void setBirth(String newBirth){this.Birth = newBirth;}public String getBirth(){return Birth;}public void setAcademic(String newAcademic){ this.Academic = newAcademic;}public String getAcademic(){return Academic;}public void setMarital(String newMarital){this.Marital = newMarital;}public String getMarital(){return Marital;}this.Original = newOriginal;}public String getOriginal(){return Original;}public void setId_Card(String newId_Card){this.Id_Card = newId_Card;}public String getId_Card(){return Id_Card;}public void setMobile(String newMobile){this.Mobile = newMobile;}public String getMobile(){return Mobile;}public void setMemo(String newMemo){this.Memo = newMemo;}public String getMemo(){return Memo;}public int compareTo(Object o){Employees n = (Employees)o;int lastCmp = pareTo(n.EmpName);return(lastCmp);}}1.2.2员工实体的操作(EmployeesBean.java)package employees;import java.sql.*;import java.util.*;import javax.naming.*;import javax.sql.*;import common.*;public class EmployeesBean{////-----得到员工的详细信息-------public Employees getEmployeesDetails(String EmpId) throws Exception { DataBase database = new DataBase();boolean result = false;Connection con = null;PreparedStatement prepStmt = null;ResultSet rs = null;try {con = database.getConnection();String sql = "select EmpId, DepId, EmpName , Sex, Nationality, Birth, Academic, Marital,Original, Id_Card, Mobile, Memo "+"from Employees where EmpId =?";prepStmt = con.prepareStatement(sql);prepStmt.setString(1,EmpId);rs = prepStmt.executeQuery();if(rs.next()){Employees employees = newEmployees(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8),rs.getString(9),rs.getString(10),rs.getString(11),rs.getString(12));prepStmt.close();return employees;}else{return null;}}finally{database.closeResultSet(rs);database.closePrepStmt(prepStmt);database.closeConnection(con);}}////-------getEmployees()//得到所有员工的详细信息---public Collection getEmployees() throws Exception {boolean result = false;Connection con = null;PreparedStatement prepStmt = null;ResultSet rs = null;Employees = new ArrayList();try {con = database.getConnection();String sql = "select EmpId, DepId, EmpName , Sex, Nationality, Birth, Academic, Marital,Original, Id_Card, Mobile, Memo "+"from Employees ";prepStmt = con.prepareStatement(sql);rs = prepStmt.executeQuery();while(rs.next()){Employees bd = new Employees(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8),rs.getString(9),rs.getString(10),rs.getString(11),rs.getString(12));Employees.add(bd);}}finally{database.closeResultSet(rs);database.closePrepStmt(prepStmt);database.closeConnection(con);}Collections.sort(Employees);return Employees;}///// nsertEmployees 插入员工的信息public int InsertEmployees(String EmpId,String EmpName,String Sex,String Nationality,String Birth,String Academic,String Marital,String Original,String Id_Card,String Mobile,String Memo,String DepId) throws Exception{Connection con = null;Statement Stmt = null;ResultSet rs=null;DataBase database = new DataBase();try {con = database.getConnection();String sql = "SELECT EmpId FROM Employees WHEREEmpId='"+EmpId+"'";Stmt = con.createStatement();rs = Stmt.executeQuery( sql );if(rs.next()){nResult=2;}else{sql="insert intoEmployees(EmpId,EmpName,Sex,Nationality,Birth,Academic,Marital,Original,Id_Card,M obile,Memo,DepId)V ALUES('"+EmpId+"','"+EmpName+"','"+Sex+"','"+Nationality+"','"+Birth+"','"+Academic+"','"+Mari tal+"','"+Original+"','"+Id_Card+"','"+Mobile+"','"+Memo+"','"+DepId+"')";nResult = Stmt.executeUpdate(sql);sql= "insert intoUsers(UserId,UserName,PassWords)values('"+EmpId+"','"+EmpName+"','"+666666+"')";nResult = Stmt.executeUpdate(sql);}return nResult;}catch( SQLException ex ){ex.printStackTrace( System.err );nResult=0;return nResult;}finally{database.close(null,Stmt,con);}}//删除一个员工的所有信息public int deleteOneEmployees(String EmpId) throws Exception{boolean result = false;Connection con = null;Statement Stmt = null;ResultSet rs=null;DataBase database = new DataBase();int nResult = 0;try {con = database.getConnection();String sql = "SELECT EmpId FROM Employees WHEREEmpId='"+EmpId+"'";Stmt = con.createStatement();rs = Stmt.executeQuery( sql );if(rs.next()){sql="DELETE from Employees where EmpId='"+EmpId+"'";nResult = Stmt.executeUpdate(sql);sql="DELETE from Users where UserId='"+EmpId+"'";nResult = Stmt.executeUpdate(sql);}else{nResult=2;}return nResult;}catch( SQLException ex ){ex.printStackTrace( System.err );nResult=0;return nResult;}finally{}}// 修改员工的信息public int updateEmployees(String EmpId,String EmpName,String Sex,String Nationality,String Birth,String Academic,String Marital,String Original,String Id_Card,String Mobile,String Memo,String DepId) throws Exception{Connection con = null;Statement Stmt = null;ResultSet rs=null;DataBase database = new DataBase();int nResult = 0;try {con = database.getConnection();String sql = "UPDA TE Employees SETEmpId='"+EmpId+"',EmpName='"+EmpName+"', Sex='"+Sex+"',Nationality='"+Nationality+"',Birth='"+Birth+"',Academic='"+Academic+"', Marital='"+Marital+"',Original='"+Original+"',Id_Card='"+Id_Card+"',Mobile='"+Mobile+"', Memo='"+Memo+"', DepId='"+DepId+"' WHERE EmpId='"+EmpId+"'";Stmt = con.createStatement();nResult = Stmt.executeUpdate(sql);sql= "update Users set UserId='"+EmpId+"',UserName='"+EmpName+"' where UserId='"+EmpId+"'";nResult = Stmt.executeUpdate(sql);return nResult;}catch( SQLException ex ){ex.printStackTrace( System.err );nResult=0;return nResult;finally{database.close(null,Stmt,con);}}}1.2.3部门实体的定义(departments.java)package departments;/*** 部门类*/public class Departments {private String DepId; //部门的编号private String DepName; //部门的名称Departments(String DepId,String DepName){ //部门的初始化this.DepId =DepId;this.DepName = DepName;}public void setDepId(String newId){this.DepId = newId;}public String getDepId(){return DepId;}public void setDepName(String newDepName) {this.DepName = newDepName;}public String getDepName() {return DepName;}}1.2.4部门实体的操作(DepartmentsBean.java)package departments;import java.sql.*;import java.util.*;import javax.sql.*;import common.*;public class DepartmentsBean{//插入部门的信息public int InsertDepartments(String DepId,String DepName) throws Exception{boolean result = false;Connection con = null;Statement Stmt = null;ResultSet rs=null;DataBase database = new DataBase();int nResult = 0;try {con = database.getConnection();String sql = "SELECT DepId FROM Departments WHEREDepId='"+DepId+"'";Stmt = con.createStatement();rs = Stmt.executeQuery( sql );if(rs.next()){nResult=2;}else{sql="insert intoDepartments(DepId,DepName)V ALUES('"+DepId+"','"+DepName+"')";nResult = Stmt.executeUpdate(sql);if(nResult==1)nResult=1;}return nResult;}catch( SQLException ex ){ex.printStackTrace( System.err );nResult=0;}finally{database.close(null,Stmt,con);}}// 查询部门的信息public Vector queryDepartments()throws Exception{Vector vt = new Vector();Connection conn = null;Statement st = null;ResultSet rs = null;DataBase database = new DataBase();try{conn = database.getConnection();st = conn.createStatement();String sql = "SELECT DepId,DepName FROM Departments ";sql = sql + " ORDER BY DepId ASC";rs = st.executeQuery( sql );while( rs.next() ){Departments Dep = newDepartments(rs.getString(1),rs.getString(2));vt.add(Dep);}}catch( SQLException ex ){ex.printStackTrace( System.err );}finally{database.close( rs, st, conn );}return vt;} //按照部门的编号进行查询某一个部门的详细信息Connection con=null;PreparedStatement prepStmt=null;DataBase database = new DataBase();ResultSet rs =null;try {con=database.getConnection();String selectStatement = "select * " + "from Departments where DepId = ? ";prepStmt = con.prepareStatement(selectStatement);prepStmt.setString(1, DepId);rs = prepStmt.executeQuery();if (rs.next()) {Departments bd = new Departments(rs.getString(1), rs.getString(2));prepStmt.close();return bd;}else {return null;}}finally{database.closeResultSet(rs);database.closePrepStmt(prepStmt);database.closeConnection(con);}} //按照部门的编号进行修改某一个部门的详细信息public int updateDepartments(String DepId,String DepName) throws Exception{Connection con = null;Statement Stmt = null;ResultSet rs=null;DataBase database = new DataBase();int nResult = 0;try {con = database.getConnection();DepName='"+DepName+"' where DepId='"+DepId+"'";Stmt = con.createStatement();nResult = Stmt.executeUpdate(sql);return nResult;}catch( SQLException ex ){ex.printStackTrace( System.err );nResult=0;return nResult;}finally{database.close(null,Stmt,con);}}//删除一个部门的所有信息public int deleteOneDepartments(String DepId) throws Exception{boolean result = false;Connection con = null;Statement Stmt = null;ResultSet rs=null;DataBase database = new DataBase();int nResult = 0;try {con = database.getConnection();String sql = "SELECT DepId FROM Employees WHERE DepId='"+DepId+"'";Stmt = con.createStatement();rs = Stmt.executeQuery( sql );if(rs.next()){nResult=2;}{sql="DELETE from Departments where DepId='"+DepId+"'";nResult = Stmt.executeUpdate(sql);}return nResult;}catch( SQLException ex ){ex.printStackTrace( System.err );nResult=0;return nResult;}finally{database.close(null,Stmt,con);}}}1.2.5员工考勤实体的定义(Evaluation.java)package evaluation;public class Evaluation {private String EvaId;private String EmpId;private String EvaDate;private String Subject;private String Result;private String Score;private String Memo;Evaluation(String EvaId,String EmpId,String EvaDate ,String Subject,String Result,String Score,String Memo){this.EvaId = EvaId;this.EmpId = EmpId;this.EvaDate = EvaDate;this.Subject = Subject;this.Result = Result;this.Memo = Memo;}public void setEvaId(String newEvaId){ this.EvaId = newEvaId;}public String getEvaId(){return EvaId;}public void setEmpId(String newEmpId){ this.EmpId = newEmpId;}public String getEmpId(){return EmpId;}public void setEvaDate(String newEvaDate){ this.EvaDate = newEvaDate;}public String getEvaDate(){return EvaDate;}public void setSubject(String newSubject){ this.Subject = newSubject;}public String getSubject(){return Subject;}public void setResult(String newResult){ this.Result = newResult;}public String getResult(){return Result;}public void setScore(String newScore){ this.Score = newScore;}return Score;}public void setMemo(String newMemo){this.Memo = newMemo;}public String getMemo(){return Memo;}}1.2.6员工考勤实体的操作(EvaluationBean.java)package evaluation;import java.sql.*;import java.util.*;import javax.naming.*;import javax.sql.*;import common.*;public class EvaluationBean{//插入员工考勤信息的信息public int InsertEvaluation(String EvaId,String EmpId,String EvaDate,String Subject,String Result,String Score,String Memo,String EmpName) throws Exception{Connection con = null;Statement Stmt = null;ResultSet rs=null;DataBase database = new DataBase();int nResult = 0;try {con = database.getConnection();String sql = "SELECT EmpId FROM Employees WHERE(EmpId='"+EmpId+"')and (EmpName='"+EmpName+"')";Stmt = con.createStatement();rs = Stmt.executeQuery( sql );if(rs.next())sql = "SELECT EvaId FROM Evaluation WHERE EvaId='"+EvaId+"'";rs = Stmt.executeQuery( sql );if(rs.next()){nResult = 3; //存在重复的编号}else{sql= "insert intoEvaluation( EvaId,EmpId,EvaDate,Subject,Result,Score,Memo) values('"+EvaId+"','"+EmpId+"','"+EvaDate+"','"+Subject+"','"+Result+"','"+Score+"','"+Memo+"')" ;nResult = Stmt.executeUpdate(sql);//nResult=1是添加成功}}else{ nResult=2; //不存在该员工}return nResult;}catch( SQLException ex ){ex.printStackTrace( System.err );nResult=0;return nResult;}finally{database.close(null,Stmt,con);}}//删除一个某一个具体的考勤信息public int deleteOneEvaluation(String EvaId) throws Exception{boolean result = false;Connection con = null;ResultSet rs=null;DataBase database = new DataBase();int nResult = 0;try {con = database.getConnection();String sql = "SELECT EvaId FROM Evaluation WHERE EvaId='"+EvaId+"'";Stmt = con.createStatement();rs = Stmt.executeQuery( sql );if(rs.next()){sql="DELETE from Evaluation where EvaId='"+EvaId+"'";nResult = Stmt.executeUpdate(sql);}else{nResult=2;}return nResult;}catch( SQLException ex ){ex.printStackTrace( System.err );nResult=0;return nResult;}finally{database.close(null,Stmt,con);}}//更新一个员工考勤的基本信息public int updateEvaluation(String EvaId,String EmpId,String EvaDate,String Subject,String Result,String Score,String Memo) throws Exception{Connection con = null;Statement Stmt = null;DataBase database = new DataBase();int nResult = 0;try {con = database.getConnection();String sql = "UPDA TE Evaluation set EvaId='"+EvaId+"',EmpId='"+EmpId+"',EvaDate='"+EvaDate+"',Subject='"+Subject+"',Result='"+Result+"',Score='"+Score+"',Memo='"+Memo+"' where EvaId='"+EvaId+"'";Stmt = con.createStatement();nResult = Stmt.executeUpdate(sql);return nResult;}catch( SQLException ex ){ex.printStackTrace( System.err );nResult=0;return nResult;}finally{database.close(null,Stmt,con);}}// 查询所有的员工考勤的信息public Vector allEvaluationInfor()throws Exception{Vector vt = new Vector();Connection conn = null;Statement st = null;ResultSet rs = null;DataBase database = new DataBase();try{// vt=null;conn = database.getConnection();String sql = "SELECT EvaId,EmpId,EvaDate,Subject,Result,Score, Memo FROM Evaluation ";sql = sql + " ORDER BY EvaId ASC";rs = st.executeQuery( sql );while( rs.next() ){Evaluation evaluation = newEvaluation(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.ge tString(6),rs.getString(7));vt.add(evaluation);}}catch( SQLException ex ){ex.printStackTrace( System.err );}finally{database.close(null,st,conn);}return vt;}// 查询一个员工的所有考勤的信息public Vector allOneEmployeeEvaluationInfor(String EmpId)throws Exception{Vector vt = new Vector();Connection conn = null;Statement st = null;ResultSet rs = null;DataBase database = new DataBase();try{conn = database.getConnection();st = conn.createStatement();String sql = "SELECT EvaId,EmpId,EvaDate,Subject,Result,Score, Memo FROM Evaluation where EmpId='"+EmpId+"'";rs = st.executeQuery( sql );while( rs.next() ){Evaluation evaluation = newEvaluation(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.ge tString(6),rs.getString(7));vt.add(evaluation)}}catch( SQLException ex ){ex.printStackTrace( System.err );}finally{database.close(null,st,conn);}return vt;}//按照员工的编号进行查询某一个员工的考勤详细信息public Evaluation getEvaluationDetails(String EvaId) throws Exception {Connection con=null;PreparedStatement prepStmt=null;DataBase database = new DataBase();ResultSet rs =null;try {con=database.getConnection();String selectStatement = "select EvaId,EmpId,EvaDate,Subject,Result,Score,Memo " + "from Evaluation where EvaId = ? ";prepStmt = con.prepareStatement(selectStatement);prepStmt.setString(1, EvaId);rs = prepStmt.executeQuery();if (rs.next()) {Evaluation bd = new Evaluation(rs.getString(1), rs.getString(2), rs.getString(3),rs.getString(4),rs.getString(5),prepStmt.close();return bd;}else{return null;}}finally{database.closeResultSet(rs);database.closePrepStmt(prepStmt);database.closeConnection(con);}}//按照员工的编号以及考勤编号进行查询某一个员工的考勤详细信息public Evaluation getEvaluationDetailsEmpId(String EvaId,String EmpId) throws Exception{Connection conn = null;Statement st = null;ResultSet rs = null;DataBase database = new DataBase();try{conn = database.getConnection();st = conn.createStatement();String sql = sql = "select EvaId,EmpId,EvaDate,Subject,Result,Score,Memo from Evaluation where (EvaId ='"+EvaId+"')and(EmpId='"+EmpId+"')";sql = sql + " ORDER BY EvaId ASC";rs = st.executeQuery( sql );if (rs.next()) {Evaluation bd = new Evaluation(rs.getString(1), rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7));}else{return null;}}finally{ database.closeResultSet(rs);database.closeConnection(conn); }}}1.2.7员工考勤信息中分页的实现(EvaluationBeanPage.java)package evaluation;import java.sql.*;import java.util.*;import javax.naming.*;import javax.sql.*;import common.*;public class EvaluationBeanPage{//返回Evaluation表项数public int getCount()throws Exception{Connection conn = null;Statement st = null;ResultSet rs = null;DataBase database = new DataBase();int count=0;try {conn = database.getConnection();st = conn.createStatement();String sql = sql = "select count(EvaId) from Evaluation ";rs = st.executeQuery( sql );if(!rs.next()){}else{count = rs.getInt(1);}}catch( SQLException ex ){ex.printStackTrace( System.err );}finally{database.close(null,st,conn);}return count;}//得到总页数public int totalPage(int pagesize) throws Exception{int Count = getCount();return (Count+pagesize-1)/pagesize;}// 查询所有的员工考勤的信息并且分页显示public ResultSet getPageof(String pg, int pagesize)throws Exception {Connection conn = null;Statement st = null;ResultSet rs = null;DataBase database = new DataBase();int page = Integer.parseInt(pg);int count = getCount();if(count==0)return null;int totalpage = (count+pagesize-1)/pagesize;if(page > totalpage)page = totalpage;try {conn = database.getConnection();st = conn.createStatement();String sql = "SELECT EvaId,EmpId,EvaDate,Subject,Result,Score, Memo FROM Evaluation ";sql = sql + " ORDER BY EvaId ASC";rs = st.executeQuery( sql );for(int i=0; i<start; i++)rs.next();}catch(SQLException e) {System.err.println("QueryPage.getPageof()" +e.getMessage());}return rs;}}1.3 本章小结整个超市综合管理信息系统是一个很大的系统,它包括,人事管理模块,公司财务管理模块,商品采购管理模块,商品销售管理模块,企业用户查询模块等,各个模块有很大的相似性,因此,在这里主要以一个模块作为样板详细做了介绍,而其它模块没有做出介绍。
基于JAVA的小型超市管理系统————————————————————————————————作者: ————————————————————————————————日期:《网站规划与建设综合实验》课程设计报告设计题目:基于JA V A的小型超市管理系统专业:XXXXXXX班级: XXXXX班指导教师:XXXXX组长姓名:XXXXX学号:XXXXX姓名: XXXXX学号:XXXXX姓名: XXXXX学号:XXXXX姓名:XXXXX学号:XXXXX姓名: XXXXX学号:XXXXX2013年6月计算机科学与技术系摘要本文首先简单给出了超市管理系统的设计背景和意义,并介绍了系统开发所用到的开发工具和语言,然后在进行了需求分析的基础上,说明了系统功能模块的划分及各模块之间的相互关系,然后着重论述了系统功能的一些重要的技术实现过程。
本系统的每一个功能模块都包含了多个功能。
整个系统主要完成对超市商品的日常管理,包括进货管理,销售管理,库存管理,员工管理和供应商管理等方面。
在功能上系统可以完成对相关信息的浏览、查询、添加、删除、修改等功能。
本课题的核心之一是销售管理、库存管理和进货管理三者之间的联系,同时系统有完整的用户管理及权限管理功能。
本系统选择的是在Myeclipse8.5平台上使用Java语言作为前台开发工具,SQL2005作为后台数据库平台,通过SQL2005将系统所需的数据和用户操作的数据与前台连接起来。
关键词:JAVA;数据库;Myeclipse;超市管理目录1绪论ﻩ错误!未定义书签。
1.1课题的开发背景 .......................................................................错误!未定义书签。
1.2课题研究的目的与意义ﻩ错误!未定义书签。
1.3开发方法 ......................................................................................错误!未定义书签。
import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.util.Arrays;import java.util.Scanner;public class Mytest {static int sign=0;//goodname数组第一个空下标号static int sign1=0;//cname数组第一个空下标号static String[] cpass=new String[20];//存放售货员名称static String[] cname=new String[20];//存放售货员登入密码static String[] goodname=new String[20];//存放商品名称static double[] goodprice=new double[20];//存放商品价格static int[] goodout=new int[20];//存放商品销售量static int[] goodnum=new int[20];//存放商品数量public static void main(String[] args)throws Exception { cname[0]="ZhouTian";//初始的售货员名称cpass[0]="723"; //初始的售货员密码createArrays();readArrays("goodname");//将文件中的内容读入到相应的数组里readArrays("goodprice");readArrays("goodnum");readArrays("cname");readArrays("cpass");readArrays("goodout");menu();//登入之后加载的主菜单}/*** 加载登入菜单*/private static void menu() {Scanner scan = new Scanner(System.in);System.out.println("\t\t\t欢迎使用商超购物管理系统\n");System.out.println("\t\t\t\t1.登录系统\n");System.out.println("\t\t\t\t2.退出 ");System.out.println("*************************************************");System.out.println("请选择,输入数字: ");int a = scan.nextInt();switch (a) {case 0:System.out.println("退出!");//按0不登入case 1:System.out.println("请输入用户名:");// 查找售货员姓名是否存在,与所对应的密码是否匹配String name = scan.next();System.out.println("请输入密码:");String pass = scan.next();int flage = 0;int ff = 0;for (int i = 0; i < cname.length; i++) {if (name.equals(cname[i])) {flage = 1;//售货员的名称匹配flage=1;ff = i;break;}}if (flage == 1) {//名称匹配之后再匹配密码if (pass.equals(cpass[ff])) {loadmenu1();//密码也匹配之后再允许登入} else {System.out.println("密码错误!");}} else {System.out.println("该用户名不具有权限");}break;case 2:System.out.println("谢谢您的使用!");break;default:break;}}/*** ,创建文件,将数组信息存入到各文件中,*/static void createArrays() {BufferedWriter bw = null;try {File file1 = new File("d:\\gname.txt");if (!file1.exists()) {bw = new BufferedWriter(new FileWriter("d:\\gname.txt"));String content1 = strToString(goodname);//数组内容转换成字符串bw.write(content1);//写入bw.close();}File file2 = new File("d:\\gprice.txt");if (!file2.exists()) {bw = new BufferedWriter(new FileWriter("d:\\gprice.txt"));String content2 = doubleToString(goodprice);//数组内容转换成字符串bw.write(content2);//写入bw.close();}File file3 = new File("d:\\gnum.txt");if (!file3.exists()) {bw = new BufferedWriter(new FileWriter("d:\\gnum.txt"));String content3 = intToString(goodnum);//数组内容转换成字符串bw.write(content3);//写入bw.close();}File file4 = new File("d:\\cname.txt");if (!file4.exists()) {bw = new BufferedWriter(new FileWriter("d:\\cname.txt"));String content4 = strToString(cname);//数组内容转换成字符串bw.write(content4);//写入bw.close();}File file5 = new File("d:\\cpass.txt");if (!file5.exists()) {bw = new BufferedWriter(new FileWriter("d:\\cpass.txt"));String content5 = strToString(cpass);//数组内容转换成字符串bw.write(content5);//写入bw.close();}File file6 = new File("d:\\gout.txt");if (!file6.exists()) {bw = new BufferedWriter(new FileWriter("d:\\gout.txt"));String content5 = intToString(goodout);//数组内容转换成字符串bw.write(content5);//写入bw.close();}} catch (IOException e) {e.printStackTrace();}}/*** 登入之后加载商超购物管理系统*/static void loadmenu1() {System.out.println("欢迎进入商超购物管理系统!");System.out.println("\t\t\t\t商超购物管理系统");System.out.println("********************************************** **********************************");System.out.println("\t\t\t\t1.商品维护");System.out.println("\t\t\t\t2.前台收银");System.out.println("\t\t\t\t3.商品管理");System.out.println("\t\t\t\t4.退出");System.out.println("************************************ ********************************************");System.out.println("请选择,输入数字或按0退出:");Scanner scan = new Scanner(System.in);int a = scan.nextInt();switch (a) {case 0:System.out.println("谢谢您的使用!");break;case 1:System.out.println("执行显示商品维护菜单");loadmenu2();break;case 2:System.out.println("执行前台收银");loadmenu6();break;case 3:System.out.println("执行商品管理");loadmenu7();break;default:break;}}/** 在商超购物管理系统中按1键时*/static void loadmenu2() {System.out.println("\t\t\t\t商超购物管理系统商品维护");System.out.println("********************************************** **********************************");System.out.println("\t\t\t\t1.添加商品\t");System.out.println("\t\t\t\t2.更改商品\t");System.out.println("\t\t\t\t3.删除商品\t");System.out.println("\t\t\t\t4.显示所有商品\t");System.out.println("\t\t\t\t5.查询商品\t");System.out.println("********************************************** **********************************");System.out.println("请选择,输入数字或按0返回上一级菜单:");Scanner scan = new Scanner(System.in);int b = scan.nextInt();switch (b) {case 0:loadmenu1();break;case 1:addgoods();break;case 2:System.out.println("执行更改商品操作");loadmenu3();// 修改商品break;case 3:System.out.println("执行商品删除操作");loadmenu4();// 商品删除break;case 4:System.out.println("显示所有商品");System.out.println("商品名称\t\t\t" + "商品价格\t\t\t" + "商品数量\t\t\t"+ "备注");showgoods();break;case 5:System.out.println("执行查询商品操作");loadmenu5();break;default:break;}}/** 在商超购物管理系统中按2键时*/static void loadmenu6() {System.out.println("\t\t\t\t商超购物管理系统前台收银");System.out.println("********************************************** **********************************");System.out.println("\t\t\t\t1.购物结算");Scanner scan = new Scanner(System.in);int ch = scan.nextInt();switch (ch) {case 0:loadmenu1();break;case 1:pay();break;default:break;}}/** 在商超购物管理系统中按3键时*/static void loadmenu7() {Scanner scan = new Scanner(System.in);System.out.println("\t\t\t商超购物管理系统商品管理");System.out.println("********************************************** **********************************");System.out.println("\t\t\t\t1.库存查询");System.out.println("\t\t\t\t2.已出售商品");System.out.println("\t\t\t\t3.售货员管理");System.out.println("请选择,输入数字或按0返回上一级菜单:");int ch = scan.nextInt();switch (ch) {case 0:loadmenu1();break;case 1:System.out.println("执行库存查询操作:");kusear();break;case 2:System.out.println("执行已出售商品查询操作");besold();break;case 3:System.out.println("执行售货员管理操作");salesman();break;default:break;}}/** 对售货员信息的增添,修改*/static void salesman(){Scanner scan = new Scanner(System.in);System.out.println("1、添加售货员");System.out.println("2、修改售货员信息");System.out.println("请选择,输入数字或按0返回上一级菜单:");int b = scan.nextInt();switch (b) {case 0:loadmenu7();//返回上一级break;case 1:addsale();//选择1键,添加售货员break;case 2:modifysale();//更改售货员的信息break;default:break;}}/* 添加售货员**/static void addsale() {Scanner scan = new Scanner(System.in);String f;// sign1 = sign1 + 1;do {System.out.println("添加售货员姓名:");String addname = scan.next();add(cname, addname, sign1);//将新信息添加到相应数组中System.out.println("添加售货员登陆密码:");String addpass = scan.next();add(cpass, addpass, sign1);//将新信息添加到相应数组中// writeArray();sign1++;//新信息添加后数组下标加1writeArray();System.out.println("是否继续(y/n)");f = scan.next();// writeArray();} while (f.equals("y"));salesman();}/** 更改售货员的信息*/static void modifysale() {String f;Scanner scan = new Scanner(System.in);System.out.println("输入更改员工名称:");String newname = scan.next();int k = searmember(newname);//查询需要改的售货员的信息,并返回其在数组中的下标if (k >= 0) {//判断售货员是否存在System.out.println("员工姓名" + "\t\t\t密码");System.out.println(cname[k] + "\t\t\t" + cpass[k]);System.out.println("选择您要更改的内容:");System.out.println("1、更改员工姓名:");System.out.println("2、更改登录密码:");int kk = scan.nextInt();switch (kk) {case 1:System.out.println("请输入已更改员工姓名:");String newnname = scan.next();cname[k] = newnname;writeArray();System.out.println("是否继续(y/n)");f = scan.next();if (f.equals("y")) {modifysale();} else {salesman();}break;case 2:System.out.println("请输入已更改密码:");String newpass = scan.next();cpass[k] = newpass;writeArray();System.out.println("是否继续(y/n)");// System.out.println("是否继续(y/n)");f = scan.next();if (f.equals("y")) {modifysale();}salesman();break;default:break;}}}/** 查询ename姓名的售货员在数组中的下标*/static int searmember(String ename) {for (int i = 0; i < cname.length; i++) {if (cname[i].equals(ename)) {return i;}}return -1;// 不存在时}/** 查询已出售的商品信息*/static void besold(){System.out.println("商品名称\t\t\t" + "商品价格\t\t\t" + "商品数量\t\t\t" + "备注");for (int i = 0; i < goodout.length; i++) {if (goodout[i] != 0) {goodprice[i]+ "\t\t\t" + goodout[i]);}}loadmenu7();}/** 查询库存中售的商品信息*/static void kusear() {Scanner scan = new Scanner(System.in);String f;do {System.out.println("输入要查询的商品名称:");String sname = scan.next();int t = ndimsear(sname);//按确切的商品名称进行查询,即非模糊查询,找出商品名称信息的下标if (t >= 0) {System.out.println("商品名称\t\t\t" + "商品价格\t\t\t" + "商品数量\t\t\t"+ "备注");goodprice[t]+ "\t\t\t" + goodnum[t] + "\t\t\t");//按下标输出商品相应的信息} else {System.out.println("没有此商品");}System.out.println("是否继续(y/n)");f = scan.next();} while (f.equals("y"));loadmenu7();}/** 按确切的商品名称进行查询,即非模糊查询,找出商品名称信息的下标*/static int ndimsear(String s) {for (int i = 0; i < goodname.length; i++) {if (goodname[i].equals(s)) {return i;}}return -1;//没查询到时}/** 商品结算*/static void pay() {Scanner scan = new Scanner(System.in);double sum = 0;String f;do {dimsearch1();//按关键字进行模糊查询,查找可能需要的商品System.out.println("请选择商品:");String bnam = scan.next();//按查询到的相关商品中选择要购买的商品System.out.println("请输入购买数量:");int bnum = scan.nextInt();int fl = seargood(bnam);System.out.println(bnam + "\t\t\t" + goodprice[fl] +"\t\t\t"+ "购买数量" + bnum + "\t\t\t" + bnum * goodprice[fl]);goodnum[fl] = goodnum[fl] - bnum;//商品的数量要进行更新goodout[fl] = goodout[fl] + bnum;//商品的销售量相应的增加sum = sum + bnum * goodprice[fl];//计算购买商品的金额System.out.println("是否继续(y/n)");f = scan.next();} while (f.equals("y"));System.out.println("总计:" + sum);System.out.println("请输入实际交费金额:");double shipay = scan.nextDouble();System.out.println("找钱:" + (shipay - sum));writeArray();//将对数组的更改写入到文件中loadmenu1();//结束购买返回}/** 查找商品返回下标*/static int seargood(String bbnam) {for (int i = 0; i <= goodname.length; i++) {if (goodname[i].equals(bbnam)) {return i;}}return -1;}/** 对商品进行各种查找*/static void loadmenu5() {Scanner scan = new Scanner(System.in);System.out.println("1、按商品数量升序查询");System.out.println("2、按商品价格升序查询");System.out.println("3、输入关键字查询商品");System.out.println("请选择,输入数字或按0返回上一级菜单:");int choice = scan.nextInt();switch (choice) {case 0:loadmenu2();//返回上一级break;case 1:numshenxu();//按商品数量升序进行查找break;case 2:priceshenxu();//按商品价格升序进行查找break;case 3:dimsearch();//按商品的关键字进行查找break;default:break;}}static void dimsearch1() {int[] k;Scanner scan = new Scanner(System.in);System.out.println("输入商品关键字:");String sear = scan.next();k = Arrays.copyOf(index(sear), index(sear).length);System.out.println("商品名称\t\t\t" + "商品价格\t\t\t" + "商品数量\t\t\t" + "备注");if (k != null) {for (int i = 0; i < k.length; i++) {System.out.println(goodname[k[i]] + "\t\t\t" + goodprice[k[i]]+ "\t\t\t" + goodnum[k[i]] + "\t\t\t");}}}/** 按商品的关键字进行查找*/static void dimsearch(){String f;do {int[] k;Scanner scan = new Scanner(System.in);System.out.println("输入商品关键字:");String sear = scan.next();k = Arrays.copyOf(index(sear), index(sear).length);System.out.println("商品名称\t\t\t" + "商品价格\t\t\t" + "商品数量\t\t\t"+ "备注");if (k != null) {for (int i = 0; i < k.length; i++) {System.out.println(goodname[k[i]] + "\t\t\t"+ goodprice[k[i]] + "\t\t\t" + goodnum[k[i]]+ "\t\t\t");}}System.out.println("是否继续(y/n)");f = scan.next();} while (f.equals("y"));loadmenu2();}static int[] index(String ss) {int countt = 0;int counttt = 0;for (int i = 0; i < goodname.length; i++) { if (goodname[i].indexOf(ss) >= 0) {countt++;}}int[] location = new int[countt];for (int i = 0; i < goodname.length; i++) { if (goodname[i].indexOf(ss) >= 0) {location[counttt] = i;counttt++;}}return location;}/** 按商品数量升序进行查找*/static void numshenxu() {int[] newnum = Arrays.copyOf(goodnum, goodnum.length);double[] newprice = Arrays.copyOf(goodprice, goodprice.length);String[] newname = Arrays.copyOf(goodname, goodname.length);for (int i = 0; i < newnum.length - 1; i++) {for (int j = 0; j < newnum.length - i - 1; j++) { if (newnum[j] < newnum[j + 1]) {int temp = newnum[j];newnum[j] = newnum[j + 1];newnum[j + 1] = temp;double temp1 = newprice[j];newprice[j] = newprice[j + 1];newprice[j + 1] = temp1;String temp2 = newname[j];newname[j] = newname[j + 1];newname[j + 1] = temp2;//相应的下标在不同的数组里进行挑换,商品的信息才能保持一致}}}System.out.println("商品名称\t\t\t" + "商品价格\t\t\t" + "商品数量\t\t\t" + "备注");for (int k = 0; k < newnum.length; k++) {if (newprice[k] != 0) {System.out.println(newname[k] + "\t\t\t" + newprice[k]+ "\t\t\t" + newnum[k] + "\t\t\t");}}loadmenu5();}/** 按价格的升序进行查找*/static void priceshenxu() {int[] newnum = Arrays.copyOf(goodnum, goodnum.length);double[] newprice = Arrays.copyOf(goodprice, goodprice.length);String[] newname = Arrays.copyOf(goodname, goodname.length);for (int i = 0; i < newprice.length - 1; i++) {for (int j = 0; j < newprice.length - i - 1; j++) { if (newprice[j] < newprice[j + 1]) {int temp = newnum[j];newnum[j] = newnum[j + 1];newnum[j + 1] = temp;double temp1 = newprice[j];newprice[j] = newprice[j + 1];newprice[j + 1] = temp1;String temp2 = newname[j];newname[j] = newname[j + 1];newname[j + 1] = temp2;//相应的下标在不同的数组里进行挑换,商品的信息才能保持一致}}}System.out.println("商品名称\t\t\t" + "商品价格\t\t\t" + "商品数量\t\t\t" + "备注");for (int k = 0; k < newnum.length; k++) {if (newprice[k] != 0) {System.out.println(newname[k] + "\t\t\t" + newprice[k]+ "\t\t\t" + newnum[k] + "\t\t\t");}}loadmenu5();}/**更改商品信息的操作*/static void loadmenu3() {Scanner scan = new Scanner(System.in);System.out.println("输入更改商品名称:");String nam = scan.next();int b = showflage(nam);print(b);System.out.println("选择您要更改的内容:"); System.out.println("1、更改商品名称::"); System.out.println("2、更改商品价格:");System.out.println("3、更改商品数量:");int ch = scan.nextInt();switch (ch) {case 0:break;case 1:int counnt = 0;String f = "y";while (f.equals("y")) {if (counnt != 0) {// Scanner scan = new Scanner(System.in);System.out.println("输入更改商品名称:");nam = scan.next();b = showflage(nam);//查找需要更改商品的下标print(b);//输出这个商品的各种信息}System.out.println("请输入已更改商品名称");String cname = scan.next();goodname[b] = cname;//更改名称System.out.println("是否继续(y/n)");f = scan.next();counnt++;writeArray();}loadmenu2();break;case 2:counnt = 0;f = "y";while (f.equals("y")) {if (counnt != 0) {// Scanner scan = new Scanner(System.in);System.out.println("输入更改商品名称");nam = scan.next();b = showflage(nam);print(b);}System.out.println("请输入已更改商品价格");double cprice = scan.nextDouble();goodprice[b] = cprice;//新价格写入数组System.out.println("是否继续(y/n)");f = scan.next();counnt++;writeArray();}loadmenu2();break;case 3:counnt = 0;f = "y";while (f.equals("y")) {if (counnt != 0) {// Scanner scan = new Scanner(System.in);System.out.println("输入更改商品名称");nam = scan.next();b = showflage(nam);print(b);}System.out.println("请输入已更改商品数量");int cnum = scan.nextInt();goodnum[b] = cnum;counnt++;writeArray();System.out.println("是否继续(y/n)");f = scan.next();}loadmenu2();break;default:break;}/** 查询nama这个商品在goodname中的下标*/static int showflage(String nama) {int flag = 0;for (int i = 0; i < goodname.length; i++) {if (goodname[i].equals(nama)) {flag = i;break;}}return flag;}static void print(int b) {System.out.println("商品名称\t\t" + "商品价格 \t\t" + "商品数量 \t\t" + "备注");System.out.println(goodname[b] + "\t\t" + goodprice[b]+ goodnum[b] + " \t\t");}/** 删除商品菜单*/static void loadmenu4() {String f;int d;do {Scanner scan = new Scanner(System.in);System.out.println("请输入要删除的商品名称:");String dname = scan.next();d = showflage(dname);delete(d);System.out.println("是否继续(y/n)");f = scan.next();writeArray();//删除之后重新写入文件} while (f.equals("y"));loadmenu2();}/** 删除商品*/static void delete(int dd) {for (int i = dd; i < goodname.length - 1; i++) { goodname[i] = goodname[i + 1];goodprice[i] = goodprice[i + 1];goodnum[i] = goodnum[i + 1];}goodname[goodname.length - 1] = null;goodprice[goodprice.length - 1] = 0;goodnum[goodnum.length - 1] = 0;}/** 查询所有商品*/static void showgoods() {int i = 0;while (goodprice[i] != 0) {System.out.print(goodname[i] + "\t\t\t" + goodprice[i] + "\t\t\t"+ goodnum[i] + "\t\t\t");if (goodnum[i] < 10) {System.out.println("\t\t\t*该商品已不足10件!");}System.out.println();i++;}loadmenu2();}/** 商品添加操作*/static void addgoods() {System.out.println("执行添加商品操作:\t");String a;do {Scanner scan = new Scanner(System.in);System.out.println("输入商品名称:");String na = scan.next();add(goodname, na, sign);System.out.println("输入添加商品价格:");double pr = scan.nextDouble();add(goodprice, pr, sign);System.out.println("输入添加商品数量:");int c = scan.nextInt();add(goodnum, c, sign);sign++;System.out.println("是否继续(y/n)");a = scan.next();writeArray();} while (a.equals("y"));loadmenu2();}/** 将数组信息写入到相应的文件里,启动程序时就要调用这个函数*/static void writeArray() {BufferedWriter bw = null;try {bw = new BufferedWriter(new FileWriter("d:\\gname.txt"));String content1 = strToString(goodname);bw.write(content1);bw.close();bw = new BufferedWriter(new FileWriter("d:\\gprice.txt"));String content2 = doubleToString(goodprice);bw.write(content2);bw.close();bw = new BufferedWriter(new FileWriter("d:\\gnum.txt"));String content3 = intToString(goodnum);bw.write(content3);bw.close();bw = new BufferedWriter(new FileWriter("d:\\cname.txt"));String content4 = strToString(cname);bw.write(content4);bw.close();bw = new BufferedWriter(new FileWriter("d:\\cpass.txt"));String content5 = strToString(cpass);bw.write(content5);bw.close();bw = new BufferedWriter(new FileWriter("d:\\gout.txt"));String content6 = intToString(goodout);bw.write(content6);bw.close();} catch (IOException e) {e.printStackTrace();}}/** 添加商品名称*/static void add(String[] aa, String n, int b) { if (b == aa.length) {aa = (String[]) Arrays.copyOf(aa, aa.length * 2);}aa[b] = n;}/** 添加商品价格*/static void add(double[] aa, double pr, int b) { if (b == aa.length) {aa = (double[]) Arrays.copyOf(aa, aa.length * 2);}aa[b] = pr;}/** 添加商品数量*/static void add(int[] aa, int cc, int b) {if (b == aa.length) {aa = (int[]) Arrays.copyOf(aa, aa.length * 2);}aa[b] = cc;}/*** 从文件中读取信息到相应的数组里*/static void readArrays(String name) throws Exception { BufferedReader br = null;try {if ("goodname".equals(name)) {br = new BufferedReader(new FileReader("d:\\gname.txt"));String content1 = br.readLine();String[] arr = strToString(content1);goodname = (String[]) Arrays.copyOf(arr, arr.length);for (int i = 0; i < goodname.length; i++) {if (!goodname[i].equals("null")) {sign++;}}} else if ("goodprice".equals(name)) {br = new BufferedReader(new FileReader("d:\\gprice.txt"));String content2 = br.readLine();double[] arr = doubleToString(content2);goodprice = (double[]) Arrays.copyOf(arr, arr.length);} else if ("goodnum".equals(name)) {br = new BufferedReader(new FileReader("d:\\gnum.txt"));String content3 = br.readLine();int[] arr = intToString(content3);goodnum = (int[]) Arrays.copyOf(arr, arr.length);} else if ("cname".equals(name)) {br = new BufferedReader(new FileReader("d:\\cname.txt"));String content4 = br.readLine();String[] arr = strToString(content4);cname = (String[]) Arrays.copyOf(arr, arr.length);for (int i = 0; i < cname.length; i++) {if (!cname[i].equals("null")) {sign1++;}}} else if ("cpass".equals(name)) {br = new BufferedReader(new FileReader("d:\\cpass.txt"));String content5 = br.readLine();String[] arr = strToString(content5);cpass = (String[]) Arrays.copyOf(arr, arr.length);} else {br = new BufferedReader(new FileReader("d:\\gout.txt"));String content6 = br.readLine();int[] arr = intToString(content6);goodout = (int[]) Arrays.copyOf(arr, arr.length);}} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}/** 将字符串转换成字符串数组*/static String strToString(String[] arry) {// String arrys="";// for(int i=0;i<arry.length;i++)// {// arrys=arry+arry[i]+",";// }// //arrys=arrys+arry[arry.length-1];// System.out.println(arrys);// return arrys;StringBuilder sb = new StringBuilder();for (int i = 0; i < arry.length; i++) {sb.append(arry[i]).append(",");}sb.deleteCharAt(sb.length() - 1);// System.out.println(sb.toString());return sb.toString();}/** 将字符串转换成字符串数组*/static String[] strToString(String ar) {String[] arry = ar.split(",");return arry;}/** 将int型数组转换成字符串*/static String intToString(int[] arrr) {String ss = "";ss = Arrays.toString(arrr);String sss = ss.replace("[", "").replace("]", "").replace(" ", "");。