C#面向?qū)ο笾M實現(xiàn)商城購物功能
更新時間:2022年02月10日 08:03:31 作者:第五楓詠
這篇文章主要為大家詳細介紹了C#面向?qū)ο笾M實現(xiàn)商城購物功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了C#實現(xiàn)商城購物功能的具體代碼,供大家參考,具體內(nèi)容如下
商品類
namespace ShoppingSystem { ? ? /* ? ? ?* 商品信息包括:商品名稱、商品價格、商品型號、商品描述等 ? ? ?*/ ? ? /// <summary> ? ? /// 商品類 ? ? /// </summary> ? ? class Goods ? ? { ? ? ? ? /// <summary> ? ? ? ? /// 商品名稱 ? ? ? ? /// </summary> ? ? ? ? private string goodName; ? ? ? ? /// <summary> ? ? ? ? /// 商品價格 ? ? ? ? /// </summary> ? ? ? ? private float goodPrice; ? ? ? ? /// <summary> ? ? ? ? /// 商品型號 ? ? ? ? /// </summary> ? ? ? ? private string[] goodModel = new string[2]; ? ? ? ? /// <summary> ? ? ? ? /// 商品類別 ? ? ? ? /// </summary> ? ? ? ? private string goodType; ? ? ? ? /// <summary> ? ? ? ? /// 商品描述 ? ? ? ? /// </summary> ? ? ? ? private string goodDescribe; ? ? ? ? /// <summary> ? ? ? ? /// 賣家 ? ? ? ? /// </summary> ? ? ? ? private Seller seller; ? ? ? ? public Seller Seller ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return seller; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? seller = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? public string GoodName ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return goodName; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? goodName = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? public float GoodPrice ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return goodPrice; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? goodPrice = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? public string[] GoodModel ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return goodModel; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? goodModel = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? public string GoodType ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return goodType; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? goodType = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? public string GoodDescribe ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return goodDescribe; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? goodDescribe = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? /// <summary> ? ? ? ? /// 構(gòu)造函數(shù),對各個變量賦值并添加商品描述 ? ? ? ? /// </summary> ? ? ? ? /// <param name="goodName">商品名</param> ? ? ? ? /// <param name="goodPrice">商品價格</param> ? ? ? ? /// <param name="goodId">商品編號</param> ? ? ? ? /// <param name="goodModel">商品型號</param> ? ? ? ? /// <param name="goodType">商品類別</param> ? ? ? ? public Goods(string goodName, float goodPrice, string[] goodModel, string goodType) ? ? ? ? { ? ? ? ? ? ? this.goodName = goodName; ? ? ? ? ? ? this.goodPrice = goodPrice; ? ? ? ? ? ? this.goodModel = goodModel; ? ? ? ? ? ? this.goodType = goodType; ? ? ? ? ? ? goodDescribe = goodName + goodModel[0] + "|" + goodModel[1] + "|" + goodPrice + "|"; ? ? ? ? } ? ? } }
商品總庫
namespace ShoppingSystem { ? ? class GoodsSql ? ? { ? ? ? ? /// <summary> ? ? ? ? /// 商品總庫 ? ? ? ? /// </summary> ? ? ? ? private Goods[] good = new Goods[20]; ? ? ? ? public Goods[] Good ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return good; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? good = value; ? ? ? ? ? ? } ? ? ? ? } ? ? } }
用戶類
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ShoppingSystem { ? ? /// <summary> ? ? /// 用戶類 ? ? /// </summary> ? ? class User ? ? { ? ? ? ? /// <summary> ? ? ? ? /// 用戶名 ? ? ? ? /// </summary> ? ? ? ? private string username; ? ? ? ? /// <summary> ? ? ? ? /// 用戶余額 ? ? ? ? /// </summary> ? ? ? ? private float userBalance; ? ? ? ? /// <summary> ? ? ? ? /// 購物車 ? ? ? ? /// </summary> ? ? ? ? private ShoppingCart cart = new ShoppingCart(); ? ? ? ? public User(string username, float userBalance) ? ? ? ? { ? ? ? ? ? ? this.username = username; ? ? ? ? ? ? this.userBalance = userBalance; ? ? ? ? ? ? cart.User = this; ? ? ? ? } ? ? ? ? public string Username ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return username; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? username = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? public float UserBalance ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return userBalance; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? userBalance = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? public ShoppingCart Cart ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return cart; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? cart = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? /// <summary> ? ? ? ? /// 加入購物車 ? ? ? ? /// </summary> ? ? ? ? /// <param name="good">要加入的商品</param> ? ? ? ? /// <param name="goodsNum">要買的數(shù)量</param> ? ? ? ? public void BuyGoods(Goods good, int goodsNum) ? ? ? ? { ? ? ? ? ? ?? ? ? ? ? ? ? cart.AddGoods(good, goodsNum); ? ? ? ? ? ? //TODO ? ? ? ? } ? ? ? ? /// <summary> ? ? ? ? /// 結(jié)算并清空購物車 ? ? ? ? /// </summary> ? ? ? ? public void CheckoutCart() ? ? ? ? { ? ? ? ? ? ? cart.CheckoutCart(); ? ? ? ? } ? ? } }
賣家類
using System; namespace ShoppingSystem { ? ? /// <summary> ? ? /// 賣家類 ? ? /// </summary> ? ? class Seller ? ? { ? ? ? ? /// <summary> ? ? ? ? /// 賣家姓名 ? ? ? ? /// </summary> ? ? ? ? private string sellerName; ? ? ? ? /// <summary> ? ? ? ? /// 賣家余額 ? ? ? ? /// </summary> ? ? ? ? private float sellerBalance; ? ? ? ? /// <summary> ? ? ? ? /// 賣家商品數(shù)組 ? ? ? ? /// </summary> ? ? ? ? private Goods[] sellerGoods = new Goods[5];? ? ? ? ? public Seller(string sellerName, float sellerBalance) ? ? ? ? { ? ? ? ? ? ? this.sellerName = sellerName; ? ? ? ? ? ? this.sellerBalance = sellerBalance; ? ? ? ? } ? ? ? ? public string SellerName ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return sellerName; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? sellerName = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? public float SellerBalance ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return sellerBalance; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? sellerBalance = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? public Goods[] SellerGoods ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return sellerGoods; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? sellerGoods = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? /// <summary> ? ? ? ? /// 上架新商品 ? ? ? ? /// </summary> ? ? ? ? /// <param name="good"></param> ? ? ? ? public void AddGood(Goods good,GoodsSql goods) ? ? ? ? { ? ? ? ? ? ? for (int i = 0; i < sellerGoods.Length; i++) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? if (sellerGoods[i] == null) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? sellerGoods[i] = good; ? ? ? ? ? ? ? ? ? ? good.Seller = this; ? ? ? ? ? ? ? ? ? ? for (int j = 0; j < goods.Good.Length; j++) ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? if (goods.Good[j] == null) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? goods.Good[j] = good; ? ? ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? Console.WriteLine("添加商品成功!"); ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? if (i == sellerGoods.Length - 1) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? Console.WriteLine("添加商品失敗!已達到可上架商品的上限!"); ? ? ? ? ? ? ? ? ? ? return; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? /// <summary> ? ? ? ? /// 更新商品信息 ? ? ? ? /// </summary> ? ? ? ? /// <param name="good">要更新的商品</param> ? ? ? ? /// <param name="goodName">商品名稱</param> ? ? ? ? /// <param name="goodPrice">商品價格</param> ? ? ? ? /// <param name="goodId">商品編號</param> ? ? ? ? /// <param name="goodModel">商品型號</param> ? ? ? ? /// <param name="goodType">商品種類</param> ? ? ? ? public void UpdateGoodInfo(Goods good, string goodName, float goodPrice, string[] goodModel, string goodType) ? ? ? ? { ? ? ? ? ? ? if (good != null) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? good.GoodName = goodName; ? ? ? ? ? ? ? ? good.GoodModel = goodModel; ? ? ? ? ? ? ? ? good.GoodType = goodType; ? ? ? ? ? ? ? ? good.GoodDescribe = goodName + goodModel[0] + "|" + goodModel[1] + "|" + goodPrice + "|"; ? ? ? ? ? ? ? ? Console.WriteLine("更新商品信息成功!"); ? ? ? ? ? ? ? ? return; ? ? ? ? ? ? } ? ? ? ? ? ? Console.WriteLine("更新商品信息失??!"); ? ? ? ? } ? ? } }
服務類
namespace ShoppingSystem { ? ? class Service ? ? { ? ? ? ? private Goods[] goods = new Goods[20]; ? ? ? ? public Goods[] Goods ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return goods; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? goods = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? /// <summary> ? ? ? ? /// 按類型搜索商品 ? ? ? ? /// </summary> ? ? ? ? /// <param name="goodType"></param> ? ? ? ? /// <param name="goods"></param> ? ? ? ? public void Search(string goodType, GoodsSql goods) ? ? ? ? { ? ? ? ? ? ? this.goods = new Goods[20]; ? ? ? ? ? ? int count = 0; ? ? ? ? ? ? for (int i = 0; i < goods.Good.Length; i++) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? if (goods.Good[i] != null && goods.Good[i].GoodType.Equals(goodType)) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? this.goods[count++] = goods.Good[i]; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? } }
購物車類
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ShoppingSystem { ? ? /// <summary> ? ? /// 購物車類 ? ? /// </summary> ? ? class ShoppingCart ? ? { ? ? ? ? /// <summary> ? ? ? ? /// 購物條目數(shù)組 ? ? ? ? /// </summary> ? ? ? ? private ShoppingItems[] items; ? ? ? ? /// <summary> ? ? ? ? /// 購物費用總計 ? ? ? ? /// </summary> ? ? ? ? private float totalPrice = 0.00f; ? ? ? ? /// <summary> ? ? ? ? /// 購物車所屬用戶 ? ? ? ? /// </summary> ? ? ? ? private User user; ? ? ? ? public ShoppingItems[] Items ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return items; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? items = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? public float TotalPrice ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return totalPrice; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? totalPrice = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? public User User ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return user; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? user = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? /// <summary> ? ? ? ? /// 添加商品到購物車 ? ? ? ? /// </summary> ? ? ? ? /// <param name="good">要加入的商品</param> ? ? ? ? /// <param name="goodsNum">要買的數(shù)量</param> ? ? ? ? public void AddGoods(Goods good, int goodsNum) ? ? ? ? { ? ? ? ? ? ? //若購物車條目為空,實例化購物車條目數(shù)組 ? ? ? ? ? ? if (items == null) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? items = new ShoppingItems[10]; ? ? ? ? ? ? } ? ? ? ? ? ? //加入商品條目到購物條目數(shù)組 ? ? ? ? ? ? for (int i = 0; i < items.Length; i++) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? if (items[i] == null) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? items[i] = new ShoppingItems(); ? ? ? ? ? ? ? ? ? ? items[i].Good = good; ? ? ? ? ? ? ? ? ? ? items[i].GoodsNum = goodsNum; ? ? ? ? ? ? ? ? ? ? totalPrice += good.GoodPrice * goodsNum; ? ? ? ? ? ? ? ? ? ? Console.WriteLine($"已將{good.GoodDescribe}數(shù)量:{goodsNum},加入購物車"); ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? if (i == items.Length - 1) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? Console.WriteLine("購物車已滿!"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? ? ?? ? ? ? ? /// <summary> ? ? ? ? /// 結(jié)算并清空購物車 ? ? ? ? /// </summary> ? ? ? ? public void CheckoutCart() ? ? ? ? { ? ? ? ? ? ? //判斷購物車是否為空 ? ? ? ? ? ? if (items == null) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? Console.WriteLine("您的購物車中沒有商品!"); ? ? ? ? ? ? ? ? return; ? ? ? ? ? ? } ? ? ? ? ? ? foreach (var item in items) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? if (item != null) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? item.Good.Seller.SellerBalance += item.Good.GoodPrice * item.GoodsNum; ? ? ? ? ? ? ? ? ? ? Console.WriteLine($"商品名稱:{item.Good.GoodName}"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? ? ? Console.WriteLine($"{user.Username}已經(jīng)清空了購物車,共計花費{totalPrice}元"); ? ? ? ? ? ? user.UserBalance -= totalPrice; ? ? ? ? ? ? items = null; ? ? ? ? ? ? //TODO ? ? ? ? } ? ? ? ? public void selectCart() ? ? ? ? { ? ? ? ? ? ? if (items == null) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? Console.WriteLine("您的購物車是空的!"); ? ? ? ? ? ? ? ? return; ? ? ? ? ? ? } ? ? ? ? ? ? foreach (var item in items) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? Console.WriteLine($"{item.Good.GoodDescribe}數(shù)量:{item.GoodsNum}"); ? ? ? ? ? ? } ? ? ? ? } ? ? } }
購物車條目類
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ShoppingSystem { ? ? /// <summary> ? ? /// 購物車中的商品條目類 ? ? /// </summary> ? ? class ShoppingItems ? ? { ? ? ? ? /// <summary> ? ? ? ? /// 商品 ? ? ? ? /// </summary> ? ? ? ? private Goods good; ? ? ? ? /// <summary> ? ? ? ? /// 要買的數(shù)量 ? ? ? ? /// </summary> ? ? ? ? private int goodsNum; ? ? ? ? public Goods Good ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return good; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? good = value; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? public int GoodsNum ? ? ? ? { ? ? ? ? ? ? get ? ? ? ? ? ? { ? ? ? ? ? ? ? ? return goodsNum; ? ? ? ? ? ? } ? ? ? ? ? ? set ? ? ? ? ? ? { ? ? ? ? ? ? ? ? goodsNum = value; ? ? ? ? ? ? } ? ? ? ? } ? ? } }
服務臺
這里其實應該封裝不少東西,我偷懶了,不搞了
using System; namespace ShoppingSystem { ? ? /// <summary> ? ? /// 軟件使用類 ? ? /// </summary> ? ? class SoftwareUsage ? ? { ? ? ? ? /// <summary> ? ? ? ? /// 獲取用戶指令 ? ? ? ? /// </summary> ? ? ? ? /// <returns></returns> ? ? ? ? public string Order() ? ? ? ? { ? ? ? ? ? ? Console.WriteLine("請先輸入指令:"); ? ? ? ? ? ? Console.WriteLine("0-退出,1-搜索,2-購買,3-清空并結(jié)算購物車,4-查詢購物車"); ? ? ? ? ? ? return Console.ReadLine(); ? ? ? ? } ? ? } }
程序入口main函數(shù):
using System; namespace ShoppingSystem { ? ? class Program ? ? { ? ? ? ? static void Main(string[] args) ? ? ? ? { ? ? ? ? ? ? GoodsSql goodsSql = new GoodsSql(); ? ? ? ? ? ? Service service = new Service(); ? ? ? ? ? ? User user = new User("岳翔", 10000000.00f); ? ? ? ? ? ? SoftwareUsage use = new SoftwareUsage(); ? ? ? ? ? ? Seller seller01 = new Seller("賣家1", 10000.00f); ? ? ? ? ? ? Seller seller02 = new Seller("賣家2", 10000.00f); ? ? ? ? ? ? Seller seller03 = new Seller("賣家3", 10000.00f); ? ? ? ? ? ? Goods good01 = new Goods("編程之美(圖書)", 120.00f, new string[]{ "質(zhì)量", "普通版" }, "圖書"); ? ? ? ? ? ? Goods good02 = new Goods("編程之美(圖書)", 145.00f, new string[]{ "質(zhì)量", "精裝版" }, "圖書"); ? ? ? ? ? ? Goods good03 = new Goods("三毛流浪記(圖書)", 20.00f, new string[]{ "質(zhì)量", "普通版" }, "圖書"); ? ? ? ? ? ? Goods good04 = new Goods("三毛流浪記(圖書)", 25.00f, new string[]{ "質(zhì)量", "精裝版" }, "圖書"); ? ? ? ? ? ? Goods good05 = new Goods("iPhone 100(手機)", 6000.00f, new string[]{ "RAM", "64GB" }, "手機"); ? ? ? ? ? ? Goods good06 = new Goods("iPhone 100(手機)", 7000.00f, new string[]{ "RAM", "128GB" }, "手機"); ? ? ? ? ? ? Goods good07 = new Goods("iPhone 100(手機)", 9000.00f, new string[]{ "RAM", "512GB" }, "手機"); ? ? ? ? ? ? Goods good08 = new Goods("Nokia(手機)", 1000.00f, new string[]{ "型號", "E63" }, "手機"); ? ? ? ? ? ? Goods good09 = new Goods("Nokia(手機)", 2000.00f, new string[]{ "型號", "N95" }, "手機"); ? ? ? ? ? ? Goods good10 = new Goods("Nokia(手機)", 2300.00f, new string[]{ "型號", "N97" }, "手機"); ? ? ? ? ? ? Goods good11 = new Goods("Mac Book Pro(電腦)", 18000.00f, new string[]{ "配置", "低配版" }, "電腦"); ? ? ? ? ? ? Goods good12 = new Goods("Mac Book Pro(電腦)", 20000.00f, new string[]{ "配置", "中配版" }, "電腦"); ? ? ? ? ? ? Goods good13 = new Goods("Mac Book Pro(電腦)", 22000.00f, new string[]{ "配置", "?配版" }, "電腦"); ? ? ? ? ? ? seller01.AddGood(good01, goodsSql); ? ? ? ? ? ? seller01.AddGood(good02, goodsSql); ? ? ? ? ? ? seller01.AddGood(good03, goodsSql); ? ? ? ? ? ? seller01.AddGood(good04, goodsSql); ? ? ? ? ? ? seller01.AddGood(good05, goodsSql); ? ? ? ? ? ? seller02.AddGood(good06, goodsSql); ? ? ? ? ? ? seller02.AddGood(good07, goodsSql); ? ? ? ? ? ? seller02.AddGood(good08, goodsSql); ? ? ? ? ? ? seller02.AddGood(good09, goodsSql); ? ? ? ? ? ? seller02.AddGood(good10, goodsSql); ? ? ? ? ? ? seller03.AddGood(good11, goodsSql); ? ? ? ? ? ? seller03.AddGood(good12, goodsSql); ? ? ? ? ? ? seller03.AddGood(good13, goodsSql); ? ? ? ? ? ? Console.Clear(); ? ? ? ? ? ? while (true) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? string order = use.Order(); ? ? ? ? ? ? ? ? switch (order) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? case "0": ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine("購物結(jié)束!"); ? ? ? ? ? ? ? ? ? ? ? ? return; ? ? ? ? ? ? ? ? ? ? case "1": ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine("請輸入搜索關鍵詞:"); ? ? ? ? ? ? ? ? ? ? ? ? string goodType = Console.ReadLine(); ? ? ? ? ? ? ? ? ? ? ? ? service.Search(goodType, goodsSql); ? ? ? ? ? ? ? ? ? ? ? ? Goods[] goods = service.Goods; ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine($"當前買家{user.Username}正在搜索商品:{goodType}"); ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine("-----------------------"); ? ? ? ? ? ? ? ? ? ? ? ? foreach (var item in goods) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (item != null) ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine($"商品名:{item.GoodName},商品類型({item.GoodModel[0]})" + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $"{item.GoodModel[1]},{item.GoodPrice}元"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine("-----------------------"); ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? case "2": ? ? ? ? ? ? ? ? ? ? ? ? if (service.Goods[0] == null) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine("請先搜索選購!"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine("請先輸入商品編號:"); ? ? ? ? ? ? ? ? ? ? ? ? int goodId = Int32.Parse(Console.ReadLine()); ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine("請先輸入商品數(shù)量:"); ? ? ? ? ? ? ? ? ? ? ? ? int goodsNum = Int32.Parse(Console.ReadLine()); ? ? ? ? ? ? ? ? ? ? ? ? user.BuyGoods(service.Goods[goodId - 1], goodsNum); ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine("-----------------------"); ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? case "3": ? ? ? ? ? ? ? ? ? ? ? ? user.CheckoutCart(); ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine($"賬戶余額:{user.UserBalance}"); ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? case "4": ? ? ? ? ? ? ? ? ? ? ? ? user.Cart.selectCart(); ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? default: ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine("您輸入的指令不正確!"); ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? } }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
c#創(chuàng)建windows服務(Windows Services)詳細步驟
這篇文章主要介紹了c#創(chuàng)建windows服務(Windows Services)詳細步驟,大家參考使用吧2013-12-12C#實現(xiàn)根據(jù)數(shù)字序號輸出星期幾的簡單實例
這篇文章主要介紹了C#實現(xiàn)根據(jù)數(shù)字序號輸出星期幾的簡單實例,代碼簡潔實用,也有助于初學者更好的理解C#的switch和if語句的流程控制,需要的朋友可以參考下2014-07-07c# SQLHelper(for winForm)實現(xiàn)代碼
數(shù)據(jù)連接池c# SQLHelper 實現(xiàn)代碼2009-02-02C# InitializeComponent()方法案例詳解
這篇文章主要介紹了C# InitializeComponent()方法案例詳解,本篇文章通過簡要的案例,講解了該項技術的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-08-08