Monday, May 28, 2007

Thousand Separator function for Java Script

     In my project, I have to display the total of selected item in thousand separated format. I am using java script to find total of selected values. Now I have to display the result in Thousand deperated format (like 12,345.00). Here the function that I have used to do that.   

 

 <script language = "javascript">
function ThousandSeparator(decimalDigits,Value)
{

// Separator Length. Here this is thousand separator
var separatorLength = 3;

var OriginalValue=Value;

var TempValue = "" + OriginalValue;

var NewValue = "";

// Store digits after decimal
var pStr;

// store digits before decimal
var dStr;

// Add decimal point if it is not there
if (TempValue.indexOf(".")==-1){TempValue+="."}

dStr=TempValue.substr(0,TempValue.indexOf("."));

pStr=TempValue.substr(TempValue.indexOf("."))

// Add "0" for remaining digits after decimal point
while (pStr.length-1< decimalDigits){pStr+="0"}

if(pStr =='.') pStr ='';

if(dStr.length > separatorLength)
{
// Logic of separation
while( dStr.length > separatorLength)
{
NewValue = "," + dStr.substr(dStr.length - separatorLength) + NewValue;
dStr = dStr.substr(0,dStr.length - separatorLength);
}

NewValue = dStr + NewValue;

}
else
{
NewValue = dStr;
}


// Add decimal part
NewValue = NewValue + pStr;

// Show Final value
alert(NewValue);



}

</script>
 Fig (1) Thousand Separator Function in Java Script

   You just need to  pass 2 parameters. Number of digits require after decimal point and value you want to conver in thousand seperated format.


Happy Programming !!

Saturday, May 26, 2007

An error occured while establishing a connection to server. When connectiing to SQL Server 2005,...SQL Network Interfaces, error:26 - Error Locating Server/Instance Specified.

      I have seen this error so many time so I thought that let me post the solution that work for me. First thing check your connection string that it points correct server. This is the most common mistake. Sometime connection string points to SQL Express, while machine does not have SQL Expressed installed.

      If the connection string is correct, second step is to check congiguration of SQL. Click on Start - All Programms - Sql Server 2005 - Configuration Tool - SQL Server Configuration Manager. 

      Click on SQL Server 2005 Network configuration - Protocols for MS SQL Server. Make sure that TCP/IP and Named Piped are Enable. If not that enable it. Now click on SQL Server 2005 Services. Restart Sql Server Browser Service and then restart SQL Server (MSSQLSERVER) service. Yupiiii !!! its all. Check your application now your error should be resolved.

Happy Programming !!

Thursday, May 24, 2007

Disable right click on page.

       Here is the code to disable right click on page.

<html>
<body oncontextmenu="return false;">
     Try right click.
</body>
</html>

   Happy Programming !!

Prototype.js

       Today while surfing, I found a good javascript framework Prototype.js. It is a JavaScript library written by Sam Stephenson. This amazingly well thought and well written piece of standards-compliant code takes a lot of the burden associated with creating rich, highly interactive web pages that characterize the Web 2.0 off your back.

       This framework helps the developers to write a good javascript witout knowing much about syntax of javascript and reduce the overhead of remembering lots of complex function.

      You can download this library from here.

       Here is a really good artilce which explains few methods of prototype.js with examples.

UML Diagrams

      I have to create class and Sequence diagrams in my recent project. I was searching for for some quick and good material for UML diagrams. I found the really cool article here.

Thursday, May 03, 2007

Custom DateTime Format Specifier

      Yesterday during surfing I foud really important material on net. I was feeling sleepy so not addded site in favorite and hence notable to give reference here. However I have copied the content in notepad. Its really very helpfull.

d

Displays the current day of the month.

dd

Displays the current day of the month, where values < 10 have a leading zero.

ddd

Displays the three-letter abbreviation of the name of the day of the week.

dddd(+)

Displays the full name of the day of the week represented by the given DateTime value.

f(+)

Displays the x most significant digits of the seconds value. The more f's in the format specifier, the more significant digits. This is total seconds, not the number of seconds passed since the last minute.

F(+)

Same as f(+), except trailing zeros are not displayed.

g

Displays the era for a given DateTime (for example, "A.D.")

h

Displays the hour, in range 112.

hh

Displays the hour, in range 112, where values < 10 have a leading zero.

H

Displays the hour in range 023.

HH

Displays the hour in range 023, where values < 10 have a leading zero.

m

Displays the minute, range 059.

mm

Displays the minute, range 059, where values < 10 have a leading zero.

M

Displays the month as a value ranging from 112.

MM

Displays the month as a value ranging from 112 where values < 10 have a leading zero.

MMM

Displays the three-character abbreviated name of the month.

MMMM

Displays the full name of the month.

s

Displays the number of seconds in range 059.

ss(+)

Displays the number of seconds in range 059, where values < 10 have a leading 0.

t

Displays the first character of the AM/PM indicator for the given time.

tt(+)

Displays the full AM/PM indicator for the given time.

y/yy/yyyy

Displays the year for the given time.

z/zz/zzz(+)

Displays the timezone offset for the given time.

 

       Take a look at the following lines of code, which demonstrate using string format specifiers to create custom-formatted date and time strings:  

DateTime dt = DateTime.Now;
Console.WriteLine(string.Format(
"Default format: {0}", dt.ToString()));
Console.WriteLine(dt.ToString(
"dddd dd MMMM, yyyy g"));
Console.WriteLine(string.Format(
("Custom Format 1: {0:MM/dd/yy hh:mm:sstt}", dt));
Console.WriteLine(string.Format(
("Custom Format 2: {0:hh:mm:sstt G\\MT zz}", dt));
 

Here is the output from the preceding code:

Default format: 9/24/2005 12:59:49 PM
Saturday 24 September, 2005 A.D.
Custom Format 1: 09/24/05 12:59:49PM

Custom Format 2: 12:59:49PM GMT -06


Happy Programming!!