基于socket网络编程的超市收银管理系统.docx
《基于socket网络编程的超市收银管理系统.docx》由会员分享,可在线阅读,更多相关《基于socket网络编程的超市收银管理系统.docx(82页珍藏版)》请在冰豆网上搜索。
基于socket网络编程的超市收银管理系统
packageentity;
importjava.io.Serializable;
/**
*收银类
*
*/
@SuppressWarnings("serial")
publicclassCashimplementsSerializable{
privateStringname;//商品名
privateStringunit;//商品单位
privateintamount;//商品数量
privatedoubleprice;//商品单价
privatedoublemoney;//商品金额
publicCash(Stringname,Stringunit,intamount,doubleprice,doublemoney){
this.name=name;
this.unit=unit;
this.amount=amount;
this.price=price;
this.money=money;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicStringgetUnit(){
returnunit;
}
publicvoidsetUnit(Stringunit){
this.unit=unit;
}
publicintgetAmount(){
returnamount;
}
publicvoidsetAmount(intamount){
this.amount=amount;
}
publicdoublegetPrice(){
returnprice;
}
publicvoidsetPrice(doubleprice){
this.price=price;
}
publicdoublegetMoney(){
returnmoney;
}
publicvoidsetMoney(doublemoney){
this.money=money;
}
}
packageentity;
importjava.io.Serializable;
/**
*商品类
*
*/
@SuppressWarnings("serial")
publicclassShangPinimplementsSerializable{
privateStringnumber;//商品编号
privateStringspname;//商品名称
privatedoubleprice;//商品单价
privateStringunit;//单位
privateintamount;//数量
publicStringgetNumber(){
returnnumber;
}
publicvoidsetNumber(Stringnumber){
this.number=number;
}
publicStringgetSpname(){
returnspname;
}
publicvoidsetSpname(Stringspname){
this.spname=spname;
}
publicdoublegetPrice(){
returnprice;
}
publicvoidsetPrice(doubleprice){
this.price=price;
}
publicStringgetUnit(){
returnunit;
}
publicvoidsetUnit(Stringunit){
this.unit=unit;
}
publicintgetAmount(){
returnamount;
}
publicvoidsetAmount(intamount){
this.amount=amount;
}
publicShangPin(Stringnumber,Stringspname,doubleprice,Stringunit,
intamount){
this.number=number;
this.spname=spname;
this.price=price;
this.unit=unit;
this.amount=amount;
}
}
packageentity;
/**
*用户类
*/
importjava.io.Serializable;
@SuppressWarnings("serial")
publicclassUserimplementsSerializable{
privateStringusername;//用户名称
privateStringpassword;//用户密码
publicStringgetUsername(){
returnusername;
}
publicvoidsetUsername(Stringusername){
this.username=username;
}
publicStringgetPassword(){
returnpassword;
}
publicvoidsetPassword(Stringpassword){
this.password=password;
}
publicUser(Stringusername,Stringpassword){
this.username=username;
this.password=password;
}
}
packageentity;
importjava.io.Serializable;
/**
*会员类
*
*/
@SuppressWarnings("serial")
publicclassVipimplementsSerializable{
privateStringvipId;//会员卡号
privateintscore;//会员积分
publicVip(StringvipId,intscore){
this.vipId=vipId;
this.score=score;
}
publicStringgetVipId(){
returnvipId;
}
publicvoidsetVipId(StringvipId){
this.vipId=vipId;
}
publicintgetScore(){
returnscore;
}
publicvoidsetScore(intscore){
this.score=score;
}
}
packagesocket;
/**
*客户端类
*
*/
importjava.io.InputStream;
importjava.io.ObjectInputStream;
importjava.io.ObjectOutputStream;
importjava.io.OutputStream;
import.Socket;
importjava.text.SimpleDateFormat;
importjava.util.Date;
importjava.util.HashMap;
importjava.util.Map;
importjava.util.Scanner;
importentity.Cash;
importentity.ShangPin;
publicclassClient{
staticScannerinput=newScanner(System.in);
privatestaticObjectreceive;
privatestaticStringusername;
staticintcount=0;
privatestaticObjectsend(Mapmap)throwsException,
Exception{//发送方法
Sockets=newSocket("127.0.0.1",8800);
OutputStreamos=s.getOutputStream();
ObjectOutputStreamoos=newObjectOutputStream(os);
oos.writeObject(map);
InputStreamis=s.getInputStream();
ObjectInputStreamois=newObjectInputStream(is);
receive=ois.readObject();
//关闭流
oos.close();
os.close();
is.close();
ois.close();
returnreceive;
}
publicstaticvoidmain(String[]args)throwsException{
System.out.println("***********欢迎使用青鸟超市管理系统****************");
System.out.println("1.登陆");
System.out.println("2.退出系统");
System.out.println("**************请选择数字1/2************");
while(true){
intchoose=input.nextInt();
if(choose==1){
do{
System.out.print("用户名称:
");
username=input.next();
System.out.print("用户密码:
");
Stringpassword=input.next();
Mapmap=newHashMap();
map.put("账号",username);
map.put("密码",password);
map.put("send","登录");
send(map);
//库存管理员界面
if("管理员".equals(receive)){
System.out
.println("*********欢迎登录青鸟超市库存管理系统*************");
admin();
}elseif("收银员".equals(receive)){
System.out
.println("*********欢迎登录青鸟超市收银系统*************");
cash();
}else{
System.out.println("用户名或者密码输入错误!
登录失败!
");
}
}while(true);
}elseif(choose==2){
System.out.println("您已经退出系统!
");
break;
}else{
System.out.println("输入错误!
请重新选择数字1/2:
");
}
}
}
privatestaticvoidadmin()throwsException{//管理员
intchoose;
while(true){
System.out
.println("请选择进行的操作:
1.商品入库\t2.商品出库\t3.新增商品\t4.查询所有商品\t5.按编号查询商品\t6.退出");
choose=input.nextInt();//选择库存操作
switch(choose){
case1:
//入库
in();
break;
case2:
//出库
out();
break;
case3:
//新增
add();
break;
case4:
//打印所有商品
checkall();
break;
case5:
//按编号查询
check();
break;
case6:
//退出
System.out.println("谢谢使用!
");
break;
default:
System.out.println("对不起,您的输入有误,请重新输入!
");
break;
}
}
}
@SuppressWarnings("unchecked")
privatestaticvoidin()throwsException{//入库
System.out.print("输入商品编号:
");
Stringnumber=input.next();
Mapmap=newHashMap();
map.put("编号",number);
map.put("send","查询编号");
send(map);
if("有此商品".equals(receive)){
System.out.print("入库数量:
");
Stringamount=input.next();
if(num(amount)==true){
inta=Integer.parseInt(amount);
if(a>=0){
map.put("入库数量",amount);
map.put("send","入库");
Mapmap1=(Map)send(map);
System.out.println("商品编号\t\t"+"商品名称\t\t"+"商品单价\t\t"
+"单位\t\t"+"数量");
for(ShangPiniterable_element:
map1.values()){
System.out.println(iterable_element.getNumber()
+"\t\t"+iterable_element.getSpname()
+"\t\t"+iterable_element.getPrice()+"\t\t"
+iterable_element.getUnit()+"\t\t"
+iterable_element.getAmount());
}
}else{
System.out.println("出库数量有误!
");
}
}
}else{
System.out.println("没有此商品,请选择编号3:
新增商品!
");
}
}
@SuppressWarnings("unchecked")
privatestaticvoidout()throwsException{//出库
System.out.print("输入商品编号:
");
Stringnumber=input.next();
Mapmap=newHashMap();
map.put("编号",number);
map.put("send","查询编号");
send(map);
if("有此商品".equals(receive)){
System.out.print("出库数量:
");
Stringamount=input.next();
if(num(amount)==true){
inta=Integer.parseInt(amount);
if(a>=0){
map.put("出库数量",amount);
map.put("send","出库");
send(map);
Mapmap1=(Map)receive;
if(a<=map1.get(number).getAmount()){
System.out.println("商品编号\t\t"+"商品名称\t\t"
+"商品单价\t\t\t"+"单位\t\t\t"+"数量");
for(ShangPinsp:
map1.values()){
System.out.println(sp.getNumber()+"\t\t"
+sp.getSpname()+"\t\t"+sp.getPrice()
+"\t\t"+sp.getUnit()+"\t\t"
+sp.getAmount());
}
}else{
System.out.println("库存不足,请核实,出库失败!
");
System.out.println("商品编号\t\t"+"商品名称\t\t"+"商品单价\t\t"
+"单位\t\t"+"数量");
System.out.println(map1.get(number).getNumber()
+"\t\t"+map1.get(number).getSpname()
+"\t\t"+map1.get(number).getPrice()+"\t\t"
+map1.get(number).getUnit()+"\t\t"
+map1.get(number).getAmount());
}
}else{
System.out.println("出库数量有误!
");
}
}
}else{
System.out.println("没有此商品!
");
}
}
@SuppressWarnings("unchecked")
privatestaticvoidadd()throwsException{//新增
while(true){
System.out.print("输入商品编号:
");
Stringnumber=input.next();
Mapmap=newHashMap();
map.put("编号",number);
map.put("send","查询编号");
send(map);
if("无此商品".equals(receive)){
System.out.print("输入商品名称:
");
Stringspname=input.next();
System.out.print("输入商品价格:
");
Stringprice=input.next();
if(price(price)==true){
System.out.print("输入商品单位:
");
Stringunit=input.next();
System.out.print("输入商品数量:
");
Stringamount=input.next();
if(num(amount)==true){
map.put("send","新增");
map.put("名称",spname);
map.put("价格",price);
map.put("单位",unit);
map.put("数量",amount);
send(map);
System.out.println("新增商品成功!
");
Mapmap2=(Map)receive;
System.out.println("商品编号\t\t"+"商品名称\t\t"
+"商品单价\t\t\t"+"单位\t\t\t"+"数量");
for(ShangPinsp:
map2.values()){
System.out.println(sp.getNumber()+"\t\t"
+sp.getSpname()+"\t\t"+sp.getPrice()
+"\t\t"+sp.getUnit()+"\t\t"
+sp.getA