|
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.
|
|
|
|
|
Yeah, I would have thought there was some way of knowing, since Vista makes that judgement on who is privileged enough to use the glass effect.
Keep your eyes open, you might spot alternatives.
|
|
|
|
|
Hi,
How can I retrieve Files/Folder from the "System Volume Information" folders from my system using C# code?
thanks & regards,
ramesh
|
|
|
|
|
Hello,
I don't really know, what you want to do,
but have a look at the "System.IO.Directory" namespace.
There are lot's of usefull features.
Here the msdn link[^]
All the best,
Martin
|
|
|
|
|
Hi,
you won't be able to do that with regular stuff such as File and Directory.
and you can't open it with Windows Explorer
it is not even a regular folder, it is more special than the RECYCLER folder.
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 am new to programming .net and i have a project to convert a java servlet that handles the headers and footers of all our websites into a .net dll so all .net apps can use this.
Any suggestions on where to start and/or articles would be appreciated, exspecally concerning the conversion of httpservlet calls.
I have been programming in Java for 3 years, and have limited .net experince, but have been a web dev for 10 years and used to program in vb6. We are using c# though.
Thanks for any suggestions, sorry so vauge.
|
|
|
|
|
You need to look at an HttpHandler. There are many examples easily found in google. Note that this doesn't work across all sites (you will need to install it on a per-site/server basis), and it doesn't cope with none ASP.NET pages.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi,
there is Visual Studio J# Express Edition 2005, which works with a language that
looks, smells and feels like Java, and integrates well with the other CLR languages.
I don't know how long it will be supported and survive, but it is there now.
I expect it could deliver your .NET DLL in a snap.
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
|
|
|
|
|
Luc Pattyn wrote: I don't know how long it will be supported and survive
It has been killed, i.e, there will be no new versions. But it will be supported in the usual MS way - extended support with security patches I guess for 10 years from Nov 2005?
Kevin
|
|
|
|
|
Thanks for the info.
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
|
|
|
|