Ejemplo n.º 1
0
        public void CreateSellingOrder(int amount)
        {
            int pending = 0;

            foreach (var order in mSellOrders)
            {
                pending += order.quantity;
            }

            if (amount > (mWallet.Count - pending))
            {
                clientForm.UpdateStatus("You don't have that many diginotes!", false);
                return;
            }

            if (mPurchaseOrders.Count > 0)
            {
                clientForm.UpdateStatus("You can't sell while having pending purchases.", false);
                return;
            }

            List <int> serials = diginoteSystem.SellOrders(username, amount);

            bool prompt = false;

            if (serials.Count == 0)
            {
                clientForm.UpdateStatus("No diginote was sold. Request Pending.", false);
                pending += amount;
                AddSellOrder();
                prompt = true;

                // Update sell orders
                mSellOrders = diginoteSystem.GetPendingSellOrders(username);
                clientForm.UpdateSellOrders(mSellOrders);

                int toSell = 0;
                foreach (var order in mSellOrders)
                {
                    toSell += order.quantity;
                }
                clientForm.UpdateDiginotes((mWallet.Count - toSell) + " (" + toSell + ")");
            }
            else if (serials.Count == amount)
            {
                clientForm.UpdateStatus("All " + amount + " diginote(s) sold!", true);
            }
            else
            {
                string msg = serials.Count + " diginote(s) sold.\n" + "Remaining " + (amount - serials.Count) + " pending.";
                clientForm.UpdateStatus(msg, true);
                pending += amount - serials.Count;
                AddSellOrder();
                prompt = true;
            }

            // Remove traded diginotes from wallet
            mWallet.Where(d => !serials.Contains(d.serialNumber));
            clientForm.UpdateDiginotes(mWallet.Count - pending + " (" + pending + ")");

            if (prompt)   // Não vendeu todas, pedir para baixar preço

            {
                var popup = new PopupForm(GetCurrentQuote(), true);

                if (popup.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    diginoteSystem.DecreaseSellPrice(popup.newValue);
                }

                popup.Dispose();
            }
        }