示例#1
0
        private void CreateNoItemStock(string cat0Name, string cat1Name)
        { //checks to see if the catagory for the no item stock search exists, if it does it makes the stock, if not it makes the category then the stock via a loop of methods.
            bool categoryExists = ChkCategoryExists(cat0Name, cat1Name);

            if (categoryExists)
            {
                Stock newStock = new Stock();
                newStock.Catagory0 = cat0Name;
                newStock.Catagory1 = cat1Name;
                newStock.Catagory2 = "Unused";
                newStock.Catagory3 = "Unused";
                string newName = cat0Name + " - " + cat1Name + " - " + "Unused" + " - " + "Unused";
                newStock.Name     = newName;
                newStock.Price    = 0;
                newStock.Quantity = 1000000;
                ListStock.Add(newStock);
                SaveStockDataFile();
                ResetNoItemChoiceStock();
            }
            else
            {
                StockCategory newStockCategory = new StockCategory();
                newStockCategory.Catagory0 = cat0Name;
                newStockCategory.Catagory1 = cat1Name;
                newStockCategory.Catagory2 = "Unused";
                newStockCategory.Catagory3 = "Unused";
                string newName = cat0Name + " - " + cat1Name + " - " + "Unused" + " - " + "Unused";
                newStockCategory.Name = newName;
                ListStockCatagories.Add(newStockCategory);
                SaveStockCatagoriesDataFile();
                ResetNoItemChoiceStock();
            }
        }
示例#2
0
        private static void RemoveTradeAsset(InvestmentAccount account, Asset asset)
        {
            int SoldQuantity;
            int totalOwnedQuantity = 0;

            if (asset.GetType() == typeof(Stock))
            {
                SoldQuantity = ((Stock)asset).quantity;

                foreach (Stock ListStock in account.AssetList.OfType <Stock>())
                {
                    if (ListStock.Symbol == ((Stock)asset).Symbol)
                    {
                        totalOwnedQuantity += ListStock.quantity;
                    }
                }

                if (totalOwnedQuantity < SoldQuantity)
                {
                    throw new InvalidTradeException("Not enough shares to trade with.");
                }
                else
                {
                    foreach (Stock ListStock in account.AssetList.OfType <Stock>())
                    {
                        if (ListStock.Symbol == ((Stock)asset).Symbol)
                        {
                            if (SoldQuantity < ListStock.quantity)
                            {
                                //reduce share, no removal
                                ListStock.changeQuantity(SoldQuantity);

                                SoldQuantity = 0;
                            }
                            else
                            {
                                //remove asset
                                SoldQuantity -= ListStock.quantity;
                                ListStock.QuantityToZero();
                            }
                        }
                    }
                }
            }
            else
            {
                SoldQuantity = ((Forex)asset).quantity;

                foreach (Forex ListForex in account.AssetList.OfType <Forex>())
                {
                    if (ListForex.currencyPair == ((Forex)asset).currencyPair)
                    {
                        totalOwnedQuantity += ListForex.quantity;
                    }
                }

                if (totalOwnedQuantity < SoldQuantity)
                {
                    throw new InvalidTradeException("Not enough quantities to trade with.");
                }
                else
                {
                    foreach (Forex ListForex in account.AssetList.OfType <Forex>())
                    {
                        if (ListForex.currencyPair == ((Forex)asset).currencyPair)
                        {
                            if (SoldQuantity < ListForex.quantity)
                            {
                                //reduce share, no removal
                                ListForex.changeQuantity(SoldQuantity);

                                SoldQuantity = 0;
                            }
                            else
                            {
                                //remove asset
                                SoldQuantity -= ListForex.quantity;
                                ListForex.QuantityToZero();
                            }
                        }
                    }
                }
            }

            int i = 0;

            while (i < account.AssetList.Count)
            {
                if ((account.AssetList[i].GetType() == typeof(Stock) && ((Stock)account.AssetList[i]).quantity == 0) ||
                    (account.AssetList[i].GetType() == typeof(Forex) && ((Forex)account.AssetList[i]).quantity == 0))
                {
                    account.RemoveInvestmentAssets(account.AssetList[i]);
                }
                else
                {
                    i++;
                }
            }
        }