1、package com.pb.client; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Scanner; import com.pb.server.Goods; import com.pb.util.Datas; import com.pb.util.SysConstants; /* * 客户端 */ public class Client { public static
2、 Scanner input=new Scanner(System.in); public static ClientBIZ clientBIZ=new ClientBIZ(); public static void main(String[] args) { System.out.println("************************欢迎使用青鸟超市管理系统**************************************"); System.out.println("1.登录\n2.退出"); System.
3、out.println("************************请选择1/2******************************"); System.out.print("请选择:"); int choose=input.nextInt(); while(true){ if(choose==1){ login(); break; }else if(choose==2){ System.out.println("成功退出,谢谢使用");
4、 }else{ System.out.println("您输入的有误请重新输入"); } } } /* * 登录视图 */ public static void login(){ while(true){ System.out.print("请输入用户名:"); String username=input.next(); System.out.print("请输入密码:"); String password=input.next(); Datas datas=clien
5、tBIZ.doLogin(username, password); if(SysConstants.SYS_USER.equals(datas.getFlag())){ loginClitroller(); break; }else if(SysConstants.SYS_ADMIN.equals(datas.getFlag())){ loginCashier(); break; }else{ System.out.println("用户或密码错误,请重新登录"); } }
6、} /* * 库管员登录界面 */ public static void loginClitroller(){ while(true){ System.out.println("**********************欢迎登录青鸟超市库存管理系统**********************************"); System.out.println("请选择要进行的操作:1.商品入库\t2.商品出库\t3.新增商品\t4.查询全部商品\t5.按编号查询商品\t6.退出"); System.out.print("请选择:");
7、 int choose=input.nextInt(); if(choose==1){ System.out.println("请输入商品编号:"); int goodsid=input.nextInt(); System.out.println("请输入商品数量:"); int num=input.nextInt(); if(clientBIZ.inGoods(goodsid, num).getFlag().equals(SysConstants.SYS_SUCCESS)){ clientBIZ.inGoods(g
8、oodsid, num); System.out.println("入库成功"); show(clientBIZ.inGoods(goodsid, num)); }else{ System.out.println("入库失败。没有此编号的商品请选择3新增商品"); } }else if(choose==2){ System.out.println("请输入商品编号:"); int goodsid=input.nextInt(); System.out.println("请输入商品数量:")
9、 int num=input.nextInt(); if(clientBIZ.outGoods(goodsid, num).getFlag().equals(SysConstants.SYS_SUCCESS)){ clientBIZ.outGoods(goodsid, num); System.out.println("出库成功"); show(clientBIZ.findGoodAll()); }else{ System.out.println("出库失败"); } }else i
10、f(choose==3){ System.out.println("请输入商品编号:"); int goodsid=input.nextInt(); if(clientBIZ.findGood(goodsid).getFlag().equals(SysConstants.SYS_SUCCESS)){ System.out.println("此商品已存在,请确认!"); show(clientBIZ.findGoodAll()); }else{ System.out.println("请输入商品的数量:");
11、 int num=input.nextInt(); System.out.println("请输入商品的价格:"); double price=input.nextDouble(); System.out.println("请输入商品的单位:"); String unilt=input.next(); System.out.println("请输入商品的名称:"); String goodsname=input.next(); Goods goods=new Goods(goodsid,goodsname,pr
12、ice,unilt,num); clientBIZ.addGoods(goods); show(clientBIZ.findGoodAll()); } }else if(choose==4){ show(clientBIZ.findGoodAll()); }else if(choose==5){ System.out.println("请输入商品编号:"); int goodsid=input.nextInt(); if(SysConstants.SYS_SUCCESS.equals(cli
13、entBIZ.findGood(goodsid).getFlag())){ System.out.println("查询成功"); appointed(clientBIZ.findGood(goodsid)); }else{ System.out.println("查询失败"); } }else if(choose==6){ System.out.println("退出成功,谢谢使用库存管理系统"); break; } } } /* * 收银员登陆界面
14、 */ public static void loginCashier(){ while(true){ System.out.println("************************欢迎登录青鸟超市收银系统*************************"); System.out.println("请选择进行的操作:1.扫描商品\t2.修改商品数量\t3.结账\t4.退出"); System.out.print("请选择:"); int choose=input.nextInt(); if(choose==1){
15、 System.out.println("请输入商品编号:"); int goodsid=input.nextInt(); if(SysConstants.SYS_SUCCESS.equals(clientBIZ.doScan(goodsid).getFlag())){ System.out.println("扫描成功"); scanner(clientBIZ.doScan(goodsid)); }else{ System.out.println("扫描失败"); } }else if(choose==2){
16、 if(clientBIZ.cheak().getFlag().equals(SysConstants.SYS_ERROR)){ System.out.println("您还没有有扫面商品"); continue; }else{ System.out.println("请输入商品编号:"); int goodsid=input.nextInt(); if(arygood(goodsid)){ System.out.println("请输入商品的数量:"); Datas datas=null
17、 if(input.hasNextInt()){ int a=input.nextInt(); if(a>1){ datas=clientBIZ.amendGoods(a, goodsid); if(datas.getFlag().equals(SysConstants.SYS_LACK)){ System.out.println("商品数量不足"); perlook(clientBIZ.findGood(goodsid)); continue;
18、 }else{ System.out.println("修改成功"); show(clientBIZ.findGoodAll()); break; } }else{ System.out.println("数量必须大于零"); continue; } }else{ input.nextInt(); System.out.println("请输入正确的格式"); continue
19、 } } System.out.println("对不起没有扫描此商品"); } }else if(choose==3){ cheakGoods(); }else if(choose==4){ System.out.println("成功退出,谢谢使用"); break; }else{ System.out.println("您输入的有误!!!!"); } } } private static boolean arygood(in
20、t id){
if(clientBIZ.cheak().getFlag().equals(SysConstants.SYS_SUCCESS)){
ArrayList 21、
//结账
public static void cheakGoods(){
double price=allcheak(clientBIZ.cheak());
if(price!=0){
System.out.println("总金额为:"+price);
System.out.println("请选择结账类型:1.会员结账\t2.普通结账");
System.out.println("请选择:");
int choose=input.nextInt();
if(choose==1){
Syste 22、m.out.println("请输入会员卡号:");
int VIPid=input.nextInt();
if(VIPid==2012){
System.out.println("会员卡正确,请输入你要支付的金额");
int money=input.nextInt();
if(money 23、if(money>=price){
cheakOut(money, price);
}else{
System.out.println("您的操作有误!!!");
}
}else{
System.out.println("会员卡号不正确!!!!!");
cheakGoods();
}
}else if(choose==2){
System.out.println("请输入金额:");
int money=input.nextInt();
24、if(money 25、}
}else{
System.out.println("您还没有扫描商品");
}
}
public static void perlook(Datas datas){
System.out.println("----------------------------------------------------------------------------------------");
System.out.println("商品编号\t\t商品名称\t\t商品价格\t\t商品单位\t\t商品数量");
System.out.prin 26、tln(datas.getGoods().getGoodsid()+"\t\t"+datas.getGoods().getGoodsname()+"\t\t"+datas.getGoods().getPrice()+
"\t\t"+datas.getGoods().getUnilt()+"\t\t"+datas.getGoods().getNum());
System.out.println("----------------------------------------------------------------------------------------" 27、);
}
//付钱
public static void cheakOut(int money,double price){
System.out.println("*******************************青鸟超市*******************************************");
System.out.println("收银员编号:1001\t\t小票号:"+Remond());
scanner(clientBIZ.cheak());
System. 28、out.println("总数量:"+clientBIZ.cheak().getBygoodsList().size()+"\t\t应收:"+price);
System.out.println("实收:"+money);
System.out.println("应找:"+(money-price));
System.out.println("此小票是你退货及查看积分的唯一凭证,请妥善保管!!");
System.out.println("========================================== 29、");
}
//随机生成的小票号
public static String Remond(){
Date date=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyMMddhhmm");
String dar=sdf.format(date)+(int)Math.random()*1000;
return dar;
}
//打印时间
public static String date(){
Date 30、 dates=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yy-MM-dd hh:mm:ss");
String date=sdf.format(dates);
return date;
}
//总价格
public static double allcheak(Datas datas){
if(datas.getFlag().equals(SysConstants.SYS_SUCCESS)){
ArrayList 31、ist();
double sum=0;
for(int i=0;i 32、");
System.out.println("序\t\t商品名称\t\t商品价格\t\t商品单位\t\t商品数量\t\t金额");
ArrayList 33、
"\t\t"+goodlist.get(i).getPrice()+"\t\t"+goodlist.get(i).getUnilt()+"\t\t"+goodlist.get(i).getNum()
+"\t\t"+goodlist.get(i).getNum()*goodlist.get(i).getPrice());
}
System.out.println("------------------------------------------------------------------------");
} 34、
//显示指定的商品信息
public static void appointed(Datas datas){
if(datas.getFlag().equals(SysConstants.SYS_SUCCESS)){
System.out.println("-------------------------------------------------------------------");
System.out.println("商品编号\t\t商品名称\t\t商品价格\t\t商品单位\t\t商品数量");
Goods goods=datas 35、getGoods();
System.out.println(goods.getGoodsid()+"\t\t"+goods.getGoodsname()+"\t\t"
+goods.getPrice()+"\t\t"+goods.getUnilt()+"\t\t"+goods.getNum());
System.out.println("-------------------------------------------------------------------");
}
}
//显示商品的全部信息信息
public static vo 36、id show(Datas datas){
System.out.println("---------------------------------------------------------------------------------");
System.out.println("商品编号\t\t商品名称\t\t商品价格\t\t商品单位\t\t商品数量");
ArrayList 37、n(list.get(i).getGoodsid()+"\t\t"+list.get(i).getGoodsname()+"\t\t"
+list.get(i).getPrice()+"\t\t"+list.get(i).getUnilt()+"\t\t"+list.get(i).getNum());
}
System.out.println("---------------------------------------------------------------------------------");
}
}
38、package com.pb.client;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import .Socket;
import .UnknownHostException;
import java.util.ArrayList;
import com.pb.server.Controller;
import com.pb.server.Goods;
import com.pb.util.Datas;
impor 39、t com.pb.util.SysConstants;
import com.pb.util.Tools;
/*
* 客户端类
*/
public class ClientBIZ {
Socket socket=null;
ObjectOutputStream oos=null;
ObjectInputStream ois=null;
//创建socket相关的对象
private void initSocket(){
try {
socket=new Socket(Tools.getValue(Sy 40、sConstants.SYS_HOSTNAME),
Integer.parseInt(Tools.getValue(SysConstants.SYS_LISTENERPORT)));
oos=new ObjectOutputStream(socket.getOutputStream());
ois=new ObjectInputStream(socket.getInputStream());
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
41、e.printStackTrace();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void closeSocket(){
try {
oos.close();
42、 ois.close();
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*
* 登录业务
*/
public Datas doLogin(String username,String password){
try{
//调用Socket访问服务器
initSock 43、et();
//创建Datas对象
Datas datas=new Datas();
//为datas附上值 为了传递登录标示
datas.setFlag(SysConstants.SYS_LOGIN);
//创建用户对象
Controller controller=new Controller();
controller.setUsername(username);
controller.setPassword(password);
44、 datas.setController(controller);
//向服务器发送信息
oos.writeObject(datas);
//接收服务器的响应
datas=(Datas)ois.readObject();
return datas;
}catch(Exception e){
e.printStackTrace();
}finally{
//关闭流
closeSocket();
}
45、
return null;
}
//商品入库
public Datas inGoods(int goodsid,int num){
try{
//调用socket登录服务器
initSocket();
//创建datas对象
Datas datas=new Datas();
//给标示赋值
datas.setFlag(SysConstants.SYS_INGOOD);
//创建商品对象
46、 Goods goods=new Goods();
goods.setGoodsid(goodsid);
goods.setNum(num);
datas.setGoods(goods);
//向服务器发送信息
oos.writeObject(datas);
//获取服务器的信息
datas=(Datas)ois.readObject();
return datas;
}catch(Exception e){
e. 47、printStackTrace();
}finally{
closeSocket();
}
return null;
}
//商品出库
public Datas outGoods(int goodsid,int num){
try{
//调用socket登录服务器的方法
initSocket();
//创建datas对象
Datas datas=new Datas();
//创 48、建Goods对象
Goods goods=new Goods();
//赋值
goods.setGoodsid(goodsid);
goods.setNum(num);
datas.setFlag(SysConstants.SYS_OUTGOOD);
datas.setGoods(goods);
//向服务器发送信息
oos.writeObject(datas);
//接收服务器的响应
datas=(Datas)oi 49、s.readObject();
return datas;
}catch(Exception e){
e.printStackTrace();
}finally{
closeSocket();
}
return null;
}
//新增商品,增加的商品的属性
public Datas addGoods(Goods goods){
try{
//调用Socket登录的方法
initSocket();
Datas datas=new Datas();
datas.setFlag(SysConstants.SYS_ADDGOOD);
datas.setGoods(goods);
//向服务器发送信息
oos.writeObject(datas);
//接受响应
datas=(Datas) ois.readObject();
return datas;
}catch(Exception






