audit.cs

来自「csharp-solution,C#高效编程源码」· CS 代码 · 共 49 行

CS
49
字号
namespace Banking
{
using System;
using System.IO;

/// <summary>
///    The purpose of this class is to
///    1. record the changes made to account balances
///    2. write a copy of those changes to a text file
///    
///    This is achieved using an event raised by the 
///    BankAccount class
/// </summary>
public class Audit
{
	private string fileName;
	private StreamWriter auditFile;

	// Constructor
    public Audit(string fileToUse)
    {
        this.fileName = fileToUse;
		this.auditFile = File.AppendText(fileToUse);
    }

	// Destructor (Finalizer)
	~Audit()
	{
		this.auditFile.Close();
	}

	public void Dispose()
	{
		this.Finalize();
		GC.SuppressFinalize(this);
	}

	public void RecordTransaction(Object sender, AuditEventArgs eventData)
	{
		BankTransaction tempTrans = eventData.getTransaction();
		if (tempTrans == null) {
			return;
		}

		this.auditFile.WriteLine("Amount: {0}\tDate: {1}", tempTrans.Amount, tempTrans.When);
	}
}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?