private void AddTypeButton_Click(object sender, EventArgs e)
        {
            if (ValidateInvestmentType())
            {
                try
                {
                    InvestmentType type = new InvestmentType()
                    {
                        InvName = this.TypeNameTextBox.Text
                    };

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

            this.TypeNameTextBox.Text = "";
        }
        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 = "";
        }
Example #3
0
        public static InvestmentType CreateInvestmentType(InvestmentType investemntType)
        {
            using (IDbConnection connection = new MySqlConnection(GetConnectionString(ConnectionName)))
            {
                var p = new DynamicParameters();
                p.Add("invName", investemntType.InvName);
                p.Add("id", 0, DbType.Int32, ParameterDirection.Output);

                connection.Execute("addInvestmentType", p, commandType: CommandType.StoredProcedure);
                investemntType.IdInvestmentType = p.Get <int>("id");

                return(investemntType);
            }
        }