Esempio n. 1
0
        private static void onNewWorld(object sender, EventArgs a)
        {
            MarketBusinessHourListener listener = null;

            if (_theInstance != null)
            {
                listener = _theInstance.onBusinesStatusChanging;
            }
            _theInstance = (StockCompanyModule)World.world.otherObjects["{227E053A-6667-43fe-8CE2-26EB55CE6A56}"];
            if (_theInstance == null)
            {
                World.world.otherObjects["{227E053A-6667-43fe-8CE2-26EB55CE6A56}"] =
                    _theInstance = new StockCompanyModule();
                Economy.onNewWorld("{227E053A-6667-43fe-8CE4-26EB55CE6A56}");
            }
            else
            {
                Economy.onWorldLoaded("{227E053A-6667-43fe-8CE4-26EB55CE6A56}");
            }
            // restoring listener registrations (may be a BankbookWindow).
            if (listener != null)
            {
                _theInstance.onBusinesStatusChanging = listener;
            }
            _theInstance.rebuildRetainSet();
            // restore registrations for BankbookListHelper
            StocksListHelper.restoreData();
            _theInstance.onTrading = new OwnershipListener(StocksListHelper.onOwnershipStatusChanged);
            Economy.runEconomy();
        }
Esempio n. 2
0
        internal bool buy(int amount)
        {
            if (amount > numInMarket)
            {
                amount = numInMarket;
            }
            if (amount <= 0)
            {
                return(false);
            }

            int  c = StockCompanyModule.calcCommition(currentPriceU, amount);
            long v = amount * currentPriceU + c;

            manager.spend(v, AccountGenre.OTHERS);

            bool r = (_numOwn == 0);

            moneySpend   += v;
            _numOwn      += amount;
            _numInMarket -= amount;
            // raise the price according to the bought amount
            currentPriceU += _currentPriceU * amount / numTotal;
            return(r);
        }
Esempio n. 3
0
        internal bool sell(int amount)
        {
            if (amount > numOwn)
            {
                amount = numOwn;
            }
            if (amount <= 0)
            {
                return(false);
            }

            int  c = StockCompanyModule.calcCommition(currentPriceU, amount);
            long v = amount * currentPriceU - c;

            manager.earn(v, AccountGenre.OTHERS);
            int prev = averageBoughtPriceU;

            _numOwn      -= amount;
            _numInMarket += amount;
            bool r = (_numOwn == 0);

            // lower the price according to the bought amount
            currentPriceU -= _currentPriceU * amount / numTotal;
            moneySpend     = prev * _numOwn;
            return(r);
        }
Esempio n. 4
0
 public StockMarketPlugIn(XmlElement e) : base(e)
 {
     _theInstance = this;
     StockMarketConfig.init(e);
     StockCompanyModule.init();
     Economy.init(e);
 }
Esempio n. 5
0
        private void listview_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            chart.chart.removeDataSourceAt(0);
            if (listview.SelectedItems.Count == 0)
            {
                tl_totStockBuy.Text   = "";
                tl_totStockSell.Text  = "";
                tl_benefit.Text       = "";
                tl_commitionBuy.Text  = "";
                tl_commitionSell.Text = "";
                tl_priceBought.Text   = "";
                tl_totExpense.Text    = "";
                tl_totIncom.Text      = "";
                numberBuy.numberMax   = 0;
                numberSell.numberMax  = 0;
                current = Company.Null;
            }
            else
            {
                ListViewItem item = listview.SelectedItems[0];
                current = (Company)item.Tag;

                int n = current.stockData.numOwn;
                tl_totStockSell.Text = tl_totStockBuy.Text = StocksListHelper.formatNum(n);
                onBuyEditChanged();
                onSellEditChanged();
                tl_benefit.Text     = CurrencyUtil.format(current.stockData.benefitPerStock);
                tl_priceBought.Text = CurrencyUtil.format(current.stockData.averageBoughtPrice);
                numberBuy.numberMax = StockCompanyModule.calcBuyableStocks(
                    current.stockData, AccountManager.theInstance.liquidAssets);
                numberSell.numberMax = current.stockData.numOwn;

                chart.chart.addDataSource(current.stockData, Color.Blue);
            }
            chart.chart.calcRange();
            chart.chart.Invalidate();
        }