473,795 Members | 3,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

proper programming? (events)

hi ,

ok , i have a programming background but i'm new to C# . i'm also self
taught so :

i have a datagridview that should act differently depending on which
user has signed in

now is it more effecient/correct if i do this:

if(user=="user1 ") {
this.dataGridVi ew2.CellBeginEd it += new
System.Windows. Forms.DataGridV iewCellCancelEv entHandler(this .dataGridView2_ CellBeginEdit_U ser1);
}else {
this.dataGridVi ew2.CellBeginEd it += new
System.Windows. Forms.DataGridV iewCellCancelEv entHandler(this .dataGridView2_ CellBeginEdit_U ser2);
}

as opposed to check for which user in ONE cellBegin event??

Thanks
Gideon

Nov 17 '06
11 1678
Hi,

<snip>
>>At a certain point a form goes beyond these simple UI object / business
object interactions. Decisions about UI state become more complicated. UI
controls need to react to the events raised by the use of other UI
controls. UI controls may be disabled if the user does not have
authorization , if the business object is read only, if a particular tab is
not selected etc. This is when I use a separate object. The code behind
remains simple and the form once again returns to simple UI control /
object interaction, e.g. this.deleteEmpl oyeeButton.Enab led =
myObject.Empl oyeeDeletionAll owed;

I agree, but in this example you still only need to set an Enabled
property. That could be done using simple property-binding.

Yes, but the logic required to work out if the button should be enabled is
something that should be encapsulated outside of the code behind in it's own
object. I guess I use the Mediator pattern.

"Define an object that encapsulates how a set of objects interact. Mediator
promotes loose coupling by keeping objects from referring to each other
explicitly, and it lets you vary their interaction independently"
Yes, we're on the same page here as well.

The mediator pattern is interesting. Here's some more information I found on
the subject in the context of an article on the Message Broker Pattern [link
after sig]:

"Mediator [Gamma95]. The Mediator pattern separates objects so that they are
only aware of the mediator but not each other. The Broker deals with similar
concerns, but it can only be used in the context of enterprise applications."

So your example does seem like the mediator pattern. And if the actual type
of "myObject" was the "UserUICapabili ties" class from my original response,
that would make even more sense. It would just need a property named,
"EmployeeDeleti onAllowed". Since it was created by a User object, it would
act as the mediator between the User and the UI.

<snip>

Thanks for the discussion.

--
Dave Sexton

"Message Broker Pattern"
http://msdn.microsoft.com/library/de...sagebroker.asp
Nov 17 '06 #11
Hi Dave ,

i didnt see your post before posting my second reply! i hit the reply
button , went to have lunch! and wrote my post only in response to Toms
post! lol and i did'nt have time to replay back! sorry....

yes , your approach makes whole lot of sense , i did'nt even give a
thought to making seperate classes! infact i've decided to seperate a
lot more .. .thanks

although the complexity at which i'm working is not much. Each user has
about 5 levels of privileges..... basically i thought it would be more
effecient to register an event with the right delegate in the first
place(when the form loads) so i would'nt have to go checking INSIDE the
function (when the event fires) , for what privilege the user has!
anyway i think the object method is more effecient! and a lot more
cleaner... .

thanks again!

Gideon

Nov 18 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2160
by: Feico | last post by:
Dear friends I am an experienced programmer, but I happen to have MS Access, which uses a language unknown to me. I want to perform an operation on all record on a table, like this For recordnumber=1 to NumberOfElements(Tabel) PerformCalculation(recordnumber.fieldname)
6
5052
by: Martin Ortiz | last post by:
Which is best approach? Should Try + Catch be used to only deal with "catastrophic" events (like divide by zero, non-existant file, etc...etc...) Or should Try + Catch be used IN PLACE of regular defensive programming? (ie if file exists do this, if not do something else) Or should Try + Catch be used TO SUPPLAMENT regular defensive programming?
26
4857
by: I_AM_DON_AND_YOU? | last post by:
This is the scenario: I have a VB.Net project comprising of a few Forms. On Form1 I have more than 20 buttons. There is a very lenghty code written in click event of each and every button. Right now I haven't used any sub procedure. I mean to say I am writing the code directly in the click event. So it's become very lengthy and therefore to figure out some problem or make any changes I have to scroll at lot. Also in addition to click...
6
1945
by: Ricky W. Hunt | last post by:
It's dawning on my a lot of my problems with VB.NET is I'm still approaching it in the same way I've programmed since the late 70's. I've always been very structured, flow-charted everything, used subroutines, etc. Now I'm trying to study this new way and I'm getting some terms confused and can find no clear definition (some even overlap or use two different words for the same thing, even when they are actually different). I'm reading a...
6
1874
by: Luke Vogel | last post by:
Hi all ... could someone point me in the right direction for programming office applications (specifically excel) using vb.net? Can vb.net replace or enhance VBA that comes with the office suite? cheers... have a great Christmas all! -- Regards Luke. ----- There are 10 types of people in this world
4
1528
by: Jon Slaughter | last post by:
When programming, say, a control should I use the objects of the control directly, reference them from this, or use, if possible, the ones passed through event arguments? e.g., in a paint event I can use this. or just access the fields and methods of the control directly or use the painteventargs argument passed. Say I want to draw a line on the control. What I'm a little confused about is when to use "this.". I know its mainly used...
15
2039
by: Jason Doucette | last post by:
If you have two overloaded functions: double maximum(double a, double b, double c); int maximum(int a, int b, int c); They work fine if you call maximum() with all arguments as doubles, or all as ints. But, if you mix up doubles with ints in the argument list, it doesn't know which maximum() to call... but only one could possibly match -- the one that takes doubles.
0
11356
MMcCarthy
by: MMcCarthy | last post by:
VBA is described as an Event driven programming language. What is meant by this? Access, like most Windows programs, is an event driven application. This means that nothing happens unless it is in response to some event that has been detected by the application. The steps are fairly straightforward: An event happens The event is detected by the application The application responds to the eventThe Windows OS will automatically detect...
43
3702
by: Adem24 | last post by:
The World Joint Programming Language Standardization Committe (WJPLSC) hereby proclaims to the people of the world that a new programming language is needed for the benefit of the whole mankind in the 21st millenium. This new language not only differs from existing ones by new features and paradigms but which also brings real advantage by rigourously preventing bad programmer habits by omitting features which are outdated. In the proposed...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.