1问题的提出……………………………………………………………………2
1.1可行性分析……………………………………………………………… 2
2需求分析……………………………………………………………………… 2
2.1商店管理的业务流程……………………………………………………2
2.2系统的功能分析………………………………………………………3
2.3用例分析………………………………………………………………3
2.3.1用例图…………………………………………………………3
2.3.2用例描述………………………………………………………4
2.3.3寻找分析类……………………………………………………7
2.4系统模块设计…………………………………………………………11
2.4.1系统模块设计…………………………………………………11
2.4.2子模块设计……………………………………………………12
2.5数据库设计……………………………………………………………13
2.5.1数据流图………………………………………………………13
2.5.2数据库E-R模型………………………………………………16
2.5.3数据库的物理模型……………………………………………16
2.6模块设计与代码实现…………………………………………………25
参考文献…………………………………………………………………………
1 问题的提出
随着商店商品的大量增加其管理难度越来越大,在计算机技术飞速发展的今天,将计算机这一信息处理利器应用于商店的日常管理已是势所必然。于是,商店进销存管理系统便应运而生。这为商店管理带来前所未有的改变,同时为企业带来意想不到的经济效益和社会效益。这主要体现在以下几个方面:
1 极大的提高了商店工作人员的工作效率,避免了以往入、出、存流程繁琐杂乱,周期长的弊端。
2 商店管理实现了操作自动化和信息电子化,全面提高了超市的管理水平。
3 基于超市管理的全面自动化可以大大减少入库管理,出库管理及库存管理中的漏洞,可以节约大量管理开支增加企业的收入。
1.1 可行性分析
由于商店规模的日益增大,进出货物数量繁多,且工作量大。原有的手工操作耗时费力,又不能保证数据的正确性,迫切需要实现计算机信息化管理,用信息化管理实现对数据的录入、查询、打印等的处理。比起传统的方法这样可以节省大量的人力物力资源,又可以缩短业务处理的时间,加强对物资安全的管理,具有很强的实用性和经济性。
2 需求分析
2.1 商店管理的业务流程
商店的日常业务经营活动主要包括采购、销售、库存盘点、账目管理等四个方面。因此如何处理好这几者之间的关系是设计商店进销存管理系统最为关键的部分。商店运营的基本业务流程如图1 所示。
图1 业务流程图
2.2 系统的功能分析
本系统开发的总体目标是建立一个能够对商店内商品流动进行监控,即在商品采购、销售、库存、账目管理等过程中进行监督与控制。经过小组讨论,该系统应具备以下功能:
1. 采购员采购商品后及时录入商品信息在数据库中进行数据更新。
2. 在收银处随时录入卖出商品信息,如名称数量单价等及时更新数据库数据。
3. 货架上商品卖到一定数量时及时生成提货报告并提供商品的库存剩余信息。
4. 在需要时可每日或每周统计一次,生成商品销售情况报告。并可以导出统计结果且可以生成excel表格。
5. 仓库管理员可以用多种方式查询各种商品信息,也可以采用多种查询条件的组合查询。并可以导出查询结果且可以生成excel表格。
2.3 用例分析
2.3.1 用例图
用例图如图(2)所示:
图(二)用例图
2.3.2 用例描述
表格1 用例描述 系统登录
用例编号 | UC01 |
用例名称 | 系统登录 |
用例概述 | 系统登录界面 |
主参与者 | 收银员、仓库管理员、admin |
基本事件流 | 1、 选择角色 2、 输入用户名和登录密码。 3、 点击确定登录按钮。 |
扩展事件流 | 1、 如果用户验证不成功则弹出对话框告知错误信息。 2、 如果用户验证成功,则显示对于角色系统界面。 |
表格 2 用例描述 商品入库
用例编号 | UC02 |
用例名称 | 商品入库 |
用例概述 | 仓库管理员将商品的各种信息录入到数据库中,并更新数据库 |
主参与者 | 仓库管理员 |
基本事件流 | 1. 仓库管理员向系统发出新增商品的请求 2. 系统显示相应界面,让仓库管理员输入信息,并自动根据商品号生成规则生成商品号 3. 仓库管理员输入商品的相关信息,包括商品名、定价、生产日期、保质期等 4. 系统确认输入的信息中,商品名没有重名 5. 系统将所输入的信息存储建档 |
扩展事件流 | 4a.如果输入的商品名有重名现象,则显示出重名的商品的相关信息,并要求仓库管理员选择修改商品名或取消输入 4b.仓库管理员选择取消输入,则结束用例,不做存储建档工作 4c.仓库管理员选择修改商品名后,转到4 |
表格3 用例描述 销售商品
用例编号 | UC03 |
用例名称 | 销售商品 |
用例概述 | 收银员收费流程 |
主参与者 | 收银员 |
基本事件流 | 1、 登录系统。 2、 判断顾客是否为会员。 3、 录入销售商品信息。 4、 统计销售总金额。 5、 选择付款方式。 6、 付款。 7、 打印收据 |
扩展事件流 | 1、 如果付款成功,则弹出消息框告诉收银员付款成功!! 2、 如果付款失败,则弹出消息框告诉收银员付款失败,并提升失败原因。 |
表格4 用例描述 商品信息查询
用例编号 | UC04 |
用例名称 | 查询商品信息 |
用例概述 | 按照选定的查询方式查询商品信息。 |
主参与者 | 仓库管理员 |
基本事件流 | 1、 登录系统。 2、 选择查询方式。 3、 根据查询条件获得查询结果。 4、 管理员选择是否打印报表 |
扩展事件流 | 1、打印查询结果(excel表格) |
表格5 用例描述 打印报表
用例编号 | UC05 |
用例名称 | 打印报表 |
用例概述 | 打印指定类型的报表 |
主参与者 | 仓库管理员、系统 |
基本事件流 | 1、 确定打印报表类型。 2、 根据报表类型生成相应报表。 3、 打印相应类型的excel表格 |
扩展事件流 | |
表格6 用例描述 销售预警
用例编号 | UC06 |
用例名称 | 销售预警 |
用例概述 | 系统根据货架信息判断是否需要生成预警报表。 |
主参与者 | 系统 |
基本事件流 | 1、 统计各个货架上各商品数量信息。 2、 判断是否达到管理员所设置的预警线。 3、 如果达到预警线,则打印报表 |
扩展事件流 | 1、打印报表 |
表格 6 用例描述 销售情况统计
用例编号 | UC06 |
用例名称 | 统计销售情况 |
用例概述 | 根据系统设置(每日或每周),统计销售情况。 |
主参与者 | 系统\admin |
基本事件流 | 1、 统计销售报表。 2、 生成销售统计结果表。 3、 打印报表。 |
扩展事件流 | |
表格7 用例描述 账目管理
用例编号 | UC07 |
用例名称 | 账目管理 |
用例概述 | Admin可以随时查看历史账目,也可以统计给定事件段的账目信息。 |
主参与者 | Admin |
基本事件流 | 1、 登录系统。 2、 确定统计时间范围。 3、 统计进货单。 4、 统计销售报表。 5、 生成账目表。 |
扩展事件流 | 1、打印报表 |
2.3.3 寻找分析类
用例1 登录系统------分析类:
1)类: 1、登录窗体类
2、三个参与者:收银员、仓库管理员、admin
2)类的属性和方法:
登录窗体------属性:
1、登录、取消两个按钮
2、角色类型单选按钮组(三个单选按钮)
3、登录名、登录密码文本框。
4、窗口标题
登录窗体----方法:
1、获取角色类型
2、获得登录名和登录密码
3、连接数据库,验证登陆信息
参与者------属性:
1、登录名、登录密码
2、角色类型标识
参与者------方法:
1、获取、设置登录名和登录密码
用例2 商品入库-----分析类:
1)类:
1、两个参与者:仓库管理员
2、商品入库窗体类、商品
2)类的属性和方法:
仓库管理员------属性:
1、登录名、登录密码
2、角色类型标识
仓库管理员-----方法:
1、发送商品入库请求
2、录入商品信息
3、修改商品名
4、取消输入
商品入库窗体类------属性:
1、 接收商品信息的各种控件
2、 各类控制按钮
商品入库窗体类------方法:
1、接收商品个信息
2、确认商品名是否重名
3、显示出重名的商品的相关信息
4、存储商品信息
用例3 销售商品---分析类
1) 类:
1、收银员
2、商品
3、顾客
4、银行(POS)
5、登录系统窗体类
6、销售商品窗体类,销售报表
7、收据
2)类中的属性和方法:
收银员---属性:
1、工卡号、姓名、密码、角色名称
收银员----方法:
顾客----属性:
1、顾客姓名,性别,年龄,是否VIP,VIP编号
2、银行卡
顾客---方法:
1、选择付款方法
2、付款
商品---属性:
1、商品编号、商品名称、商品价格、生产商、商品购买数量
2、是否参与活动
商品----方法:
1、设置与获取属性的方法
POS机---属性:
1、编号、使用商、银行
POS机---方法:
1、获得顾客银行卡信息
2、与银行进行交易的方法
3、打印回单
收据---属性:
1、商品信息列表、收据编号(流水号)、应收金额、
实收金额、找零。
2、VIP信息。购物日期。
登录系统窗体类---属性:
1、登录、取消两个按钮
2、角色类型单选按钮组(三个单选按钮)
3、登录名、登录密码文本框。
4、窗口标题
登录窗体类----方法:
1、获取角色类型
2、获得登录名和登录密码
3、连接数据库,验证登陆信息
销售商品窗体类----属性:
1、商品信息列表
2、VIP顾客信息
3、收据单
销售商品窗体类--方法:
1、根据商品编号从数据库中获得商品信息,并添加到商 品信息列表。
2、获取VIP客户信息。
3、结算交易金额。并创建收据单。
4、打印收据单
销售报表----属性:
1、报表编号、销售日期,成本金额,销售金额,利润。
用例4 商品信息查询---分析类:
类:1.仓库管理员
2.商品
3.商品查询报表
4、商品信息查询窗口
类的属性和方法:
商品——属性:
1.商品的编号
2.商品的名称
3.商品的价格
商品——方法:
1.获取各属性的get方法
商品报表——属性:
1.报表编号
2.商品信息列表
商品报表——方法
1.生成报表编号
2.获取商品信息列表
用例5 销售预警-----分析类:
类::
1、货架
2、仓库管理员
3、预警报表
类的属性和方法:
货架-----属性:
1、货架编号
2、商品列表
3、各商品放置数量
4、各商品预警线
货架----方法:
1、对各商品的上架、下架
2、获取各商品当前在架数量
3、获取各商品信息
4、获取和设置各商品预警线
商品----属性:
1、商品编号
2、商品名称。。。。
商品----方法:
1、获取各属性的get方法
预警报表----属性:
1、货架编号、报表编号
2、发生预警的商品列表
3、发生预警的商品在仓库中的信息列表
4、预警发生时间
预警报表----方法:
1、生成报表编号
2、设置货架编号
3、生成预警商品列表
4、获得预警商品在库信息列表
5、获得预警发生时间
6、打印报表,生成excel表格
用例6 销售情况统计
类:1、销售情况统计窗口类
2、销售报表
3、销售统计表
类的属性和方法:
销售报表----属性
1、报表编号(流水号)
2、销售日期,成本金额,销售金额,利润。
销售统计表----属性:
1、统计表编号,统计日期,承办总金额,销售总金额
总利润。
用例7 账目管理
类:1、登录系统窗体
2、账目管理窗体
3、admin
4、账目类
5、进货表
6、销售统计表
类的属性和方法:
系统登录窗体
账目管理窗体
销售统计表----属性:
1、统计表编号,统计日期,某商品的具体销售情况
账目类----属性:
1、账目编号,生成账目日期,
2、成本总金额,销售总金额,总利润。
3、每种商品的编号,进货总量、进货成本、销售成本,
利润。
2.4 系统模块设计
2.4.1 系统模块设计
图三 系统模块设计
2.4.2 子模块分析
1. 仓库管理员模块类图分析,如图四
图四 仓库管理员主界面类图分析
2. 账目管理模块类图分析,如图五
图五 账目管理模块类图分析
2.5 数据库设计
该系统采用的是SQL2008,数据库采用powerdesigner1.25设计。
2.5.1 数据流图
通过对商店营业的业务流程分析得知,该系统的数据流图:
1.顶层数据流图,如图六
图六 顶层数据流图
2. 二级数据流图如下
3. 数据字典
表八 数据项列表
名称 | 代码 | 数据类型 | 长度 |
VIP编号 | VIPnumber | Variable characters (20) | 20 |
会员积分 | VIPpoints | Integer | |
供应商名称 | OEMSname | Variable characters (20) | 20 |
供应商地址 | OEMSaddress | Variable characters (30) | 30 |
供应商电话 | OEMSphone | Variable characters (20) | 20 |
供应商编号 | OEMSnumber | Variable characters (20) | 20 |
供应商联系人 | OEMSlinkman | Variable characters (20) | 20 |
入会日期 | entranceTime | Variable characters (20) | 20 |
利润 | profit | Money (8) | 8 |
利润 | profits | Money (8) | 8 |
商品名称 | goodsName | Variable characters (20) | 20 |
商品数量 | goodsAcount | Integer | |
商品数量 | goodsCount | Integer | |
商品类型 | goodsType | Variable characters (20) | 20 |
商品编号 | goodsNumber | Variable characters (20) | 20 |
商品编号 | goodsID | Variable characters (20) | 20 |
商品销售价格 | salePrice | Money (8) | 8 |
姓名 | name | Variable characters (20) | 20 |
工卡号 | securityNumbe | Variable characters (20) | 20 |
工卡号 | securityNumber | Variable characters (20) | 20 |
年龄 | age | Integer | |
性别 | sex | Characters (2) | 2 |
总利润 | sumProfits | Money (8) | 8 |
总成本 | sumPrimeCost | Money (8) | 8 |
总销售金额 | sumSalesAmount | Money (8) | 8 |
成本 | cost | Money (8) | 8 |
折扣 | discounts | Float (2) | 2 |
折扣规则编号 | discountNumber | Variable characters (20) | 20 |
收据编号 | receiptNumber | Variable characters (20) | 20 |
数量 | saleAmount | Integer | |
电话 | phone | Variable characters (20) | 20 |
登录密码 | password | Variable characters (20) | 20 |
结束日期 | endTime | Variable characters (20) | 20 |
结束日期 | dateEnd | Variable characters (20) | 20 |
统计日期 | statsTime | Variable characters (20) | 20 |
账目管理日期 | manageTime | Variable characters (20) | 20 |
账目编号 | accountNumber | Variable characters (20) | 20 |
货架编号 | shelfNumber | Variable characters (20) | 20 |
起始日期 | startTime | Variable characters (20) | 20 |
起始日期 | dateStart | Variable characters (20) | 20 |
进货价格 | inPrice | Money (8) | 8 |
进货单编号 | orderNumber | Variable characters (20) | 20 |
进货日期 | PurchaseDate | Variable characters (20) | 20 |
金额 | saleMoney | Variable characters (20) | 20 |
销售数量 | saleCount | Integer | |
销售日期 | salesDate | Variable characters (20) | 20 |
销售统计编号 | statsNumber | Variable characters (20) | 20 |
销售记录编号 | saleRecorderNumber | Variable characters (20) | 20 |
销售金额 | saleTotalMoney | Money (8) | 8 |
销售金额 | salesAmount | Money (8) | 8 |
预警线 | preFlightLine | Integer | |
表九 数据结构
名称 | 代码 |
Admin | AdminInfo |
VIP顾客 | VIPcustomer |
仓库管理员 | StorekeeperInfo |
供应商 | OEMsTable |
商品 | Goods |
折扣表 | DiscountTable |
收据 | Receipt |
收银员 | CashierInfo |
账目 | Account |
货架 | GoodsShelf |
进货单 | PurchaseOrder |
销售统计表 | SaleStats |
销售记录 | SalesRecorder |
表十 数据流
名称 | 代码 | 实体 2 | 实体 1 |
付款 | pay | 货架 | 收据 |
供应 | supply | 进货单 | 供应商 |
入库 | Stocking | 进货单 | 商品 |
商品上架 | goodsShelve | 商品 | 货架 |
成本统计 | costAccount | 进货单 | 销售统计表 |
折扣 | discount | 货架 | 折扣表 |
生产 | product | 商品 | 供应商 |
账目管理 | accountManage | 销售统计表 | 账目 |
销售 | sale | 销售记录 | 货架 |
销售统计 | stats | 销售记录 | 销售统计表 |
2.5.2 数据库E-R模型
对系统的数据流进行具体分析后,得出数据库的概念模型,E-R模型,如图七。
图七 概念模型E-R图
2.5.3 数据库的物理模型
1. 该系统采用SQL2008数据库,用poerdesigner12.5进行分析与设计。进过分析,综合考虑系统的信息有效、安全性,该数据库的物理模型如图八所示。
图八 物理模型
2.6 模块设计与代码实现
1. 商品入库模块设计如图九:
图九 商品入库界面设计
关键代码如下:
///////////按钮事件处理 public void actionPerformed(ActionEvent e) { if(e.getSource()==this.m_btnBack){ this.setVisible(false); this.homeFrame.setVisible(true);
}else if(e.getSource()==this.m_btnFlush){ this.m_txGoodsCount.setText(""); this.m_txGoodsInPrice.setText(""); this.m_txGoodsName.setText(""); this.m_txGoodsNumber.setText(""); this.m_txGoodsSalePrice.setText(""); this.m_txGoodsType.setText(""); this.m_txOEMSnumber.setText(""); }else if(e.getSource()==this.m_btnOK){ this.sqlGoodsManage.createAddGoodsInfoConnection(); int index=-1; index=this.sqlGoodsManage.insertGoodsInfo(this.createNewGoods()); if(index==0){ JOptionPane.showMessageDialog(this, "商品成功入库!!"); }else if(index==1){ JOptionPane.showMessageDialog(this, "该商品已经在仓库中!!"); }else if(index==2){ JOptionPane.showMessageDialog(this, "没有改供应商哦!!"); }else if(index==3){ JOptionPane.showMessageDialog(this, "商品入库失败!!"); }
}
} ////////创建商品对象 private Goods createNewGoods(){ Goods goods=new Goods(); goods.setM_goodsNumber(this.m_txGoodsNumber.getText()); goods.setM_goodsName(this.m_txGoodsName.getText()); goods.setM_goodsType(this.m_txGoodsType.getText()); goods.setM_inPrice(Double.parseDouble(this.m_txGoodsInPrice.getText())); goods.setM_goodsCount(Integer.parseInt(this.m_txGoodsCount.getText())); goods.setM_OEMSnumber(this.m_txOEMSnumber.getText()); return goods; }
|
2. 商品销售模块设计如图十:
图十 商品销售界面
关键代码如下:
//////销售商品 private void saleGoods(){ String goodsNumber=this.m_txGoodsNumber.getText(); int goodsCount=Integer.parseInt(this.m_txGoodsCount.getText()); ResultSet rest=null; this.goodsManage.createSaleGoodsConnection(); rest=this.goodsManage.saleGoods(goodsNumber); try { if(rest.next()){ this.tableData[index][0].setValue(goodsNumber); this.tableData[index][1].setValue(rest.getString(2)); this.tableData[index][2].setValue(goodsCount+""); double price=rest.getDouble(3); double total=price*goodsCount; this.tableData[index][3].setValue(total+""); index++; this.m_tbGoodsList.updateUI(); }else{ JOptionPane.showMessageDialog(this, "轻输入正确的商品编号!!"); } this.goodsManage.updateGoodsShelf(goodsCount); } catch (SQLException e) { e.printStackTrace(); }finally{ this.goodsManage.closeSaleConnection(); }
} //////计算消费金额 private void caculate(){ double total =0; double temp=0; for(int i=0;i<this.tableData.length;i++){ if(this.tableData[i][3].toString()!=null){ temp=Double.parseDouble(this.tableData[i][3].toString()); total+=temp; } } JOptionPane.showMessageDialog(this, "消费总金额为: "+total+" 元!!");
} |
3. 商品信息查询模块设计如图十一:
图十一 商品信息查询
关键代码如下:
///////商品信息查询功能实现 private void searchGoodsInfo(){ String sqlGoodsNum="",sqlGoodsName="",sqlGoodsType="",sqlGoodsPrice="",sqlOEMSname="",sqlOEMSnumber=""; String sqlSearchGoodsInfo="select goodsInfo.goodsNumber,goodsName,inPrice,goodsType,goodsCount,PurchaseOrder.OEMSnumber,OEMSname" + " from goodsInfo,PurchaseOrder,OEMsInfo where OEMsInfo.OEMSnumber=PurchaseOrder.OEMSnumber and " + "goodsInfo.goodsNumber=PurchaseOrder.goodsNumber and ( "; if(this.cbGoodsName.isSelected()){ sqlGoodsName=" or goodsName='"+this.m_txGoodsName.getText()+"'"; } if(this.cbGoodsNum.isSelected()){ sqlGoodsNum=" or goodsInfo.goodsNumber='"+this.m_txGoodsNumber.getText()+"'"; } if(this.cbGoodsPrice.isSelected()){ sqlGoodsPrice=" or inPrice="+Double.parseDouble(this.m_txGoodsPrice.getText()); } if(this.cbGoodsType.isSelected()){ sqlGoodsType=" or goodsType='"+this.m_txGoodsType.getText()+"'"; } if(this.cbOEMSname.isSelected()){ sqlOEMSname=" or OEMSname='"+this.m_txOEMSname.getText()+"'"; } if(this.cbOEMSnumber.isSelected()){ sqlOEMSnumber=" or PurchaseOrder.OEMSnumber='"+this.m_txOEMSnumber.getText()+"'"; } sqlSearchGoodsInfo+=sqlGoodsName+sqlGoodsNum+sqlGoodsPrice+sqlGoodsType+sqlOEMSname+sqlOEMSnumber+")"; sqlSearchGoodsInfo=sqlSearchGoodsInfo.replaceFirst("or", ""); ResultSet rest=null; this.sqlGoodsManage.createSearchGoodsInfoConnection(); rest=this.sqlGoodsManage.selectGoodsInfo(sqlSearchGoodsInfo); try { while(rest.next()){ Goods goods=new Goods(); goods.setM_goodsNumber(rest.getString(1)); goods.setM_goodsName(rest.getString(2)); goods.setM_inPrice(rest.getDouble(3)); goods.setM_goodsType(rest.getString(4)); goods.setM_goodsCount(rest.getInt(5)); goods.setM_OEMSnumber(rest.getString(6)); goods.setM_OEMSname(rest.getString(7)); this.goodsList.add(goods); } } catch (SQLException e) { e.printStackTrace(); }finally{ this.sqlGoodsManage.closeSelectCon(); } } //////显示商品信息 private void showNextGoodsInfo(){ for(int i=0;i<this.tableData.length;i++){ Goods goods=null; if(this.index<this.goodsList.size()){ goods=this.goodsList.get(index); index++; for(int j=0;j<this.tableData[0].length;j++){ this.tableData[i][j].setValue(goods.getProperTy(j+1)); } }else{ for(int j=0;j<this.tableData[0].length;j++){ this.tableData[i][j].setValue(""); } this.m_btnNext.setEnabled(false); }
} this.tableSearchInfo.updateUI(); } |
4. 商品销售统计模块界面设计如图十二:
图十二 商品销售统计
关键代码如下:
public GoodsSaleStatsFrame(AdminHomeFrame adminHome) { this.adminHome=adminHome; setTitle("商品销售统计界面"); setBounds(new Rectangle(100, 100, 800, 700)); getContentPane().setLayout(null); this.setBounds(100, 100, 800, 700);
/////////// this.inItPane(); ////按钮注册事件 this.m_btnDetermineSet.addActionListener(this); this.m_btnPrintStatisticsTable.addActionListener(this); this.m_btnReturnMainMenu.addActionListener(this); this.m_btnStatisticsSales.addActionListener(this); this.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ GoodsSaleStatsFrame count=(GoodsSaleStatsFrame)e.getComponent(); count.setVisible(false); count.adminHome.setVisible(true); } });
////// } |
5 .系统登录模块设计如图十三
图 十三 系统登录界面
关键代码如下:
////////////按钮事件处理 public void actionPerformed(ActionEvent e) { if(e.getSource()==btnOK){ String sql=""; String employeeName=""; if(this.m_raAdmin.isSelected()){ sql="select * from AdminInfo where securityNumber=? and password=?"; }else if(this.m_raCashier.isSelected()){ sql="select * from cashierInfo where securityNumbe=? and password=?"; }else if(this.m_raStorekeeper.isSelected()){ sql="select * from storekeeperInfo where securityNumber=? and password=?"; } try { this.con=DriverManager.getConnection(this.DBURL, this.DBUSER, this.DBPSW); this.sqlIn=this.con.prepareStatement(sql); ResultSet ret=null; this.sqlIn.setString(1, this.m_txEmployeeID.getText()); this.sqlIn.setString(2, this.m_txPassword.getText()); ret=this.sqlIn.executeQuery(); if(!ret.next()){ JOptionPane.showMessageDialog(this, "请输入正确的密码或在ID号!!"); return; } employeeName=ret.getString(2); } catch (SQLException e1) { e1.printStackTrace(); }finally{ try { this.sqlIn.close(); this.con.close(); } catch (SQLException e1) { e1.printStackTrace(); } } if(this.m_raAdmin.isSelected()){ this.setVisible(false); this.frame_AdminHome.setVisible(true); }else if(this.m_raCashier.isSelected()){ this.setVisible(false); this.frame_SaleGoods.setVisible(true); this.frame_SaleGoods.setCashierName(employeeName); }else if(this.m_raStorekeeper.isSelected()){ this.setVisible(false); this.frame_WarehouseManagemnet.setVisible(true); this.frame_WarehouseManagemnet.setSoreKeeperName(employeeName); }
}else if(e.getSource()==btnCancel){ System.exit(0);
}
} |
添加商品数据库连接
package sql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import dateitem.Goods;
public class GoodsManageSQL {
////////数据库连接
private final String DBDRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
private final String DBURL="jdbc:sqlserver://localhost:1433;database=db_SPMposManageSystem";
private final String DBUSER="sa";
private final String DBPSW="a5119550";
private Connection con;
private PreparedStatement sqlAddGoodsInfo,
sqlDeleteGoodsInfo,
sqlModifyGoodsInfo;
private Statement sqlSearchGoodsInfo,sqlModify;
private Statement sqlAddPurcahseOrder;
private Statement sqlSaleGoods;
/////////////////
public GoodsManageSQL(){
try {
Class.forName(this.DBDRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
/////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
/**
* 创建添加商品的数据库连接
*/
public void createAddGoodsInfoConnection(){
try {
this.con=DriverManager.getConnection(this.DBURL, this.DBUSER, this.DBPSW);
String sql="insert into goodsInfo values(?,?,?,?,?)";
this.sqlAddGoodsInfo=con.prepareStatement(sql);
this.sqlSearchGoodsInfo=con.createStatement();
this.sqlModify=con.createStatement();
this.sqlAddPurcahseOrder=con.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 添加商品
* @param goods
* @return
*/
public int insertGoodsInfo(Goods goods){
int flage=3;
ResultSet rest=null;
String OEMSnumber=goods.getM_OEMSnumber();
try {
String sql="";
sql="select * from OEMsInfo where OEMSnumber='"+OEMSnumber+"'";
rest=this.sqlSearchGoodsInfo.executeQuery(sql);
if(!rest.next()){ ////如果数据库中没有改供应商编号,则返回2
return 2;
}
/////获取商品信息
sql="select goodsCount from goodsInfo where goodsNumber='"+goods.getM_goodsNumber()+"'";
rest=this.sqlSearchGoodsInfo.executeQuery(sql);
if(rest.next()){ ////如果数据库中已经存在该编号的商品,则更新
sql="update goodsInfo set goodsCount="+rest.getInt(1)+goods.getM_goodsCount()+"where goodsNumber='"+goods.getM_goodsNumber()+"'";
this.sqlModify.executeUpdate(sql);
}else{
this.sqlAddGoodsInfo.setString(1, goods.getM_goodsNumber());
this.sqlAddGoodsInfo.setString(2, goods.getM_goodsName());
this.sqlAddGoodsInfo.setDouble(3, goods.getM_inPrice());
this.sqlAddGoodsInfo.setInt(4, goods.getM_goodsCount());
this.sqlAddGoodsInfo.setString(5, goods.getM_goodsType());
if(this.sqlAddGoodsInfo.executeUpdate()>0){
flage=0; ////成功插入商品信息,返回0
}
}
////////新建商品订单
double primeMoeny=goods.getM_inPrice()*goods.getM_goodsCount();
Date date=new Date();
String time=(date.getYear()+1900)+"/"+date.getMonth()+"/"+date.getDay();
sql="insert into PurchaseOrder values('"+OEMSnumber+goods.getM_goodsNumber()+time+"','"+goods.getM_goodsNumber()+"','"+
OEMSnumber+"','"+time+"',"+primeMoeny+")";
this.sqlAddPurcahseOrder.execute(sql);
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
this.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return flage;
}
/**
* 创建查询商品信息数据库连接
*/
public void createSearchGoodsInfoConnection(){
try {
con=DriverManager.getConnection(this.DBURL, this.DBUSER, this.DBPSW);
this.sqlSearchGoodsInfo=con.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
}
public ResultSet selectGoodsInfo(String sql){
ResultSet rest=null;
try {
rest=this.sqlSearchGoodsInfo.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rest;
}
public void closeSelectCon(){
try {
this.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 创建商品信息修改数据库连接(只需修改商品名称,库存量,类型)
*/
public void createModifyGoodsInfoConnection(){
try {
con=DriverManager.getConnection(this.DBURL, this.DBUSER, this.DBPSW);
String sql="update goodsInfo set goodsName=? , goodsCount=? , goodsType=? where goodsNumber=?";
this.sqlModifyGoodsInfo=con.prepareStatement(sql);
} catch (SQLException e) {
e.printStackTrace();
}
}
public boolean updateGoodsInfo(Goods goods){
boolean flage=false;
try {
this.sqlModifyGoodsInfo.setString(1, goods.getM_goodsName());
this.sqlModifyGoodsInfo.setInt(2, goods.getM_goodsCount());
this.sqlModifyGoodsInfo.setString(3, goods.getM_goodsType());
this.sqlModifyGoodsInfo.setString(4, goods.getM_goodsNumber());
int n=this.sqlModifyGoodsInfo.executeUpdate();
if(n>0){
return true;
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
this.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return flage;
}
public void createSaleGoodsConnection(){
try {
con=DriverManager.getConnection(this.DBURL, this.DBUSER, this.DBPSW);
this.sqlSaleGoods=con.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
}
public ResultSet saleGoods(String goodsNumber){
ResultSet rst=null;
String sql="select goodsShelf.goodsNumber,goodsName,goodsShelf.salePrice "+
"from goodsInfo,goodsShelf "+
"where goodsInfo.goodsNumber=goodsShelf.goodsNumber and goodsShelf.goodsNumber='"+goodsNumber+"'";
try {
rst=this.sqlSaleGoods.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rst;
}
public void updateGoodsShelf(int count){
String sql="";
sql="update goodsShelf set goodsCount=goodsCount-"+count+"";
try {
this.sqlSaleGoods.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
}
}
public void closeSaleConnection(){
try {
this.con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
商品类
package dateitem;
public class Goods
{
private String m_goodsNumber;
private String m_goodsName;
private double m_inPrice;
private double m_salePrice;
private int m_goodsCount;
private String m_goodsType;
private String m_OEMSnumber;
private String m_OEMSname;
/**
@roseuid 4C348523028D
*/
public Goods()
{
}
public String getM_goodsNumber() {
return m_goodsNumber;
}
public void setM_goodsNumber(String number) {
m_goodsNumber = number;
}
public String getM_goodsName() {
return m_goodsName;
}
public void setM_goodsName(String name) {
m_goodsName = name;
}
public double getM_inPrice() {
return m_inPrice;
}
public void setM_inPrice(double price) {
m_inPrice = price;
}
public double getM_salePrice() {
return m_salePrice;
}
public void setM_salePrice(double price) {
m_salePrice = price;
}
public int getM_goodsCount() {
return m_goodsCount;
}
public void setM_goodsCount(int count) {
m_goodsCount = count;
}
public String getM_goodsType() {
return m_goodsType;
}
public void setM_goodsType(String type) {
m_goodsType = type;
}
public String getM_OEMSnumber() {
return m_OEMSnumber;
}
public void setM_OEMSnumber(String snumber) {
m_OEMSnumber = snumber;
}
public String getM_OEMSname() {
return m_OEMSname;
}
public void setM_OEMSname(String sname) {
m_OEMSname = sname;
}
public String getProperTy(int index){
switch(index){
case 1:
return this.m_goodsNumber;
case 2:
return this.m_goodsName;
case 3:
return this.m_inPrice+"";
case 4:
return this.m_goodsType;
case 5:
return this.m_goodsCount+"";
case 6:
return this.m_OEMSnumber;
case 7:
return this.m_OEMSname;
default:
return null;
}
}
}
主类
package bin;
import javax.swing.JFrame;
public class Start {
public static void main(String[] args) {
new MainFrame();
}
}
class MainFrame extends JFrame{
private LoginFrame frame_Login;
private SaleGoodsFrame frame_SaleGoods;
private WarehouseManagementFrame frame_WarehouseManagemnet;
private AdminHomeFrame frame_AdminHome;
public MainFrame(){
this.frame_AdminHome=new AdminHomeFrame();
this.frame_SaleGoods=new SaleGoodsFrame();
this.frame_WarehouseManagemnet=new WarehouseManagementFrame();
this.frame_Login=new LoginFrame(this.frame_SaleGoods,
this.frame_WarehouseManagemnet,this.frame_AdminHome);
}
}
参考文献
1. 耿祥义 张跃平 编著 Java 2 实用教程(第三版) 清华大学出版社
2. 王珊 萨师煊 编著 数据库系统概论(第四版) 高等教育出版社
本文来源:https://www.2haoxitong.net/k/doc/07d192de5022aaea998f0f61.html
文档为doc格式