|
Hi,
all methods are part of one class or other; there are no global methods.
A public static method is called by ClassName.MethodName(parms) .
A public non-static method is called by MyClassInstance.MethodName(parms) .
You normally pass MyClassInstance to whomever is interested, and/or you define an interface (which promises availability of some methods, but does not specify a particular class implementing them),
or, best of all, you pass a delegate (that is how you keep dependencies low).
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:39 AM
|
|
|
|
|
got it thnx ... i was still in web world (where i've been for too long it seems) where most member functions are public by default ... these were private by default so making them public worked
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|
|
so a question about general approaches...
in a desktop app (winforms say) is it better to open and close database connections with each form as it loads / unloads OR is it better to open a connection when the app starts and leave it open for the duration?
this is a low volume scenario with no more than 50 users expected simultaneously fyi
thnx
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|
|
You could do either. I think the general approach is to create a connection each time because of something called Connection Pooling which is a cache of connections.
Either way, you want to seperate your DB calls from you GUI code - this is a good abstraction. Wrap up the DB access stuff in a Data Access Layer.
Regards,
Rob Philpott.
|
|
|
|
|
ok cool thnx ... when you say separate the db calls do you mean the open / close connection stuff or even further and use a whole class for the data calls for each form?
my approach would be to use stored procs / views and call them from the code ... is that not good?
thnx again
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|
|
Well, I'd be inclined to create a seperate project in your solution which provides class(es) which do the data access stuff. This project would reference System.Data, System.Data.SqlClient etc.
Your form code would reference this project and would not have any references to System.Data. This way, you seperate presentation from data acccess. This way if you change one data access function you only need to do it in one place and not in different forms etc.
The next 'step' would be to have some sort of client server architecture where the forms apps would talk to a server which in turn would forward the class on to the database, but this may be heavy-handed for what you want to do.
Regards,
Rob Philpott.
|
|
|
|
|
so a project is just a collection of classes?
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|
|
A project is a collection of classes, but it's also more than that. Typically in Visual Studio, a Solution is a collection of projects. Each project would normally be compiled into an assembly (which is a DLL).
It's normal to break up an application in this way. You might have your front end in its own project. Maybe you've got some custom controls, they'd be in another project (so that they could be reused elsewhere). You might have some business functionality in another project, and certainly data access would be another one. All these seperate projects comprise your solution.
When you build your solution, each project is compiled into its own assembly and they are all placed in the same folder. (This is private deployment if you want to look it up).
Projects obviously need to know about each other, and this is where references come in. If you right click on one in VS, there's an add reference option. Here you can reference your other projects and also system wide assemblies from the GAC.
Hope that makes some sense.
Regards,
Rob Philpott.
|
|
|
|
|
As mentioned by Rob, there is a Connection Cache in ADO.NET. They are cached based on the connection string. So as long as you keep your connection strings the same, there is almost no overhead closing your connections and reopening them.
|
|
|
|
|
thnx
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|
|
Hi all !
i'm trying to do something with one of my button. I got a logon form and i want to change de "visible" status tu true if the logon is accepted. The button is in the main form so i tried something like this :
<br />
if (str33 == encpassword)<br />
{<br />
PassTextBox.Clear();<br />
<br />
ChangeButton.Show();<br />
<br />
Main open = new Main();<br />
open.ChauffButton.Text = "dfg";<br />
<br />
<br />
}<br />
but it dosent worked. I jsut dont get it. Theres no error, nothing seem to be wrong but the status dont change. I even tried to change de text and got no result
Can someone help me on this please ?
BTW i'm using VS express 2008
Thanks !
|
|
|
|
|
from your code i'm not sure which bit isn't working or what you want to work?
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|
|
l a u r e n wrote: from your code i'm not sure which bit isn't working or what you want to work?
the
Main open = new Main();
open.ChauffButton.Text = "dfg";
part.
the text dosent change and if i change this by "open.ChauffButton.Visible = true;" it's not working either
|
|
|
|
|
|
Ok, you need to pick up a beginners book on C#. Firstly, Welcome to CP, check out the post at the top for some etiquette, specifically on "text speak", everyone hates it. It's the only universal truth. Now without knowing which control is what, and judging off your hungarian notation (naming variables based off their control type) I'm going to assume the following...
Firstly, that this code is executed on a button press.
Secondly str33 = sometextbox.Text which has a password in it
Thirdly, that encpassword is a plaintext password
Fourthly, that PassTextBox is a textbox
Fifthly, that Changebutton is a button that you wish to show ONLY when the password is correct
Sixthly, that open should pop up if the password is correct
Now this goes against all convention of not posting code, but this is just one that needs dire attention.
I'm going to go line by line and address some issues
if (str33 == encpassword)
{
PassTextBox.Clear() should be PassTextBox.Text = "" or you can use PassTextBox.Enabled = false or PassTextBox.Visible = false , they will all do some sort of desired effect, clearing the textbox, disabling it or simply wiping it off the form
ChangeButton.Show() should be ChangeButton.Visible = !ChangeButton.Visible assuming Visibility is set to false (which I assume because you are trying to show it)
Main open = new Main();
you have initialized a form here, but you never showed it
open.Show(); is what you need
From here open.ChauffButton.Text should work, I don't really remember because I never access controls like this, consider placing this code elsewhere like on the load event of your form 'open'.
Those modifications, and you'll be off to a start.
modified on Tuesday, February 3, 2009 11:44 AM
|
|
|
|
|
thanks for your answer EliottA
i will take notes of all you say
i realize theres a lot of infos i didn't wrote so that was not easy to help me. I will do better next time.
I will try to find a way to make it small and clear and understandable for all of you (i will find a good language translater LOL)
btw, i didn't get my answer (as i say, i realize you hadd no chance to understand what i try to do) but i will work on a way to put it more clear and more in standard form
|
|
|
|
|
Your answer is in there, I threw in the code you will need to make it work, infact I gave you multiple options based off the multiple assumptions I had to make. Most importantly, you forgot open.show() to show the form!!
|
|
|
|
|
thanks again EliotA for your answer
the point is i forgot to tell that the main form is already open so if i made a open.show(); i will have 2 forms open and its not what i whant. I already try a open.refresh(); to see if the text change and nothing appen, i also try a open.update(); and no result.
i think will follow your first advise, i think i will get a "c# for dummies" and learn the base to get the things a still dont get.
thanks alot again !
|
|
|
|
|
I have created an application to draw rectangle by using graphics..i got solution to resize,increase,decrease the rectangle..now i want rotate that rectangle...with mouse move events..(float angle should be dynamically)..
..i tried matrix rotation..but am not getting that how float angle will be generated dynamically by moving mouse...
plzzzzzzz Help me...
|
|
|
|
|
As was said the last time you asked this question...
Dragonfly_lee wrote: 1.listen the mouse click and move events.
2.Check the method - RotateTransform of Graphic object. E.g.
gfx.RotateTransform(rotationAngle);
Source[^]
|
|
|
|
|
ya i have seen that message..but rotation angle will be dynamically i want to mention..how should i calculate that rotation angle..when mouse moves on form..
|
|
|
|
|
well clearly he is saying that from the mouse click you can get the point where it was clicked ... then you can track the movement from that point to figure out a direction and hence the angle no?
i think...
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|
|
try storing the initial mouse click position then use that point, along with the center point of the object and the current mouse pos and use pythagaros (not sure on spelling) thery to calculate angle base on three point, oh you will also have to calculate the distance from points
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
I'm starting a new project which will run a WinForms user interface.
I want the interface to be modular and make good use of code refactoring but it seems this is near impossible with Winforms C#.
At first I evaluated Smart Clients and found that it is exactly what we need, but given our time and resource constraint, it was not a viable solution.
Is there a best practice to create a windows application with seperate panels? Preferably, these panels should be able to contain any specified user control or form.
Every solution I ended up with so far came down to massive code duplication.
|
|
|
|
|
evilnoodle wrote: I want the interface to be modular and make good use of code refactoring but it seems this is near impossible with Winforms C#.
How so?
Have you looked at the CAB stuff in the Enterprise Library? Not that'd I recommend that...
Regards,
Rob Philpott.
|
|
|
|