Example #1
0
        public void CreatePurchaseOrder(int amount)
        {
            if (mSellOrders.Count > 0)
            {
                clientForm.UpdateStatus("You can't buy while having pending sell orders.", false);
                return;
            }

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

            bool prompt = false;

            // não comprou nenhuma. purchase order nova
            if (serials.Count == 0)
            {
                clientForm.UpdateStatus("No diginote was bought. Pending...", false);
                // Atualizar pending purchases
                mPurchaseOrders = diginoteSystem.GetPendingPurchaseOrders(username);
                clientForm.UpdatePurchaseOrders(mPurchaseOrders);
                prompt = true;
            }
            // comprou algumas, mas não todas
            else if (serials.Count < amount)
            {
                clientForm.UpdateStatus(serials.Count + " diginotes were sold. Rest are pending.", true);
                prompt = true;
            }
            // comprou todas
            else
            {
                clientForm.UpdateStatus("All diginotes bought!", true);
            }

            // Atualizar wallet
            mWallet = diginoteSystem.GetDiginotes(username);
            int pending = 0;

            foreach (var order in mSellOrders)
            {
                pending += order.quantity;
            }
            clientForm.UpdateDiginotes((mWallet.Count - pending) + " (" + pending + ")");

            if (prompt)
            { // Não vendeu todas, pedir para aumentar preço
                var popup = new PopupForm(GetCurrentQuote(), false);

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

                popup.Dispose();
            }
        }
Example #2
0
        public void DecreaseSellOrderPrice()
        {
            if (mSellOrders.Count == 0)
            {
                clientForm.UpdateStatus("You don't have pending sell orders.", false);
                return;
            }

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

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

            popup.Dispose();
        }
Example #3
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();
            }
        }