I'm creating an EPoS system for a university project but I've run into a brick wall with a piece of complex code concerning Event Arguments.
These pieces of code are on a Payment Form which handles the end of a transaction. I have declared the PaymentMadeEvent as so:
public delegate void PaymentMadeEvent(object sender, paymentMadeEventArgs e);
public event PaymentMadeEvent PaymentForm_PaymentMade;
Next I've declared a boolean value in a separate public class at the bottom of the code page as so:
public class paymentMadeEventArgs: EventArgs
{
private bool paymentSuccess = true;
public bool PaymentSuccess
{
get { return paymentSuccess; }
set { paymentSuccess = value; }
}
}
Next I've copied an example piece of code that handles the payment when it's entered:
private void PaymentHasBeenMade(object sender, EventArgs e)
{
try
{
total = decimal.Parse(txtBoxAmountToPay.Text) - decimal.Parse(txtBoxAmountTendered.Text);
}
catch
{
MessageBox.Show("An Error has occured, please enter a valid amount.");
return;
}
if(total >0)
{
txtBoxAmountToPay.Text = String.Format("{0:c}", total);
}
else
{
MessageBox.Show("Please give " + String.Format("{0:c}", -total) + " in change.");
PaymentForm_PaymentMade(this, new paymentMadeEventArgs(){ PaymentSuccess = true });
}
}
The error is a
System.NullReferenceException
which seems to be coming from this line here:
PaymentForm_PaymentMade(this, new paymentMadeEventArgs(){ PaymentSuccess = true });
Can anyone see what I'm doing wrong?
Thanks in advance.