public bool AddWatchlist(Asset asset)
        {
            List <WatchList> globalList = Globals.WatchList;

            WatchList tmpWatchlist = new WatchList();

            tmpWatchlist.Symbol = asset.Symbol;
            tmpWatchlist.Name   = asset.Name;

            SqlCommand cmdGetWatchlist = new SqlCommand("SELECT * FROM AssetWatchList WHERE Symbol='" + asset.Symbol + "' AND UserId='" + Auth.Id + "'", conn);

            using (SqlDataReader reader = cmdGetWatchlist.ExecuteReader())
            {
                if (!reader.HasRows)
                {
                    //
                    reader.Close();
                    SqlCommand cmdInsert = new SqlCommand("INSERT INTO AssetWatchList (UserId, Symbol, Name, Date) VALUES (@UserId, @Symbol, @Name, @Date)", conn);
                    cmdInsert.Parameters.AddWithValue("UserId", Auth.Id);
                    cmdInsert.Parameters.AddWithValue("Symbol", tmpWatchlist.Symbol);
                    cmdInsert.Parameters.AddWithValue("Name", tmpWatchlist.Name);
                    DateTime curDate = DateTime.Now;
                    cmdInsert.Parameters.AddWithValue("Date", curDate);

                    cmdInsert.ExecuteNonQuery();

                    globalList.Add(tmpWatchlist);

                    return(true);
                }

                return(false);
            }
        }
Exemplo n.º 2
0
        private void LvWatchlist_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            WatchList item = lvWatchlist.SelectedItem as WatchList;

            if (item == null)
            {
                return;
            }

            tbMarketPrice.Text = Globals.Db.GetLastDateClosingValue(item.Symbol).ToString();
            tbSymbol.Text      = item.Symbol;
        }
Exemplo n.º 3
0
        private void LvWatchlist_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            WatchList item = lvWatchlist.SelectedItem as WatchList;

            if (item == null)
            {
                return;
            }

            lblSymbolAssign.Content = item.Symbol;
            lblNameAssign.Content   = item.Name;
            lblDateAssign.Content   = item.Date;
            lblOpenPrice.Content    = item.OpenPrice;
            lblHighPrice.Content    = item.HighPrice;
            lblLowPrice.Content     = item.LowPrice;
        }
Exemplo n.º 4
0
        private void BtnBuy_Click(object sender, RoutedEventArgs e)
        {
            WatchList item = lvWatchlist.SelectedItem as WatchList;

            if (item == null)
            {
                return;
            }

            Portfolio tmpPortfolio = new Portfolio();

            if (!int.TryParse(tbNumOfShares.Text, out int NumOfShares))
            {
                MessageBox.Show("Please input a valid number for shares", "Portfolio Asset Management System");
                return;
            }
            if (!double.TryParse(tbPurchasePrice.Text, out double PurchasePrice))
            {
                MessageBox.Show("Please input a valid number for Purchase Price", "Portfolio Asset Management System");
                return;
            }
            if (!double.TryParse(tbSellPrice.Text, out double SellPrice))
            {
                MessageBox.Show("Please input a valid number for Sell Price", "Portfolio Asset Management System");
                return;
            }
            if (!double.TryParse(tbMarketPrice.Text, out double ClosePrice))
            {
                ClosePrice = 0.00;
                //return;
            }
            tmpPortfolio.Symbol        = tbSymbol.Text;
            tmpPortfolio.NumOfShares   = NumOfShares;
            tmpPortfolio.PurchasePrice = PurchasePrice;
            tmpPortfolio.SellPrice     = 0.00;
            tmpPortfolio.ClosePrice    = ClosePrice;
            Globals.Db.AddPortfolio(tmpPortfolio);

            RefreshPortfolio();

            //tbMarketPrice.Text = Globals.Db.GetLastDateClosingValue(tmpPortfolio.Symbol).ToString();
            // tbSymbol.Text = item.Symbol;
        }
        public List <WatchList> GetWatchlist()
        {
            List <WatchList> lstWatchlist = new List <WatchList>();

            if (!Auth.IsLogged)
            {
                return(null);
            }

            SqlCommand cmdGetWatchlist = new SqlCommand("  SELECT * FROM AssetWatchList as AW " +
                                                                                                       // " INNER JOIN MarketHistory as MH ON AW.Symbol = MH.Symbol "+
                                                        " WHERE AW.UserId = '" + Auth.Id + "'", conn); //"' AND convert(varchar, AW.Date, 23) = MH.Date", conn);

            using (SqlDataReader reader = cmdGetWatchlist.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        WatchList tmpWatchList = new WatchList();
                        tmpWatchList.Id     = (int)reader["Id"];
                        tmpWatchList.Symbol = (string)reader["Symbol"];
                        tmpWatchList.Name   = (string)reader["Name"];
                        tmpWatchList.Date   = (DateTime)reader["Date"];
                        //tmpWatchList.OpenPrice = double.Parse(reader["OpenPrice"].ToString());
                        // tmpWatchList.HighPrice = double.Parse(reader["HighPrice"].ToString());
                        // tmpWatchList.LowPrice = double.Parse(reader["LowPrice"].ToString());
                        // tmpWatchList.ClosePrice = double.Parse(reader["ClosePrice"].ToString());
                        // tmpWatchList.Volume = (int)reader["Volume"];

                        lstWatchlist.Add(tmpWatchList);
                    }
                    return(lstWatchlist);
                }
            }

            return(null);
        }