Beispiel #1
0
        public int CreateTransaction(Transaction t)
        {
            int ret = 0;
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {
                    try
                    {
                        string query = "NewTransaction";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("DateOfOrder", t.DateOfOrder);
                        cmd.Parameters.AddWithValue("PurchaceID", t.OrderID);
                        cmd.Parameters.AddWithValue("CustomerID", t.CustomerID);
                        cmd.Parameters.AddWithValue("BankingID", t.BankID);

                        ret = int.Parse(cmd.ExecuteScalar().ToString());

                        transaction.Commit();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        transaction.Rollback();
                        connect.Close();
                    }
                }
            }
            return ret;
        }
Beispiel #2
0
        // Create transaction
        public int create(int orderID, int custID, int bankID)
        {
            // Establishes transaction model
            TransactionModel transModel = new TransactionModel();

            // Holds the new transaction
            Transaction newTrans = new Transaction();

            // Stored details for the transaction
            newTrans.DateOfOrder = DateTime.Now;
            newTrans.OrderID = orderID;
            newTrans.CustomerID = custID;
            newTrans.BankID = bankID;

            // Adds object to the database
            int transactionID = transModel.CreateTransaction(newTrans);

            // Returns the transactionID
            return transactionID;
        }
Beispiel #3
0
        public List<Transaction> ListTransactions()
        {
            var transationList = new List<Transaction>();

            using (connect = new MySqlConnection(_connectionString))
            {
                try
                {
                    string query = "ListTransaction";
                    var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                    connect.Open();

                    var reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        var transaction = new Transaction();
                        transaction.ID = int.Parse(reader["Sale_Transaction_ID"].ToString());
                        transaction.DateOfOrder = DateTime.Parse(reader["Date_Of_Order"].ToString());
                        transaction.OrderID = int.Parse(reader["Purchase_ID"].ToString());
                        transaction.CustomerID = int.Parse(reader["Customer_ID"].ToString());
                        transaction.BankID = int.Parse(reader["Banking_ID"].ToString());

                        transationList.Add(transaction);
                    }

                    connect.Close();
                }
                catch (InvalidOperationException ioException)
                {
                    connect.Close();
                }

                return transationList;
            }
        }
Beispiel #4
0
 // Calls the main method for getting a transtion.
 public Transaction SearchTransaction(Transaction t)
 {
     return SearchTransaction(t.ID);
 }
Beispiel #5
0
        // Main method for getting an transaction.
        public Transaction SearchTransaction(int ID)
        {
            var transaction = new Transaction();

            using (connect = new MySqlConnection(_connectionString))
            {
                try
                {
                    string query = "GetTransaction";
                    var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                    cmd.Parameters.AddWithValue("SaleTransactionID", ID);

                    connect.Open();

                    var reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        transaction.ID = int.Parse(reader["Sale_Transaction_ID"].ToString());
                        transaction.DateOfOrder = DateTime.Parse(reader["Date_Of_Order"].ToString());
                        transaction.OrderID = int.Parse(reader["Purchase_ID"].ToString());
                        transaction.CustomerID = int.Parse(reader["Customer_ID"].ToString());
                        transaction.BankID = int.Parse(reader["Banking_ID"].ToString());

                    }

                    connect.Close();
                }
                catch (InvalidOperationException ioException)
                {
                    connect.Close();
                }

                return transaction;
            }
        }