public void setTableAttributes()
        {
            //Binding is the reason for .ToList() , the count changed - it freezes it is not there
            List <Stock> allTransactions = SavedTransactions.getSavedTransactionsStock();
            List <Stock> reference       = new List <Stock>();

            foreach (var tableAttribute in allTransactions)
            {
                if (tableAttribute.getImporter() == mainWindow.getCurrentUser().getUsername())
                {
                    reference.Add(tableAttribute);
                }
            }
            tableAttributes = new List <Stock>(reference);
            if (tableAttributes != null)
            {
                foreach (var transaction in tableAttributes)
                {
                    if (transaction.getWriteDate() != null && transaction.getWriteDate().Length >= 12)
                    {
                        transaction.setWriteDate(transaction.getWriteDate().Substring(0, 12));
                    }
                    else
                    {
                        transaction.setWriteDate(DateTime.Now.ToString("yyyy/MM/dd"));
                    }
                }
            }
        }
        public void setUserStatistics(User currentUser)
        {
            int      numberOfTransactions = 0;
            int      totalIncome          = 0;
            int      totalSpendings       = 0;
            string   latestImportDate     = "";
            string   todaysDate           = DateTime.Now.ToString("yyyy-MM-dd");
            DateTime todayDate            = Convert.ToDateTime(todaysDate);

            usernameLabel.Content = currentUser.getUsername();
            foreach (var transactions in SavedTransactions.getSavedTransactionsStock())
            {
                string username = currentUser.getUsername();
                if (transactions.getImporter() == username)
                {
                    numberOfTransactions++;
                    latestImportDate = transactions.getWriteDate();
                }
            }
            noTransactionsLabel.Content = numberOfTransactions;
            if (latestImportDate.Length >= 12)
            {
                lastImportDateLabel.Content = latestImportDate.Substring(0, 12);
            }
            else
            {
                lastImportDateLabel.Content = latestImportDate;
            }
            DateTime importDate;

            if (latestImportDate.Length > 0)
            {
                importDate = Convert.ToDateTime(latestImportDate);
                float diffTicks = (todayDate - importDate).Days;
                if (diffTicks >= 30)
                {
                    urgencyLabel.Content              = "Recommended!";
                    urgencyLabel.Foreground           = new SolidColorBrush(Color.FromRgb(217, 30, 24));
                    mainWindow.exclamImage.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    urgencyLabel.Content    = "Not urgent";
                    urgencyLabel.Foreground = new SolidColorBrush(Color.FromRgb(46, 204, 113));
                    if (mainWindow.exclamImage.Visibility != System.Windows.Visibility.Visible)
                    {
                        mainWindow.exclamImage.Visibility = System.Windows.Visibility.Hidden;
                    }
                }
            }
            else
            {
                urgencyLabel.Content        = "You haven't imported yet!";
                lastImportDateLabel.Content = "You haven't imported yet!";
            }
        }
        public void displayAllData()
        {
            SeriesCollection = new SeriesCollection();
            Labels           = new string[SavedTransactions.getSavedTransactionsStock().Count];
            LineSeries lineSeries = new LineSeries();

            lineSeries.Title = "All";
            ChartValues <int> stats              = new ChartValues <int>();
            List <DateTime>   distinctDays       = new List <DateTime>();
            List <string>     distinctDaysString = new List <string>();
            int counter = 0;

            foreach (var transactions in SavedTransactions.getSavedTransactionsStock())
            {
                DateTime dt = DateTime.ParseExact(transactions.getWriteDate(), "yyyy-MM-dd", CultureInfo.InvariantCulture);
                if (!distinctDays.Contains(dt))
                {
                    distinctDays.Add(dt);
                }
            }
            distinctDays.Sort();

            Dictionary <string, int> importedTransactionsToDays = new Dictionary <string, int>();

            foreach (var x in distinctDays)
            {
                counter = 0;
                string[] splittedDate = x.ToString().Split(' ');
                string   date         = splittedDate[0] + splittedDate[1] + splittedDate[2];
                date = date.Remove(date.Length - 1);
                date = date.Replace('.', '-');
                foreach (var y in SavedTransactions.getSavedTransactionsStock())
                {
                    if (date == y.getWriteDate())
                    {
                        counter++;
                    }
                }
                importedTransactionsToDays.Add(date, counter);
            }
            int i = 0;

            foreach (var x in importedTransactionsToDays)
            {
                stats.Add(x.Value);
                Labels[i] = x.Key.ToString();
                i++;
            }
            lineSeries.Values = stats;
            SeriesCollection.Add(lineSeries);
        }
Beispiel #4
0
        private void importHistoryButton_Click(object sender, RoutedEventArgs e)
        {
            List <string> stockNames = new List <string>();

            foreach (var x in SavedTransactions.getSavedTransactionsStock())
            {
                if (!stockNames.Contains(x.getStockName()))
                {
                    stockNames.Add(x.getStockName());
                }
            }
            ImportStatsChartStock importStatsChart = new ImportStatsChartStock(stockNames);

            importStatsChart.displayAllData();
            mainWindow.MainFrame.Content = importStatsChart;
        }
        public void setTableAttributes()
        {
            //Binding is the reason for .ToList() , the count changed - it freezes it is not there
            List <Stock> allTransactions = SavedTransactions.getSavedTransactionsStock();
            List <Stock> reference       = new List <Stock>();

            stockChoices = new List <string>();
            foreach (var tableAttribute in allTransactions)
            {
                if (tableAttribute.getImporter() == mainWindow.getCurrentUser().getUsername())
                {
                    reference.Add(tableAttribute);
                }
                if (!stockChoices.Contains(tableAttribute.getStockName()))
                {
                    stockChoices.Add(tableAttribute.getStockName());
                }
            }
            tableAttributes = new List <Stock>(reference);
            if (tableAttributes != null)
            {
                foreach (var transaction in tableAttributes)
                {
                    if (transaction.getProfit() != null && transaction.getProfit() != "-")
                    {
                        try
                        {
                            double profit = double.Parse(transaction.getProfit());
                            var    f      = new NumberFormatInfo {
                                NumberGroupSeparator = "."
                            };
                            var s = profit.ToString("n", f);
                            transaction.setProfit(s);
                        }
                        catch (Exception e)
                        {
                        }
                    }
                    else
                    {
                        transaction.setProfit("-");
                    }
                }
            }
        }
        public void displayData(string stockName)
        {
            SeriesCollection = new SeriesCollection();
            Labels           = new string[SavedTransactions.getSavedTransactionsStock().Count];
            LineSeries lineSeries = new LineSeries();

            lineSeries.Title = stockName;
            ChartValues <int> stats              = new ChartValues <int>();
            List <DateTime>   distinctDays       = new List <DateTime>();
            List <string>     distinctDaysString = new List <string>();
            int counter = 0;

            foreach (var transactions in SavedTransactions.getSavedTransactionsStock())
            {
                if (transactions.getStockName() == stockName)
                {
                    DateTime dt = DateTime.ParseExact(transactions.getWriteDate(), "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    if (!distinctDays.Contains(dt))
                    {
                        distinctDays.Add(dt);
                    }
                }
            }
            distinctDays.Sort();
            distinctDays.Reverse();

            Dictionary <string, int> importedTransactionsToDays = new Dictionary <string, int>();

            foreach (var x in distinctDays)
            {
                counter = 0;
                string[] splittedDate = x.ToString().Split(' ');
                string   date         = splittedDate[0] + splittedDate[1] + splittedDate[2];
                date = date.Remove(date.Length - 1);
                date = date.Replace('.', '-');
                foreach (var y in SavedTransactions.getSavedTransactionsStock())
                {
                    if (date == y.getWriteDate() && stockName == y.getStockName())
                    {
                        counter++;
                    }
                }
                importedTransactionsToDays.Add(date, counter);
            }
            int i = 0;

            foreach (var x in importedTransactionsToDays)
            {
                stats.Add(x.Value);
                Labels[i] = x.Key.ToString();
                i++;
            }
            lineSeries.Values = stats;
            SeriesCollection.Add(lineSeries);

            /*
             * //modifying the series collection will animate and update the chart
             * SeriesCollection.Add(new LineSeries
             * {
             *  Title = "Series 4",
             *  Values = new ChartValues<double> { 5, 3, 2, 4 },
             *  LineSmoothness = 0, //0: straight lines, 1: really smooth lines
             *  PointGeometry = Geometry.Parse("m 25 70.36218 20 -28 -20 22 -8 -6 z"),
             *  PointGeometrySize = 50,
             *  PointForeground = Brushes.Gray
             * });
             *
             * //modifying any series values will also animate and update the chart
             * SeriesCollection[3].Values.Add(5d);
             */
        }