コード例 #1
0
        public ActionResult ListArchives(int?Page, int?Year, int?Month)
        {
            int[] years = DataBaseHandler.GetYears();
            ViewBag.Years  = new SelectList(years);
            ViewBag.Months = new SelectList(Enumerable.Range(1, 12));
            StaticPagedList <WeatherEntry> fullData;
            int pageSize   = 50;
            int pageNumber = (Page ?? 1);

            if (Year != null)
            {
                ViewBag.Year = Year;
                if (Month != null)
                {
                    ViewBag.Month = Month;
                    fullData      = DataBaseHandler.GetData(pageNumber, pageSize, (int)Year, (int)Month);
                }
                else
                {
                    fullData = DataBaseHandler.GetData(pageNumber, pageSize, (int)Year);
                }
            }
            else
            {
                fullData = DataBaseHandler.GetData(pageNumber, pageSize);
            }
            return(View(fullData));
        }
コード例 #2
0
        public void LoadValues()
        {
            while (SearchResultList.Items.Count > 0)
            {
                SearchResultList.Items.RemoveAt(0);
            }
            MySqlDataReader reader = DataBaseHandler.GetData("SELECT StockName, FullName, CurrentPrice FROM Stock");

            while (reader.Read())
            {
                string     Symbol   = (string)reader["StockName"];
                string     FullName = (string)reader["FullName"];
                double     Price    = (double)reader["CurrentPrice"];
                StackPanel panel    = new StackPanel();
                panel.Orientation = Orientation.Horizontal;
                panel.Children.Add(Helper.CreateTextBlock(Symbol, TextAlignment.Left, 100, 20));
                panel.Children.Add(Helper.CreateTextBlock(FullName, TextAlignment.Left, 350, 20));
                panel.Children.Add(Helper.CreateTextBlock("$" + Math.Round(Price, 4), TextAlignment.Left, 150, 20));
                Button EditButton = new Button();
                EditButton.Content = "Edit";
                EditButton.Width   = 60;
                EditButton.Height  = 40;
                EditButton.Click  += (o, i) => this.Frame.Navigate(typeof(Pages.Admin.StockEditorPage), Symbol);
                Button DeleteButton = new Button();
                DeleteButton.FontFamily = new FontFamily("Segoe MDL2 Assets");
                DeleteButton.Content    = "";
                DeleteButton.Click     += (o, i) => DeleteStockButtonClick(Symbol);
                DeleteButton.Width      = 40;
                DeleteButton.Height     = 40;
                panel.Children.Add(EditButton);
                panel.Children.Add(DeleteButton);
                SearchResultList.Items.Add(panel);
            }
        }
コード例 #3
0
        public void LoadValues()
        {
            MySqlDataReader reader = DataBaseHandler.GetData("SELECT AlgoTrader.ID, AlgoTrader.Target, AlgoTrader.UserID, AlgoTrader.ShortRequirement, AlgoTrader.LongRequirement, AlgoTrader.MinAmount, AlgoTrader.MaxAmount, AlgoTrader.Aggresion, Users.Balance FROM AlgoTrader, Users WHERE AlgoTrader.UserID = Users.ID");

            while (reader.Read())
            {
                int        ID               = (int)reader["ID"];
                string     Target           = (string)reader["Target"];
                double     ShortRequirement = (double)reader["ShortRequirement"];
                double     LongRequirement  = (double)reader["LongRequirement"];
                int        MinAmount        = (int)reader["MinAmount"];
                int        MaxAmount        = (int)reader["MaxAmount"];
                double     Aggresion        = (double)reader["Aggresion"];
                double     Price            = (double)reader["Balance"];
                StackPanel panel            = new StackPanel();
                panel.Orientation = Orientation.Horizontal;
                panel.Children.Add(Helper.CreateTextBlock(ID.ToString(), TextAlignment.Left, 35, 20));
                panel.Children.Add(Helper.CreateTextBlock(Target, TextAlignment.Left, 100, 20));
                panel.Children.Add(Helper.CreateTextBlock(ShortRequirement.ToString(), TextAlignment.Left, 200, 20));
                panel.Children.Add(Helper.CreateTextBlock(LongRequirement.ToString(), TextAlignment.Left, 200, 20));
                panel.Children.Add(Helper.CreateTextBlock(MinAmount.ToString(), TextAlignment.Left, 150, 20));
                panel.Children.Add(Helper.CreateTextBlock(MaxAmount.ToString(), TextAlignment.Left, 150, 20));
                panel.Children.Add(Helper.CreateTextBlock(Math.Round(Aggresion, 5).ToString(), TextAlignment.Left, 150, 20));
                panel.Children.Add(Helper.CreateTextBlock(Price.ToString(), TextAlignment.Left, 100, 20));
                Button DeleteButton = new Button();
                DeleteButton.FontFamily = new FontFamily("Segoe MDL2 Assets");
                DeleteButton.Content    = "";
                DeleteButton.Click     += (o, i) => DeleteStockButtonClick(ID);
                DeleteButton.Width      = 40;
                DeleteButton.Height     = 40;
                panel.Children.Add(DeleteButton);
                SearchResultList.Items.Add(panel);
            }
        }
コード例 #4
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     StockName = (e.Parameter as string).Split('/')[0];
     bidOffer  = (BidOffer)int.Parse((e.Parameter as string).Split('/')[1]);
     if (bidOffer == BidOffer.offer)
     {
         BuySellButton.Background = new SolidColorBrush(Colors.Red);
         BuySellButton.Content    = "Sell";
         int QuantityOwned  = DataBaseHandler.GetCount("SELECT SUM(Quantity) From Inventories WHERE StockName = '" + StockName + "' AND UserID = " + DataBaseHandler.UserID);
         int AlreadySelling = DataBaseHandler.GetCount("SELECT SUM(Quantity) FROM Pool WHERE Type = 1 AND User = "******"Available To Sell: " + (QuantityOwned - AlreadySelling);
     }
     else
     {
         double          Balance     = DataBaseHandler.GetCountDouble("SELECT SUM(Balance) FROM Users WHERE ID = " + DataBaseHandler.UserID);
         MySqlDataReader reader      = DataBaseHandler.GetData("SELECT Price, Quantity FROM Pool WHERE Type = 0 AND User = "******"Price"] * (int)reader["Quantity"];
         }
         double FundsAvailable = Balance - MoneyInPool;
         FundsAvailableBlock.Text = "Funds Available: " + Math.Round(FundsAvailable, 2);
     }
 }
コード例 #5
0
        private void LoadTrades()
        {
            TradeList.Items.Clear();
            MySqlDataReader reader = DataBaseHandler.GetData("SELECT Time, StockName, BuyerID, Price, Quantity FROM Trades WHERE BuyerID = " + DataBaseHandler.UserID + " OR SellerID = " + DataBaseHandler.UserID + " ORDER BY TIME DESC");

            while (reader.Read())
            {
                DateTime   Time      = (DateTime)reader["Time"];
                string     StockName = (string)reader["StockName"];
                int        BuyerID   = (int)reader["BuyerID"];
                double     Price     = (double)reader["Price"];
                int        Quantity  = (int)reader["Quantity"];
                StackPanel Panel     = new StackPanel();
                Panel.Orientation = Orientation.Horizontal;
                string Date = Time.Date.ToString().Split(' ')[0];
                Date = Date.Split('/')[0] + "/" + Date.Split('/')[1] + "/" + Date.Split('/')[2][2] + Date.Split('/')[2][3];
                Panel.Children.Add(Helper.CreateTextBlock(Date, TextAlignment.Left, 110, 20));
                if (BuyerID == DataBaseHandler.UserID)
                {
                    Panel.Children.Add(Helper.CreateTextBlock("Bid", TextAlignment.Left, 55, 20));
                }
                else
                {
                    Panel.Children.Add(Helper.CreateTextBlock("Offer", TextAlignment.Left, 55, 20));
                }
                Panel.Children.Add(Helper.CreateTextBlock(StockName, TextAlignment.Left, 80, 20));
                Panel.Children.Add(Helper.CreateTextBlock("$" + Math.Round(Price, 2), TextAlignment.Left, 75, 20));
                Panel.Children.Add(Helper.CreateTextBlock(Quantity.ToString(), TextAlignment.Left, 148, 20));
                TradeList.Items.Add(Panel);
            }
        }
コード例 #6
0
        private void LoadBidsAndOffer()
        {
            BidsAndOffersList.Items.Clear();
            MySqlDataReader reader = DataBaseHandler.GetData("SELECT Type, StockName, Price, Quantity FROM Pool WHERE User = "******"Type"];
                string     StockName = (string)reader["StockName"];
                double     Price     = (double)reader["Price"];
                int        Quantity  = (int)reader["Quantity"];
                StackPanel Panel     = new StackPanel();
                Panel.Orientation = Orientation.Horizontal;
                if (Type)
                {
                    Panel.Children.Add(Helper.CreateTextBlock("Offer", TextAlignment.Left, 55, 20));
                }
                else
                {
                    Panel.Children.Add(Helper.CreateTextBlock("Bid", TextAlignment.Left, 55, 20));
                }
                Panel.Children.Add(Helper.CreateTextBlock(StockName, TextAlignment.Left, 80, 20));
                TextBlock PriceBox = Helper.CreateTextBlock("$" + Price.ToString(), TextAlignment.Left, 75, 20);
                if (Price.ToString().Contains('.'))
                {
                    Helper.CreateTextBlock("$" + Price.ToString().Split('.')[0] + "." + Price.ToString().Split('.')[1].Substring(0, 2), TextAlignment.Left, 75, 20);
                }
                Panel.Children.Add(PriceBox);
                Panel.Children.Add(Helper.CreateTextBlock(Quantity.ToString(), TextAlignment.Left, 148, 20));
                BidsAndOffersList.Items.Add(Panel);
            }
        }
コード例 #7
0
        //Send the information to the database to see if the user can be loged in / registier
        async void OnlineConnector(string Act, string formNick, string formPassword, string email)
        {
            //Turn password into a MD5 hash so that the password is not being
            formPassword = CalculateMD5Hash(formPassword);
            if (Act == "Login")
            {
                //Search for account on DB
                MySqlDataReader reader   = DataBaseHandler.GetData("SELECT * FROM Users WHERE Email = '" + email + "'");
                string          Nickname = "";
                int             UserId   = -1;
                string          Password = "";
                while (reader.Read())
                {
                    Nickname = (string)reader["Nickname"];
                    UserId   = (int)reader["ID"];
                    Password = (string)reader["Password"];
                }
                //If user has been found UserID will be greater or equal to 0
                if (UserId >= 0)
                {
                    if (Password == formPassword)
                    {
                        DataBaseHandler.Nickname = Nickname;
                        //Store UserID for future commands to DB
                        DataBaseHandler.UserID = UserId;
                        //Navigate to the main page of the app
                        this.Frame.Navigate(typeof(Pages.FeaturedStock));
                    }
                    else
                    {
                        //Display error message to user
                        MessageDialog Message = new MessageDialog("The Password is incorrect");
                        await Message.ShowAsync();

                        return;
                    }
                }
            }
            else
            {
                //Check if this email is taken
                int taken = DataBaseHandler.GetCount("SELECT COUNT(ID) FROM Users WHERE Email = '" + email + "'");
                if (taken == 0)
                {
                    //Insert user data into the DB
                    DataBaseHandler.UserID = DataBaseHandler.GetCount(string.Format("INSERT INTO Users(Nickname, Email, Password) VALUES('{0}', '{1}', '{2}'); SELECT LAST_INSERT_ID();", formNick, email, formPassword));
                    //Navigate to the main page of the app
                    this.Frame.Navigate(typeof(Pages.FeaturedStock));
                }
                else
                {
                    //Display error message to the user
                    MessageDialog Message = new MessageDialog("The Email is already taken");
                    await Message.ShowAsync();

                    return;
                }
            }
        }
コード例 #8
0
        public AlgoTraderCreatorPage()
        {
            this.InitializeComponent();
            MySqlDataReader reader = DataBaseHandler.GetData("SELECT FullName FROM Stock");

            while (reader.Read())
            {
                StockNameBox.Items.Add((string)reader["FullName"]);
            }
        }
コード例 #9
0
        private async void BuySellButtonClicked(object sender, RoutedEventArgs e)
        {
            int Quantity;

            if (int.TryParse(QuantityBox.Text, out Quantity))
            {
                double Price = DataBaseHandler.GetCountDouble("SELECT SUM(CurrentPrice) FROM Stock WHERE StockName = '" + StockName + "'");
                switch (bidOffer)
                {
                case BidOffer.bid:
                    double          Balance     = DataBaseHandler.GetCountDouble("SELECT SUM(Balance) FROM Users WHERE ID = " + DataBaseHandler.UserID);
                    MySqlDataReader reader      = DataBaseHandler.GetData("SELECT Price, Quantity FROM Pool WHERE Type = 0 AND User = "******"Price"] * (int)reader["Quantity"];
                    }
                    double FundsAvailable = Balance - MoneyInPool;
                    int    CanAfford      = (int)(FundsAvailable / Price);
                    if (Quantity > CanAfford)
                    {
                        Quantity = CanAfford;
                    }
                    ;
                    QuantityBox.Text = Quantity.ToString();
                    DataBaseHandler.SetData(string.Format("INSERT INTO Pool (Type, Price, User, StockName, Quantity) VALUES ({0}, {1}, {2}, '{3}', {4})", (int)bidOffer, Math.Round(Price, 2), DataBaseHandler.UserID, StockName, Quantity));
                    this.Frame.Navigate(typeof(Pages.User.Portfolio));
                    break;

                case BidOffer.offer:
                    int QuantityOwned  = DataBaseHandler.GetCount("SELECT SUM(Quantity) From Inventories WHERE StockName = '" + StockName + "' AND UserID = " + DataBaseHandler.UserID);
                    int AlreadySelling = DataBaseHandler.GetCount("SELECT SUM(Quantity) FROM Pool WHERE Type = 1 AND User = "******" AND StockName = '" + StockName + "'");
                    int CanSell        = QuantityOwned - AlreadySelling;
                    if (Quantity > CanSell)
                    {
                        Quantity = CanSell;
                    }
                    QuantityBox.Text = Quantity.ToString();
                    DataBaseHandler.SetData(string.Format("INSERT INTO Pool (Type, Price, User, StockName, Quantity) VALUES ({0}, {1}, {2}, '{3}', {4})", (int)bidOffer, Math.Round(Price, 2), DataBaseHandler.UserID, StockName, Quantity));
                    this.Frame.Navigate(typeof(Pages.User.Portfolio));
                    break;
                }
            }
            else
            {
                MessageDialog message = new MessageDialog("Quantity is not valid");
                await message.ShowAsync();

                return;
            }
        }
コード例 #10
0
 public DataTable LoginUser(string email, string password)
 {
     try
     {
         string          Password = EncryptText(password);
         object[]        paras    = { email, Password };
         DataBaseHandler dbh      = new DataBaseHandler();
         DataTable       dt       = dbh.GetData(CmdCommands.LoginUser, paras);
         return(dt);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #11
0
        private void TenClick(object sender, RoutedEventArgs e)
        {
            MySqlDataReader reader = DataBaseHandler.GetData("SELECT Time, Price FROM PricingHistory WHERE StockName = '" + StockName + "' AND Time > '" + DateTime.Now.AddMinutes(-10).ToString("yyyy-MM-dd HH:mm:ss") + "'");
            PriceChartList  Test   = new PriceChartList();

            ViewModel = new ObservableCollection <PriceChartList>();
            while (reader.Read())
            {
                Test.PriceHistory.Add(new PriceHis()
                {
                    Time = (DateTime)reader["Time"], Price = (double)reader["Price"]
                });
            }
            ViewModel.Add(Test);
            Line.Series[0].ItemsSource = ViewModel[0].PriceHistory;
        }
コード例 #12
0
        private void LoadBiggestFallers()
        {
            MySqlDataReader reader = DataBaseHandler.GetData("SELECT StockName, CurrentPrice, OpeningPriceToday FROM Stock ORDER BY CurrentPrice - OpeningPriceToday ASC LIMIT 4");

            while (reader.Read())
            {
                StackPanel panel = new StackPanel();
                panel.Orientation         = Orientation.Horizontal;
                panel.HorizontalAlignment = HorizontalAlignment.Left;
                double CurrentPrice = (double)reader["CurrentPrice"];
                panel.Children.Add(Helper.CreateTextBlock((string)reader["StockName"], TextAlignment.Left, 100, 18));
                panel.Children.Add(Helper.CreateTextBlock(Math.Round(CurrentPrice, 4).ToString(), TextAlignment.Left, 100, 18));
                panel.Children.Add(Helper.CreateTextBlock(Math.Round(CurrentPrice - (double)reader["OpeningPriceToday"], 4).ToString(), TextAlignment.Left, 100, 18));
                BiggestFallers.Items.Add(panel);
            }
        }
コード例 #13
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            MySqlDataReader reader = DataBaseHandler.GetData("SELECT FullName FROM Stock");
            ComboBox        box    = new ComboBox();

            trader.trigger = new Trigger();
            while (reader.Read())
            {
                box.Items.Add((string)reader["FullName"]);
                StockName.Add((string)reader["FullName"]);
            }
            box.SelectionChanged += StockChoiceChanged;
            panel.Children.Add(Helper.CreateTextBlock("If ", TextAlignment.Left, 25, 22, 10));
            panel.Children.Add(box);
        }
コード例 #14
0
        private void LoadValues(string Symbol)
        {
            MySqlDataReader reader = DataBaseHandler.GetData("SELECT FullName, Description, CurrentPrice FROM Stock WHERE StockName = '" + Symbol + "'");
            string          FullName = "", Description = "";
            float           CurrentPrice = 0;

            while (reader.Read())
            {
                FullName     = (string)reader["FullName"];
                CurrentPrice = (float)reader["CurrentPrice"];
            }
            SymbolBlock.Text      = Symbol;
            PriceBlock.Text       = CurrentPrice.ToString();
            DescriptionBlock.Text = Description;
            OriginalStockName     = Symbol;
        }
コード例 #15
0
        private void LoadPrices()
        {
            int             QuantityOwned = DataBaseHandler.GetCount("SELECT SUM(Quantity) From Inventories WHERE StockName = '" + StockName + "' AND UserID = " + DataBaseHandler.UserID);
            MySqlDataReader reader        = DataBaseHandler.GetData("SELECT * FROM Stock WHERE StockName = '" + StockName + "'");

            while (reader.Read())
            {
                string FullName          = (string)reader["FullName"];
                double Price             = (double)reader["CurrentPrice"];
                string Description       = (string)reader["Description"];
                double OpeningPrice      = (double)reader["OpeningPriceToday"];
                double RealChangeInPrice = Price - OpeningPrice;
                double PercentageChange  = RealChangeInPrice / OpeningPrice;
                int    VolumeTraded      = (int)reader["VolumeTraded"];
                StockNameTitle.Text  = FullName;
                DescriptionText.Text = Description;
                if (RealChangeInPrice != 0)
                {
                    ChangeInPricePercentage.Text = "Change In Price: " + PercentageChange.ToString().Split('.')[0] + "." + PercentageChange.ToString().Split('.')[1].Substring(0, 4) + "%";
                    ChangeInPrice.Text           = "Change In Price: " + RealChangeInPrice.ToString().Split('.')[0] + "." + RealChangeInPrice.ToString().Split('.')[1].Substring(0, 4);
                }
                else
                {
                    ChangeInPrice.Text           = "Change In Price: 0.00";
                    ChangeInPricePercentage.Text = "Change In Price: 0.00%";
                }
                if (RealChangeInPrice < 0)
                {
                    ChangeInPrice.Foreground           = new SolidColorBrush(Colors.Red);
                    ChangeInPricePercentage.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    ChangeInPrice.Foreground           = new SolidColorBrush(Colors.Green);
                    ChangeInPricePercentage.Foreground = new SolidColorBrush(Colors.Green);
                }
                CurrentPriceBlock.Text = "Current Price: " + Price.ToString().Split('.')[0] + "." + Price.ToString().Split('.')[1].Substring(0, 4);
                VolumeTradedToday.Text = "Volume Traded: " + VolumeTraded.ToString();
                if (QuantityOwned > 0)
                {
                    VolumeTradedToday.Text += "\nStock Owned: " + QuantityOwned;
                }
                SellButtonObject.Width = 250;
                BuyButtonObject.Width  = SellButtonObject.Width;
                WatchListButton.Width  = SellButtonObject.Width;
            }
        }
コード例 #16
0
        void LoadTraders()
        {
            TradersList.Items.Clear();
            MySqlDataReader reader = DataBaseHandler.GetData("SELECT * FROM UserAlgoTraders WHERE OwnerID = " + DataBaseHandler.UserID);

            while (reader.Read())
            {
                StackPanel panel = new StackPanel();
                panel.Orientation = Orientation.Horizontal;
                panel.Children.Add(Helper.CreateTextBlock(((int)reader["ID"]).ToString(), TextAlignment.Left, 25, 22));
                Button b = new Button();
                b.Content = "Remove";
                b.Click  += (s, ev) => { DataBaseHandler.SetData("DELETE FROM UserAlgoTraders WHERE ID = " + reader["ID"]); LoadTraders(); };
                panel.Children.Add(b);
                TradersList.Items.Add(panel);
            }
        }
コード例 #17
0
        private void LoadBalance()
        {
            double          Balance     = DataBaseHandler.GetCountDouble("SELECT SUM(Balance) FROM Users WHERE ID = " + DataBaseHandler.UserID);
            MySqlDataReader reader      = DataBaseHandler.GetData("SELECT Price, Quantity FROM Pool WHERE Type = 0 AND User = "******"Price"] * (int)reader["Quantity"];
            }
            BalanceText.Text = "Balance: $" + Math.Round(Balance, 2);
            if (Balance < 0)
            {
                BalanceText.Foreground = new SolidColorBrush(Colors.Red);
            }
            else
            {
                BalanceText.Foreground = new SolidColorBrush(Colors.Green);
            }
            double FundsAvailable = Balance - MoneyInPool;

            FundsAvailableText.Text = "  Funds Available: $" + Math.Round(FundsAvailable, 2);
            if (FundsAvailable < 0)
            {
                FundsAvailableText.Text       = "  Funds Available: $0";
                FundsAvailableText.Foreground = new SolidColorBrush(Colors.Red);
            }
            MySqlDataReader reader2    = DataBaseHandler.GetData("SELECT DISTINCT StockName FROM Inventories WHERE UserID = " + DataBaseHandler.UserID);
            List <string>   StockNames = new List <string>();

            while (reader2.Read())
            {
                StockNames.Add((string)reader2["StockName"]);
            }
            double InventoryValue = 0.00d;

            for (int i = 0; i < StockNames.Count; i++)
            {
                double CurrentPrice  = DataBaseHandler.GetCountDouble("SELECT SUM(CurrentPrice) FROM Stock WHERE StockName = '" + StockNames[i] + "'");
                int    QuantityOwner = DataBaseHandler.GetCount("SELECT SUM(Quantity) From Inventories WHERE UserID = " + DataBaseHandler.UserID + " AND " + " StockName = '" + StockNames[i] + "'");
                InventoryValue += CurrentPrice * (double)QuantityOwner;
            }
            InventoryValueText.Text = "  Invetory Value: $" + Math.Round(InventoryValue, 2);
        }
コード例 #18
0
        public Pool()
        {
            this.InitializeComponent();
            this.Demands = new ObservableCollection <PieChartData>();
            MySqlDataReader reader = DataBaseHandler.GetData("SELECT DISTINCT StockName FROM Pool");

            while (reader.Read())
            {
                Demands.Add(new PieChartData((string)reader["StockName"]));
            }
            foreach (PieChartData pcd in Demands)
            {
                pcd.Value = DataBaseHandler.GetCount("SELECT COUNT(*) FROM Pool WHERE StockName = '" + pcd.Name + "'");
            }
            SfChart chart = new SfChart();

            chart.Header = "Stocks In Pool";
            CategoryAxis primaryCategoryAxis = new CategoryAxis();

            primaryCategoryAxis.Header = "Stocks";
            chart.PrimaryAxis          = primaryCategoryAxis;
            NumericalAxis secondaryNumericalAxis = new NumericalAxis();

            secondaryNumericalAxis.Header = "Percentage in Pool";
            chart.SecondaryAxis           = secondaryNumericalAxis;
            PieSeries series1 = new PieSeries();

            series1.ItemsSource  = this.Demands;
            series1.XBindingPath = "Name";
            series1.YBindingPath = "Value";
            chart.Series.Add(series1);
            ChartLegend legend = new ChartLegend();

            chart.Legend = legend;
            MainThing.Children.Add(chart);
        }
コード例 #19
0
        public void LoadWatchList()
        {
            MySqlDataReader reader2 = DataBaseHandler.GetData("SELECT DISTINCT StockName FROM WatchList WHERE User = "******"StockName"]);
            }
            foreach (string s in stocks)
            {
                MySqlDataReader reader = DataBaseHandler.GetData("SELECT StockName, FullName, CurrentPrice, OpeningPriceToday FROM Stock WHERE StockName = '" + s + "'");
                while (reader.Read())
                {
                    string     Symbol            = s;
                    string     FullName          = (string)reader["FullName"];
                    double     Price             = (double)reader["CurrentPrice"];
                    double     OpeningPrice      = (double)reader["OpeningPriceToday"];
                    double     RealChangeInPrice = Price - OpeningPrice;
                    double     PercentageChange  = RealChangeInPrice / OpeningPrice;
                    StackPanel panel             = new StackPanel();
                    panel.Orientation = Orientation.Horizontal;
                    panel.Children.Add(Helper.CreateTextBlock(Symbol, TextAlignment.Left, 100, 20));
                    panel.Children.Add(Helper.CreateTextBlock(FullName, TextAlignment.Left, 250, 20));
                    panel.Children.Add(Helper.CreateTextBlock(Price.ToString().Split('.')[0] + Price.ToString().Split('.')[1].Substring(0, 4), TextAlignment.Left, 100, 20));
                    TextBlock RealChangeInPriceBlock = Helper.CreateTextBlock(0.ToString(), TextAlignment.Left, 100, 20);
                    if (RealChangeInPrice != 0)
                    {
                        RealChangeInPriceBlock = Helper.CreateTextBlock(RealChangeInPrice.ToString().Substring(0, 6), TextAlignment.Left, 100, 20);
                    }
                    if (RealChangeInPrice < 0)
                    {
                        RealChangeInPriceBlock.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        RealChangeInPriceBlock.Foreground = new SolidColorBrush(Colors.Green);
                    }
                    panel.Children.Add(RealChangeInPriceBlock);
                    TextBlock PercentageChangeBlock = new TextBlock();
                    if (PercentageChange.ToString().Contains('.'))
                    {
                        RealChangeInPriceBlock = Helper.CreateTextBlock(PercentageChange.ToString().Split('.')[0] + "." + PercentageChange.ToString().Split('.')[1].Substring(0, 2) + "%", TextAlignment.Left, 100, 20);
                    }
                    else
                    {
                        RealChangeInPriceBlock = Helper.CreateTextBlock(PercentageChange.ToString() + "%", TextAlignment.Left, 100, 20);
                    }
                    if (RealChangeInPrice < 0)
                    {
                        PercentageChangeBlock.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        PercentageChangeBlock.Foreground = new SolidColorBrush(Colors.Green);
                    }
                    panel.Children.Add(PercentageChangeBlock);
                    WatchListList.Items.Add(panel);
                }
            }
        }
コード例 #20
0
        private void LoadInventory()
        {
            InventoryList.Items.Clear();
            MySqlDataReader reader     = DataBaseHandler.GetData("SELECT DISTINCT StockName FROM Inventories WHERE Quantity > 0 AND UserID = " + DataBaseHandler.UserID);
            List <string>   StockNames = new List <string>();

            while (reader.Read())
            {
                StockNames.Add((string)reader["StockName"]);
            }
            for (int i = 0; i < StockNames.Count; i++)
            {
                Console.WriteLine(i);
                string          s = StockNames[i];
                string          FullName = "";
                int             QuantityOwned = DataBaseHandler.GetCount("SELECT SUM(Quantity) From Inventories WHERE StockName = '" + s + "' AND UserID = " + DataBaseHandler.UserID);
                double          AverageCost = DataBaseHandler.GetCountDouble("SELECT AVG(LastTradedPrice) From Inventories WHERE StockName = '" + s + "' AND UserID = " + DataBaseHandler.UserID);
                double          CurrentPrice = 0, OpeningPrice = 0, High, Low;
                MySqlDataReader StockReader = DataBaseHandler.GetData("SELECT * FROM Stock WHERE StockName = '" + s + "'");
                while (StockReader.Read())
                {
                    FullName     = (string)StockReader["FullName"];
                    CurrentPrice = (double)StockReader["CurrentPrice"];
                    OpeningPrice = (double)StockReader["OpeningPriceToday"];
                    High         = (double)StockReader["HighToday"];
                    Low          = (double)StockReader["LowToday"];
                }
                double     Profit            = CurrentPrice - AverageCost;
                double     RealChangeInPrice = CurrentPrice - OpeningPrice;
                double     PercentageChange  = RealChangeInPrice / OpeningPrice;
                StackPanel Panel             = new StackPanel();
                Panel.Orientation = Orientation.Horizontal;
                Panel.Children.Add(Helper.CreateTextBlock(s, TextAlignment.Left, 100, 20));
                Panel.Children.Add(Helper.CreateTextBlock(FullName, TextAlignment.Left, 250, 20));
                Panel.Children.Add(Helper.CreateTextBlock(QuantityOwned.ToString(), TextAlignment.Left, 100, 20));
                Panel.Children.Add(Helper.CreateTextBlock(Math.Round(CurrentPrice, 2).ToString(), TextAlignment.Left, 125, 20));
                TextBlock RealChangeInPriceBlock = Helper.CreateTextBlock(Math.Round(RealChangeInPrice, 2).ToString(), TextAlignment.Left, 100, 20);
                if (RealChangeInPrice < 0)
                {
                    RealChangeInPriceBlock.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    RealChangeInPriceBlock.Foreground = new SolidColorBrush(Colors.Green);
                }
                Panel.Children.Add(RealChangeInPriceBlock);

                TextBlock PercentageChangeBlock = Helper.CreateTextBlock(Math.Round(PercentageChange, 2) + "%", TextAlignment.Left, 100, 20);
                if (RealChangeInPrice < 0)
                {
                    PercentageChangeBlock.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    PercentageChangeBlock.Foreground = new SolidColorBrush(Colors.Green);
                }
                Panel.Children.Add(PercentageChangeBlock);
                Panel.Children.Add(Helper.CreateTextBlock(Math.Round(Profit, 2).ToString(), TextAlignment.Left, 200, 20));
                InventoryList.Items.Add(Panel);
            }
        }
コード例 #21
0
        public void Search(SearchParams DataValue)
        {
            MySqlDataReader reader;

            if (DataValue.CustomSeach)
            {
                reader = DataBaseHandler.GetData(DataValue.Value);
            }
            else
            {
                reader = DataBaseHandler.GetData("SELECT StockName, FullName, CurrentPrice, OpeningPriceToday FROM Stock WHERE FullName LIKE '%" + DataValue.Value + "%' OR StockName LIKE '%" + DataValue.Value + "%'");
            }
            while (reader.Read())
            {
                string     Symbol            = (string)reader["StockName"];
                string     FullName          = (string)reader["FullName"];
                double     Price             = (double)reader["CurrentPrice"];
                double     OpeningPrice      = (double)reader["OpeningPriceToday"];
                double     RealChangeInPrice = Price - OpeningPrice;
                double     PercentageChange  = RealChangeInPrice / OpeningPrice;
                StackPanel panel             = new StackPanel();
                panel.Orientation = Orientation.Horizontal;
                panel.Children.Add(Helper.CreateTextBlock(Symbol, TextAlignment.Left, 100, 20));
                panel.Children.Add(Helper.CreateTextBlock(FullName, TextAlignment.Left, 350, 20));
                if (Price.ToString().Contains('.'))
                {
                    panel.Children.Add(Helper.CreateTextBlock("$" + Price.ToString().Split('.')[0] + '.' + Price.ToString().Split('.')[1].Substring(0, 4), TextAlignment.Left, 150, 20));
                }
                else
                {
                    panel.Children.Add(Helper.CreateTextBlock("$" + Price.ToString(), TextAlignment.Left, 150, 20));
                }
                TextBlock RealChangeInPriceBlock = Helper.CreateTextBlock(RealChangeInPrice.ToString(), TextAlignment.Left, 125, 20);
                if (RealChangeInPrice.ToString().Contains('.'))
                {
                    RealChangeInPriceBlock = Helper.CreateTextBlock(RealChangeInPrice.ToString().Substring(0, 6), TextAlignment.Left, 125, 20);
                }
                if (RealChangeInPrice < 0)
                {
                    RealChangeInPriceBlock.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    RealChangeInPriceBlock.Foreground = new SolidColorBrush(Colors.Green);
                }
                panel.Children.Add(RealChangeInPriceBlock);
                TextBlock PercentageChangeBlock;
                if (PercentageChange.ToString().Contains('.'))
                {
                    PercentageChangeBlock = Helper.CreateTextBlock(PercentageChange.ToString().Substring(0, 4) + "%", TextAlignment.Left, 100, 20);
                }
                else
                {
                    PercentageChangeBlock = Helper.CreateTextBlock(PercentageChange.ToString() + "%", TextAlignment.Left, 100, 20);
                }
                if (RealChangeInPrice < 0)
                {
                    PercentageChangeBlock.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    PercentageChangeBlock.Foreground = new SolidColorBrush(Colors.Green);
                }
                panel.Children.Add(PercentageChangeBlock);
                SearchResultList.Items.Add(panel);
            }
        }