public void BaseBuyTest() { TradeParticipant customer = new TradeParticipant("customer"); Coin coin = new Coin(10); Coin coin1 = new Coin(10); Coin coin2 = new Coin(10); Coin coin3 = new Coin(5); Coin coin4 = new Coin(3); Coin coin5 = new Coin(2); Coin coin6 = new Coin(1); customer.Wallet.AddItems(new List<Coin>{coin,coin1,coin2,coin3,coin4,coin5,coin6}); TradeParticipant vmachine = new TradeParticipant("vmachine"); GoodsItem item = new GoodsItem(10, "coffee"); GoodsItem item1 = new GoodsItem(10, "coffee"); GoodsItem item2= new GoodsItem(10, "coffee"); GoodsItem item3 = new GoodsItem(10, "coffee"); GoodsItem item4 = new GoodsItem(7, "green tea"); GoodsItem item5 = new GoodsItem(3, "tea"); GoodsItem item6 = new GoodsItem(3, "tea"); GoodsItem item7 = new GoodsItem(1, "napkin"); GoodsItem item8 = new GoodsItem(1, "napkin"); vmachine.GoodsStorage.AddItems(new List<GoodsItem> { item, item1, item2, item3, item4, item5, item6, item7, item8, item }); Coin coin0 = new Coin(10); Coin coin01 = new Coin(10); Coin coin02 = new Coin(10); Coin coin03 = new Coin(5); Coin coin04 = new Coin(3); Coin coin05 = new Coin(2); Coin coin06 = new Coin(1); vmachine.Wallet.AddItems(new List<Coin> { coin0, coin01, coin02, coin03, coin04, coin05, coin06 }); var cmoney_amount = customer.Wallet.MoneyAmount; var cgoods_amount = customer.GoodsStorage.GoodsCount; var vmoney_amount = vmachine.Wallet.MoneyAmount; var vgoods_count = vmachine.GoodsStorage.GoodsCount; customer.Buy(vmachine, item4, new List<Coin>() { coin3,coin4 }); //8-1 coin06 in Assert.AreEqual(cmoney_amount - 7, customer.Wallet.MoneyAmount, "customer wallet"); Assert.AreEqual(vgoods_count - 1, vmachine.GoodsStorage.GoodsCount, "vm goods storage"); Assert.AreEqual(vmoney_amount + 7, vmachine.Wallet.MoneyAmount, "vm wallet"); customer.Buy(vmachine, item5, new List<Coin>() { coin5,coin6 });// 0 customer.Buy(vmachine, item1, new List<Coin>() { coin1 });// customer.Sell(vmachine, item4, new List<Coin>() { coin05,coin03 });// Assert.AreEqual(cmoney_amount-7-3-10+7, customer.Wallet.MoneyAmount, "customer wallet"); Assert.AreEqual(2, customer.GoodsStorage.GoodsCount, "customer goods storage"); }
public GoodsTransitionState FromGoods(GoodsItem item) { switch (item.Status) { case GoodsItemStatus.Registered: return(new RegisteredTransitionState(item, Instance)); case GoodsItemStatus.Arrived: return(new ArrivedTransitionState(item, Instance)); case GoodsItemStatus.Accepted: return(new AcceptedTransitionState(item, Instance)); case GoodsItemStatus.Storing: return(new StoringTransitionState(item, Instance)); case GoodsItemStatus.WaitingForUnloading: return(new WaitingForUnloadTransitionState(item, Instance)); case GoodsItemStatus.Unloaded: return(new UnloadedTransitionState(item, Instance)); case GoodsItemStatus.Rejected: return(new RejectedTransitionState(item, Instance)); case GoodsItemStatus.Removed: return(new RemovedTransitionState(item, Instance)); default: throw new ArgumentException("Incorrect status"); } }
void OnItemRefresh(int index, ListViewItem item) { // Debug.Log("OnItemRefresh:"+index); GoodsItem goodsItem = item as GoodsItem; goodsItem.Init(currentList[index]); }
public void UpdateEquip(GoodsItem gi) { int i = Convert.ToInt32(gi.IsDressed); //using System; db.UpdateInto("T_Backpack", new string[] { "Dressed" }, new string[] { i.ToString() }, "ID", gi.Goods.ID.ToString()); }
//角色装备按钮点击事件 public void ShowGoodsItem(UISceneWidget eventObj, GoodsItem gi, bool isLeft) { if (gi.Goods.GoodsType == GoodsType.Equip) { UIGoodsItem uigi = null; BackpackRoleEquip roleEquip = null; if (isLeft) { uigi = eventObj.GetComponent <UIGoodsItem>(); } else { roleEquip = eventObj.GetComponent <BackpackRoleEquip>(); } UIGoods.Instance.Close(); //关闭道具界面 UIEquip.Instance.Show(gi, isLeft, uigi, roleEquip); //显示装备界面 } else /*if(gi.Goods.GoodsType == GoodsType.Drug)*/ { UIGoodsItem uigi = eventObj.GetComponent <UIGoodsItem>(); UIEquip.Instance.Close(); //关闭装备界面 UIGoods.Instance.Show(gi, uigi); //显示道具界面 } //如果是装备类型,且为背包装备,或者不为装备类型,可以出售物品 if ((gi.Goods.GoodsType == GoodsType.Equip && isLeft) || gi.Goods.GoodsType != GoodsType.Equip) { this.uigi = eventObj.GetComponent <UIGoodsItem>(); EnableButton(); //出售价格 = 物品单价 × 物品数量 mLabel_Price.text = (this.uigi.goodsItem.Goods.Price * this.uigi.goodsItem.Count).ToString(); } }
public void UpdatePower(GoodsItem goodsItem) { // int startVal = CharacterTemplate.Instance.GetPower(); if (isLeft) //如果是在左边,即为装备页面 { // uiGoodsItem.Clear(); //清空该装备格子 OperatingDB.Instance.CreateDataBase(); //打开数据库 CharacterTemplate.Instance.Puton(goodsItem); //穿上装备 OperatingDB.Instance.db.CloseSqlConnection(); OperatingDB.Instance.UpdateEquipStatus(goodsItem); //更新数据库背包穿着状态 } else //从身上脱下 { roleEquip.Clear(); //把身上的装备清空 OperatingDB.Instance.CreateDataBase(); //打开数据库 CharacterTemplate.Instance.Unload(goodsItem); //卸下装备 OperatingDB.Instance.db.CloseSqlConnection(); OperatingDB.Instance.UpdateEquipStatus(goodsItem); //更新数据库背包穿着状态 } // OperatingDB.Instance.UpdateEquipStatus(goodsItem); //更新数据库背包穿着状态 int endVal = CharacterTemplate.Instance.GetPower(); // uiPower.ShowPowerChange(startVal, endVal); //更新战斗力 UIBackpack.Instance.mLabel_Power.text = endVal.ToString(); UIBackpack.Instance.UpdateCount(); //更新背包数量 }
void OnGoodsItemValueChange(ListViewItem item, bool isOn) { GoodsItem goodsItem = item as GoodsItem; m_cost += goodsItem.goodsData.goodsPrice * (isOn ? 1 : -1); UpdateCost(m_cost); }
public void VendingReturnChangeTest() { Customer customer = new Customer("customer"); Coin coin = new Coin(10); Coin coin1 = new Coin(10); customer.Wallet.AddItem(coin); customer.Wallet.AddItem(coin1); VendingMachine vmachine = new VendingMachine("vmachine"); GoodsItem item = new GoodsItem(15, "green tea"); vmachine.GoodsStorage.AddItem(item); Coin coin0 = new Coin(5); Coin coin01 = new Coin(3); Coin coin02 = new Coin(2); vmachine.Wallet.AddItem(coin0); vmachine.Wallet.AddItem(coin01); vmachine.Wallet.AddItem(coin02); customer.InsertCoin(coin, vmachine); customer.InsertCoin(coin1, vmachine); vmachine.SellTheItem(item, customer); Assert.AreEqual(5, customer.Wallet.MoneyAmount, "customer wallet"); Assert.AreEqual(1, customer.GoodsStorage.GoodsCount, "customer goods storage"); Assert.AreEqual(1, customer.Wallet.GetItems(a => a == coin0, -1).Count, "customer wallet"); Assert.AreEqual(25, vmachine.Wallet.MoneyAmount, "vm wallet"); Assert.AreEqual(0, vmachine.GoodsStorage.GoodsCount, "vm goods storage"); }
/// <summary> /// продажа товара /// </summary> /// <param name="sellItem"></param> /// <param name="customer"></param> /// <returns></returns> public virtual bool SellTheItem(GoodsItem sellItem, Customer customer) { if (ChechGoodsIsEnough(sellItem)) { if (CheckIfEnoughMoney(sellItem,DBalance)) { if (DoesHaveEnoughChange(sellItem, DBalance)) { return _SellTheItem(sellItem, customer); } else { CancelOrder(customer); DoesNotHaveEnoughChange(); return false; } } else { //CancelOrder(customer); DoesNotHaveEnoughMoney(); return false; } } else { CancelOrder(customer); DoesNotHaveEnoughGoods(); return false; } }
private void vending_ctrl_BuyClicked(object sender, RoutedEventArgs e) { GoodsItem sellitem = vmachine.GoodsStorage.GetItem(a => a.Ttype == (int)sender); vmachine.SellTheItem(sellitem, customer); Refresh(); }
/// <summary> /// Сохраняет в базе модель создания элемента. /// </summary> /// <param name="token">Токен безопасности.</param> /// <param name="model">Модель создания сущности для сохранения.</param> /// <param name="result">Результат выполнения..</param> public override GoodsItemGridItemModel SaveCreateModel(SecurityToken token, GoodsItemCreateModel model, JGridSaveModelResult result) { var entity = new GoodsItem { Description = model.Description, DimensionKindID = model.DimensionKindID, GoodsItemID = model.Id, ItemCategoryID = model.ItemCategoryID, Particular = model.Particular, Title = model.Title, UserCode = model.UserCode, }; RemontinkaServer.Instance.EntitiesFacade.SaveGoodsItem(token, entity); var item = RemontinkaServer.Instance.EntitiesFacade.GetGoodsItem(token, entity.GoodsItemID); return(new GoodsItemGridItemModel { Id = item.GoodsItemID, Title = item.Title, Description = item.Description ?? string.Empty, ItemCategoryTitle = item.ItemCategoryTitle, Particular = item.Particular ?? string.Empty, UserCode = item.UserCode ?? string.Empty }); }
public static GameLevel_VictoryProto GetProto(byte[] buffer) { GameLevel_VictoryProto proto = new GameLevel_VictoryProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.GameLevelId = ms.ReadInt(); proto.Grade = (byte)ms.ReadByte(); proto.Star = (byte)ms.ReadByte(); proto.Exp = ms.ReadInt(); proto.Gold = ms.ReadInt(); proto.KillTotalMonsterCount = ms.ReadInt(); proto.KillMonsterList = new List <MonsterItem>(); for (int i = 0; i < proto.KillTotalMonsterCount; i++) { MonsterItem _KillMonster = new MonsterItem(); _KillMonster.MonsterId = ms.ReadInt(); _KillMonster.MonsterCount = ms.ReadInt(); proto.KillMonsterList.Add(_KillMonster); } proto.GoodsTotalCount = ms.ReadInt(); proto.GetGoodsList = new List <GoodsItem>(); for (int i = 0; i < proto.GoodsTotalCount; i++) { GoodsItem _GetGoods = new GoodsItem(); _GetGoods.GoodsType = (byte)ms.ReadByte(); _GetGoods.GoodsId = ms.ReadInt(); _GetGoods.GoodsCount = ms.ReadInt(); proto.GetGoodsList.Add(_GetGoods); } } return(proto); }
public void ShowGoods(GoodsItem data) { string name = Path.GetFileName(data.image); string url = Application.streamingAssetsPath + "/GoodsData/" + name; GoodsPic.texture = t; GoodsName.text = "名称:" + data.productName; GoodsPrice.text = "¥:" + data.price.ToString(); if (LastSelected != data) { LastSelected = data; } //if (File.Exists(url)) //{ // t = Util.LoadByIO(url); // if (LastSelected != data) // { // LastSelected = data; // GoodsPic.texture = t; // GoodsName.text = "名称:" + data.productName; // GoodsPrice.text = "¥:" + data.price.ToString(); // } //} //获取当前商品的游戏列表 //GameManager.GetGoods_GameList(GameManager.Token, data.productId); }
public StateChangeCommand FromTransitionType(GoodsItem item, GoodsItemStatus status, string reasoning = "", int areaId = 0) { var log = new TransitionLog(_repository, item); switch (status) { case GoodsItemStatus.Arrived: return(new ArriveCommand(item, log)); case GoodsItemStatus.Accepted: return(new AcceptCommand(item, log)); case GoodsItemStatus.Storing: return(new StoreCommand(item, log, areaId)); case GoodsItemStatus.WaitingForUnloading: return(new WaitingForUnloadCommand(item, log)); case GoodsItemStatus.Unloaded: return(new UnloadCommand(item, log)); case GoodsItemStatus.Removed: return(new RemoveCommand(item, log)); case GoodsItemStatus.Rejected: return(new RejectCommand(item, log, reasoning)); default: throw new ArgumentException("Incorrect target state"); } }
public void Show(GoodsItem gi, bool isLeft, UIGoodsItem uigi, BackpackRoleEquip roleEquip) { // gameObject.SetActive(true); SetVisible(true); goodsItem = gi; uiGoodsItem = uigi; this.roleEquip = roleEquip; Vector3 pos = transform.localPosition; //自身坐标 this.isLeft = isLeft; if (isLeft) //如果在左边显示 { transform.localPosition = new Vector3(-Mathf.Abs(pos.x), pos.y, pos.z); //Mathf.Abs取绝对值 mLabel_Equip.text = "装备"; } else { transform.localPosition = new Vector3(Mathf.Abs(pos.x), pos.y, pos.z); mLabel_Equip.text = "脱下"; } mSprite_Equip.spriteName = gi.Goods.ICON; mLabel_Name.text = gi.Goods.Name; mLabel_Quality.text = gi.Goods.Quality.ToString(); mLabel_Damage.text = gi.Goods.Damage.ToString(); mLabel_Hp.text = gi.Goods.HP.ToString(); mLabel_Des.text = gi.Goods.Des; mLabel_Lv.text = gi.Level.ToString(); }
public async Task <GoodsResponse> AddGoods([FromBody] GoodsItem body) { GoodsResponse response = new GoodsResponse(); if (body.GoodsId == "") { response.ReplyMsg = "商品编码不能为空"; return(response); } else if (gr.CheckGoodsById(body.GoodsId) > 1) { response.ReplyMsg = "该商品已存在"; return(response); } else if (body.GoodsName == "") { response.ReplyMsg = "商品名称不能为空"; return(response); } else if (body.GoodsPrice == 0) { response.ReplyMsg = "商品价格不能为0"; return(response); } else if (body.GoodsNum == 0) { response.ReplyMsg = "商品库存不能为空"; return(response); } else { /* var file = HttpContext.Request.Form.Files[0]; * Stream stream = file.OpenReadStream(); * string fileName = DateTime.Now.Ticks.ToString() + file.FileName; * var ImagePath = gr.StreamToFile(stream, fileName); * string gname = g.GoodsName; */ Goods goods = new Goods { GoodsId = body.GoodsId, GoodsName = body.GoodsName, GoodsPrice = body.GoodsPrice, GoodsKind = body.GoodsKind, GoodsNum = body.GoodsNum, CreateDateTime = DateTime.Now }; var count = await gr.AddGoods(goods); if (count > 0) { response.ReplyMsg = "商品上架成功"; } else { response.ReplyMsg = "商品上架失败"; } return(response); } }
public void AddGoods(GoodsData data) { GoodsItem item = Object.Instantiate(goodsItemPrefab).GetComponent <GoodsItem>(); goodsList.AddItem(item); item.SetData(data); item.AddValueChangedHandle(OnGoodsItemValueChange); }
public async Task <GoodsResponse> AddGoods([FromBody] GoodsItem body) { GoodsResponse response = new GoodsResponse(); if (body.GoodsId == "") { response.ReplyMsg = "商品编码不能为空"; return(response); } if (gr.CheckGoodsById(body.GoodsId) > 0) { response.ReplyMsg = "该商品已存在"; return(response); } else if (body.GoodsName == "") { response.ReplyMsg = "商品名称不能为空"; return(response); } else if (body.GoodsPrice == 0) { response.ReplyMsg = "商品价格不能为0"; return(response); } else if (body.GoodsKind == "") { response.ReplyMsg = "商品类型不能为空"; return(response); } else if (body.GoodsNum == 0) { response.ReplyMsg = "商品库存不能为空"; return(response); } else { Goods goods = new Goods { GoodsId = body.GoodsId, GoodsName = body.GoodsName, GoodsPrice = body.GoodsPrice, GoodsKind = body.GoodsKind, GoodsNum = body.GoodsNum, CreateDateTime = DateTime.Now }; var count = await gr.AddGoods(goods); if (count > 0) { response.ReplyMsg = "商品上架成功"; } else { response.ReplyMsg = "商品上架失败"; } return(response); } }
public async Task <GoodsResponse> AlterGoodsInfo([FromBody] GoodsItem body) { GoodsResponse response = new GoodsResponse(); if (body.GoodsId == "") { response.ReplyMsg = "商品编码不能为空"; return(response); } else if (body.GoodsName == "") { response.ReplyMsg = "商品名称不能为空"; return(response); } else if (body.GoodsNum.Equals("")) { response.ReplyMsg = "商品库存不能为空"; return(response); } else if (body.GoodsKind == "") { response.ReplyMsg = "商品类型不能为空"; return(response); } else if (body.GoodsPrice.Equals("")) { response.ReplyMsg = "商品价格不能为空"; return(response); } else { Goods goods = new Goods { GoodsId = body.GoodsId, GoodsName = body.GoodsName, GoodsPrice = body.GoodsPrice, GoodsKind = body.GoodsKind, GoodsNum = body.GoodsNum, CreateDateTime = DateTime.Now }; var count = await gr.EditGoods(goods); if (count > 0) { response.ReplyMsg = "用户信息修改成功"; } else if (count == 0) { response.ReplyMsg = "尚未修改任何信息"; } else { response.ReplyMsg = "用户信息修改失败"; } return(response); } }
//设置装备信息 public void SetGoodsItem(GoodsItem gi) { if (gi == null) { return; } this.goodsItem = gi; Sprite.spriteName = gi.Goods.ICON; }
//更新装备状态 public void UpdateEquipStatus(GoodsItem gi) { CreateDataBase(); int i = Convert.ToInt32(gi.IsDressed); //using System; db.UpdateInto("T_Backpack", new string[] { "Dressed" }, new string[] { i.ToString() }, "ID", gi.Goods.ID.ToString()); db.CloseSqlConnection(); }
//显示 public void Show(GoodsItem gi, UIGoodsItem uigi) { SetVisible(true); this.gi = gi; this.uigi = uigi; mLabel_Name.text = gi.Goods.Name; mSprite_Icon.spriteName = gi.Goods.ICON; mLabel_Des.text = gi.Goods.Des; mLabel_Number.text = "使用(" + gi.Count + ")"; }
GoodsItem CurrItem; // 当前选中商品项 protected override void Initialize() { Screen = GetControl <Dropdown>(this, "Screen"); Search = GetControl <InputField>(this, "Search"); AddBtn = Get(this, "Add"); ModBtn = Get(this, "Modify"); DelBtn = Get(this, "Delete"); Title = Get(this, "Title"); List = Get(this, "List"); Item = NewElement <GoodsItem>(this, Get(List, "GoodsItem")); }
//物品使用 public void GoodsUse(GoodsItem gi, int count) { //处理物品使用后是否还存在 gi.Count -= count; OperatingDB.Instance.UpdateDrug(gi.Goods.ID); //更新数据库药品数量 if (gi.Count <= 0) { GoodsManager.instance.goodsItemList.Remove(gi); //移除物品 OperatingDB.Instance.DeleteGoods(gi.Goods.ID); //删除数据库背包物品 } }
public ResultModel Update(GoodsItem goods) { try { _shopService.UpdateGoods(goods); return(ResultModel.Success); } catch (Exception e) { return(new ResultModel(e)); } }
public void GoodsItemTest() { var category = CreateTestItemCategory(); try { var item = new GoodsItem(); item.Title = "Title"; item.Particular = "Particular"; item.ItemCategoryID = category.ItemCategoryID; item.BarCode = "BarCode"; item.Description = "Description"; item.UserCode = "UserCode"; item.DimensionKindID = DimensionKindSet.Thing.DimensionKindID; var store = CreateStore(); store.SaveGoodsItem(item); var savedItem = store.GetGoodsItem(item.GoodsItemIDGuid); Assert.IsNotNull(savedItem); Assert.AreEqual(savedItem.Title, item.Title); Assert.AreEqual(savedItem.Particular, item.Particular); Assert.AreEqual(savedItem.ItemCategoryID, item.ItemCategoryID); Assert.AreEqual(savedItem.BarCode, item.BarCode); Assert.AreEqual(savedItem.DimensionKindID, item.DimensionKindID); Assert.AreEqual(savedItem.Description, item.Description); Assert.AreEqual(savedItem.UserCode, item.UserCode); item.Title = "Title2"; item.Particular = "Particular3"; item.BarCode = "BarCode4"; item.Description = "Description5"; item.UserCode = "UserCode2"; store.SaveGoodsItem(item); savedItem = store.GetGoodsItem(item.GoodsItemIDGuid); Assert.IsNotNull(savedItem); Assert.AreEqual(savedItem.Title, item.Title); Assert.AreEqual(savedItem.Particular, item.Particular); Assert.AreEqual(savedItem.ItemCategoryID, item.ItemCategoryID); Assert.AreEqual(savedItem.BarCode, item.BarCode); Assert.AreEqual(savedItem.Description, item.Description); Assert.AreEqual(savedItem.UserCode, item.UserCode); store.DeleteGoodsItem(item.GoodsItemIDGuid); savedItem = store.GetGoodsItem(item.GoodsItemIDGuid); Assert.IsNull(savedItem); } finally { DeleteTestItemCategory(); } }
public ActionResult <GoodsItem> PostGoodsItem(GoodsItem goods) { try { orderDb.GoodsItems.Add(goods); orderDb.SaveChanges(); } catch (Exception e) { return(BadRequest(e.InnerException.Message)); } return(goods); }
private Transaction TransactionPerform(TradeParticipant participant1, TradeParticipant participant2, List<Coin> money, GoodsItem sellItem, TransactionType Ttype) { var transaction = Transaction.Create(this, participant2, money, sellItem, Ttype); if (transaction != null) { transaction.Perform(); return transaction; } return null; }
public void deleteBasketContents(GoodsItem item) { List <GoodsItem> basket = getBasket(); for (int i = 0; i < basket.Count; i++) { if (basket[i].merchantsGoodsID.Equals(item.merchantsGoodsID)) { basket.Remove(basket[i]); break; } } }
public ResultModel Create(GoodsItem goods) { try { int id = _shopService.CreateGoods(goods); var res = new ResultModel(true, new { id = id }); return(res); } catch (Exception e) { return(new ResultModel(e)); } }
//设置物品信息 public void SetGoodsItem(GoodsItem goodsItem) { this.goodsItem = goodsItem; Sprite.spriteName = goodsItem.Goods.ICON; if (goodsItem.Count <= 1) { Label.text = ""; } else { Label.text = goodsItem.Count.ToString(); } }
public static Transaction Create(TradeParticipant participant1, TradeParticipant participant2, List<Coin> money, GoodsItem sellItem, TransactionType Ttype) { Transaction transaction = new Transaction( participant1, participant2, money, sellItem, Ttype); return transaction; }
/// <summary> /// Adds the item of goods to the table /// </summary> protected void btn_AddItem_Click(object sender, EventArgs e) { List <GoodsItem> basket = Basket.getBasket(); GoodsItem newItem = new GoodsItem(); basket.Add(newItem); newItem.amount = txt_ItemAmount.Text; newItem.currencyCode = int.Parse(txt_ItemCurrency.Text); newItem.currencyCodeSpecified = true; newItem.nameOfGoods = txt_ItemName.Text; newItem.merchantsGoodsID = Guid.NewGuid().ToString(); ObjectDataSource1.Update(); updateAmount(); }
public GoodsItem Create([FromBody] GoodsItemModel item) { var goods = new GoodsItem(item.Name, item.Shipper, _user.Id, new GoodsCharacteristics { TemperatureLow = item.TemperatureLow, TemperatureHigh = item.TemperatureHigh, HumidityLow = item.HumidityLow, HumidityHigh = item.HumidityHigh, Volume = item.Volume }); return(_service.Create(goods)); }
public void PrimaryBuyTest() { TradeParticipant customer = new TradeParticipant("customer"); Coin coin = new Coin(10); customer.Wallet.AddItem(coin); TradeParticipant vmachine = new TradeParticipant("vmachine"); GoodsItem item = new GoodsItem(10,"coffee"); vmachine.GoodsStorage.AddItem(item); customer.Buy(vmachine, item, new List<Coin>() { coin }); Assert.AreEqual(0,customer.Wallet.MoneyAmount,"customer wallet"); Assert.AreEqual(1,customer.GoodsStorage.GoodsCount, "customer goods storage"); Assert.AreEqual(10,vmachine.Wallet.MoneyAmount, "vm wallet"); Assert.AreEqual(0,vmachine.GoodsStorage.GoodsCount, "vm goods storage"); }
private Transaction(TradeParticipant participant1, TradeParticipant participant2, List<Coin> money, GoodsItem sellItem,TransactionType Ttype) { if (Ttype == TransactionType.Sell) { this.participant1 = participant1; this.participant2 = participant2; } else { this.participant1 = participant2; this.participant2 = participant1; } this.money=money; this.sellItem=sellItem; this.Ttype=Ttype; }
public void VendingReturnChangeTest() { Customer customer = new Customer("customer"); Coin coin = new Coin(10); Coin coin1 = new Coin(10); customer.Wallet.AddItem(coin); customer.Wallet.AddItem(coin1); VendingMachine vmachine = new VendingMachine("vmachine"); GoodsItem item = new GoodsItem(15, "green tea"); vmachine.GoodsStorage.AddItem(item); Coin coin0 = new Coin(5); Coin coin01 = new Coin(3); Coin coin02 = new Coin(2); vmachine.Wallet.AddItem(coin0); vmachine.Wallet.AddItem(coin01); vmachine.Wallet.AddItem(coin02); customer.InsertCoin(coin, vmachine); customer.InsertCoin(coin1, vmachine); vmachine.SellTheItem(item, customer); Assert.AreEqual(5, customer.Wallet.MoneyAmount, "customer wallet"); Assert.AreEqual(1, customer.GoodsStorage.GoodsCount, "customer goods storage"); Assert.AreEqual(1, customer.Wallet.GetItems(a=>a==coin0,-1).Count, "customer wallet"); Assert.AreEqual(25, vmachine.Wallet.MoneyAmount, "vm wallet"); Assert.AreEqual(0, vmachine.GoodsStorage.GoodsCount, "vm goods storage"); }
public void VendingDoesHaveEnoughChangeTest() { Customer customer = new Customer("customer"); Coin coin = new Coin(10); Coin coin1 = new Coin(5); customer.Wallet.AddItem(coin); customer.Wallet.AddItem(coin1); VendingMachine vmachine = new VendingMachine("vmachine"); GoodsItem item = new GoodsItem(7, "green tea"); vmachine.GoodsStorage.AddItem(item); customer.InsertCoin(coin, vmachine); customer.InsertCoin(coin1, vmachine); vmachine.SellTheItem(item, customer); Assert.AreEqual(15, customer.Wallet.MoneyAmount, "customer wallet"); Assert.AreEqual(0, customer.GoodsStorage.GoodsCount, "customer goods storage"); Assert.AreEqual(0, vmachine.Wallet.MoneyAmount, "vm wallet"); Assert.AreEqual(1, vmachine.GoodsStorage.GoodsCount, "vm goods storage"); }
/// <summary> /// продаем товар /// </summary> /// <param name="sellItem"></param> /// <param name="customer"></param> /// <returns></returns> private bool _SellTheItem(GoodsItem sellItem, Customer customer) { List<Coin> change; if (customer.GetTheGood(sellItem)) { GoodsStorage.RemoveItems(a => a == sellItem); change = CountChange(sellItem, DBalance); } else { change = CountChange(null, DBalance); } if (customer.GetCoins(change)) { Wallet.RemoveItems(a => change.Contains(a)); DBalance = 0; NewMessage("Thank you!"); return true; } return false; }
//sell to participant2 what sellItem, for money public Transaction Sell(TradeParticipant participant2,GoodsItem sellItem,List<Coin> money) { return TransactionPerform(this, participant2, money, sellItem, TransactionType.Sell); }
////buy from participant2 what _goodsItem, for money public Transaction Buy(TradeParticipant participant2,GoodsItem buyItem,List<Coin> money) { return TransactionPerform(this, participant2, money, buyItem, TransactionType.Buy); }
/// <summary> /// проверяем хватает ли денег /// </summary> /// <param name="sellItem"></param> /// <param name="DBalance"></param> /// <returns></returns> private bool CheckIfEnoughMoney(GoodsItem sellItem, decimal DBalance) { decimal moneyAmount = DBalance; if (moneyAmount >= sellItem.Value) { return true; } else { //NewMessage("Sorry money amount is not enough"); return false; } }
/// <summary> /// Проверяем хватает ли сдачи /// </summary> /// <param name="sellItem"></param> /// <param name="DBalance"></param> /// <returns></returns> private bool DoesHaveEnoughChange(GoodsItem sellItem, decimal DBalance) { decimal changeAmount = GetChangeAmount(sellItem, DBalance); if (changeAmount == 0) return true; if (CountChange(sellItem, DBalance) != null) return true; return false; }
public void DoesHaveEnoughChangeTest() { TradeParticipant customer = new TradeParticipant("customer"); Coin coin = new Coin(10); Coin coin1 = new Coin(5); customer.Wallet.AddItem(coin); customer.Wallet.AddItem(coin1); TradeParticipant vmachine = new TradeParticipant("vmachine"); GoodsItem item = new GoodsItem(7, "green tea"); vmachine.GoodsStorage.AddItem(item); customer.Buy(vmachine, item, new List<Coin>() { coin, coin1 }); Assert.AreEqual(15, customer.Wallet.MoneyAmount, "customer wallet"); Assert.AreEqual(0, customer.GoodsStorage.GoodsCount, "customer goods storage"); Assert.AreEqual(0, vmachine.Wallet.MoneyAmount, "vm wallet"); Assert.AreEqual(1, vmachine.GoodsStorage.GoodsCount, "vm goods storage"); }
public virtual bool GetTheGood(GoodsItem goodItem) { GoodsStorage.AddItem(goodItem); return true; }
public void ReturnChangeTest2() { TradeParticipant customer = new TradeParticipant("customer"); Coin coin = new Coin(10); Coin coin1 = new Coin(5); customer.Wallet.AddItem(coin); customer.Wallet.AddItem(coin1); TradeParticipant vmachine = new TradeParticipant("vmachine"); GoodsItem item = new GoodsItem(10, "coffee"); vmachine.GoodsStorage.AddItem(item); customer.Buy(vmachine, null, new List<Coin>() { coin, coin1 }); Assert.AreEqual(15, customer.Wallet.MoneyAmount, "customer wallet"); Assert.AreEqual(0, customer.GoodsStorage.GoodsCount, "customer goods storage"); Assert.AreEqual(0, vmachine.Wallet.MoneyAmount, "vm wallet"); Assert.AreEqual(1, vmachine.GoodsStorage.GoodsCount, "vm goods storage"); }
/// <summary> /// Выдаем товар /// </summary> /// <param name="goodItem"></param> /// <param name="customer"></param> public virtual void TakeTheGood(GoodsItem goodItem,Customer customer) { if (customer.GetTheGood(goodItem)) { GoodsStorage.RemoveItems(a => a.Equals(goodItem)); DBalance = 0; } }
private decimal GetChangeAmount(GoodsItem sellItem, decimal DBalance) { if (sellItem != null) { return DBalance - sellItem.Value; } else { return DBalance; } }
/// <summary> /// Проверяем наличие товара /// </summary> /// <param name="sellItem"></param> /// <returns></returns> private bool ChechGoodsIsEnough(GoodsItem sellItem) { if (GoodsStorage.GetItem(a => a.Equals(sellItem)) != null) { return true; } return false; }
/// <summary> /// Рассчитываем сдачу /// </summary> /// <param name="sellItem"></param> /// <param name="DBalance"></param> /// <returns></returns> private List<Coin> CountChange(GoodsItem sellItem, decimal DBalance) { decimal changeAmount = GetChangeAmount(sellItem, DBalance); Coin _coin = null; List<Coin> _coins = new List<Coin> { }; while (changeAmount > 0) { Func<Coin, bool> changeCondition = a => a.Value <= changeAmount && (changeAmount - a.Value) >= 0 && !_coins.Contains(a); _coin = Wallet.GetMaxCoinUnderCondition(a => changeCondition(a)); if (_coin != null) { changeAmount -= _coin.Value; _coins.Add(_coin); } else { break; } } if (changeAmount == 0) { return _coins; } return null; }
public void ReturnChangeTest3() { TradeParticipant customer = new TradeParticipant("customer"); Coin coin = new Coin(3); Coin coin1 = new Coin(5); Coin coin2 = new Coin(2); customer.Wallet.AddItem(coin); customer.Wallet.AddItem(coin1); customer.Wallet.AddItem(coin2); TradeParticipant vmachine = new TradeParticipant("vmachine"); GoodsItem item = new GoodsItem(10, "coffee"); vmachine.GoodsStorage.AddItem(item); customer.Buy(vmachine, null, new List<Coin>() { coin, coin1,coin2 }); Assert.AreEqual(10, customer.Wallet.MoneyAmount, "customer wallet"); Assert.AreEqual(3, customer.Wallet.GetItems(a => a.Value >0, -1).Count, "customer wallet"); Coin coin3 = new Coin(10); vmachine.Wallet.AddItem(coin3); customer.Buy(vmachine, null, new List<Coin>() { coin, coin1, coin2 }); Assert.AreEqual(10, customer.Wallet.MoneyAmount, "customer wallet"); Assert.AreEqual(1, customer.Wallet.GetItems(a => a.Value == 10, -1).Count, "customer wallet"); Assert.AreEqual(10, vmachine.Wallet.MoneyAmount, "vm wallet"); Assert.AreEqual(3, vmachine.Wallet.GetItems(a => a.Value > 0, -1).Count, "vm wallet"); }