using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Formats.Asn1.AsnWriter;
namespace ConsoleApp5
{
internal class FileName
{
static void Main(string[] args)
{
int count = 0;
int nums = 0;
ShoppingCart[] shoops = new ShoppingCart[10];
#region 登录
while (true)
{
Console.WriteLine("===============智能点菜系统-测试账号===============");
Console.WriteLine("账号:lilei\t\t\t密码:123456");
Console.WriteLine("账号:hanmeimei\t\t\t密码:123456");
Console.WriteLine("账号:xiaoai\t\t\t密码:123456");
Console.WriteLine("====================================================");
string[] account = { "lilei", "hanmeimei", "xiaoai" };
int passWord = 123456;
Console.Write("请输入账号:");
string newAccount = Console.ReadLine();
bool flag = false;
for (int i = 0; i < account.Length; i++)
{
if (newAccount.Equals(account[i]))
{
flag = true;
}
}
//判断账号是否输入正确
if (flag == false)
{
Console.WriteLine("账号不存在,请重新输入");
continue;
}
Console.Write("请输入密码:");
int newPassWord = int.Parse(Console.ReadLine());
//判断密码是否错误
if (passWord != newPassWord)
{
Console.WriteLine("密码错误,请重新输入");
continue;
}
else
{
break;
};
}
#endregion
Console.WriteLine("======================登录成功=======================");
while (true)
{
Console.WriteLine();
Console.WriteLine("================欢迎来到智能点菜系统=================");
Console.WriteLine("||\t1.开始点菜,2.购物车,F.返回主界面,Q.退出 ||");
Console.WriteLine("=====================================================");
Console.WriteLine();
Console.Write("请输入要操作的的菜单序号:");
string select = Console.ReadLine();
Store[] stores = new Store[3];
Store store1 = new Store();
store1.StoreCoding = "S001";
store1.StoreName = "饺子馆";
stores[0] = store1;
Store store2 = new Store();
store2.StoreCoding = "S002";
store2.StoreName = "川菜馆";
stores[1] = store2;
Store store3 = new Store();
store3.StoreCoding = "S003";
store3.StoreName = "小碗肉";
stores[2] = store3;
Food[] foods = new Food[4];
Food food1 = new Food();
food1.FoodCoding = "F001";
food1.FoodName = "韭菜馅";
food1.FoodPrice = 12.80;
foods[0] = food1;
Food food2 = new Food();
food2.FoodCoding = "F002";
food2.FoodName = "猪肉馅";
food2.FoodPrice = 15.00;
foods[1] = food2;
Food food3 = new Food();
food3.FoodCoding = "F003";
food3.FoodName = "茴香馅";
food3.FoodPrice = 11.00;
foods[2] = food3;
Food food4 = new Food();
food4.FoodCoding = "F004";
food4.FoodName = "酸菜馅";
food4.FoodPrice = 13.00;
foods[3] = food4;
string foodCodings = "";
int number = 0;
switch (select)
{
case "1":
Console.WriteLine("=========================店铺========================");
foreach (Store a in stores)
{
a.Show();
}
Console.WriteLine("======================================================");
Console.WriteLine("请输入店铺编码:");
string foodCoding = Console.ReadLine();
switch (foodCoding)
{
case "S001":
Console.WriteLine("==========================菜品=========================");
foreach (Food b in foods)
{
b.Show();
}
Console.WriteLine("=======================================================");
break;
case "S002":
break;
case "S003":
break;
}
while (true)
{
ShoppingCart s = new ShoppingCart();
int index_two = 0;
Console.WriteLine("请输入要点的菜品编码:");
s.FoodCoding = Console.ReadLine();
for (int i = 0; i < foods.Length; i++)
{
if (foods[i].FoodCoding.Equals(s.FoodCoding))
{
index_two = i;
break;
}
}
s.FoodName = foods[index_two].FoodName;
s.FoodPrice = foods[index_two].FoodPrice;
Console.WriteLine("请输入购买的份数:");
s.Frequency = int.Parse(Console.ReadLine());
Console.WriteLine("购物车添加成功,可以在主界面进入购物车。");
Console.WriteLine("是否继续添加:Y是,F返回主界面?");
shoops[nums] = s;
nums++;
count++;
string flags = Console.ReadLine();
if (flags.Equals("Y"))
{
continue;
}
else
{
break;
}
}
Console.Write("请选择要操作的菜单编号:");
string control = Console.ReadLine();
double sum = 0;
if (control == "1")
{
Console.Write("请输入收货地址:");
string address = Console.ReadLine();
Console.WriteLine("================结算完成=================");
Console.WriteLine();
Console.WriteLine("================消费清单=================");
Console.WriteLine("||\t姓名:\t\t李奕贤\t\t||");
Console.WriteLine("||\t电话:\t\t18564026510\t||");
Console.WriteLine($"||\t地址:\t\t{address}\t\t||");
Console.WriteLine("||\t--------------------------\t||");
for (int i = 0; i < count; i++)
{
Console.WriteLine("||\t菜名:\t\t{0}\t\t||", shoops[i].FoodName);
Console.WriteLine($"||\t价格:\t\t{shoops[i].FoodPrice,5:f2}\t\t||");
Console.WriteLine("||\t数量:\t\t{0}\t\t||", shoops[i].Frequency);
sum += shoops[i].FoodPrice * shoops[i].Frequency;
}
Console.WriteLine("||\t--------------------------\t||");
Console.WriteLine($"||\t总额:\t\t{sum,5:f2}\t\t||");
Console.WriteLine("=========================================");
return;
}
else if (control == "F")
{
break;
}
break;
case "2":
Console.WriteLine("===========购物车管理=============");
Console.WriteLine("||\t1.结算,F返回主界面\t||");
Console.WriteLine("==================================");
Console.WriteLine("=======================购物车清单==========================");
ShoppingCart shop = new ShoppingCart();
for (int i = 0; i < shoops.Length; i++)
{
if (shoops[i] != null)
{
shoops[i].Show();
}
}
Console.WriteLine("============================================================");
break;
case "F":
continue;
break;
case "Q":
Console.WriteLine("======================退出成功=======================");
return;
break;
default:
Console.WriteLine("输入有误!");
break;
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5
{
internal class Food
{
//菜品编码
private string _foodCoding;
//菜品名称
private string _foodName;
//菜品价格
private double _foodPrice;
//店铺编码
private string _storeCoding;
public string FoodCoding { get => _foodCoding; set => _foodCoding = value; }
public string FoodName { get => _foodName; set => _foodName = value; }
public double FoodPrice { get => _foodPrice; set => _foodPrice = value; }
public string StoreCoding { get => _storeCoding; set => _storeCoding = value; }
//展示菜品信息的方法
public void Show()
{
Console.WriteLine($"||\t编码:{_foodCoding}\t名称:{_foodName}\t价格:{_foodPrice,7:f2}元\t||");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5
{
internal class ShoppingCart
{
//菜品编码
private string _foodCoding;
//菜品名称
private string _foodName;
//用户账号
private string _userAccount;
//用户名
private string _userName;
//菜品价格
private double _foodPrice;
//购买份数
private int _frequency;
//标记位,设置初始值为false
private bool _flagBit = false;
public string FoodCoding { get => _foodCoding; set => _foodCoding = value; }
public string FoodName { get => _foodName; set => _foodName = value; }
public string UserAccount { get => _userAccount; set => _userAccount = value; }
public string UserName { get => _userName; set => _userName = value; }
public double FoodPrice { get => _foodPrice; set => _foodPrice = value; }
public int Frequency { get => _frequency; set => _frequency = value; }
public bool FlagBit { get => _flagBit; set => _flagBit = value; }
//展示购物车清单的方法
public void Show()
{
Console.WriteLine($"||\t编码:{_foodCoding}\t名称:{_foodName}\t价格:{_foodPrice,5:f2}\t数量:{_frequency}\t||");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp5
{
internal class Store
{
//店铺名称
private string _storeName;
//店铺编码
private string _storeCoding;
//属性
public string StoreName { get => _storeName; set => _storeName = value; }
public string StoreCoding { get => _storeCoding; set => _storeCoding = value; }
//展示店铺信息的方法
public void Show()
{
Console.WriteLine($"||\t编码:{_storeCoding}\t\t名称:{_storeName}\t||");
}
}
}