Пример #1
0
        public void CreateSavingAccount(int client_id, decimal amount, decimal ceiling)
        {
            DateTime openingDate = DateTime.Now;

            if (amount <= ceiling)
            {
                string queryString = $"INSERT INTO SavingAccounts (client_id, amount, rate, ceiling, openingDate) " +
                                     $"VALUES ({client_id}, {amount}, {Interest}, {ceiling},'{openingDate}');";
                ConnectionDB.NonQuerySQL(queryString);

                string queryStringID    = $"SELECT id FROM CurrentAccounts WHERE client_id={client_id};";
                int    currentAccountId = ConnectionDB.ReturnID(queryStringID);

                string queryStringAddInDonator = $"Declare @ClientId int " +
                                                 $"SELECT @ClientId = client_id FROM Donator WHERE client_id = {client_id} " +
                                                 $"IF(@ClientId IS NULL) " +
                                                 $"BEGIN " +
                                                 $"INSERT INTO Donator(client_id, donatorCA_id) VALUES({client_id}, {currentAccountId}) " +
                                                 $"END ;";
                ConnectionDB.NonQuerySQL(queryStringAddInDonator);
            }
            else
            {
                Console.WriteLine("You can' t create a savign account when the amount is bigger than the ceiling");
            }
        }
Пример #2
0
        public static void ModifyPassword()
        {
            int ID = Person.ID;

            Console.WriteLine("Enter your password : "******"SELECT id FROM Person WHERE id = '{ID}' AND password ='******';";
            int    id          = ConnectionDB.ReturnID(queryString);

            if (ID == id)
            {
                Console.WriteLine("Enter your new password : "******"UPDATE Person SET password = '******' WHERE id = '{ID}';";
                ConnectionDB.NonQuerySQL(newqueryString);
            }
            else
            {
                Console.WriteLine("password is wrong");
            }
        }
Пример #3
0
        public void WithdrawMoney(double amount)
        {
            int     client_id     = ID;
            string  queryString1  = $"SELECT amount FROM CurrentAccounts WHERE client_id={ client_id};";
            decimal currentAmount = ConnectionDB.ReturnDecimal(queryString1);

            string  queryString2 = $"SELECT overdraft FROM CurrentAccounts WHERE client_id={ client_id};";
            decimal overdraft    = ConnectionDB.ReturnDecimal(queryString2);

            string queryString3     = $"SELECT id FROM CurrentAccounts WHERE client_id={ client_id};";
            int    currentAccountID = ConnectionDB.ReturnID(queryString3);

            if (Convert.ToDouble(currentAmount - overdraft) >= amount)
            {
                DateTime dateOp      = DateTime.Now;
                string   queryString = $"UPDATE CurrentAccounts SET amount = (amount - {amount}) WHERE  client_id = {  client_id }; " +
                                       $"INSERT INTO \"Transaction\" (currentAccount_id, transactionType, amount, executionDate, \"status\") " +
                                       $"VALUES({currentAccountID}, 'withdraw', {amount}, '{dateOp}', \'done\')";
                ConnectionDB.NonQuerySQL(queryString);
            }
            else
            {
                Console.WriteLine("Not enough money on current account.");
            }
        }
Пример #4
0
        public void DeleteClient(int client_id, int destinaryAccount)
        {
            EmptySavingAccount(client_id);
            EmptyCurrentAccount(client_id, destinaryAccount);
            string queryString = $"UPDATE Person SET IsActive = 0 WHERE id = {client_id}";

            ConnectionDB.NonQuerySQL(queryString);
        }
Пример #5
0
        public void CreateCurrentAccount(int client_id, double amount, decimal overdraft)
        {
            DateTime openingDate = DateTime.Today;

            string queryString = $"INSERT INTO CurrentAccounts (client_id, amount, overdraft, openingDate) " +
                                 $" VALUES ({client_id}, {amount}, {overdraft}, '{openingDate}');";

            ConnectionDB.NonQuerySQL(queryString);
        }
Пример #6
0
        public void CreateClient(string name, double amount, decimal overdraft)
        {
            PasswordGenerator();
            string password = CryptPassword(Password);

            string queryString = $"INSERT INTO Person (name, password) VALUES ('{name}', '{password}');";

            ConnectionDB.NonQuerySQL(queryString);
            queryString = $"SELECT id FROM Person WHERE name = '{name}' AND password = '******';";
            int client_id = ConnectionDB.ReturnID(queryString);

            CurrentAccount currentAccount = new CurrentAccount();

            currentAccount.CreateCurrentAccount(client_id, amount, overdraft);
        }
Пример #7
0
        public void QueryTransferFromSavingToCurrent(int emitterId, int beneficiaryId, double amount, DateTime executionDate)
        {
            string  checkSavingAccountContent = $"SELECT amount FROM SavingAccounts WHERE id = {emitterId}";
            decimal savingAccountAmount       = ConnectionDB.ReturnDecimal(checkSavingAccountContent);

            if ((Convert.ToDouble(savingAccountAmount) - amount) >= 0)
            {
                string queryString =
                    $"INSERT INTO \"Transaction\" (savingAccount_id, transactionType, beneficiaryCurrentAccount_id, amount, executionDate, status) " +
                    $"VALUES (" +
                    $"{emitterId}, " +
                    $"\'Money Transfer\', " +
                    $"{beneficiaryId}, " +
                    $"{amount}, " +
                    $"\'{executionDate}\'," +
                    $"\'pending\');";
                ConnectionDB.NonQuerySQL(queryString);
            }
        }
Пример #8
0
        public void QueryTransferFromCurrentToSaving(int emitterId, int beneficiaryId, double amount, DateTime firstExecution, DateTime lastExecution, Int32 interval)
        {
            string  checkCurrentAccountContent = $"SELECT amount FROM CurrentAccounts WHERE id = {emitterId}";
            decimal CurrentAccountContent      = ConnectionDB.ReturnDecimal(checkCurrentAccountContent);
            string  getCurrentAccountOverdraft = $"SELECT overdraft FROM CurrentAccounts WHERE id = {emitterId}";
            decimal CurrentAccountOverdraft    = ConnectionDB.ReturnDecimal(getCurrentAccountOverdraft);

            string  checkSavingAccountContent = $"SELECT amount FROM SavingAccounts WHERE id = {beneficiaryId}";
            decimal SavingAccountContent      = ConnectionDB.ReturnDecimal(checkSavingAccountContent);
            string  checkSavingAccountCeiling = $"SELECT ceiling FROM SavingAccounts WHERE id = {beneficiaryId}";
            decimal SavingAccountCeiling      = ConnectionDB.ReturnDecimal(checkSavingAccountCeiling);

            bool IsValidDonator = Client.AddFromBeneficiary(emitterId, beneficiaryId);

            if (Convert.ToDouble(CurrentAccountContent - CurrentAccountOverdraft) >= amount && IsValidDonator)
            {
                if (((Convert.ToDouble(SavingAccountContent)) + amount) < Convert.ToDouble(SavingAccountCeiling))
                {
                    string queryString =
                        $"INSERT INTO \"Transaction\" (currentAccount_id, transactionType, beneficiarySavingAccount_id, amount, executionDate, lastExecutionDate, intervalDays, status) " +
                        $"VALUES (" +
                        $"{emitterId}, " +
                        $"'Money Transfer', " +
                        $"{beneficiaryId}, " +
                        $"{amount}, " +
                        $"'{firstExecution}'," +
                        $"'{lastExecution}'," +
                        $"{interval}," +
                        $"'pending');";
                    ConnectionDB.NonQuerySQL(queryString);
                }
                else
                {
                    Console.WriteLine($"Impossible transfer. Transfer would exceed ceiling limit.");
                }
            }
            else
            {
                Console.WriteLine($"There is not enough money on current account to perform transfer");
            }
        }
Пример #9
0
        public void QueryTransferFromSavingToCurrent(int emitterId, int beneficiaryId, double amount, DateTime firstExecution, DateTime lastExecution, Int32 interval)
        {
            string  checkSavingAccountContent = $"SELECT amount FROM SavingAccounts WHERE id = {emitterId}";
            decimal SavingAccountContent      = ConnectionDB.ReturnDecimal(checkSavingAccountContent);

            if ((Convert.ToDouble(SavingAccountContent) - amount) >= 0)
            {
                string queryString =
                    $"INSERT INTO \"Transaction\" (savingAccount_id, transactionType, beneficiaryCurrentAccount_id, amount, executionDate, lastExecutionDate, intervalDays, status) " +
                    $"VALUES (" +
                    $"{emitterId}, " +
                    $"'Money Transfer', " +
                    $"{beneficiaryId}, " +
                    $"{amount}, " +
                    $"'{firstExecution}'," +
                    $"'{lastExecution}'," +
                    $"{interval}," +
                    $"'pending');";
                ConnectionDB.NonQuerySQL(queryString);
            }
        }
Пример #10
0
        public void QueryTransferFromCurrentToCurrent(int emitterId, int beneficiaryId, double amount, DateTime firstExecution, DateTime lastExecution, Int32 interval)
        {
            int     debitClient_id             = Person.ID;
            string  checkCurrentAccountContent = $"SELECT amount FROM CurrentAccounts WHERE id = {emitterId}";
            decimal CurrentAccountContent      = ConnectionDB.ReturnDecimal(checkCurrentAccountContent);
            string  getCurrentAccountOverdraft = $"SELECT overdraft FROM CurrentAccounts WHERE id = {emitterId}";
            decimal CurrentAccountOverdraft    = ConnectionDB.ReturnDecimal(getCurrentAccountOverdraft);

            if (Convert.ToDouble(CurrentAccountContent + CurrentAccountOverdraft) > amount)
            {
                string queryString =
                    $"INSERT INTO \"Transaction\" (currentAccount_id, transactionType, beneficiaryCurrentAccount_id, amount, executionDate, lastExecutionDate, intervalDays, status) " +
                    $"VALUES (" +
                    $"{emitterId}, " +
                    $"'Money Transfer', " +
                    $"{beneficiaryId}, " +
                    $"{amount}, " +
                    $"'{firstExecution}'," +
                    $"'{lastExecution}'," +
                    $"{interval}," +
                    $"'pending');";
                ConnectionDB.NonQuerySQL(queryString);
            }
        }
Пример #11
0
        public static void AddDonators(int donatorCurrentAccountId)
        {
            string queryStringDonator = $"INSERT INTO Donator (client_id, donatorCA_id) VALUES ({Client.ID},{donatorCurrentAccountId});";

            ConnectionDB.NonQuerySQL(queryStringDonator);
        }
Пример #12
0
        public void DeleteSavingAccount(int account_id)
        {
            string queryString = $"DELETE FROM SavingAccounts WHERE id ='{account_id}';";

            ConnectionDB.NonQuerySQL(queryString);
        }