Hi colleagues,
In fact I don't have a problem but just don't know which way is good
and better.
I need some advice which programming way I shall use. Since a couple
of days I'm investing my knowledge in Events and Delegates to get more
used to it.
Here I've situation which way should you use and why?
I've a page an ASPX page named. Creditlimit.aspx and a business logic
class Bank.cs.
In Creditlimit.aspx I'm setting the creditlimits for a customer.
e.g. customerID A1001 has creditlimit 1250$, CustomerID B5404 has
creditlimit 1550$.
So I can set the creditlimit. I also have in another help table the
global creditlimit set value 2500$.
So no one customer should exceed this creditlimit. I mean when the
user enters 3500$ the application won't allow it to set.
I've solved this problem in 2 ways:
Way 1 - Traditional way:
-------------------------------------------------
In Creditlimit.aspx.cs (code behind)
I retrieve the global creditlimit calling a function in business logic
(class bank: method: GetglbCreditLimit) to get global creditlimit,
which returns me 3500$ and put that in an decimal field in aspx.cs
(code behind page).
then I compare the value (textbox control) with this value. If it
exceed the global credit limit it just send a status/error message to
the screen that it's not allowed. So I just compare the 2 field
values....
Ok this was the easy way. it's clear and easy.
Way 2 - Event Delegate way:
--------------------------------------------------
Here I'm using a delegate/event handler way.
I've created a Delegate and a event.
public delegate void OverCreditLimit(object o,
CreditLimitEventArgs e);
public class CreditLimit
{
public event OverCreditLimit NSF; //non-sufficient funds
.....
then I'm calling the CheckOverlimit function in business logic in Bank
class. if the entered credilimit/requested credit limit is than
GlobalCreditlimit, It trigger the event and invokes the delegate.
in aspx page I've set the eventhandler to property eventhandler
property see below...
//check credit limit - it should not exceed the global
credit limit set up in UDC:Finance/Creditlimit
Bank objBank = new Bank();
objBank .NSF += CheckCreditLimitHandler; // set to a
function that it diplays the error on the page
so when it exceeds CheckCreditLimit in Aspx.cs page displays the
error.
SO My question is in fact.... Both methods gives me the SAME result...
Why should I choose for the Event/Delegate method or why not?????????
I'm a little bit confused when to use event/delegates and when not? In
this circumstances would you use it or not?
thanks for sharing your thoughts,
mesut