コード例 #1
0
        /// <summary>
        /// This function deletes all the user's currently saved stocks and calls the
        /// database manager to add rows in the table for each of the stocks selected to
        /// save effectively replacing old entries with new. does not add anything if the
        /// stocks list is empty, but it will still delete all currently saved stocks (if any).
        /// </summary>
        /// <param name="stocks">List of all stock ID's to add to the current User's saved
        /// stocks list. if empty, currently saved stocks are deleted and none are added.</param>
        public void saveNewStocks(List <int> stocks)
        {
            cDatabaseManager db = new cDatabaseManager();

            db.deleteStocksForUser(cUser.UserID);
            if (stocks.Count > 0)
            {
                db.saveStocksForUser(stocks, cUser.UserID);
            }
        }
コード例 #2
0
        /// <summary>
        /// Called when the add stock button is pressed. If the user has
        /// less than 20 stocks already saved, the add stock window appears
        /// and the user can select a new stock to add to their favorites list.
        /// </summary>
        /// <param name="sender">Default param.</param>
        /// <param name="e">Default param.</param>
        private void btn_AddStock_Click(object sender, EventArgs e)
        {
            if (gridView_SavedStocks.Rows.Count < 20)                   //if user has less than 20 stocks saved
            {
                fAddStock add = new fAddStock();

                if (add.ShowDialog() == DialogResult.OK)                 //open new stock window, check for close OK (no cancel)
                {
                    cDatabaseManager db = new cDatabaseManager();

                    List <int> save_stocks = new List <int>();
                    save_stocks.Add(add.sID);                        //get selected stock id from add stock window
                    db.saveStocksForUser(save_stocks, cUser.UserID); //save it to db
                    updateSavedStocksGrid();                         // update stock grid to reflect changes
                }
            }
            else
            {
                //more than 20 stocks saved
                MessageBox.Show("Cannot save more than 20 stocks", "Stop");
            }
        }