Esempio n. 1
0
        private void ok_button_Click(object sender, EventArgs e)
        {
            int     numShares       = 0;
            int     stopPercentage  = 0;
            decimal buyPrice        = 0;
            decimal fixedStopPrice  = 0;
            bool    useTrailingStop = false;
            bool    useDividends    = false;
            bool    useOptions      = false;

            try
            {
                numShares = int.Parse(shares_textBox.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Number of shares is not a valid number");
                return;
            }

            try
            {
                buyPrice = decimal.Parse(buyPrice_textBox.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Buy price is not a valid number");
                return;
            }

            if (fixedPrice_radioButton.Checked)
            {
                try
                {
                    fixedStopPrice = decimal.Parse(fixedStopPrice_textBox.Text);
                }
                catch (FormatException)
                {
                    MessageBox.Show("Fixed stop price is not a valid number");
                    return;
                }
            }
            else
            {
                try
                {
                    stopPercentage = int.Parse(stopLossPercentage_textBox.Text);
                }
                catch (FormatException)
                {
                    MessageBox.Show("Stop loss percentage is not a valid number");
                    return;
                }
                useTrailingStop = useTrailingStop_checkBox.Checked;
                useDividends    = useDividends_checkBox.Checked;
                useOptions      = useOptionSales_checkBox.Checked;
            }


            // Add position to the database
            PositionsTable.AddRecord(
                symbol_textBox.Text,
                stopPercentage,
                useTrailingStop,
                buy_dateTimePicker.Value,
                numShares,
                buyPrice,
                useDividends,
                useOptions,
                fixedStopPrice
                );

            Close();
        }