Exemplo n.º 1
0
        /// <summary>
        /// Metoda usuwa zakupiony indeks z bazy danych
        /// i odswieza widok w razie potrzeby
        /// </summary>
        /// <param name="myStock">Transakcja do odswiezenia</param>
        /// <param name="quantity">Ilosc sprzedanych akcji</param>
        private void RemoveSoldStock(MyStock myStock, int quantity)
        {
            DatabaseController dbController = new DatabaseController();

            if (myStock.transactionVolume == quantity)
            {
                m_myStockIndexesList.Remove(m_myStockIndexesList.Find(x => x.transactionID == myStock.transactionID));
                dbController.myStockProfits.RemoveRange(dbController.myStockProfits.Where(x => x.transactionID == myStock.transactionID));
                dbController.Remove(myStock);
                if (m_myStockIndexesList.Count > 0)
                {
                    ListOfMyStocks.SelectedIndex = 0;
                }
                else
                {
                    RealStockTab.IsSelected      = true;
                    MyStockTab.IsEnabled         = false;
                    ListOfMyStocks.SelectedIndex = -1;
                }
            }
            else
            {
                myStock.transactionVolume -= quantity;
                dbController.Update(myStock);
            }

            dbController.SaveChanges();
            OnPropertyChanged("myStockIndexesList");
            UpdateMyStockDetailData();
            UpdateSelectedMyStock();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Metoda dodaje nowy zakupiony indeks do bazy danych
        /// </summary>
        /// <param name="myStock">Indeks do dodania</param>
        private void AddNewBoughtStock(MyStock myStock)
        {
            DatabaseController dbController = new DatabaseController();

            dbController.Add(myStock);
            dbController.SaveChanges();
            m_myStockIndexesList.Add(dbController.myStocks.OrderBy(x => x.transactionDate).Last());
            MyStockTab.IsEnabled = true;
            UpdateMyStockDetailData();
            OnPropertyChanged("myStockIndexesList");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Metoda odswieza informacje o aktualnych zarobkach we
        /// wszystkich zakupionych indeksach
        /// </summary>
        private void UpdateMyStockDetailData()
        {
            DatabaseController databaseController = new DatabaseController();

            foreach (MyStock stock in databaseController.myStocks)
            {
                var currentItem = databaseController.stockIndexes.Where(x => x.symbol == stock.symbol).FirstOrDefault();
                stock.profit = ((currentItem.price - stock.indexPrice) * stock.transactionVolume);
                databaseController.SaveChanges();
            }
            myStockIndexesList = databaseController.myStocks.OrderBy(x => x.symbol).ToList();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Metoda odswieza dane o historycznych zarobkach zakupionych indeksow
        /// </summary>
        /// <param name="myStock">transakcja dla ktorej odswiezyc dane</param>
        private void UpdateMyStockProfit(MyStock myStock)
        {
            DatabaseController databaseController = new DatabaseController();
            DateTime           newestProfit;

            if (databaseController.myStockProfits.Where(x => x.transactionID == myStock.transactionID).Any())
            {
                newestProfit = databaseController.myStockProfits
                               .Where(x => x.symbol == myStock.symbol)
                               .OrderByDescending(x => x.date)
                               .FirstOrDefault().date;
            }
            else
            {
                newestProfit = myStock.transactionDate;
            }

            bool NeedToUpdateHistorical = !databaseController.historicalIndexes
                                          .Where(x => x.symbol == myStock.symbol)
                                          .Where(x => x.date.Date == DateTime.Today.AddDays(-1))
                                          .Any();

            if (NeedToUpdateHistorical && myStock.transactionDate < DateTime.Today)
            {
                databaseController.FillHistoricalTable(myStock.symbol);
            }

            var list = databaseController.historicalIndexes
                       .Where(x => x.symbol == myStock.symbol)
                       .Where(x => x.date > newestProfit)
                       .OrderByDescending(x => x.date)
                       .ToList();

            foreach (var l in list)
            {
                databaseController.myStockProfits.Add(new MyStockProfit
                {
                    date          = l.date,
                    profit        = l.price - myStock.indexPrice,
                    transactionID = myStock.transactionID,
                    symbol        = myStock.symbol
                });
                databaseController.SaveChanges();
            }
        }