예제 #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 EmptyCurrentAccount(int client_id, int destinaryAccount)
        {
            string          queryString = $"SELECT amount FROM CurrentAccounts WHERE client_id = {client_id};";
            double          amount      = (double)ConnectionDB.ReturnDecimal(queryString);
            string          queryStringGetCurrentAccountId = $"SELECT id FROM CurrentAccounts WHERE client_id = {client_id};";
            int             currentAccountId = ConnectionDB.ReturnID(queryStringGetCurrentAccountId);
            InstantTransfer instant          = new InstantTransfer();

            instant.RecordTransferFromCurrentToCurrent(currentAccountId, destinaryAccount, amount);
        }
예제 #5
0
        public void EmptySavingAccount(int client_id)
        {
            List <int> idSavingAccount = ConnectionDB.GetSavingAccountIds(client_id);
            string     queryStringGetCurrentAccountId = $"SELECT id FROM CurrentAccounts WHERE client_id = {client_id}";
            int        currentAccountId = ConnectionDB.ReturnID(queryStringGetCurrentAccountId);

            foreach (int id in idSavingAccount)
            {
                string          queryString = $"SELECT amount FROM SavingAccounts WHERE id = {id};";
                double          amount      = (double)ConnectionDB.ReturnDecimal(queryString);
                InstantTransfer instant     = new InstantTransfer();
                instant.RecordTransferFromSavingToCurrent(id, currentAccountId, amount);
            }
        }
예제 #6
0
        public static void Login(String userName)
        {
            Console.Write("Enter your password : "******"SELECT id FROM Person WHERE name = '{userName}' AND password ='******';";
            int    id          = ConnectionDB.ReturnID(queryString);

            Person.ID = id;
        }
예제 #7
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);
        }
예제 #8
0
        public static bool AddFromBeneficiary(int emitterId, int beneficiaryId)
        {
            string queryString1 = $"SELECT client_id FROM SavingAccounts WHERE id={beneficiaryId};";
            int    client_id    = ConnectionDB.ReturnID(queryString1);
            string queryString  = $"SELECT id FROM Donator WHERE client_id={client_id} and donatorCA_id={emitterId} ;";

            try
            {
                int id = ConnectionDB.ReturnID(queryString);
                return(true);
            }
            catch
            {
                throw new ArgumentException("Selected Account is invalid");
            }
        }
예제 #9
0
        public static int GetAccountOwnerId(int currentAccountId, AccountType type)
        {
            String tableName;

            if (type == AccountType.Current)
            {
                tableName = "CurrentAccounts";
            }
            else if (type == AccountType.Saving)
            {
                tableName = "SavingAccounts";
            }
            else
            {
                throw new ArgumentException("Account type not valid");
            }

            string queryString    = $"SELECT client_id FROM {tableName} WHERE id=" + currentAccountId;
            int    accountOwnerId = ConnectionDB.ReturnID(queryString);

            return(accountOwnerId);
        }