Select “Both Relation and Foreign Key Constraint” when creating relationship in VS Dataset designer.

MS VS Dataset Designer  allows to create a relationship (a DataRelation object) that maintains information about parent-child records in two data tables in a dataset using Relation Dialog Box.
It has option to specify type of relationship:
Both Relation and Foreign Key Constraint

Creates both a relation and foreign key constraint (see below for descriptions).

Foreign Key Constraint Only

A ForeignKeyConstraint restricts the action performed when a value in a column (or columns) is either deleted or updated.

Relation Only

A DataRelation is used to relate two DataTable objects to each other through DataColumn objects.

The default is “Relation Only“, and it causes problems, if your code  modifies primary key of referenced table and you expected cascade updates.
 
Based on my experience, it is better to use “Both Relation and Foreign Key Constraint” and specify 
Update and Delete rules as  Rule.Cascade .

May be the VS Relation Dialog Box.should not specify the defaut, but force developer to make consious desision.

Javascript to re-calculate summary based on user drop-down lists selections

I wanted to implement client javascript to re-calculate summary based on a few options(in drop-down lists) selected by the user .
The closest JS sample I found  was  Complex Client-Side Shopping Cart .But it wasn’t exactly what I wanted.
 
I created an array of custom class objects. Class has InitialPrice and SelectedPrice properties as well as

this.Diff = function( ) {
return this.SelectedPrice-this.InitialPrice; 
}
 

Each DropDownList  calls onchange Event Handler, which updates SelectedPrice value and calls RecalculateTotal();

 The RecalculateTotal() basically does the following:

var totalDiff=0.0;
for(var i=0; i<g_arrOpnClasses.length;i++)
{
var opnClass= g_arrOpnClasses[i];
totalDiff=totalDiff+opnClass.Diff();
}

and shows recalculated summary.

  
Because it was my first JS code with classes, I’ve read a few articles to solve problems, that I meet: 
 
 
To access the HTML element the event took place on:
Event Object for IE and Firefox.
function count(evt) {

var evt = evt || event;

var myObject = evt.target || evt.srcElement;
 
and more complicated (but more generic) approach described at How To Create A Global Event Object For Both IE and FireFox
 
Considered to use JSON
To populate initial values in array I considered to use JSON, but later found that it is not nesessary. Any way below are a few links that were informative for me:

Developer should not use “Hide extensions for known file types” in Windows Explorer

One my colleague got a new PC and had a problem opening file using simple code(just from MSDN example ):
 
FileInfo fi1 = new FileInfo(relativePath);



        if (!fi1.Exists)
….
It showed that file doesn’t exist. We’ve tried also File.Exists(relativePath), changed the path to absolule- the same result-
file is visible in Windows Explorer, but doesn’t exist in code. Note that directory was shown in debugger as existing.
We’ve created(using Windows Explorer) a new Text file, named “test.txt” and tried to open it in code- the same “file not exist” problem.
We’ve checked different security settings- the same.
Finally I recognized, that  Windows Explorer was set to “Hide extensions for known file types” and file visible as “test.txt” was actually created as

test.txt.txt.
The lesson: developer (and any user who has understanding of file extensions) should never have “Hide extensions for known file types” in Windows Explorer.
By the way: If you want to use a relative path from Windows Service, reset current directory  in the code
System.IO.Directory.SetCurrentDirectory (System.AppDomain.CurrentDomain.BaseDirectory);

Convert DataSet and DataTable to Xml String helper functions

I created 2 helper functions(can be modified as extensions in .Net Framework 3.5) to output/trace content of DataSet  or DataTable
public static string ToStringAsXml(DataSet ds)

{

 StringWriter sw = new StringWriter();
ds.WriteXml(sw, XmlWriteMode.IgnoreSchema);

string s = sw.ToString();

return s;

}
 

public static string ToStringAsXml(DataTable dt)
{
 StringWriter sw = new StringWriter();
dt.WriteXml(sw, XmlWriteMode.IgnoreSchema);
string s = sw.ToString();
return s;

}