码迷,mamicode.com
首页 > Web开发 > 详细

.Net学习笔记----2015-06-30(超市收银系统01-仓库类)

时间:2015-06-30 16:13:11      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

GUID:

  产生一个不会重复的ID

        static void Main(string[] args)
        {
            //产生一个不会重复的编号
            Console.WriteLine(Guid.NewGuid().ToString());
            Console.WriteLine(Guid.NewGuid().ToString());
            Console.WriteLine(Guid.NewGuid().ToString());
            Console.WriteLine(Guid.NewGuid().ToString());
            Console.WriteLine(Guid.NewGuid().ToString());
            Console.ReadKey();
        }

 

分析:

  技术分享

 

父类:全用的是自动属性

    public class ProductFather
    {
        public double Price
        {
            get;
            set;
        }

        public string Name
        {
            get;
            set;
        }
        public double Count
        {
            get;
            set;
        }

        public string ID
        {
            get;
            set;
        }

        public ProductFather(string id, double price, double count,string name)
        {
            this.ID = id;
            this.Price = price;
            this.Count = count;
            this.Name = name;
        }
    }

子类:Acer

    class Acer : ProductFather
    {
        public Acer(string id, double price, double count, string name)
            : base(id, price, count, name)
        {

        }
    }

子类:SumSung

    class Acer : ProductFather
    {
        public Acer(string id, double price, double count, string name)
            : base(id, price, count, name)
        {

        }
    }

子类:JiangYou

    class JiangYou : ProductFather
    {
        public JiangYou(string id, double price, double count, string name)
            : base(id, price, count, name)
        {

        }
    }

子类:Banana

    class Banana : ProductFather
    {
        public Banana(string id, double price, double count, string name)
            : base(id, price, count, name)
        {

        }
    }

 

仓库类:

    class CangKu
    {
        //List<ProductFather> list = new List<ProductFather>();
        //存储货物
        //list接收的是List<>,相当于货架
        List<List<ProductFather>> list = new List<List<ProductFather>>();

        /// <summary>
        /// 向用户展示货物
        /// </summary>
        public void ShowPros()
        {
            foreach (var item in list)
            {
                Console.WriteLine("仓库现有:" + item[0].Name + "," + "\t" + item.Count + "个," + "\t" + "每个" + item[0].Price + "元。");
            }
        }
        //list[0]存储Acer电脑   list[1]存储三星手机   list[2]存储酱油   list[3]存储香蕉
        /// <summary>
        /// 在创建仓库对象的时候,向仓库中添加货架
        /// </summary>
        public CangKu()
        {
            list.Add(new List<ProductFather>());
            list.Add(new List<ProductFather>());
            list.Add(new List<ProductFather>());
            list.Add(new List<ProductFather>());
        }
        /// <summary>
        /// 进货
        /// </summary>
        /// <param name="strType">货物的类型</param>
        /// <param name="count">货物的数量</param>
        public void JinPros(string strType, int count)
        {
            for (int i = 0; i < count; i++)
            {
                switch (strType)
                {
                    case "Acer": list[0].Add(new Acer(Guid.NewGuid().ToString(), 1000, 100,"宏基笔记本电脑"));
                        break;
                    case "SamSung": list[1].Add(new SamSung(Guid.NewGuid().ToString(), 2000, 300,"三星手机"));
                        break;
                    case "JiangYou": list[2].Add(new JiangYou(Guid.NewGuid().ToString(), 10, 3000,"老抽"));
                        break;
                    case "Banana": list[3].Add(new Banana(Guid.NewGuid().ToString(), 12, 1000,"香蕉"));
                        break;
                }
            }
        }
        /// <summary>
        /// 取货
        /// </summary>
        /// <param name="strType">货物的类型</param>
        /// <param name="count">数量</param>
        public ProductFather[] QuPros(string strType, int count)
        {
            ProductFather[] pros = new ProductFather[count];
            for (int i = 0; i < count; i++)
            {
                switch (strType)
                {
                    case "Acer":
                        //判断如果货物数量为0,提示缺货
                        if (list[0].Count == 0)
                        {
                            Console.WriteLine("缺货");
                        }
                        else
                        {
                            pros[i] = list[0][0];
                            list[0].RemoveAt(0);
                        }
                        break;
                    case "SamSung":
                        if (list[1].Count == 0)
                        {
                            Console.WriteLine("缺货");
                        }
                        else
                        {
                            pros[i] = list[1][0];
                            list[1].RemoveAt(0);
                        }
                        break;
                    case "JiangYou":
                        if (list[2].Count == 0)
                        {
                            Console.WriteLine("缺货");
                        }
                        else
                        {
                            pros[i] = list[2][0];
                            list[2].RemoveAt(0);
                        }
                        break;
                    case "Banana":
                        if (list[3].Count == 0)
                        {
                            Console.WriteLine("缺货");
                        }
                        else
                        {
                            pros[i] = list[3][0];
                            list[3].RemoveAt(0);
                        }
                        break;
                }
            }
            return pros;
        }

    }

 

.Net学习笔记----2015-06-30(超市收银系统01-仓库类)

标签:

原文地址:http://www.cnblogs.com/mikie/p/4610804.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!