|
public DeviceData(int Type, object Device)
Where is return Type? This is function and if you do not want to have return type, use void
Edit: To check object for type use:
if (device is Recloser)
dev = (Recloser)Device;
This (int Type) shroud be avoided, you can make a mistake, and it the code can become unreadable
|
|
|
|
|
Saksida Bojan wrote: Where is return Type? This is function and if you do not want to have return type, use void
It's probably a constructor.
|
|
|
|
|
Exactly.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
The IDE is supposed to snivel at the switch-block. I don't think you can put a declaration in the case-blocks, unless you enclose the entire case block in {}. So this:
case 5:
LTC dev = new LTC();
dev = (LTC)Device;
break;
becomes this:
case 5:
{
LTC dev = new LTC();
dev = (LTC)Device;
break;
}
Roger Wright wrote: public int GetDevice(dev)
I don't know if this is a proof of concept, but I think you need to provide a type, or remove the parameter and use the local variable instead.
|
|
|
|
|
both syntax of Switch case are valid
The problem lies in decleration "LTC dev = new LTC(); " is declared within case block. It doesn't exists outside
|
|
|
|
|
Hmm. Perhaps an unusual approach you describe.
Why, for starters do you need an integer defining the type? The actual object itself has type which we can query.
The different type 'dev' variables you create are only going to have local scope (ie last as long as the case part). And, from memory, I don't think its going to allow you redeclare a variable multiple times in a single switch. Normally, dev would be some sort of member variable.
This:
Recloser dev = new Recloser();
dev = (Recloser)Device;
makes no sense. You'd use:
Recloser dev = (Recloser)Device;
Perhaps what you want is multiple constructors, each taking a different subclass of device?
public DeviceData(Recloser device)
{
dev = device;
}
etc.
Another question - why have a single data access class which handles all these different 'devices' - why not have one per class? That would make life quite a bit simpler as you won't have to be continually determining what device you've got before taking actions.
All very vague I'm afraid.
Regards,
Rob Philpott.
|
|
|
|
|
Excellent points - Thanks!
It was, necessarily, very late when I was working on this, so my own reasoning might not be at its best.
The idea of using a single class was to save on mostly redundant code, but this morning I can think of several better ways to do this. I totally forgot about the mechanism for determining the type of device. Looking at it now, I can see my own bias for procedural programming in the approach... gotta work on that mindset.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Firstly, have you considered existing technologies to handle DAL. NHibernate is very good and.NET's own LINQ framework has both the Entity Framework and LINQ to SQL that could all make your task easier?
If you don't want, or can't, go down a ORM route using the technologies above, the task becomes much harder. One common route is to generate the code that handles CRUD operations in the DAL for each class. I've had to implemented a "Lite / Dummies'" version of ORM, decorating classes with table mappings attributes and properties to be persisted with column mapping attirbutes (column name, type, any conversion functions and whether the column takes part in the table's PK), the CRUD databse operations can then be performed by one class which inspects the object passed to it by relefection.
Things that you might run up against, depending upon your implemenation:
- Relations between tables e.g. delete from table A, but this breaks a FK constraint to table B, or you have an property that is itself a of a type you persit: you need to persist in the correct order and make sure that the owner object has a PK /FK relationship to the child object, and the OK of the child object must be defined.
- Null handling
- Default Value handling
- Defining primary keys on tables
- Conversion from object property type to DB cloumn types and exceptional cases were the standard conversion is insufficient
- Inheritence Problems (how do you represent an inheritance hierearchy in the DB, Table per sublcass, table per hierarchy etc).
All these problems are soluable (with varying degrees of sucess and complexity), and it's important not to try and solve them up front, but be aware you might come across them. Unless you are doing this as a learning exercise (which is a good thing to do) I'd consider the Entity Framework or NHibernate.
Good luck!
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
This definitely is a learning experience, despite the fact that the app will be useful at work. Most of the considerations you mention are new to me, and probably aren't significant in so simple an app - managing history records for 5 or 6 types of equipment. It's the sort of thing one could do easily as a simple web page using ADO, but I'm using this as a tool to become more familiar with C#.
Thanks for the suggestions!
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Roger, I'm only 300 miles from you and I need work (and a trip to Laughlin), might I be of assistance?
P.S. I should have mentioned also, I'll be in Sedona for part of next week, that's half-way already.
|
|
|
|
|
Advertising?
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
It's the best lead I've had in weeks.
|
|
|
|
|
We do need to get together one of these days, but a working trip would interfere with our drinking. After all, we're practically neighbors. I wish I could break away for a day to see you in Sedona, since it's just around the corner, but I'm swamped at work for a while. If the company ever decides to hire a real programmer, I'll definitely contact you. In the meantime, they expect me to do this with a spreadsheet - which is completely impractical - hence my effort to create a reasonable facsimile of a working data management program in my free time at home.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Roger Wright wrote: interfere with our drinking
I don't know about you, but with me the first drink interferes with any others.
Roger Wright wrote: a working data management program in my free time at home.
Keep pluggin' and askin' as necessary.
|
|
|
|
|
hi,
I have to show the number and name of file being copied.I have assigned the file name and number to a label.But, Gui is being so responsive that it can be displayed visually correct.It looks like the process has hung and only display the last filename and number after task completion.I have to show the filename and number just while it is being copied.
regards
Bill
|
|
|
|
|
Yes. You have to use Background Worker .
For Your Ref[^]
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Like we have FlowLayoutPanel, where controls can automatically get laid out according to their sizes and sequence, I have a requirement of a fluid layout.
In a rectangle or area (say 500w X 100h), there are some fixed small controls. lets say a rectangle control of (100w X 30h) is fixed at point (0 top , 150 left) Now, I need to fill this bigger rectangle with small shaped controls with constant areas but variable widths. Height can be maximum wherever possible.
The controls not adjacent to fixed control will be rectangles So, no problems. The controls adjacent to fixed controls will need to take polygon shape of variable heights to fit in the balance space.
Any logic already existing? Any approaches?
And yes, this is for winforms.
|
|
|
|
|
Som Shekhar wrote: Any logic already existing?
AFAIK it doesn't exsist. Maybe 3rd party control would have it.
Som Shekhar wrote: Any approaches?
I Would use OnResize event and programaticly calculate the behaver
|
|
|
|
|
Saksida Bojan wrote: AFAIK
Yes, "AFAIK" applies to me too. I just hoped that others may have some experience or thoughts.
|
|
|
|
|
Ok, I'm making this program for my statistic class Dealing with boundaries and Limits..
When user enters a set of numbers, I would like it to count the same numbers it enters, for example.
1,2,7,8,3,5,8,8.
1 = 1
2 = 1
3 = 1
5 = 1
8 = 3
without writing like 100 if else loops
if ( num =1)
num1 += 1;
else
if ( num =2)
num2 += 1;
etc, any idea how to do this program?
|
|
|
|
|
Can you use a dictionary with logic like this -
Dictionary<int, int> objCount;<br />
int num;
if (objCount.ContainsKey(num))<br />
{<br />
objCount[num]++;<br />
}<br />
else<br />
{<br />
objCount.Add(num, 1);<br />
}
There's nothing left in my right brain and nothing right in my left brain. |
|
|
|
|
|
int[] myNumberCounter = new int[100]; <br />
<br />
myNumberCounter[12]++;<br />
myNumberCounter[2]++;<br />
myNumberCounter[19]++;<br />
|
|
|
|
|
Whether that is a good idea or not depends on what kind of data you are going to get. If the data is an int (i.e. a 32 bit number), then declaring an array to hold it is a little excessive. Likewise, if the data is likely to be "clumpy" with many values below 1000, and many above 30000, but few in between, then an array is unlikely to be efficient.
Additionally, you will need to provide checking to ensure you will not exceed the arry blounds. Extending an array is very inefficient, as the entire array has to be copied to a new, bigger, array.
If you do not know what data you will recieve, then a Dictionary is likely to be a better solution.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
I agree - mostly - in this case it was "sort of" indicated values in the area of
0- ~100. And if that's the case i would deam Dictionary excessive, otherwise I agree.
|
|
|
|
|
Homework.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|