VB.Net overlap dates.

March 20, 2008

If you want to check overlap between dates you can use this function

Public Shared Function IsOverlapDate(ByVal D1Begin As Date, ByVal D1End As Date, ByVal D2Begin As Date, ByVal D2End As Date) As Boolean

If Date.Compare(D1Begin, D2End) <= 0 And Date.Compare(D1End, D2Begin) >= 0 Then

Return True

End If

Return False

End Function

‘_____________________________________________________

Then try to test The function

Dim DBegin1 as New Date(2008,2,14)

Dim DEnd1 as New Date(2008,3,22)

Dim DBegin2 as New Date(2008,3,10)

Dim DEnd2 as New Date(2008,4,21)

Dim DBegin3 as New Date(2008,4,2)

Dim DEnd3 as New Date(2008,4,3)

Dim blnResult as Boolean

blnResult = IsOverlapDate(DBegin1,DEnd1,DBegin2,DEnd2) ‘ It is return true

blnResult = IsOverlapDate(DBegin3,DEnd3,DBegin2,DEnd2) ‘ It is return true

blnResult = IsOverlapDate(DBegin1,DEnd1,DBegin3,DEnd3) ‘ It is return false

Advertise from my country.

March 17, 2008

myad.jpg

It isn’t about software developer but i like it.If you want to watch it click the picture.

.Net Interview Questions

March 5, 2008

ASP.NET DataGrid questions

ASP.NET Interview Questions

Hanselman ASP.NET Interview Questions

Advanced C# interview questions

Design Patterns resources.

March 5, 2008

These below links are articles about Design Patterns that i found.

You may familar with C++ for use this resource.

http://users.csc.calpoly.edu/~dbutler/tutorials/winter96/patterns/

Some of demonstate how to use Design Patterns with .Net from msdn

http://msdn2.microsoft.com/en-us/magazine/cc301852.aspx

This site is most reference about Design Patterns if you are .Net developer.
It was used to be #1 when you google “Design patterns”.
It describe all of 23 Gof patterns and has some coding sample.
And now it is include AJAX Design Patterns and alos WPF Design Patterns.

http://www.dofactory.com/Patterns/Patterns.aspx

This is amount of articles explain about how to use Design Patterns.
http://www.c-sharpcorner.com/Articles/ArticleListing.aspx?SectionID=1&SubSectionID=62

And at wikipedia it is describe all about Design Patterns and some related links.

http://en.wikipedia.org/wiki/Design_pattern_(computer_science)

Display Hello World without semicolon

March 4, 2008

C# version

namespace WriteHelloWorld
{
class Program
{
static void Main(string[] args)
{

while (!”0″.Equals(System.Console.Title = “Hello world”).Equals(System.Console.ReadLine()))
{
}

}
}
}

C++ version
#include “stdio.h”

int main()
{
while( !printf( “Hello Worldn” ) )
{
}
}

Display password javascript

February 15, 2008

When I read The Dramatic Password Reveal

I decided to wrote display password mode by javascript.

Here it is.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>

<script type=’text/javascript’>

function DisplayPassword()
{
var chk = document.getElementById(‘chkPassword’);
var PWD=document.getElementById(‘PWD’);
var tPWD=document.getElementById(‘tPWD’);
if(chk.checked)
{
tPWD.style.display=’block’;
PWD.style.display=’none’;
}
else
{
tPWD.style.display=’none’;
PWD.style.display=’block’;
}

}
function ChangeValue(v)
{
var PWD=document.getElementById(‘PWD’);
var tPWD=document.getElementById(‘tPWD’);
if(v==’1′)
{
tPWD.value = PWD.value;
}
else
{
PWD.value = tPWD.value;
}
}
</script>
</HEAD>

<BODY>
<INPUT TYPE=”password” id=”PWD” onkeyup=’ChangeValue(1);’>
<INPUT TYPE=’text’ id=”tPWD” onkeyup =’ChangeValue(2);’>
<br>
<INPUT TYPE=”checkbox” NAME=”” id=”chkPassword” onclick=”DisplayPassword();” value=”Show Password”>
<script type=’text/javascript’>
document.getElementById(‘tPWD’).style.display=’none’;
</script>
</BODY>
</HTML>

display-pass.png

Handler Error VB.Net

February 14, 2008

Every program has error and we meet it again and again sometimes we need to copy exception message and VB 2005 not provide convenient way to copy it.

This article demonstrate how we handler exception while development phase.

 

 

 

1. Create class for contain exception data.

 

Public Class ExceptionData

 

Public FileName As String

Public ClassName As String

Public Method As String

Public Section As String

Public Ex As Exception

 

Sub New(ByVal strFileName As String, ByVal strClassName As String)

Me.FileName = strFileName

Me.ClassName = strClassName

 

End Sub

 

End Class

 

 

2. Create class for handler Error.

this class is use for create text for display for us.

 

 

Public Class ErrorHandler

 

Public Shared Sub ShowError(ByVal cEx As ExceptionData)

 

Dim f As New frmShowErrorforDebug

f.ErrorDisplay = GetStringfromException(cEx)

f.ShowDialog()

End Sub

 

Public Shared Function GetStringfromException(ByVal File As String, ByVal ClassName As String, ByVal Method As String, ByVal Section As String, ByVal EX As Exception) As String

 

Dim strB As New System.Text.StringBuilder

 

strB.Append(“Error Occur “).Append(vbCrLf).Append(vbCrLf)

 

 

strB.Append(“File :”).Append(File).Append(vbCrLf)

strB.Append(“ClassName :”).Append(ClassName).Append(vbCrLf)

strB.Append(“Method :”).Append(Method).Append(vbCrLf)

 

 

If Not IsNothing(Section) Then

If Section.Trim <> “” Then

strB.Append(“Section :”).Append(Section).Append(vbCrLf)

 

End If

End If

 

strB.Append(“Source :”).Append(EX.Source).Append(vbCrLf)

strB.Append(“Method throw current exception :”).Append(EX.TargetSite.Name).Append(vbCrLf)

 

strB.Append(“Message :”).Append(EX.Message).Append(vbCrLf)

 

strB.Append(vbCrLf).Append(vbCrLf)

strB.Append(“Stack Trace :”).Append(EX.StackTrace)

 

Return strB.ToString

 

End Function

Public Shared Function GetStringfromException(ByVal cEx As ExceptionData) As String

Return GetStringfromException(cEx.FileName, cEx.ClassName, cEx.Method, cEx.Section, cEx.Ex)

 

 

End Function

End Class

 

3. Create frmShowErrorforDebug

 

in this case we just use for Windowsform application, this form is just contain one textbox for show error data and two button one for copy error data to clipboard ,two for close form.

If you want to handler error for web application you just change from windows form to webform instead.

 

Public Class frmShowErrorforDebug

Public ErrorDisplay As String

 

 

Private Sub frmShowError_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.TextBox1.Text = errordisplay

End Sub

 

Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click

Clipboard.SetText(Me.TextBox1.Text)

 

End Sub

 

Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click

Me.Close()

End Sub

End Class

 

Now we already created classes for handler error and then we will test it.

 

 

Public Class frmLogin

 

Private FileName As String = “frmLogin.vb”

 

Private cEx As New ExceptionData(FileName, “frmLogin”)

 

Private Sub btnTestError_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestError.Click

 

cEx.Method = “btnTestError_Click”

Try

 

Dim str As String = “Hello”

cEx.Section = “Convert str to dbl”

Dim dbl As Double = CDbl(str)

 

Catch ex As Exception

 

 

 

cEx.Ex = ex

ErrorHandler.ShowError(cEx)

 

 

 

End Try

End Sub

End Class

It done.

How i hide left navigate and right navigate YUI Calendar ?

August 8, 2007

In my project i must use YUI Calendar control for build static calendar show to user.
but I can’t find the solution to hide left navigate and right navigate.
after i search yahoo api , I don’t found any thing.

but now,after i try to hack calendar.js
I know the solution for hide left navigator and right navigator

First solution
1.Open calendar.js this file is in yui2.3.0\yui\build\calendar\
2.you just go to line 2321 and you will see javascript code for about render left and right navigator
then you just comment this code
you must separate comment to two group because you should not comment code for display month name

/*
if (renderLeft) {
var leftArrow = this.cfg.getProperty(defCfg.NAV_ARROW_LEFT.key);
// Check for deprecated customization – If someone set IMG_ROOT, but didn’t set NAV_ARROW_LEFT, then set NAV_ARROW_LEFT to the old deprecated value
if (leftArrow === null && YAHOO.widget.Calendar.IMG_ROOT !== null) {
leftArrow = YAHOO.widget.Calendar.IMG_ROOT + DEPR_NAV_LEFT;
}
var leftStyle = (leftArrow === null) ? “” : ‘ style=”background-image:url(‘ + leftArrow + ‘)”‘;
html[html.length] = ‘ ‘;
}

*/
html[html.length] = this.buildMonthLabel(); /* This line is for display Month don’t comment it */
/*
if (renderRight) {
var rightArrow = this.cfg.getProperty(defCfg.NAV_ARROW_RIGHT.key);
if (rightArrow === null && YAHOO.widget.Calendar.IMG_ROOT !== null) {
rightArrow = YAHOO.widget.Calendar.IMG_ROOT + DEPR_NAV_RIGHT;
}
var rightStyle = (rightArrow === null) ? “” : ‘ style=”background-image:url(‘ + rightArrow + ‘)”‘;
html[html.length] = ‘ ‘;
}
*/
3.and then you just save calendar.js when you create Calendar you don’t see left navigate button and right navigate button.

But this solution will make all of calendar of your app don’t display left and right navigate button except you will separate calendar.js.
well I think we shoul have a better solution

Lets’go to second solution

Second solution.
1.like first solution.You just open calendar.js
2.you just set id of both left and right navgate button in this case I name ALeft and ARight.
if (renderLeft) {
var leftArrow = this.cfg.getProperty(defCfg.NAV_ARROW_LEFT.key);
// Check for deprecated customization – If someone set IMG_ROOT, but didn’t set NAV_ARROW_LEFT, then set NAV_ARROW_LEFT to the old deprecated value
if (leftArrow === null && YAHOO.widget.Calendar.IMG_ROOT !== null) {
leftArrow = YAHOO.widget.Calendar.IMG_ROOT + DEPR_NAV_LEFT;
}
var leftStyle = (leftArrow === null) ? “” : ‘ style=”background-image:url(‘ + leftArrow + ‘)”‘;
html[html.length] = ‘ ‘;
}

html[html.length] = this.buildMonthLabel();

if (renderRight) {
var rightArrow = this.cfg.getProperty(defCfg.NAV_ARROW_RIGHT.key);
if (rightArrow === null && YAHOO.widget.Calendar.IMG_ROOT !== null) {
rightArrow = YAHOO.widget.Calendar.IMG_ROOT + DEPR_NAV_RIGHT;
}
var rightStyle = (rightArrow === null) ? “” : ‘ style=”background-image:url(‘ + rightArrow + ‘)”‘;
html[html.length] = ‘ ‘;
}
3.In a page you wish build calendar and wish to hide left and right navigator.
you just write this code

function HideNav()
{
try
{
document.getElementById(‘ALeft’).style.display=’none’;
document.getElementById(‘ARight’).style.display=’none’;
}
catch(ex)
{
setTimeout(‘HideNav()’,100)
}
}
setTimeout(‘HideNav()’,100)

I use setTimeout because I want to object calendar loaded.
when first excute function HideNav if element ALeft or ARight dosen’t loaded.
it will setTimeout again and again until ALeft and ARigh loaded and hide it.

Now.I think this solution work for me.
But you may have a problem.
e.g. When your page have more than one calendar and you want to hide navigate button of some calendar.and now each navigator button have same id (ALeft and ARight)

Ajax Tabcontrol inside Update panel can’t find CSS

August 8, 2007

I use Ajax Tabcontrol inside Updatepanel
and each tabcontrol contain Usercontrol
each Usercontrol reference CSS file

when first run It fine.
but when I update data.
Page display is crash.

I found solutino fo solve this problem
you just copy code for reference to css file in usercontrol
to page