C#订餐系统

using System;
using System.Collections;
using System.Linq;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)    //方法必须包含在类中;程序的编译和运行从main()方法开始;
        {   orderUtil order = new orderUtil();    //订餐系统;
            order.initial();
            order.startMenu();
        }
    }
    class Food
    {
        public string name;
        public double price;
        public int numb;
    }
    class orderSet
    {
        public string name;
        //public string foodName;
        //public int foodNumb;
        public string dishMesg;
        public int dateTime;
        public string address;
        public int isFinish = 0;
        public double countPrice;
    }
    class orderUtil
    {
        public static int size = 3;
        Food[] foods = new Food[3];
        orderSet[] orderSets = new orderSet[size];
        public void initial()
        {

            for (int i = 0; i < foods.Length; i++)
            {
                foods[i] = new Food();
            }
            foods[0].name = "红烧带鱼";
            foods[0].price = 38;
            foods[0].numb = 0;
            foods[1].name = "鱼香肉丝";
            foods[1].price = 20;
            foods[1].numb = 0;
            foods[2].name = "时令鲜蔬";
            foods[2].price = 10;
            foods[2].numb = 0;
            for (int j = 0; j < orderSets.Length; j++)
            {
                orderSets[j] = new orderSet();
            }
            orderSets[0].name = "张晴";
            orderSets[0].dishMesg = "红烧带鱼*2";
            orderSets[0].dateTime = 18;
            orderSets[0].address = "天成路207号";
            orderSets[0].isFinish = 1;
            orderSets[0].countPrice = 76;
            orderSets[1].name = "张晴";
            orderSets[1].dishMesg = "鱼香肉丝*2";
            orderSets[1].dateTime = 21;
            orderSets[1].address = "天成路207号";
            orderSets[1].isFinish = 0;
            orderSets[1].countPrice = 45;
        }
        public void startMenu()
        {
            //Console.WriteLine("欢迎使用吃货联盟订餐系统" + "\n" + "*************************");
            //Console.WriteLine("1.我要订餐" + "\n" + "2.查看餐袋" + "\n" + "3.签收订单" + "\n" + "4.删除订单" + "\n" + "5.我要点赞" + "\n" + "6.退出系统" + "\n" + "*************************");
            //Console.Write("请选择: ");
            orderStart start = new orderStart();
            start.start();
            bool b = true;
            while (b)
            {
                int i = 0;
                //int i = int.Parse(Console.ReadLine());
                string str = Console.ReadLine();
                foreach (var item in str)
                {
                    if ('0' <= item && item <= '9')
                    {
                        i = int.Parse(str);

                    }
                    else
                    {
                        Console.WriteLine("输入错误,非数字,请重新输入:");
                        continue;
                    }
                }
                int j = 0;
                switch (i)
                {
                    case 1:
                        Console.WriteLine("***我要订餐***");
                        size++;
                        Console.WriteLine("序号" + " " + "菜名" + " " + "单价" + " " + "点赞数");
                        for (int k = 0; k < foods.Length; k++)
                        {
                            Console.WriteLine(k + 1 + ". " + foods[k].name + " " + foods[k].price + " " + foods[k].numb);
                        }
                        add();
                        Console.Write("输入0返回:");
                        j = int.Parse(Console.ReadLine());
                        if (j == 0)
                        {
                            start.start();
                        }
                        break;
                    case 2:
                        Console.WriteLine("***查看餐袋***");
                        display();
                        Console.Write("输入0返回: ");
                        j = int.Parse(Console.ReadLine());
                        if (j == 0)
                        {
                            start.start();
                        }
                        break;
                    case 3:
                        Console.WriteLine("***签收订单***");
                        Console.Write("请输入要签收的订单号: ");
                        int l = int.Parse(Console.ReadLine());
                        sign(l);
                        Console.Write("输入0返回: ");
                        j = int.Parse(Console.ReadLine());
                        if (j == 0)
                        {
                            start.start();
                        }
                        break;
                    case 4:
                        Console.WriteLine("***删除订单***");
                        Console.Write("请输入要删除的订单号:");
                        int ij = int.Parse(Console.ReadLine());
                        delete(ij);
                        Console.Write("输入0返回: ");
                        j = int.Parse(Console.ReadLine());
                        if (j == 0)
                        {
                            start.start();
                        }
                        break;
                    case 5:
                        Console.WriteLine("***我要点赞***");
                        Console.WriteLine("序号" + " " + "菜名" + " " + "单价" + " " + "点赞数");
                        for (int k = 0; k < foods.Length; k++)
                        {
                            Console.WriteLine(k + 1 + ". " + foods[k].name + " " + foods[k].price + " " + foods[k].numb);
                        }
                        Console.Write("请选择你要点赞的菜品序号:");
                        int ik = int.Parse(Console.ReadLine());
                        praise(ik);
                        Console.Write("输入0返回: ");
                        j = int.Parse(Console.ReadLine());
                        if (j == 0)
                        {
                            start.start();
                        }
                        break;
                    case 6:
                        b = false;
                        Console.WriteLine("谢谢使用,欢迎下次光临");
                        break;
                }
            }
        }
        public void display()
        {
            for (int k = 0; k < orderSets.Length; k++)
            {
                if (orderSets[k].name != null)
                {
                    Console.WriteLine("序号:{0} 姓名:{1} 菜品信息:{2} 订单日期:{3} 地址:{4} 总价:{5}", k + 1, orderSets[k].name, orderSets[k].dishMesg, orderSets[k].dateTime, orderSets[k].address, orderSets[k].countPrice + " 订单状态:" + (orderSets[k].isFinish == 1 ? "已完成" : "已预定"));
                }
            }
        }
        public void add()
        {
            for (int i = 0; i < orderSets.Length; i++)
            {
                if (orderSets[i].name == null)
                {
                    Console.Write("请输入订餐人姓名:");
                    orderSets[i].name = Console.ReadLine();
                    Console.Write("请选择您要点的菜品编号:");
                    int j = int.Parse(Console.ReadLine());
                    orderSets[i].dishMesg = foods[j - 1].name;
                    Console.Write("请选择您需要的份数:");
                    int k = int.Parse(Console.ReadLine());
                    orderSets[i].dishMesg += (" * " + k);
                    Console.Write("请输入您期望的送餐时间:");
                    orderSets[i].dateTime = int.Parse(Console.ReadLine());
                    Console.Write("请输入送餐地址:");
                    orderSets[i].address = Console.ReadLine();
                    Console.WriteLine("订餐成功");
                    int im = foods[j - 1].price * k > 50 ? 5 : 0;
                    orderSets[i].countPrice = (foods[j - 1].price * k + im);
                    Console.Write("您订的是:" + orderSets[i].dishMesg + "\n" + "送餐时间:" + orderSets[i].dateTime + "\n" + "餐费:" + foods[j - 1].price * k + "送餐费:" + im + "总计:" + orderSets[i].countPrice);
                    break;
                }
            }
        }
        public void sign(int i)
        {
            for (int j = 0; j < orderSets.Length; j++)
            {
                if (i - 1 == j && orderSets[j].name != null && orderSets[j].isFinish == 0)
                {
                    orderSets[j].isFinish = 1;
                    Console.WriteLine("签收完成,请返回主菜单查看餐袋");
                    //Console.WriteLine("1.查看订单状态 2.退出");
                    //if (int.Parse(Console.ReadLine())==1)
                    //{
                    //    Random random = new Random();
                    //    int r = random.Next(1, 11);
                    //    Console.WriteLine("序号:{0} 姓名:{1} 菜名:{2} 份量:{3} 订单日期:{4} 地址:{5} 价格:{6}", j + 1, orderSets[j].name, orderSets[j].foodName, orderSets[j].foodNumb, orderSets[j].dateTime, orderSets[j].address, (foods[j - 1].price * orderSets[i].foodNumb + r) + "订单状态:" + (orderSets[j].isFinish == 1 ? "已完成" : "已预定"));
                    //}
                    break;
                }
                else if (i - 1 == j && orderSets[j].name != null)
                {
                    Console.WriteLine("该订单已完成,无需签收");
                }
                else if (j == orderSets.Length - 1)
                {
                    Console.WriteLine("无该订单号,请重新输入");
                    sign(int.Parse(Console.ReadLine()));
                }
            }
        }
        public void delete(int i)
        {
            for (int j = 0; j < orderSets.Length; j++)
            {
                if (i - 1 == j && orderSets[j].name != null && orderSets[j].isFinish == 1)
                {

                    for (int k = j; k < orderSets.Length - 1; k++)
                    {
                        //orderSets[k].name = orderSets[k+1].name;
                        //orderSets[k].dishMesg= orderSets[k+1].dishMesg;                       
                        //orderSets[k].dateTime = orderSets[k+1].dateTime;
                        //orderSets[k].address = orderSets[k+1].address;
                        //orderSets[k].isFinish = orderSets[k+1].isFinish;
                        //orderSets[k].countPrice = orderSets[k+1].countPrice;
                        orderSets[k] = orderSets[k + 1];
                        if (orderSets[k + 1] == null)
                        {
                            break;
                        }
                    }
                    Console.WriteLine("订单删除成功,请返回主菜单查看餐袋");
                    //orderSets[orderSets.Length - 1].name = null;
                    break;
                }
                else if (i - 1 == j && orderSets[j].name != null)
                {
                    Console.WriteLine("您选择的订单未签收,不能删除");
                    break;
                }
                else if (j == orderSets.Length - 1)
                {
                    Console.WriteLine("无该订单号,请重新输入");
                    delete(int.Parse(Console.ReadLine()));
                }
            }
        }
        public void praise(int i)
        {
            foods[i - 1].numb++;
            Console.WriteLine("点赞成功");
        }
    }
    class orderStart
    {
        public void start()
        {
            Console.WriteLine("欢迎使用吃货联盟订餐系统" + "\n" + "*************************");
            Console.WriteLine("1.我要订餐" + "\n" + "2.查看餐袋" + "\n" + "3.签收订单" + "\n" + "4.删除订单" + "\n" + "5.我要点赞" + "\n" + "6.退出系统" + "\n" + "*************************");
            Console.Write("请选择: ");
        }
    }
    
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值