Exemple #1
0
 private void WithdrawalButton_Click(object sender, EventArgs e)
 {
     if (ValidateTextBox())
     {
         String         name = (String)this.CurrentInvestmentsDataGridView.CurrentRow.Cells["Name"].Value;
         Investment     selectedInvestment = SqlConnector.GetInvestment(name);
         UserInvestment ui      = SqlConnector.GetUserInvestment(user.idUser, selectedInvestment.IdInvestment);
         double         tempVal = Double.Parse(this.ValueToWithdrawTextBox.Text);
         if (ui.ValuePLN == tempVal)
         {
             SqlConnector.FinishInvestment(ui.IdUserInvestment);
         }
         else if (tempVal > 0 && tempVal < ui.ValuePLN)
         {
             double am = tempVal / selectedInvestment.Value;
             SqlConnector.AddHistoryInvestment(ui, tempVal, am);
             SqlConnector.WithdrawPartOfInvestment(ui.IdUserInvestment, tempVal);
         }
         else
         {
             MessageBox.Show("Incorret data! Try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         InitializeList();
     }
     else
     {
         MessageBox.Show("Incorret data! Try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemple #2
0
        public static void UpdateDifference(UserInvestment ui)
        {
            using (IDbConnection connection = new MySqlConnection(GetConnectionString(ConnectionName)))
            {
                var p = new DynamicParameters();
                p.Add("id", ui.idUser);
                p.Add("investmentID", ui.IdInvestment);
                p.Add("amount", ui.Amount);

                connection.Execute("updateDifference", p, commandType: CommandType.StoredProcedure);
            }
        }
Exemple #3
0
        public static void EditUserInvestment(UserInvestment ui)
        {
            using (IDbConnection connection = new MySqlConnection(GetConnectionString(ConnectionName)))
            {
                var p = new DynamicParameters();
                p.Add("idInv", ui.IdInvestment);
                p.Add("valPLN", ui.ValuePurcharsed);
                p.Add("am", ui.Amount);
                p.Add("valP", ui.ValuePLN);

                connection.Execute("EditUserInvestment", p, commandType: CommandType.StoredProcedure);
            }
        }
Exemple #4
0
        public static void AddHistoryInvestment(UserInvestment ui, double vPLN, double am)
        {
            using (IDbConnection connection = new MySqlConnection(GetConnectionString(ConnectionName)))
            {
                var p = new DynamicParameters();
                p.Add("idU", ui.idUser);
                p.Add("idInv", ui.IdInvestment);
                p.Add("valPLN", ui.ValuePLN);
                p.Add("fullAmount", ui.Amount);
                p.Add("valS", vPLN);
                p.Add("am", am);
                p.Add("dateP", ui.DatePurchased);

                connection.Execute("addHistoryInvestment", p, commandType: CommandType.StoredProcedure);
            }
        }
Exemple #5
0
        public static UserInvestment AddUserInvestment(UserInvestment UserInvestment)
        {
            using (IDbConnection connection = new MySqlConnection(GetConnectionString(ConnectionName)))
            {
                var p = new DynamicParameters();
                p.Add("idUser", UserInvestment.idUser);
                p.Add("idInvestment", UserInvestment.IdInvestment);
                p.Add("datePurchased", UserInvestment.DatePurchased);
                p.Add("valPurchased", UserInvestment.ValuePurcharsed);
                p.Add("Amount", UserInvestment.Amount);
                p.Add("valPLN", UserInvestment.ValuePLN);
                p.Add("id", 0, DbType.Int32, ParameterDirection.Output);

                connection.Execute("addUserInvestment", p, commandType: CommandType.StoredProcedure);
                UserInvestment.IdUserInvestment = p.Get <int>("id");

                return(UserInvestment);
            }
        }
        private void AddInvestmentButton_Click(object sender, EventArgs e)
        {
            if (ValidateUserInvestment())
            {
                try
                {
                    Investment     i  = (Investment)this.NameComboBox.SelectedItem;
                    UserInvestment ui = new UserInvestment();
                    ui.IdInvestment    = i.IdInvestment;
                    ui.idUser          = this.user.idUser;
                    ui.ValuePLN        = Double.Parse(this.InvValueTextBox.Text);
                    ui.ValuePurcharsed = Double.Parse(this.RateTextBox.Text);
                    ui.Amount          = Double.Parse(this.AmountTextBox.Text);
                    ui.DatePurchased   = this.InvestDateTimePicker.Value;
                    if (!FindInvestment(i.IdInvestment))
                    {
                        ui = SqlConnector.AddUserInvestment(ui);
                    }
                    else
                    {
                        SqlConnector.EditUserInvestment(ui);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Something went wrong", "Duplicate error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Incorret data! Try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            this.InvValueTextBox.Text       = "";
            this.RateTextBox.Text           = "";
            this.AmountTextBox.Text         = "";
            this.InvestDateTimePicker.Value = DateTime.Today;
        }