Beispiel #1
0
        private void loadStockPortfoliosFromDB()
        {
            // connect to DB
            cn = getSGBDConnection();
            if (!verifySGBDConnection())
            {
                return;
            }

            // get all employees
            SqlCommand    cmd    = new SqlCommand("SELECT * FROM STOCK_PORTFOLIO", cn);
            SqlDataReader reader = cmd.ExecuteReader();

            listBox1.Items.Clear();

            // load employees
            while (reader.Read())
            {
                StockPortfolio stock = new StockPortfolio();
                stock.Id   = reader["id"].ToString();
                stock.Risk = reader["risk"].ToString();
                listBox1.Items.Add(stock);
            }

            // close connection to BD
            cn.Close();

            //Show first employee
            currentListEntry = 0;
            showEntry();
        }
Beispiel #2
0
        private void submitEntry(StockPortfolio stock)
        {
            if (!verifySGBDConnection())
            {
                return;
            }
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "INSERT STOCK_PORTFOLIO (id, risk) " +
                              "VALUES (@id, @risk) ";
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@id", stock.Id);
            cmd.Parameters.AddWithValue("@risk", Convert.ToDecimal(stock.Risk));
            cmd.Connection = cn;

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to update contact in database. \n ERROR MESSAGE: \n" + ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }
Beispiel #3
0
        /**
         * Loan Data Handling Helper Functions
         */
        private bool saveStockPortfolio()
        {
            StockPortfolio stock = new StockPortfolio();

            try
            {
                stock.Id   = idTxt.Text;
                stock.Risk = riskTxt.Text;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
            if (adding)
            {
                submitEntry(stock);
                loadStockPortfoliosFromDB();
            }
            else
            {
                updateStockPortfolio(stock);
                listBox1.Items[currentListEntry] = stock;
            }
            return(true);
        }
Beispiel #4
0
        /**
         * Interaction Helper Functions
         */
        // form field's content related
        private void showEntry()
        {
            if (listBox1.Items.Count == 0 | currentListEntry < 0)
            {
                return;
            }
            StockPortfolio stock = new StockPortfolio();

            stock        = (StockPortfolio)listBox1.Items[currentListEntry];
            idTxt.Text   = stock.Id;
            riskTxt.Text = stock.Risk;
        }
Beispiel #5
0
        private void updateStockPortfolio(StockPortfolio stock)
        {
            int rows = 0;

            if (!verifySGBDConnection())
            {
                return;
            }
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "UPDATE STOCK_PORTFOLIO " +
                              "SET risk = @risk " +
                              "WHERE id = @id";
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@id", stock.Id);
            cmd.Parameters.AddWithValue("@risk", Convert.ToDecimal(stock.Risk));
            cmd.Connection = cn;

            try
            {
                rows = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to update contact in database. \n ERROR MESSAGE: \n" + ex.Message);
            }
            finally
            {
                if (rows == 1)
                {
                    MessageBox.Show("Update OK");
                }
                else
                {
                    MessageBox.Show("Update NOT OK");
                }

                cn.Close();
            }
        }