コード例 #1
0
        private void CreateInvestmentbutton_Click(object sender, EventArgs e)
        {
            if (ValidateInvestment())
            {
                try
                {
                    Investment investment = new Investment();
                    investment.InvName = this.NameTextBox.Text;
                    InvestmentType t = (InvestmentType)this.InvestemntTypeComboBox.SelectedItem;
                    investment.IdInvestmentType = t.IdInvestmentType;
                    investment.DataSource       = this.DataSourceTextBox.Text;
                    Currency c = (Currency)this.CurrencyComboBox.SelectedItem;
                    investment.IdCurrency = c.IdCurrency;

                    investment.InitializeValue();
                    investment = SqlConnector.CreateInvestment(investment);
                    availableInvestments.Add(investment);
                    InitializeLists();
                }
                catch (MySql.Data.MySqlClient.MySqlException)
                {
                    MessageBox.Show("This investemnt already exists", "Duplicate error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Incorret data! Try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            this.NameTextBox.Text       = "";
            this.DataSourceTextBox.Text = "";
            this.InvestemntTypeComboBox.SelectedItem = "";
        }