.Net学习笔记----2015-06-30(超市收银系统01-仓库类)
生活随笔
收集整理的這篇文章主要介紹了
.Net学习笔记----2015-06-30(超市收银系统01-仓库类)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
GUID:
產(chǎn)生一個(gè)不會(huì)重復(fù)的ID
static void Main(string[] args){//產(chǎn)生一個(gè)不會(huì)重復(fù)的編號 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();}?
分析:
?
父類:全用的是自動(dòng)屬性
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>();//存儲(chǔ)貨物//list接收的是List<>,相當(dāng)于貨架List<List<ProductFather>> list = new List<List<ProductFather>>();/// <summary>/// 向用戶展示貨物/// </summary>public void ShowPros(){foreach (var item in list){Console.WriteLine("倉庫現(xiàn)有:" + item[0].Name + "," + "\t" + item.Count + "個(gè)," + "\t" + "每個(gè)" + item[0].Price + "元。");}}//list[0]存儲(chǔ)Acer電腦 list[1]存儲(chǔ)三星手機(jī) list[2]存儲(chǔ)醬油 list[3]存儲(chǔ)香蕉/// <summary>/// 在創(chuàng)建倉庫對象的時(shí)候,向倉庫中添加貨架/// </summary>public CangKu(){list.Add(new List<ProductFather>());list.Add(new List<ProductFather>());list.Add(new List<ProductFather>());list.Add(new List<ProductFather>());}/// <summary>/// 進(jìn)貨/// </summary>/// <param name="strType">貨物的類型</param>/// <param name="count">貨物的數(shù)量</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,"三星手機(jī)"));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">數(shù)量</param>public ProductFather[] QuPros(string strType, int count){ProductFather[] pros = new ProductFather[count];for (int i = 0; i < count; i++){switch (strType){case "Acer"://判斷如果貨物數(shù)量為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;}}?
轉(zhuǎn)載于:https://www.cnblogs.com/mikie/p/4610804.html
總結(jié)
以上是生活随笔為你收集整理的.Net学习笔记----2015-06-30(超市收银系统01-仓库类)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: KL距离(相对熵)
- 下一篇: idea常用快捷键以及自定义快捷键