/// <summary>
        /// Кeeps all the customer account information in the database
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="accountCustomer"></param>
        public static void SaveCustomerAccount(Customer customer, AccountCustomer accountCustomer)
        {
            string sqlSaveNewAccountCustomer =
                $"insert into user_account (Iban, FullName, Egn, Gender," +
                $" Address, PostalCode, City, Country, MobilePhone, " +
                $" HomePhone, Email, DataOfAccount) values " +
                $"(@Iban, " +
                $"@FullName, " +
                $"@Egn, " +
                $"@Gender, " +
                $"@Address, " +
                $"@PostalCode, " +
                $"@City, " +
                $"@Country, " +
                $"@MobilePhone, " +
                $"@HomePhone, " +
                $"@Email, " +
                $"@DataOfAccount);";

            MySqlCommand commandSaveNewCustomerAccount = GetCommand(sqlSaveNewAccountCustomer,
                                                                    new MySqlParameter[]
            {
                new MySqlParameter("@Iban", customer.account.Iban),
                new MySqlParameter("@FullName", customer.FirstName + " "
                                   + customer.MiddleName + " " + customer.LastName),
                new MySqlParameter("@Egn", customer.Egn),
                new MySqlParameter("@Gender", customer.gender.ToString()),
                new MySqlParameter("@Address", customer.Address),
                new MySqlParameter("@PostalCode", customer.PostalCode),
                new MySqlParameter("@City", customer.City),
                new MySqlParameter("@Country", customer.Country),
                new MySqlParameter("@MobilePhone", customer.MobilePhone),
                new MySqlParameter("@HomePhone", customer.HomePhone),
                new MySqlParameter("@Email", customer.Email),
                new MySqlParameter("@DataOfAccount", DateTime.Now),
            });

            commandSaveNewCustomerAccount.Connection.Open();
            commandSaveNewCustomerAccount.ExecuteScalar();
            commandSaveNewCustomerAccount.Connection.Close();
        }
Exemplo n.º 2
0
            public static decimal GetNewBalance(AccountCustomer accountSender, decimal amountTransfer)
            {
                decimal resultNewBalanceSender = 0;

                if (accountSender.Balance < amountTransfer)
                {
                    throw new ArgumentException("Invalid transfer." +
                                                " The transfer amount is greater than the balance !");
                }

                if (amountTransfer <= 2000)
                {
                    resultNewBalanceSender = (accountSender.Balance - amountTransfer) -
                                             (feeTransfer + ((amountTransfer * feeTo2000) / 100));
                }
                else
                {
                    resultNewBalanceSender = (accountSender.Balance - amountTransfer) -
                                             (feeTransfer + ((amountTransfer * feeOver2000) / 100));
                }

                return(resultNewBalanceSender);
            }
Exemplo n.º 3
0
            /// <summary>
            /// Retains the transfer service data in the database table
            /// and the transfer fee in another table
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="receiver"></param>
            /// <param name="amountTransfer"></param>
            public static void TransferMoney(AccountCustomer sender, AccountCustomer receiver,
                                             decimal amountTransfer)
            {
                try
                {
                    if (sender.Iban == null)
                    {
                        throw new ArgumentException("Sender IBAN is null.");
                    }

                    if (DataBaseOperations.getBalance(sender.Iban).Balance >= amountTransfer + GetFeeTransfer(amountTransfer))
                    {
                        string sqlSender = $"select idUserAccount from user_account where iban = @ibanSender;";

                        MySqlCommand command = DataBaseOperations.GetCommand(sqlSender,
                                                                             new MySqlParameter[] { new MySqlParameter("@ibanSender", sender.Iban) });

                        command.Connection.Open();

                        int pkSender = Convert.ToInt32(command.ExecuteScalar());

                        string sqlReseiver = $"select idUserAccount from user_account where iban = @ibanReceiver;";

                        command.CommandText = sqlReseiver;
                        command.Parameters.AddWithValue("@ibanReceiver", receiver.Iban);

                        int pkReceiver = Convert.ToInt32(command.ExecuteScalar());

                        //Transfer
                        string sqlTransfer = $"insert into transfer_customer" +
                                             $"(IDSender_Customer, IDRecipient_Customer, DataOfTransfer, Amount_Transfer) values (" +
                                             $"@IDSender_Customer," +
                                             $"@IDRecipient_Customer," +
                                             $"@DataOfTransfer," +
                                             $"@Amount_Transfer)";

                        MySqlParameter[] parametersTransfer =
                        {
                            new MySqlParameter("@IDSender_Customer",    pkSender),
                            new MySqlParameter("@IDRecipient_Customer", pkReceiver),
                            new MySqlParameter("@DataOfTransfer",       DateTime.Now),
                            new MySqlParameter("@Amount_Transfer",      amountTransfer.ToString().Replace(",", "."))
                        };

                        command.CommandText = sqlTransfer;
                        command.Parameters.AddRange(parametersTransfer);

                        command.ExecuteScalar();

                        //Get Fee
                        //INSERT
                        string sqlChargesTransfer = $"insert into fee_charges_transfer" +
                                                    $"(iduser_account, date_fee, amount) values (" +
                                                    $"@iduser_account," +
                                                    $"@date_fee," +
                                                    $"@amount)";

                        MySqlParameter[] parametersChargesTransfer =
                        {
                            new MySqlParameter("@iduser_account", pkSender),
                            new MySqlParameter("@date_fee",       DateTime.Now),
                            new MySqlParameter("@amount",         GetFeeTransfer(amountTransfer).ToString().Replace(",", "."))
                        };

                        command.CommandText = sqlChargesTransfer;
                        command.Parameters.AddRange(parametersChargesTransfer);

                        command.ExecuteScalar();
                        command.Connection.Close();
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
            }