|
Basically it seems you are having trouble getting the type in the abstract base class.
Try something like:
foreach (AchieveTargetBase x in (AchieveTargetBase[])ActiveRecordBase.FindAll(this.GetType(), Expression.Eq("Subject", subj), Expression.Eq("YearGroup", year)))
|
|
|
|
|
Basically it seems you are having trouble getting the type in the abstract base class.
That's the problem, yes. (And for some reason I couldn't just sum it up like that yesterday - I was tired!)
I tried the code you suggested first, in the AchieveTargetBase class, but it doesn't work because I'm not initialising ActiveRecord against that class (as I want that class as a base for the others, not an actual ActiveRecord class/table).
Would using this work? That's probably a rhetorical question since I'll try it in a few minutes when I've finished my current task.
|
|
|
|
|
I solved it using a generic class.
----------------------------------------------------------
public class GetListOfEntries<T> : ActiveRecordBase where T : AchieveTargetBase
{
private Subject _subj;
private int _year;
public GetListOfEntries(Subject subj, int year)
{
_subj = subj;
_year = year;
}
public string[] ReturnListOfEntries()
{
List<string> Entries = new List<string>();
foreach (T x in (T[])ActiveRecordBase.FindAll(typeof(T), Expression.Eq("Subject", _subj), Expression.Eq("YearGroup", _year)))
{
Entries.Add(x.Comment);
}
string[] ret = Entries.ToArray();
Array.Sort(ret);
return ret;
}
}
----------------------------------------------------------
Which works great.
Thanks for the help.
|
|
|
|
|
Hey all,
I've been given some fairly whiffy code to update, which I'm going to port over to C#. The port is going very well, but I have an architectural-type question which I hope you guys can help with.
The original developer was clearly a fan of the VB's select-case statement; the app isn't very big, but so far I've found at least 50 seperate instances of this flow control structure (some of which are clearly copied and pasted). Whilst I can quite easily refactor some of the concepts into objects, there is one area I'm not to sure about.
One part of the program reads data in from a file, and depending on the value read in, decides on a course of action. The decision is made by a slect case statement, which to my mind adds fragility to the application as it's probable that more value/decision pairs will need to be made. (Actually, this must have happened to the original developer on seperate occasions, as there are over 70 cases which the comments suggest were added over time!)
Given this, are there any recommended patterns I could look to implement instead of replicating the switch case in my code?
"It was the day before today.... I remember it like it was yesterday."
-Moleman
|
|
|
|
|
First a few questions:
What kind of file is it? I'm guessing a flat file with multiple distinct data segments?
Are there any common elements to each of the data segments?
Is this a forward only read?
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
It's a bit of a duff system, to be honest, but basically El Supremo (the original dev) has created what he terms a "transport mechanism" - it's not really - and it goes something like this:
He takes a plain ordinary text file, and writes in it some header information such as:
original path = C:\test.txt
output path = z:\test.txt
creation date = blah blah blah
Then after this "header" has been defined, he writes all the bytes of the original file - whatever it is. Finally, he inserts the length of the file (in bytes) before the header. So in the finished article you get something like this:
15465
original path = C:\test.txt
output path = z:\test.txt
creation date = blah blah blah
A whole bunch of bytes go here.
The killer is that the header can appear in any order whatsoever and some things are optional (except that the length of the file always appears before it). To actually extract the data I calculate the length of the file, minus the length of the data bytes to get to the first byte of the data.
Man, perhaps I should put this into Coding Horrors
"It was the day before today.... I remember it like it was yesterday."
-Moleman
|
|
|
|
|
Hi Martin,
if the header lines are just a distraction, I don't see why you would bother
to provide a switch or some fancy patterns, just skip it the way you described.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I think you're probably right (either that, or I should get a new job!)
"It was the day before today.... I remember it like it was yesterday."
-Moleman
|
|
|
|
|
That's truely ugly, I doubt there's a clean way of parsing that, typical situation where you end up with the MOASS (Mother Of All Switch/Select Statements) Ignore what you can me thinks.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
I'd look into a mixture of the Factory Idiom and the Strategy Design Pattern.
Basically, one method (factory method) takes the argument that would be used as the Select Case argument and returns the correct "strategy", which are implementations of a simple interface (IStrategy.Execute() could be your only method in the interface. The factory creates the right strategy based on the the value read in the file and returns the reference to the interface.
|
|
|
|
|
martin_hughes wrote: One part of the program reads data in from a file, and depending on the value read in, decides on a course of action. The decision is made by a slect case statement
Actually, this is one of those places where a select statement is appropriate. When reading raw data from a file, you are at the boundary of your application. As such, the data doesn't represent objects that you can manipulate, so you are forced to use conditionals to decide what to do. Usually, the course of action is to create an object to encapsulate the data. From there, the rest of the application deals with the object(s) rather than the raw data, and you can design your classes in such a way as to take advantage of polymorphism. But at the boundary of your application, you need a way to interpret the data and transform it into objects. switch/select statements are fine for this.
Now having said all of that, if you can figure out a way to serialize the data to file so that it can be deserialized directly into objects by your environment, then cool. Otherwise, don't be bothered by the switch/select statements.
All my opinion, of course. 
|
|
|
|
|
Greetings,
Below code would do the following upon user clicks the button:
if user clicks on a specific cell on the instantiated form's datagridview, the appropriate row's data is copied into the caller form's datagridview.
Problem is: the anonym method is fired as many times as user clicks "this" form's button (in order to show up the other form, whose datagridview contains the data to be copied onto "this" form' gridview) BUT I'd like it to be fired only ONCE at a time. thanks for any thread, g (placing "return" didn't help)
<br />
public int I = 0;<br />
private void btnHozzaadas_Click(object sender, EventArgs e)<br />
{<br />
Guid[] array = new Guid[15];<br />
<br />
<br />
<br />
tetelArErAnSzerk.Owner = this;<br />
<br />
tetelArErAnSzerk.anyagDataGridView.CellClick += delegate<br />
{<br />
<br />
if (tetelArErAnSzerk.anyagDataGridView.CurrentCell.OwningColumn.DataPropertyName == "AnyagHozzaadas")<br />
{<br />
<br />
DataView datatableView = felhasznAnyagSzallitasBindingSource.List as DataView;<br />
DataRowView rowView = datatableView.AddNew();<br />
<br />
Debmut9DataSet.Felhaszn_AnyagSzallitasRow felhasznaltanyagdatarow = (felhasznaltanyagszallitasDataGridView.Rows[I].DataBoundItem as DataRowView).Row<br />
as Debmut9DataSet.Felhaszn_AnyagSzallitasRow;<br />
<br />
rowView["TetelArId"] = (tetelArBindingSource.Current as DataRowView)["TetelArId"];<br />
felhasznaltanyagdatarow.AnyagId = new Guid();<br />
Guid anyagid = ((tetelArErAnSzerk.anyagDataGridView.CurrentRow.DataBoundItem as DataRowView).Row as<br />
Debmut9DataSet.AnyagRow).AnyagId;<br />
array[I] = anyagid;<br />
if (I == 0)<br />
<br />
{ felhasznaltanyagdatarow.AnyagId = anyagid; }<br />
<br />
<br />
if (I > 0)<br />
{<br />
for (int J = 0; J < felhasznaltanyagszallitasDataGridView.Rows.Count - 1; J++)<br />
{<br />
<br />
for (int K = 1; K < felhasznaltanyagszallitasDataGridView.Rows.Count - 1; K++)<br />
{<br />
if (J == K)<br />
{<br />
K++;<br />
}<br />
if (array[J] == array[K])<br />
{<br />
MessageBox.Show("Component exists, Cant be added again!", "Not added...", MessageBoxButtons.OK, MessageBoxIcon.Warning);<br />
felhasznAnyagSzallitasBindingSource.Remove(rowView);<br />
<br />
<br />
return;<br />
}<br />
<br />
}<br />
<br />
<br />
}<br />
}<br />
<br />
felhasznaltanyagdatarow.AnyagId = anyagid;<br />
<br />
felhasznaltanyagszallitasDataGridView.Rows[I].Cells["Anyagszallfelhaszn_Megnevezes"].Value = ((tetelArErAnSzerk.anyagDataGridView.CurrentRow.DataBoundItem as DataRowView).Row as<br />
Debmut9DataSet.AnyagRow).AnyagNev;<br />
felhasznaltanyagszallitasDataGridView.Rows[I].Cells["Anyagszallfelhaszn_Szall_szolg"].Value = ((tetelArErAnSzerk.anyagDataGridView.CurrentRow.DataBoundItem as DataRowView).Row as<br />
Debmut9DataSet.AnyagRow).AnyagSzallito;<br />
felhasznaltanyagszallitasDataGridView.Rows[I].Cells["Anyagszallfelhaszn_Me"].Value = tetelArErAnSzerk.anyagDataGridView.CurrentRow.Cells["Anyag_Me"].FormattedValue;<br />
felhasznaltanyagszallitasDataGridView.Rows[I].Cells["Anyagszallfelhaszn_ear"].Value = ((tetelArErAnSzerk.anyagDataGridView.CurrentRow.DataBoundItem as DataRowView).Row as<br />
Debmut9DataSet.AnyagRow).AnyagBer;<br />
egysegar[I] = ((tetelArErAnSzerk.anyagDataGridView.CurrentRow.DataBoundItem as DataRowView).Row as<br />
Debmut9DataSet.AnyagRow).AnyagBer;<br />
felhasznAnyagSzallitasBindingSource.MoveLast();<br />
<br />
felhasznaltanyagszallitasDataGridView.Refresh();<br />
I++;<br />
MessageBox.Show("Added successfully", "Added...", MessageBoxButtons.OK, MessageBoxIcon.Information);<br />
return;<br />
}<br />
};<br />
tetelArErAnSzerk.Show();<br />
}<br />
|
|
|
|
|
Hi,
your code is hard to read without indentation, with long lines, etc.
better is to use CODE PRE tags.
I think the problem is every time you click the button, a delegate is ADDED
to the DGVcell; you should do this only once.
You may want to read my article on events (and the one on CodeRescue).
-- modified at 17:42 Thursday 16th August, 2007
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi Luc,
Thanks for your post
Gonna go & read your article. Cheers
|
|
|
|
|
hi all
does anyone know if anything similar to layers exist in the windows api ? I did ask in another forum a while back and was pointed in the direction of nested splitcontainers by brady, but having played with these they don't really do what I'm after and having thought about it I probably do need something more like layers.
When I've written web based tools like this I use layers, where you can create a new layer, resize it and move it around the work area whilst maintaining each of their individual x/y & w/h. That has worked well for me and I would like to try and translate this into a windows app but I can't seem to find anything like layers.
Sorry if this sounds confused (but I am a little )
tia for any advice/pointers
tim
|
|
|
|
|
I guess you could use winforms panels with the background set to transparent? Or are you looking for more of a docking/pallette style solution like Visual Studio?
|
|
|
|
|
Hi,
I have a dataset in C#. In that I'm applying the select metod. I want to know whether it is possible to use the Order by in the Select method. When I am using it is giving me the error message that "Missing Operand after Order by" Could anyone pls help. It's urgent.
This is my code relating to DataSet's select Method:
DataRow[] drFirstCnd = dsricsdup.Tables[0].Select("P_INDU_SUBSECTOR_CD NOT IN('AGNC','OFFC','SPRA') AND P1_INDU_SUBSECTOR_CD = ' ' ORDER BY P_SP_INDU_CD");
Thanks
Meeram395
|
|
|
|
|
I don't think order by is supported
|
|
|
|
|
I'm not exactly sure, I don't se why not.
But shouldn't there be a WHERE (not an AND) before P1_INDU_SUBSECTOR_CD = ' '
-Kevin
|
|
|
|
|
Sorry folks, any good forum for Windows Mobile Application development.
|
|
|
|
|
You mean like the Mobile Development forum here?
only two letters away from being an asset
|
|
|
|
|
Hi All,
Do you have a code that allows me convert 3GP to MPEG4 file format?
I receive video in the form of 3gp format and would like to change them in to MPEG4 file format.
Thanks for your time
-- modified at 10:54 Thursday 16th August, 2007
|
|
|
|
|
I posted this a week ago in the Windows Forms forum, but got no responses so I'm trying it again here.
I'm trying to extend the window frame into the client area on Vista using interop to the DWMAPI. I have it working just fine when the client is running the Vista Aero theme (that's the one with glass enabled).
The problem comes in when I switch the client to running the Vista Aero Basic theme (which doesn't have glass enabled). Instead of the frame being extended into the client area without the glass effect, I don't get any change.
I know it can be done because the Vista Explorer and IE 7 do this when running under Aero Basic. My question is how is this happening? I know it's not a function of the DWM, since the call to DwmIsCompositionEnabled[^] returns false . Does anybody know what API's are being called?
|
|
|
|
|
Not sure if this is exactly what you want but I did find this video interesting on
MSDN Nuggets
Keep your eyes open, you might spot alternatives.
|
|
|
|
|
Thanks for the link. It helped confirm that I was doing everything correctly, but still didn't help figure out why the frame isn't extending on the Aero Basic theme. I emailed Daniel to see if he can provide any more insight into what is going on.
|
|
|
|