예제 #1
0
        public void ExecuteTransaction(Transaction transactionIn)
        {
            if (transactionIn is BuyTransaction)
            {
                var transaction = (BuyTransaction)transactionIn;

                if (transaction.Execute())
                {
                    transactionList.Add(transaction);
                    WriteToFile(transaction);
                }

                else
                    throw new IllegalCashTransactionException();
            }

            if (transactionIn is InsertCashTransaction)
            {
                var transaction = (InsertCashTransaction)transactionIn;

                if (transaction.Execute())
                {
                    transactionList.Add(transaction);
                    WriteToFile(transaction);
                }

                else
                    throw new IllegalCashTransactionException();
            }
        }
예제 #2
0
        public void WriteToFile(Transaction t)
        {
            string path = "transactions.txt";

            if (t is BuyTransaction)
            {
                var item = (BuyTransaction)t;
                if (!File.Exists(path))
                {
                    using (StreamWriter writer = File.CreateText(path))
                    {
                        writer.WriteLine("Købtransaktion: \t" + item.transactionID + "\t" + item.currentUser.userName + "\t" + item.date);
                    }
                }
                else
                {
                    using (StreamWriter writer = File.AppendText(path))
                    {
                        writer.WriteLine("Købtransaktion: \t" + item.transactionID + "\t" + item.currentUser.userName + "\t" + item.date);
                    }
                }
            }

            if (t is InsertCashTransaction)
            {
                var item = (InsertCashTransaction)t;
                if (!File.Exists(path))
                {
                    using (StreamWriter writer = File.CreateText(path))
                    {
                        writer.WriteLine("Indsætning/ hævning: \t" + item.transactionID + "\t" + item.currentUser.userName + "\t" + item.date);
                    }
                }
                else
                {
                    using (StreamWriter writer = File.AppendText(path))
                    {
                        writer.WriteLine("Indsætning/ hævning: \t" + item.transactionID + "\t" + item.currentUser.userName + "\t" + item.date);
                    }
                }
            }
        }