private void LoadWatchList()
 {
     if (DataBaseHandler.GetCount("SELECT COUNT(User) FROM WatchList WHERE User = "******" AND StockName = '" + StockName + "'") != 0)
     {
         WatchListButton.Content = "Remove From Watch List";
     }
 }
Exemple #2
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);
     }
 }
        //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;
                }
            }
        }
 private void WatchListClick(object sender, RoutedEventArgs e)
 {
     if (DataBaseHandler.GetCount("SELECT COUNT(User) FROM WatchList WHERE User = "******" AND StockName = '" + StockName + "'") == 0)
     {
         DataBaseHandler.SetData(string.Format("INSERT INTO WatchList (User, StockName) VALUES ({0}, '{1}')", DataBaseHandler.UserID, StockName));
         WatchListButton.Content = "Remove From Watch List";
     }
     else
     {
         DataBaseHandler.SetData(string.Format("DELETE FROM WatchList WHERE User = {0} AND StockName = '{1}'", DataBaseHandler.UserID, StockName));
         WatchListButton.Content = "Add To Watch List";
     }
 }
Exemple #5
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;
            }
        }
        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;
            }
        }
        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);
        }
Exemple #8
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);
        }
Exemple #9
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     if (Helper.FirstLoad)
     {
         SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
         SystemNavigationManager.GetForCurrentView().BackRequested += (s, ev) => {
             if (Frame.CanGoBack)
             {
                 Frame.GoBack();
                 ev.Handled = true;
             }
         };
         Helper.FirstLoad = false;
     }
     if (DataBaseHandler.GetCount("SELECT SUM(Admin) FROM Users WHERE ID = " + DataBaseHandler.UserID) == 0)
     {
         AdminButton.IsEnabled  = false;
         AdminButton.Background = new SolidColorBrush(Colors.White);
         AdminButton.Content    = "";
     }
     LoadBiggestRiser();
     LoadBiggestFallers();
 }
Exemple #10
0
        private async void CreateButtonClicked(object sender, RoutedEventArgs e)
        {
            string Symbol      = SymbolBlock.Text;
            string FullName    = NameBlock.Text;
            int    Taken       = DataBaseHandler.GetCount("SELECT COUNT(*) FROM Stock WHERE StockName = '" + Symbol + "'");
            string Description = DescriptionBlock.Text;

            if (Symbol.Length != 6)
            {
                MessageDialog message = new MessageDialog("Symbol must be exactly 6 letters long");
                await message.ShowAsync();

                return;
            }
            if (Taken == 1)
            {
                MessageDialog message = new MessageDialog("Symbol is taken, try another name");
                await message.ShowAsync();

                return;
            }
            if (FullName.Length == 0)
            {
                MessageDialog message = new MessageDialog("Name is required");
                await message.ShowAsync();

                return;
            }
            if (Description.Length == 0)
            {
                MessageDialog message = new MessageDialog("Description is required");
                await message.ShowAsync();

                return;
            }
            float StartingPrice;
            int   IPOQuantity;

            if (!(float.TryParse(PriceBlock.Text, out StartingPrice) && StartingPrice > 0))
            {
                MessageDialog message = new MessageDialog("Price is not valid");
                await message.ShowAsync();

                return;
            }
            if ((!(int.TryParse(QuantityBlock.Text, out IPOQuantity) && IPOQuantity > 0) || !NewStock))
            {
                MessageDialog message = new MessageDialog("IPO Quantity is not valid");
                await message.ShowAsync();

                return;
            }
            if (!NewStock)
            {
                DataBaseHandler.SetData("DELETE FROM Stock WHERE StockName = '" + OriginalStockName + "'");
                DataBaseHandler.SetData("UPDATE Inventories SET StockName = + '" + Symbol + "' Where StockName = '" + OriginalStockName + "'");
                DataBaseHandler.SetData("UPDATE Trades SET StockName = + '" + Symbol + "' Where StockName = '" + OriginalStockName + "'");
                DataBaseHandler.SetData("UPDATE WatchList SET StockName = + '" + Symbol + "' Where StockName = '" + OriginalStockName + "'");
                DataBaseHandler.SetData("UPDATE Pool SET StockName = + '" + Symbol + "' Where StockName = '" + OriginalStockName + "'");
                DataBaseHandler.SetData("UPDATE PricingHistory SET StockName = + '" + Symbol + "' Where StockName = '" + OriginalStockName + "'");
            }
            else
            {
                DataBaseHandler.SetData(string.Format("INSERT INTO Inventories(UserID, StockName, Quantity, LastTradedPrice) VALUES ({0}, '{1}', {2}, {3})", IPOQuantity, Symbol, 1, StartingPrice));
            }
            DataBaseHandler.SetData(string.Format("INSERT INTO Stock(StockName, FullName, Description, CurrentPrice, OpeningPriceToday, HighToday, LowToday, VolumeTraded) VALUES ('{0}', '{1}', '{2}', {3}, {4}, {5}, {6}, {7})", Symbol, FullName, Description, StartingPrice, StartingPrice, 0f, float.MaxValue, 0));
            this.Frame.Navigate(typeof(Pages.Admin.StockListPage));
        }
        private async void CreateButtonClicked(object sender, RoutedEventArgs e)
        {
            uint   MinAmount        = 0;
            uint   MaxAmount        = 0;
            double ShortRequirement = 0;
            double LongRequirement  = 0;
            double Aggresion        = 0;
            string email            = "AlgoTrader" + (string)StockNameBox.SelectedItem + "@" + 100 + ".com";
            int    UserId           = DataBaseHandler.GetCount(string.Format("INSERT INTO Users(NickName, Email, Password, Balance, Admin, LMM) VALUES ('{0}', '{1}', '{2}', {3}, {4}, {5}); SELECT LAST_INSERT_ID();", "AlgoTrader", email, "Password", 1000000, 0, 0.20f));

            if ((string)StockNameBox.SelectedItem == "")
            {
                MessageDialog message = new MessageDialog("No Stock Selected");
                await message.ShowAsync();

                return;
            }
            if (double.TryParse(ShortRequirementBox.Text, out ShortRequirement))
            {
                MessageDialog message = new MessageDialog("Short Requirement needs to be a number");
                await message.ShowAsync();

                return;
            }
            if (ShortRequirement > 1.1f && ShortRequirement < 2.1f)
            {
                MessageDialog message = new MessageDialog("Short Requirement needs to be between 1.1 and 2.1");
                await message.ShowAsync();

                return;
            }
            if (double.TryParse(ShortRequirementBox.Text, out LongRequirement))
            {
                MessageDialog message = new MessageDialog("Long Requirement needs to be a number");
                await message.ShowAsync();

                return;
            }
            if (LongRequirement > 1.1f && LongRequirement < 2.1f)
            {
                MessageDialog message = new MessageDialog("Long Requirement needs to be between 1.9 and 2.9");
                await message.ShowAsync();

                return;
            }
            if (uint.TryParse(MinAmountBox.Text, out MinAmount))
            {
                MessageDialog message = new MessageDialog("Minimum Amount needs to be a integer");
                await message.ShowAsync();

                return;
            }
            if (uint.TryParse(MinAmountBox.Text, out MaxAmount))
            {
                MessageDialog message = new MessageDialog("Maximum Amount needs to be a integer");
                await message.ShowAsync();

                return;
            }
            if (MaxAmount < MinAmount)
            {
                MessageDialog message = new MessageDialog("Minimum Amount needs smaller than Max Amount");
                await message.ShowAsync();

                return;
            }
            if (double.TryParse(AggresionBox.Text, out Aggresion))
            {
                MessageDialog message = new MessageDialog("Aggresion needs to be a number");
                await message.ShowAsync();

                return;
            }
            if (LongRequirement > 1.1f && LongRequirement < 2.1f)
            {
                MessageDialog message = new MessageDialog("Aggresion needs to be between 0 and 1");
                await message.ShowAsync();

                return;
            }
            DataBaseHandler.SetData(string.Format("INSERT INTO AlgoTrader(Target, UserID, ShortRequirement, LongRequirement, MinAmount, MaxAmount, Aggresion) VALUES ('{0}', {1}, {2}, {3}, {4}, {5}, {6})", (string)StockNameBox.SelectedItem, UserId, ShortRequirement, LongRequirement, MinAmount, MaxAmount, Aggresion));
            this.Frame.Navigate(typeof(Pages.Admin.AlgoTraderManager));
        }
        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);
            }
        }