|
Above links which preferd was good but in Persian or Arabic language is different and harder, if you need in this languages i prefer you searching in sourcenevis.ir.
-Amir Mohammad Nasrollahi
/* LIFE RUNS ON CODE */
|
|
|
|
|
i have developed inventory system software using C# with sqlserver 2008 database on Visual Studio 2008..
i want to use this application over the internet(ONLINE)
|
|
|
|
|
|
Member 9966941 wrote: over the internet
Then I hope you have built in a web service to sit between your database and your client!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
When a custom control (DeviceMonitor) was generated along with the property as follow:
public bool isConnected {get; set;}
then in the main form to add the control to the form...
DeviceMonitor devMon = new DeviceMonitor();
Control deviceControl= devMon;
this.Controls.Add(deviceControl);
Somewhere in the code, I would need to acquire the "isConnected". I tried
if (deviceControl.IsConnected)
{
...
}
but the .net doesn't see the property value of "isConnected".
How do I get this property value this way? Should I use this instead in the main form:
DeviceMonitor devMon = new DeviceMonitor();
this.Controls.Add(devMon);
This way, I can get it as:
if (devMon.IsConnected)
{
...
}
Any response?
|
|
|
|
|
I'm just starting to learn this stuff, I'm about halfway through this e-book course…
It's just now starting to cover "properties"…
Maybe there is something new in the .Net that allows properties on a Boolean?
As far as I know, Boolean is only true or false.
I forgot what the default value is a Boolean…
I'm more guessing than giving you an answer because I'm still learning C# myself.
Get rid of the: get; set
And replace that with: true
Then you can make a call to your Boolean "isConnected"…
Hopefully someone will correct me if I'm wrong.
Good luck
|
|
|
|
|
WidmarkRob wrote: I'm more guessing than giving you an answer because I'm still learning C# myself. True.
WidmarkRob wrote: Get rid of the: get; set
And replace that with: true Completely wrong, I'm afraid. OP has coded the property correctly, but has not instantiated the object properly.
Use the best guess
|
|
|
|
|
uhh that's not it. Keep on learning! There's so much to learn!
|
|
|
|
|
C# is case sensitive.
So isConnected != IsConnected
brisingr_aerowing@Gryphon-PC $ rake in_the_dough
Raking in the dough
brisingr_aerowing@Gryphon-PC $ make lots_of_money
Making lots_of_money
|
|
|
|
|
I don't understand your question
modified 26-Jul-13 10:34am.
|
|
|
|
|
You defined deviceControl as Control , which, if oyu look at the documentation for Control , doesn't have a IsConnected property.
You have to use the code you listed second, under "should I use this instead".
I suggest picking up a beginners book on C# and working through it. This is a very basic concept you're going to have to learn completely before building on it.
|
|
|
|
|
So, where does my answer fit in?
I'm halfway through a book I picked up at 'brainmeasures dot com'...
|
|
|
|
|
Truthfully? Not even close. Sorry, but you've got some more work to do.
|
|
|
|
|
Like I said, I'm only about halfway through my book…
I went back over the book, I didn't find anything in there talking about using properties on different data types…
There were a few examples, only on string and int…
Maybe, just maybe… It talks about using properties on different data types further in the book.
Also, I just got done scouring MSDN and couldn't find anything that talks about using properties on different data types…
I also click through the related topics and subjects, still couldn't find anything…
Could you point me to a place online or if you have time… Explain it to me here.
It would definitely be appreciated for your help.
I would like to learn C sharp the right way, I want to be able to write the code myself… I don't want to be a script kiddie!
|
|
|
|
|
Properties are just little bits of code that gets/sets a value or reference. You access them the exact same way no matter what the class exposing them is. Why use properties at all?? Property "setters" can be written to validate the value being passed in before it's used by the object. They can also be used to kick off other pieces of code, usually depending on the value being passed in.
Every class exposes it's own set of properties and methods. What each one does is explained in the documentation for that class.
For example, the String class, docs are here[^], only exposes two properties itself, Chars and Length.
I don't really know what your having a problem with.
|
|
|
|
|
I get all of that, "Black Box" type of writing code… Hiding implementation.
The only examples I've ever seen or talked about were on strings and ints… It never mentions other types like byte, long, boolean etc. etc.
My question is I guess:
can you use properties on all of those types?
|
|
|
|
|
Can you use the properties exposed by those types (don't use "on"), yes of course!
Using a property exposed by any type at all is exactly the same no matter what type it is.
|
|
|
|
|
I have been programming in C# for a long time. My engineer has programmed this way on the 1st option. I'm trying to figure out and need to revise the code to work with USB device. I've came up with the solution with loss/recovery of the USB device with WndProc process.
|
|
|
|
|
I have been programming in C# for a long time.
Then why did you ask this question? If what you said is true, this should have been obvious to you.
|
|
|
|
|
I would have to agree with the 2nd option.
|
|
|
|
|
|
Tried to cast the control. Still nothing.
|
|
|
|
|
You have to cast it to the type that contains the property your trying to use, not the one that doesn't.
|
|
|
|
|
Just to add to the other responses:
Your DeviceMonitor is a UserControl, which means that it is derived from Control (it has to be, otherwise it can't be displayed - even Form is derived from Control via a couple of other classes). That means it inherits (and you can access) all the properties of a Control in your class. But it doesn't work the other way...
DeviceMonitor devMon = new DeviceMonitor();
Control deviceControl= devMon;
this.Controls.Add(deviceControl); devMon contains a reference to your DeviceMonitor instance, so you can access all the properties and methods of the DeviceMonitor class via devMon:
if (devMon.isConnected)
{
...
} But deviceControl is a Control reference: it can contain a Control instance, or an instance of any class which is derived from Control, but it can only access the properties and methods of the Control class because that is the only class type it can guarantee that deviceControl contains. It is perfectly legal and correct to say:
DeviceMonitor devMon = new DeviceMonitor();
Control deviceControl= devMon;
this.Controls.Add(deviceControl);
deviceControl = new TextBox(); So the compiler will not let you access a derived class property or method via the base class variable.
It's a bit like cars: a Car has four wheels and an engine, but a Ford Fiesta also has Cruise Control, which a Ford Model T doesn't. If you declare a variable as a Car, then you can't access myCar.CruiseControl because the Car may be a Model T.
BTW: You don't need to use the deviceControl in your code - you can use a derived class anywhere you can use the base class. So this will work as well:
DeviceMonitor devMon = new DeviceMonitor();
this.Controls.Add(devMon);
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|