|
I am just wondering if there is a pattern for programming conditions which are not known by the programmer at programming time; i.e. the conditions are set by the user.
For example, the user may define a set IF conditions, and corresponding actions. If the IFs were finite, that would be easy. However, the user has a variable set of conditions/rules. A good example of this is a ERP-purchasing module application. The routing of a purchase order depends on approval level. The levels of approval are determined by the company policy. There could be any number of approval levels.
In other word
IF condition 1... then action 1
IF condition 2... then action 2
..
IF Condition n.... then action n
but N is unknown at programming time. So I can't use the the typical if-else block.
Any suggestions on how to handle this.
|
|
|
|
|
Is this the sort of thing you mean? User Defined Dynamic Workflows in Workflow Foundation 4?[^]
I'm almost certain that I've seen an article posted here about creating 1 to n dynamic workflows - I'll leave you to search for it.
I would also think it possibel to do this by giving the users a blotter on which they can describe a workflow which is stored in a database. You then create forms based on the steps they have stored. That was off the top of my head so feel free to poke hole sin it. The idea, not my head...
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
If I understood correctly you may use "not" !. I mean may be you shouldn't check all possibilities for user input. For example instead of checking this
string userInput; //Got this from user input sould be "c"
if(userInput == "a")
{}
else if(userInput == "b")
{}
else if(userInput == "c")
{//Correct}
You can use
if(userInput == "c")
{//Correct}
else
{}
|
|
|
|
|
I find myself wondering how this question could possibly reflect a real-world scenario.
The fact that there are "any number of approval levels" does not justify an assumption that the possible conditions are "infinite:" there is probably a fixed number of maximum approvals possible, or required. And, probably, a certain minimum of approvals required to even process the order.
That the set of all possible permutations of approvals would require a unique action for each permutation: also seems a dubious assumption.
And, isn't there some "hierarchy" involved here: a decision by upper-management to cancel/void/dis-approve takes precedence over other lower-level decision makers, which means you can deduce the action required without consideration of certain other levels ?
In the real world, "hierarchy" also "kicks-in," in financial transactions, dependent upon customer credit, and $ize of order, as well as customer history, or internal (or external credit agency) rating.
My guess is there is a finite, and well-defined, set of actions to be taken based on approvals of purchase order.
So, present an interface with CheckBoxes: logical analysis of which are Checked then can be mapped to a list of appropriate actions. Or, present a TreeView with CheckBoxes, where you handle "hierarchy" by activating, or de-activting, sub-nodes, depending on whether "parent" nodes are checked. Then iterate the TreeView (recursively), and generate a list of actions based on all Checked Nodes.
"The first principle is that you must not fool yourself, and you are the easiest person to fool." Richard Feynman
|
|
|
|
|
The answer to this depends on how flexible the user input and required response is supposed to be. It can go from simply holding a list of allowed values to embedding a scripting engine. To give any useful guidance we'll need to know more about what the user is expecting to be able to enter as conditions and actions.
|
|
|
|
|
SilimSayo wrote: I am just wondering if there is a pattern for programming conditions which are
not known by the programmer at programming time; i.e. the conditions are set by
the user.
That is not specific enough. There are a number of ways of dealing with that of which the specifics matter which way to implement it.
SilimSayo wrote: For example, the user may define a set IF conditions, and corresponding actions
As expressed that requires an interpreter idiom (which is a pattern.)
SilimSayo wrote: but N is unknown at programming time. So I can't use the the typical if-else
block.
That of course has nothing to do with the problem as you expressed it. If you have defined conditions/actions and ALL the user does is pick from that set then the solution is trivial - use a set with an appropriate definition block. This is a very, very simple form of interpreter.
However that doesn't solve it if the conditions/actions themselves are user defined.
|
|
|
|
|
I would consider a collection of Func<bool>, Action pairs. then simply foreach the collection and if the Func<bool> returns true invoke the Action.
building the collection is another matter and would really depend on what conditions you want the user to be able to define
Pedis ex oris
Quidquid latine dictum sit, altum sonatur
|
|
|
|
|
Please help! do I need to synchronize mysql to Access database. preferably via xml. I managed to get mysql database structure:
Table name="data">
<Field name="id" type="int(11)" null="NO" key="PRI" default="" autoincrement="false"/>
<Field name="data" type="varchar(255)" null="NO" key="" default="" autoincrement="false"/>
<Field name="data2" type="varchar(255)" null="NO" key="" default="" autoincrement="false"/>
</Table>
I do not know how to write the database access.When I need to add a column in MySQL to create and access databases, without losing the original data.I also needed to synchronize data that has changed. many thanks for your help
|
|
|
|
|
What do you mean "write the database access?"
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
MS Access does not read XML. You can create a MYSQL connection in ODBC, and you can link MS Access to any ODBC data source i.e. use linked tables. Linked tables don't store data so if you make a change in the data in Access, you would be changing data in MYSQL and vice-versa.
|
|
|
|
|
You could write an API as an application to sit in front of MySQL and then a macro or application to sit in front of the Access database to consume the XML, but it would be... interesting, not to mention the deadlocks you would probably get would be a nightmare to sort out.
|
|
|
|
|
hi
i try to reverse string on access in sql query and C# like this:
SQL = "SELECT StrReverse(Des) from MyTbl";
dsView = new DataSet();
adp = new OleDbDataAdapter(SQL, Main.Conn);
adp.Fill(dsView, "MyTbl");
adp.Dispose();
dataGridView1.DataSource = dsView.Tables["MyTbl"].DefaultView;
and i get this error: Undefined function 'StrReverse' in expression.
but if i run this query on access its works excellent
what can be the problem ?
|
|
|
|
|
StrReverse is a VBA function that is not available outside of Access. You can only use the supported SQL functions from outside of Access.
The list of what Access supports in SQL statements can be found here[^].
Basically, if you can use the function name in VB, you can't use it in SQL.
|
|
|
|
|
In addition to Dave Kreskowiak's answer. OleDb also has "predefined" keywords. Sometimes you'll need to change column names or change the SQL to pass around this.
Just for info.
(PS: I don't think that's the case here btw)
V.
|
|
|
|
|
hey.. can anyone tell me that how can i convert files(doc,pdf etc) to UDF(universal disk formate) using .net libraries.. if not then is there any third party software tht does so.. doc to udf conversion ? i have checked out but found plenty of third party softwares that convert udf to other formats not ..other formats to udf ????plz reply otherwise i will be fired.. lolx
|
|
|
|
|
That makes no sense. It's like asking how to convert a doc file to a zip file. Or like asking how to convert a stack of paper to a suitcase. The paper goes inside, it does not "become" the suitcase.
What do you really want? Put files together in an UDF file? Or convert an ISO to UDF perhaps?
|
|
|
|
|
hmm thanks.. iso to udf.. regards
|
|
|
|
|
Ok, I don't know of any .NET libraries that will help you with that.
|
|
|
|
|
and wht about the third party softwares ?
|
|
|
|
|
Nero can definitely do it, I thought MagicISO too but I'm not very sure about that one.
|
|
|
|
|
hmm ok thanks.. very much..
|
|
|
|
|
Hi everyone,
I'm having trouble with the Application.DoEvents() in my c# application.
The application is for setting up a measurement with an oscilloscope and reading the data.
I have a loop, doing roughly this:
SetupHardware();
while(this.Run == true)
{
Application.DoEvents();
StartMeasurement();
ReadData();
AddDataToGraphControl();
}
I added the "Application.DoEvents()" because the user can change instrument settings with a form, and the controls' events need to be handled for that. Also the "Stop" button sets the global boolean "Run" to false.
Since the Application.DoEvents() doesn't seem to handle ALL pending events (I'm probably doing something wrong here, but that's another story), I started googling about Appication.DoEvents(), and found that I should avoid using it, and use multithreading instead.
I'd like to believe that, but I think in this case the use of Applicaition.DoEvents is the best practice here...
Can someone shine some light on this? Am I correct in thinking this is an exception to the "don't-use-DoEvents()" rule? How could I approach this using multitheading (which I haven't used before)?
modified 7-Feb-12 5:36am.
|
|
|
|
|
DoEvents is rarely the correct approach, and I don't think this is an exception. What you should do is have a thread which handles the instrument I/O (well, I, in this case ) and fires events which the main thread hooks up to:
class InstrumentThread {
Thread t;
public event EventHandler<InstrumentEventArgs> DataReceived;
public Thread Thread { get { return t; } }
public InstrumentThread(){
t = new Thread(Run);
}
private void Run(){
while(running){
StartMeasurement();
ReadData();
DataReceived(new InstrumentDataEventArgs(data));
}
}
}
class InstrumentEventArgs : EventArgs {
SomeType Data { get; private set; }
public InstrumentEventArgs(SomeType data) { Data = data; }
}
class MyForm : Form {
public MyForm(){
it = new InstrumentThread();
it.DataReceived += InstrumentDataReceived;
it.Thread.Start();
}
void InstrumentDataReceived(object sender, InstrumentEventArgs ea){
if(InvokeRequired) {
BeginInvoke(new EventHandler<InstrumentEventArgs>(InstrumentDataReceived), new object[] { sender, ea });
return;
}
AddDataToGraphControl(ea.Data);
}
}
|
|
|
|
|
Thank you for your reply. I'm still struggling with the instrument setup (setting vertical range, timebase, etc).
These settings should (to maintain a decent framerate) only be written to the instrument when the user changes a setting on the form. And on a fixed position: before StartMeasurement() (well, most importan is not between StartMeasurement() and ReadData(); that would cause problems).
I could ofcourse do:
NumericUpDown_VerticalRange_ValueChanges(Object sender, EventArgs e)
{
this.InstrumentSetupChanged = true;
}
and then in the InstrumentThread's Run method use
private void Run(){
while(running){
StartMeasurement();
ReadData();
DataReceived(new InstrumentDataEventArgs(data));
}
}
But I doubt working with this flag is a proper approach?
|
|
|
|
|
I'd have no problem with that, though normally I'd push messages onto a queue or something and then clear it where you put your comment. But if the message is just 'do something' then a flag is fine.
|
|
|
|