Saturday, May 31, 2008

Microsoft E-Reference Library 24x7

Joined Microsoft E-Reference Library 24x7 on Books24x7
Good gift from Microsoft for allowing to access some of the rarely available books in market on various category of Technology includig books on

  • Programming Books
  • Certification Books (MCAD, MCDBA, MCPD, MCTS, etc).
  • Books in Business categor
  • Software Design and Software Engineering Books

Some of good Title i would like to read

  • Developing More-Secure Microsoft ASP.NET 2.0 Applications
  • Working with Microsoft Visual Studio 2005 Team System
  • Improving .NET Application Performance and Scalability: Patterns & Practices
  • Programming Microsoft ASP.NET 3.5
  • Microsoft ASP.NET 3.5 Step by Step
  • Microsoft Windows Workflow Foundation Step by Step
  • Microsoft Windows Communication Foundation Step by Step
  • And lot more...

http://microsofteref.books24x7.com/
http://books24x7.com/

Thursday, May 29, 2008

Implement Code Format in Asp.net Application

Implement Code Format in Asp.net Application


Lets understand how to embed code formatting in Asp.net Application. This can be useful while user enters the code online, and we need to format the code and able the preview the same. Example, on online forum or blog if user enters code, application should be smart to understand the part of code and able to format.

This Code Format utility used Manoli Csharp Format, I have used the sourcecode and demonstrate how this can be useful to implement code format in asp.net application.

Step1: Download Sourcecode from Manoli Online Code Format
To accomplish this task, download source code of manoli csharpformat.
Direct link for downloading Sourcecode of Manoli CsharpFormat

Step2: Compile the Class Library Project to generate binaries.

Step3: Create an asp.net application, while will be used to display Formatted Code.

Step4: Right Click project and Add Reference.
- Add Reference of binaries generated by Manoli Code Format Class Library Project

Step5: Add csharp.css file available with Manoli Code Format Sourcecode.
- Right Click and Add Existing Item and browse through location where csharp.css file is located. (This file will be available with sourcecode)
- And add link reference in default.aspx
<link href="csharp.css" rel="stylesheet" type="text/css" />

After adding .dll file and .css file your solution explorer.




Step6: Add the 2 textbox controls, 1 button control and 1 label control.
2 – Textbox control, 1 for taking input and other for displaying generated html code.
1 – Label control for displaying preview.



Step7: Add ValidateRequest=”false” in page derective for taking HTML Input
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs"
Inherits="_Default"
ValidateRequest="false" %>

Step8: Looking class diagram of Manoli Code Formatter
- You can create object for each language you wish to format.



Step9: Writing a Code to make everything works.

protected
void btnPreview_Click(object sender, EventArgs e)
{
string InputCode = txtInputCode.Text;
string HTMLCode = SmartFormat(InputCode, "C#", true, true);
lblPreview.Text = HTMLCode;
txtCode.Text = HTMLCode;
}

/// <summary>
/// SmartFormat - Takes InputCode as string
/// and returns Generated HTML Code.
/// </summary>
/// <param name="InputCode"></param>
/// <returns></returns>
private string SmartFormat(string InputCode, string Language,
bool LineNumber,bool AlternateBackground)
{
string OutputHTML = string.Empty;
if (InputCode != string.Empty)
{
SourceFormat FormatCode;
Language = Language.ToUpper();
switch (Language)
{
case "C#":
FormatCode = new CSharpFormat();
break;
case "JS":
case "JavaScript":
FormatCode = new JavaScriptFormat();
break;
case "VB":
FormatCode = new VisualBasicFormat();
break;
case "HTML":
case "XML":
case "ASPX":
FormatCode = new HtmlFormat();
break;
case "SQL":
FormatCode = new TsqlFormat();
break;
case "MSH":
FormatCode = new MshFormat();
break;
default:
FormatCode = new CSharpFormat();
break;
}
FormatCode.LineNumbers = LineNumber;
FormatCode.Alternate = AlternateBackground;
OutputHTML = FormatCode.FormatCode(InputCode);
}
return OutputHTML;
}
Output


Download Example Demo Application

Similarly you can use different combination of language and output can use the code format utility in asp.net application.

Wednesday, May 28, 2008

Trim Characters in SQL Server

How to Trim Characters in SQL Server

If you are looking for following solution than probably this post can help you out:

  • How to Trim Characters in SQL Server
  • How to Extract Part of String in SQL Server
  • Returning only Numeric Part of String in SQL Server
  • Trim String in SQL Server
  • Trim Left and Right Portion of String in SQL Server
  • How to Sort Numeric String in SQL Server.

Note: The Example I am going to discuss is the solution for above mention criteria, understand it and you can be able to derive solution for your problem.

I want to sort a string like this.

Nodes

1-49

100-249

1000-2499

10000+

250-499

2500-4999

50-99

500-749

5000-9999

750-999


Lets go step by step and then letter sum it up.

Step1: To undergo this task I need to extract characters from left till this “-“ or “+” character.

Let find length till this “-“

select distinct MyExpr,charindex('-',MyExpr)-1 as Nodes from MyTable

1-49

1

10000+

-1

750-999

3

5000-9999

4

250-499

3

1000-2499

4

500-749

3

2500-4999

4

100-249

3

50-99

2

































So I also require separate statement for

select distinct MyExpr,charindex('-',MyExpr)-1 as Nodes from MyTable

1-49

-1

10000+

5

750-999

-1

5000-9999

-1

250-499

-1

1000-2499

-1

500-749

-1

2500-4999

-1

100-249

-1

50-99

-1

Now lets extract part of string by using substring function and case select statement.

select distinct MyExpr as Nodes,

substring(MyExpr,1,(

case

when charindex('-',MyExpr)-1 = '-1'

then charindex('+',MyExpr)-1

else charindex('-',MyExpr)-1 end

)

)

as 'NodesSort'

from MyTable

Order by 'NodesSort'

So this gives us extraction of Part of string from string. You can also see trim right portion of string.

1-49

1

100-249

100

1000-2499

1000

10000+

10000

250-499

250

2500-4999

2500

50-99

50

500-749

500

5000-9999

5000

750-999

750


Now casting the string and displaying in sorted order.

Casting string to int and applying order by for sorting.

select distinct MyExpr as Nodes,

-- SORT Logic

cast(

substring(MyExpr,1,(

case

when charindex('-',MyExpr)-1 = '-1'

then charindex('+',MyExpr)-1

else charindex('-',MyExpr)-1 end

)

)

as int) as 'NodesSort'

from MyTable

order by 'NodesSort'

1-49

1

50-99

50

100-249

100

250-499

250

500-749

500

750-999

750

1000-2499

1000

2500-4999

2500

5000-9999

5000

10000+

10000


This method is not optimal, as we are using functions within function to achieve task, but yet you can achieve the solution, if anyone of you know more better way to achieve same task than please share.

Sunday, May 25, 2008

Best Wireless Keyboard and Mouse

Best Wireless Keyboard and Mouse.

Logitech Cordless Desktop S 510

Is best keyboard and mouse, how lets consider few factor on which i came to conclusion and which turns to right decision.


Few days back i was like one of you searching on net for best wirless keyboard and mouse, i had read reviews on circuity city, bestbuy websites, but they were making me more confuse., oops and schemes, discount, special offer for buying low cost keyboard, mouse were making the situation worst.


Ok let me share how i have conclude that Logitech Cordless Desktop S 510 is best keyboard and mouse.
  • Brand Trust (Logitech is most reliable than any other brand when it comes to mouse and keyboard.)
  • Performance when operating from far Distance, signals are not fadeing and they are accurate.
  • Battery Life, it is most power saver keyboard and mouse as compare to other products available in market, which was another factor which made my decision easy.
  • Cost Effective, Smart choice. There were lot of keyboard i came across which were available for as low price as 20 bucks, but when i compare with power saving and ease of use, most turns to headache.
  • Shape and design of keyboard, it is very convinient, it is really easy to use. (Specially for those who love to use TVS Gold style keyboard.)
  • Keyboard is Smooth and soft, it is not making disturbing noice, which seems important when you work during late night.

About price i had purchase for 49.99 USD + Tax

I am personally using these pair of keyboard and mouse from last 3 months and it had made my life so easy that made me share my experience.

Good Luck and Happy shopping.

Saturday, May 24, 2008

Black Friday

Had anyone notice that specially for Friday the traffic from Search Engine to the website was the lowest? What happen suddenly i have re-check and feeling that things are not normal for friday, but now everything seems undercontrol!

If anyone of you got the conclusion of problem with Search Engine on Friday, than share your knowledge.




Result from Google Analytics

On Friday (Abnormal Change)



On Normal Day

Thursday, May 22, 2008

Disable Multiple Button Click in Asp.net

This post is a step enhance version of my previous post: Preventing Multiple Button Click on Asp.net Page

Problem: How to disable button immediately on user click in asp.net so that user cannot click multiple time.

Solution: To solve this problem use regular html button, including runat=”server” attribute and write the disable client-side click event which disable button immediately and server-side event which runs the actual code for click event.


To perform this task add javascript function.

Client-Side Event to disable button immediately.
<head runat="server">
<script language = "javascript">
var c=0;
function DisableClick()
{
var objName = 'Button1';
document.getElementById(objName).disabled=true;
c=c+1;
msg = 'Please Wait...('+ c +')!';
document.getElementById(objName).value= msg;
var t=setTimeout('DisableClick()',1000);
}
</script>
</head>

Note: Replace “Button1” with object name of button control

And following button code in body.


Button Control – HTML Button instead of Asp button.
<INPUT id="Button1"
onclick="DisableClick();" type="button"
value="Submit Payment" name="Button1"
runat="server" onserverclick="Button1_Click">

Note: onclick event is calling javascript client-side function and onserverclick event is calling server-side function which performs actual task.


Server-Side Event to perform actual task
This task can be any as per your logic, for an example I am performing some heavy time consuming task, you can even make use of Threading concept to minimize code…

protected void Button1_Click(object sender, EventArgs e)
{
ArrayList a = new ArrayList();
for (int i = 0; i < 10000; i++)
{
for (int j = 0; j < 1000; j++)
{
a.Add(i.ToString() + j.ToString());
}
}
Response.Write("I am done: " +
DateTime.Now.ToLongTimeString());
}



Before Button Click








During Button Click







After Task is done





Related Links:

Tuesday, May 20, 2008

InStr Function in SQL Server

Visual basic support “InStr” Function, which Returns the starting position of the specified expression in a character string.


To perform same task in SQL Server used CHARINDEX Function.

“CharIndex” Function is equivalent to “InStr” Function of SQL Server.

Example 1:

select Phone,charindex('-',Phone) from customers

Result

030-0074321

4

(5) 555-4729

8

(5) 555-3932

8

(171) 555-7788

10

0921-12 34 65

5

0621-08460

5

88.60.15.31

0

You can also specify start position

Example 2:

select Phone,charindex('-',Phone,5) from customers

here start position is 5.

Result

030-0074321

0

(5) 555-4729

8

(5) 555-3932

8

(171) 555-7788

10

0921-12 34 65

5

0621-08460

5

88.60.15.31

0

Most Recent Post

Community Updates

Subscribe Blog via Email

Enter your email address:



Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.
Page copy protected against web site content infringement by Copyscape