Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to make better msg from Data Tier?
Message
From
28/10/2007 20:01:44
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01263197
Message ID:
01264659
Views:
16
Go Sox! (I'm originally from Connecticut, so I guess I have to root for Boston ... although I really don't watch baseball or football anymore).

Sorry about the C# code, Dmitry. I guess I had it in my head that you were doing .NET work, as well as VFP. And since I usually answer questions in the .NET forum, I guess I didn't notice that this was the SQL forum! <g>

~~Bonnie


>Bonnie,
>
>Thank you very much for the code. I will print and study it tomorrow to see how to "translate" your code into VFP. Right now I can't concentrate on anything but football and baseball <g>. I just finished watching Patriots and in the next 30 minutes will start watching Red Sox. I have so much on my plate today <g>.
>
>Again, thank you for your help.
>
>>>I am still not convinced that I want to go back to checking duplicate ID in a separate validating routine. The only thing I have against this method is that it requires for me to create this method and to maintain it.
>>
>>How about having your base TextBox class do all that? We have our base classes automatically check for Rules compliance (typically in the control's OnValidating method) and set the color of the control accordingly. So, for example, the MyTextBox class would have these two methods, called from OnValidating:
>>
>>
>>public virtual void CheckRule()
>>{
>>	try
>>	{
>>		if (this.Parent is IMyContainer && this.oBinding != null)
>>		{
>>			DataTable table = (DataTable)this.oBinding.DataSource;
>>			string field = this.oBinding.BindingMemberInfo.BindingField;
>>			int row = this.BindingContext[table].Position;
>>
>>			if (((IMyContainer)this.Parent).CheckRule(table, field, row) > 0)
>>				this.IsRed = true;
>>			else
>>				this.IsRed = false;
>>		}
>>		else
>>			this.IsRed = false;
>>	}
>>	catch (Exception)
>>	{
>>		this.IsRed = false;
>>	}
>>}
>>public virtual void CheckColors()
>>{
>>	if (this.IsRed)
>>	{
>>		if (this.Enabled == true)
>>		{
>>			this.BackColor = System.Drawing.Color.Red;
>>			this.ForeColor = System.Drawing.Color.White;
>>		}
>>		else
>>		{
>>			this.BackColor = System.Drawing.SystemColors.Control;
>>			this.ForeColor = System.Drawing.Color.Red;
>>		}
>>	}
>>	else
>>	{
>>		if (this.Enabled == true)
>>		{
>>			this.BackColor = System.Drawing.SystemColors.Window;
>>			this.ForeColor = System.Drawing.SystemColors.WindowText;
>>		}
>>		else
>>		{
>>			this.BackColor = System.Drawing.SystemColors.Control;
>>			this.ForeColor = System.Drawing.SystemColors.WindowText;
>>		}
>>	}
>>}
>>
>>
>>The CheckRule() method in each Parent container basically passes the call up through each Parent (which can be things like Panel, GroupBox, Usercontrol, etc.) until it gets to the top (the Form). The base class for the Form doesn't do anything, that's up to the individual sub-classed Forms. We have a pretty complicated Rules class which contains a RulesCollection that's basically populated from the database from the Form. But, here's an example of how a Form might handle the CheckRule method, using the oRules collection. The RulesCollection.CheckRule() method does all the work.:
>>
>>
>>public override int CheckRule(DataTable data, string field, int row)
>>{
>>	return this.oRules.CheckRule(data, field, row);
>>}
>>
>>
>>You could also loop through every Rule comparing against the DataSet. In our first app, we didn't put this code in the Framework classes, but I've been re-vamping our Framework and this definitely needs to be added:
>>
>>protected virtual int CheckRules(DataSet ds, MyRule rule)
>>{
>>	int num = 0;
>>
>>	if (rule.Table.DataSet.Equals(ds) && ds.HasChanges())
>>	{
>>		for (int it = 0; it < ds.Tables.Count; it++)
>>			if (rule.Table.Equals(ds.Tables[it]))
>>				for (int ir = 0; ir < ds.Tables[it].Rows.Count; ir++)
>>					if (ds.Tables[it].Rows[ir].RowState != DataRowState.Unchanged)
>>						num += this.CheckRule(ds.Tables[it], rule.Field, ir);
>>	}
>>
>>	return num;
>>}
>>The above method would be called in your Form's Save method, like this:
>>
>>if (this.oData.HasChanges())
>>{
>>	for (int i = 0; i < this.oRules.Count; i++)
>>		num += this.CheckRules(this.oData, this.oRules[i]);
>>}
>>
>>
>>Anyway, that's enough for now. Enough for you to get the picture I hope.
>>
>>~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform