コード例 #1
0
 public List <ViewObject> viewTransactions(int acct)
 {
     try
     {
         List <ViewObject> viewObjects = new List <ViewObject>();
         if (CheckIfExists(acct) == false)
         {
             return(null);
         }
         viewCommand.Parameters[0].Value = acct;
         viewCommand.Parameters[1].Value = acct;
         rd = viewCommand.ExecuteReader();
         while (rd.Read())
         {
             ViewObject temp = new ViewObject(rd.GetInt16(0), rd.GetInt16(1), rd.GetString(2).TrimEnd(), rd.GetInt16(3), rd.GetString(4).TrimEnd(), rd.GetDouble(5), rd.GetDateTime(6));
             viewObjects.Add(temp);
         }
         rd.Close();
         return(viewObjects);
     }
     catch (EmpressException e)
     {
         //Console.WriteLine("Error code :" + e.ErrorCode);
         //Console.WriteLine("Error message: " + e.Message);
         //Console.WriteLine(e.StackTrace);
     }
     catch (Exception e)
     {
         //Console.WriteLine("Error message: " + e.Message);
         //Console.WriteLine(e.StackTrace);
     }
     return(null);
 }
コード例 #2
0
        private bool CheckIfExists(int Acct_No)
        {
            command.Connection  = connection;
            command.CommandText = "SELECT * FROM Customer_Accounts WHERE Acct_No = " + Acct_No;
            EmpressDataReader temp = command.ExecuteReader();

            temp.Read();
            temp.Close();
            if (temp.HasRows == false)
            {
                return(false);
            }
            return(true);
        }
コード例 #3
0
        public void makeTransaction(int source_acct, int dist_acct, double amount)
        {
            try
            {
                command.Connection  = connection;
                command.CommandText = "START WORK";
                command.ExecuteNonQuery();

                sourceUpdate.CommandText = "UPDATE Customer_Accounts SET Balance TO Balance - " + amount + " WHERE Acct_No = " + source_acct;
                sourceUpdate.ExecuteNonQuery();

                distUpdate.CommandText = "UPDATE Customer_Accounts SET Balance TO Balance + " + amount + " WHERE Acct_No = " + dist_acct;
                distUpdate.ExecuteNonQuery();

                rd = transIdUpdate.ExecuteReader();
                int transId = 0;
                while (rd.Read())
                {
                    transId = rd.GetInt16(0);
                }

                insertCommand.CommandText = "INSERT INTO transactions VALUES ( " + transId + ", " + source_acct + ", " + dist_acct + ", " + amount + ",  CURRENT_TIMESTAMP)";
                insertCommand.ExecuteNonQuery();

                command.CommandText = "COMMIT WORK";
                command.ExecuteNonQuery();
            }
            catch (EmpressException e)
            {
                command.Connection  = connection;
                command.CommandText = "ROLLBACK WORK";
                command.ExecuteNonQuery();
                throw new MoneyTransferException(e.ErrorCode);
                //Console.WriteLine("Error code :" + e.ErrorCode);
                //Console.WriteLine("Error message: " + e.Message);
                //Console.WriteLine(e.StackTrace);
            }
            catch (Exception e)
            {
                //Console.WriteLine("Error message: " + e.Message);
                //Console.WriteLine(e.StackTrace);
            }
        }