Wednesday, July 9, 2008

WCF in .net

Windows Communication Foundation (WCF) is an SDK for developing and deploying services on Windows. WCF provides a runtime environment for your services, enabling you to expose CLR types as services, and to consume other services as CLR types. Although in theory you could build services without WCF, in practice building services is significantly easier with WCF. WCF is Microsoft’s implementation of a set of industry standards defining service interactions, type conversion, marshaling, and various protocols’ management. Because of that, WCF provides interoperability between services. WCF provides developers with the essential off-the-shelf plumbing required by almost any application, and as such, it greatly increases productivity. The first release of WCF provides many useful facilities for developing services, such as hosting, service instance management, asynchronous calls, reliability, transaction management, disconnected queued calls, and security. WCF also has an elegant extensibility model that you can use to enrich the basic offering. In fact, WCF itself is written using this extensibility model. The rest of the chapters in this book are dedicated to those aspects and features. Most all of the WCF functionality is included in a single assembly called System.ServiceModel.dll in the System.ServiceModel namespace.

Friday, July 4, 2008

Self-Join in SQL

when one table joins to itself, with one or two aliases to avoid confusion. A self join can be of any type, as long as the joined tables are the same.
If you have a table of members who can refer each other for services, then this might be a job for a SELF JOIN in sql where you INNER JOIN a table to itself
Syntax
CREATE PROCEDURE TestSelfJoin AS
SELECT c.custname AS 'Customer', r.custname AS 'Referrer'
FROM customers AS c
INNER JOIN customers AS r ON c.referredby=r.custnum
WHERE c.referredby<>'99999'
ORDER BY c.custname;

Wednesday, July 2, 2008

Event Objects In Javascript

Src Element
In Explorer =
The element which fired the event.
In FireFox = target, but in Firefox the nodes of type text can also fire events,
so to keep things working you'll need to climb up the tree until you find a element's (tag's) node:
var node = e.target;
while(node.nodeType != node.ELEMENT_NODE)
node = node.parentNode;


To get the Position of the window browser
relative to the screen.
In Explorer =
window.screenLeft
window.screenTop
In FireFox =
window.screenX - someValue,
window.screenY + someValue
These properties are not extactly the same as the Explorer.
In explorer they give the coordinates of the origin of
the IE control, while in Firefox they give the origin
of the Firefox window itself.

Function to element's event_name.
In Explorer = element.attachEvent( event_name, function)
In FireFox =
element.addEventListener(event_name, function, false)

Function to the node element
In Explorer =contains(node)
In FireFox =
DOM level 2 does not have an equivalent method,
but a very simple method like the shown below can be used
(it works in Firefox and Explorer):
function contains(a, b)
{
// we climb through b parents
// till we find a
while(b && (a!=b) && (b!=null))
b = b.parentNode;
return a == b;
}
The new DOM level 3 standard defines
node.compareDocumentPosition() and
Firefox already implements it, but Explorer doesn't.

To obtain the window in which the document is.

In Explorer =document.parentWindow
In FireFox = document.defaultView.
Note that the window object is available everywhere.

Access a form
In Explorer = myForm
In FireFox =document.myForm, it works everywhere.



Tuesday, July 1, 2008

Validate Multiple Email Addresses in javascript

function mailValidation()
{
var emailfield = document.getElementById('controlId').value;
var email = emailfield.split(';');
if(email.length > 0)
{
document.getElementById('spanId').innerHTML="";
for(var i=0;i < email.length;i++)
{
if(!validateEmails(email[i],1,1,'spanId','controlId'))
{
alert("Test");
}
var toSpan = document.getElementById('spanId').innerHTML;

}
if(toSpan != "")
{
return false;
}
}
}
function validateEmails(addr,man,db,SpanId,controlId)
{
if (addr == '' && man) {
if (db)
document.getElementById(SpanId).innerHTML="Enter To address ";
document.getElementById(controlId).focus();
return false;
}
if (addr == '') return true;
var invalidChars = '\/\'\\ ",:?!()[]\{\}^|';
for (i=0; i if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
if (db)
document.getElementById(SpanId).innerHTML="To address contains invalid characters(Enter in the format:name@example.com;name@example.com)";
document.getElementById(controlId).focus();
return false;
}
}
for (i=0; i if (addr.charCodeAt(i)>127) {
if (db)
document.getElementById(SpanId).innerHTML="To address contains non ascii characters";
document.getElementById(controlId).focus();
return false;
}
}

var atPos = addr.indexOf('@',0);
if (atPos == -1) {
if (db)
document.getElementById(SpanId).innerHTML="Email address must contain an @";
document.getElementById(controlId).focus();
return false;
}
if (atPos == 0) {
if (db)
document.getElementById(SpanId).innerHTML="Email address must not start with @";
document.getElementById(controlId).focus();
return false;
}
if (addr.indexOf('@', atPos + 1) > - 1) {
if (db)
document.getElementById(SpanId).innerHTML="Email address must contain only one @";
document.getElementById(controlId).focus();
return false;
}
if (addr.indexOf('.', atPos) == -1) {
if (db)
document.getElementById(SpanId).innerHTML="Email address must contain a period in the domain name";
document.getElementById(controlId).focus();
return false;
}
if (addr.indexOf('@.',0) != -1) {
if (db)
document.getElementById(SpanId).innerHTML="period must not immediately follow @ in email address";
document.getElementById(controlId).focus();
return false;
}
if (addr.indexOf('.@',0) != -1){
if (db)
document.getElementById(SpanId).innerHTML="period must not immediately precede @ in email address";
document.getElementById(controlId).focus();
return false;
}
if (addr.indexOf('..',0) != -1) {
if (db)
document.getElementById(SpanId).innerHTML="Two periods must not be adjacent in email address";
document.getElementById(controlId).focus();
return false;
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
if (db)
document.getElementById(SpanId).innerHTML="Invalid primary domain in email address";
document.getElementById(controlId).focus();
return false;
}

}

javascript validation for gridview

var theGridView = null;
theGridView = document.getElementById(gridViewCtlId);
for ( var rowCount = 1; rowCount < theGridView.rows.length; rowCount++ )
{
var theGridViewRemarks = theGridView.rows[rowCount].cells[0];
var textbox = theGridView.rows[rowCount].cells[0];
if(isFireFox())
{
var value= textbox .firstChild.nextSibling;
alert(value);
}
else
{
var value= textbox .firstChild;
alert(value)
}
}