C#简单超市收银系统源码.docx
《C#简单超市收银系统源码.docx》由会员分享,可在线阅读,更多相关《C#简单超市收银系统源码.docx(17页珍藏版)》请在冰豆网上搜索。
![C#简单超市收银系统源码.docx](https://file1.bdocx.com/fileroot1/2023-1/30/58b926ad-2dc7-473d-9a0c-bfe1dbd24be5/58b926ad-2dc7-473d-9a0c-bfe1dbd24be51.gif)
C#简单超市收银系统源码
C#简单超市收银系统源码
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespace_16超市收银系统
{
classProductFather
{
publicdoublePrice
{
get;
set;
}
publicstringName
{
get;
set;
}
publicstringID
{
get;
set;
}
publicProductFather(stringid,doubleprice,stringName)
{
this.ID=id;
this.Price=price;
this.Name=Name;
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespace_16超市收银系统
{
classSamSung:
ProductFather
{
publicSamSung(stringid,doubleprice,stringName)
:
base(id,price,Name)
{
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespace_16超市收银系统
{
classAcer:
ProductFather
{
publicAcer(stringid,doubleprice,stringName)
:
base(id,price,Name)
{
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespace_16超市收银系统
{
classBanana:
ProductFather
{
publicBanana(stringid,doubleprice,stringName)
:
base(id,price,Name)
{
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespace_16超市收银系统
{
classJiangYou:
ProductFather
{
publicJiangYou(stringid,doubleprice,stringName)
:
base(id,price,Name)
{
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespace_16超市收银系统
{
classSupperMarket
{
//创建仓库对象
CangKuck=newCangKu();
///
///创建超市对象的时候,给仓库的货架上导入货物
///
publicSupperMarket()
{
ck.JinPros("Acer",1000);
ck.JinPros("SamSung",1000);
ck.JinPros("JiangYou",1000);
ck.JinPros("Banana",1000);
}
///
///跟用户交互的过程
///
publicvoidAskBuying()
{
Console.WriteLine("欢迎观临,请问您需要些什么?
");
Console.WriteLine("我们有Acer、SamSung、Jiangyou、Banana");
stringstrType=Console.ReadLine();
Console.WriteLine("您需要多少?
");
intcount=Convert.ToInt32(Console.ReadLine());
//去仓库取货物
ProductFather[]pros=ck.QuPros(strType,count);
//下面该计算价钱了
doublerealMoney=GetMoney(pros);
Console.WriteLine("您总共应付{0}元",realMoney);
Console.WriteLine("请选择您的打折方式1--不打折2--打九折3--打85折4--买300送505--买500送100");
stringinput=Console.ReadLine();
//通过简单工厂的设计模式根据用户的舒服获得一个打折对象
CalFathercal=GetCal(input);
doubletotalMoney=cal.GetTotalMoney(realMoney);
Console.WriteLine("打完折后,您应付{0}元",totalMoney);
Console.WriteLine("以下是您的购物信息");
foreach(variteminpros)
{
Console.WriteLine("货物名称:
"+item.Name+","+"\t"+"货物单价:
"+item.Price+","+"\t"+"货物编号:
"+item.ID);
}
}
///
///根据用户的选择打折方式返回一个打折对象
///
///用户的选择
///返回的父类对象但是里面装的是子类对象
publicCalFatherGetCal(stringinput)
{
CalFathercal=null;
switch(input)
{
case"1":
cal=newCalNormal();
break;
case"2":
cal=newCalRate(0.9);
break;
case"3":
cal=newCalRate(0.85);
break;
case"4":
cal=newCalMN(300,50);
break;
case"5":
cal=newCalMN(500,100);
break;
}
returncal;
}
///
///根据用户买的货物计算总价钱
///
///
///
publicdoubleGetMoney(ProductFather[]pros)
{
doublerealMoney=0;
//realMoney=pros[0].Price*pros.Length;
for(inti=0;i{
realMoney+=pros[i].Price;
//realMoney=pros[i]*pros.Length;
}
returnrealMoney;
}
publicvoidShowPros()
{
ck.ShowPros();
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespace_16超市收银系统
{
///
///不打折该多少钱就多少钱
///
classCalNormal:
CalFather
{
publicoverridedoubleGetTotalMoney(doublerealMoney)
{
returnrealMoney;
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespace_16超市收银系统
{
///
///按折扣率打折
///
classCalRate:
CalFather
{
///
///折扣率
///
publicdoubleRate
{
get;
set;
}
publicCalRate(doublerate)
{
this.Rate=rate;
}
publicoverridedoubleGetTotalMoney(doublerealMoney)
{
returnrealMoney*this.Rate;
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespace_16超市收银系统
{
///
///买M元送N元
///
classCalMN:
CalFather
{
//买500送100
publicdoubleM
{
get;
set;
}
publicdoubleN
{
get;
set;
}
publicCalMN(doublem,doublen)
{
this.M=m;
this.N=n;
}
publicoverridedoubleGetTotalMoney(doublerealMoney)
{
//600-100
//1000-200
//1200
if(realMoney>=this.M)
{
returnrealMoney-(int)(realMoney/this.M)*this.N;
}
else
{
returnrealMoney;
}
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespace_16超市收银系统
{
classCangKu
{
List>list=newList>();
///
///向用户展示货物
///
publicvoidShowPros()
{
foreach(variteminlist)
{
Console.WriteLine("我们超市有:
"+item[0].Name+","+"\t"+"有"+item.Count+"个,"+"\t"+"每个"+item[0].Price+"元");
}
}
//list[0]存储Acer电脑
//list[1]存储三星手机
//list[2]存储酱油
//list[3]存储香蕉
///
///在创建仓库对象的时候像仓库中添加货架
///
publicCangKu()
{
list.Add(newList());
list.Add(newList());
list.Add(newList());
list.Add(newList());
}
///
///进货
///
///货物的类型
///货物的数量
publicvoidJinPros(stringstrType,intcount)
{
for(inti=0;i{
switch(strType)
{
case"Acer":
list[0].Add(newAcer(Guid.NewGuid().ToString(),1000,"宏基笔记本"));
break;
case"SamSung":
list[1].Add(newSamSung(Guid.NewGuid().ToString(),2000,"棒之手机"));
break;
case"JiangYou":
list[2].Add(newJiangYou(Guid.NewGuid().ToString(),10,"老抽酱油"));
break;
case"Banana":
list[3].Add(newBanana(Guid.NewGuid().ToString(),50,"大香蕉"));
break;
}
}
}
///
///从仓库中提取货物
///
///
///
///
publicProductFather[]QuPros(stringstrType,intcount)
{
ProductFather[]pros=newProductFather[count];
for(inti=0;i{
switch(strType)
{
case"Acer":
pros[i]=list[0][0];
list[0].RemoveAt(0);
break;
case"SamSung":
pros[i]=list[1][0];
list[1].RemoveAt(0);
break;
case"JiangYou":
pros[i]=list[2][0];
list[2].RemoveAt(0);
break;
case"Banana":
pros[i]=list[3][0];
list[3].RemoveAt(0);
break;
}
}
returnpros;
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespace_16超市收银系统
{
classSupperMarket
{
//创建仓库对象
CangKuck=newCangKu();
///
///创建超市对象的时候,给仓库的货架上导入货物
///
publicSupperMarket()
{
ck.JinPros("Acer",1000);
ck.JinPros("SamSung",1000);
ck.JinPros("JiangYou",1000);
ck.JinPros("Banana",1000);
}
///
///跟用户交互的过程
///
publicvoidAskBuying()
{
Console.WriteLine("欢迎观临,请问您需要些什么?
");
Console.WriteLine("我们有Acer、SamSung、Jiangyou、Banana");
stringstrType=Console.ReadLine();
Console.WriteLine("您需要多少?
");
intcount=Convert.ToInt32(Console.ReadLine());
//去仓库取货物
ProductFather[]pros=ck.QuPros(strType,count);
//下面该计算价钱了
doublerealMoney=GetMoney(pros);
Console.WriteLine("您总共应付{0}元",realMoney);
Console.WriteLine("请选择您的打折方式1--不打折2--打九折3--打85折4--买300送505--买500送100");
stringinput=Console.ReadLine();
//通过简单工厂的设计模式根据用户的舒服获得一个打折对象
CalFathercal=GetCal(input);
doubletotalMoney=cal.GetTotalMoney(realMoney);
Console.WriteLine("打完折后,您应付{0}元",totalMoney);
Console.WriteLine("以下是您的购物信息");
foreach(variteminpros)
{
Console.WriteLine("货物名称:
"+item.Name+","+"\t"+"货物单价:
"+item.Price+","+"\t"+"货物编号:
"+item.ID);
}
}
///
///根据用户的选择打折方式返回一个打折对象
///
///用户的选择
///返回的父类对象但是里面装的是子类对象
publicCalFatherGetCal(stringinput)
{
CalFathercal=null;
switch(input)
{
case"1":
cal=newCalNormal();
break;
case"2":
cal=newCalRate(0.9);
break;
case"3":
cal=newCalRate(0.85);
break;
case"4":
cal=newCalMN(300,50);
break;
case"5":
cal=newCalMN(500,100);
break;
}
returncal;
}
///
///根据用户买的货物计算总价钱
///
///
///
publicdoubleGetMoney(ProductFather[]pros)
{
doublerealMoney=0;
//realMoney=pros[0].Price*pros.Length;
for(inti=0;i{
realMoney+=pros[i].Price;
//realMoney=pros[i]*pros.Length;
}
returnrealMoney;
}
publicvoidShowPros()
{
ck.ShowPros();
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespace_16超市收银系统
{
classProgram
{
staticvoidMain(string[]args)
{
//创建超市对象
SupperMarketsm=newSupperMarket();
//展示货物
sm.ShowPros();
//跟用户交互
sm.AskBuying();
Console.ReadKey();
}
}
}