Detect invalid characters in sql

A customer needs to know whether the names of the users contain some invalid characters, like tab characters.

This is the code of a function which validates a string in sql:

CREATE FUNCTION IsNameValid( @Name NVARCHAR(100) )
RETURNS BIT
BEGIN
    SELECT @Name = RTRIM(ltrim(@Name))
    IF(@name IS null) OR (@Name = '')
      RETURN 1
    
    DECLARE @len AS INT
    DECLARE @index AS INT
    DECLARE @ascii AS int
    SELECT @len =  LEN(@Name),@index = 1
    WHILE(@index <= @len)
    BEGIN
      SELECT @ascii = ASCII(substring(@Name,@index,1))
      IF ((@ascii BETWEEN 65 AND 90)
         OR (@ascii BETWEEN 97 AND 122)
         OR (@ascii BETWEEN 193 AND 252)
         OR (@ascii = 32)
         OR (@ascii = 45)
         OR (@ascii = 46)
         OR (@ascii BETWEEN 48 AND 57)
         )
      begin
         SELECT @index = @index + 1
         CONTINUE
      end
      ELSE
         RETURN 0
    END
    RETURN 1
END

Usage:

--select invalid users
SELECT *
FROM [User]
WHERE dbo.IsNameValid([FirstName]) = 0 
OR dbo.IsNameValid([LastName]) = 0

ASTreeView 1.5.3 Release Notes

ASTreeView has been updated to version 1.5.3. In the new version, developer can have more flexibility to control Add/Edit/Delete/DragDrop with customized javascript handler.

In addition, from 1.5.3, two versions of ASTreeView will be available, one for .Net Framework 2.0(build with Ajax Extension 1.0), one for .Net Framework 3.5(build with Ajax Extension 3.5 ). Samples also will be available in two version, one for VS2005 and one for VS2008.

New Features in 1.5.3:

1. Supports customized javascript handler

For example, if the developer wants to cancel add node action if server returns some specified condition. He can":

(a) Set EnableOnNodeAddedScriptReturn="true"
(b) Set OnNodeAddedScript="addedHandler(elem)"
(c) Write the addedHandler:

function addedHandler( elem ){
    var message = '';
    var result = true;
    
    var aTag = elem.getElementsByTagName('A')[0];
    
    if( aTag.getAttribute('addfailed') == 'true' ){
        alert( aTag.innerHTML );
        return false;
    }
    else{
        message = (">>add completed. [Node]" 
        + elem.getAttribute("treeNodeValue") + "<br />" );
    }
    document.getElementById("<%=divConsole.ClientID %>").innerHTML 
    += message;
    return result;
}

in this case, when the server side return the node with “addfailed” in the anchor, the astreeview will cancel the add action.

Same approach can be applied on Edit, Delete and DragDrop.

Some screenshots:
image

image

View Live Demo

2. Improved CSS for ASTreeView

CSS of ASTreeView has been update to align better between node icon and node text.

3. Improved ViewState Management

ViewState of ASTreeView has been move from hidden to viewstate. This can improve the performance of astreeview.

4. Strong Named Assembly

From 1.5.3 the ASTreeView.dll will be signed strong name.

Download ASTreeView 1.5.3

ASTreeView 1.5.2 Release Notes

ASTreeView has been updated to version 1.5.2, the main BIG improvement is that a new NodeType – TextNode has been added. With TextNode, you can set two links in one node which is not possible in previous versions. Even javascript can be the content of the nodes in a TextNode.

New Features:

1. TextNode type is added.

The content of tree nodes is now more flexible. You can add html, javascript in the new node type – TextNode:
image
Please visit the online demo.

2. Added EnableDragDropOnIcon property.

If this property is set to true, then, the user can drag and drop on the node icon.

3. Added EnableOnNodeDragAndDropStartScriptReturn.

If this parameter is set, then in the OnNodeDragAndDropStartScript, if "false" is returned, then, the drag and drop will be canceled.

 

Bug fixed and improvements:

  • *Changed the href of context menu item from # to javascript:void(0);
    *ASTreeView CSS is imporoved.
    *Fixed drag and drop bug in Opera.

Fix IE Blocking iFrame Cookies Problem

For security reason, Internet Explorer block the cookie manipulation of a page when the page is inside an iframe. This is really ridiculous because the two frames are totally two different sites and the security policy has already block the dom operation between the two frames. Why block the cookie operation inside the iframe itself? Other browsers don’t have such issue. So, IE really really sucks.

But the major users are using the f**king, so we have to face the problem.

Here’s my steps( I assume we have two sites www.testaccor.com and www.testcomptanoo.com ) to resolve this issue by creating a policy for IE:

1. Download the IBM Privacy Policy Editor from http://www.alphaworks.ibm.com/tech/p3peditor (I also set it in the sample package)

2. Create a folder “w3c” in testcomptanoo.com root.

3. Open the editor, select “Create a policy from a template”, and click “OK”.

clip_image002

4. Select the template “Access logging & user tracking”, and “OK”

clip_image004

5. Here’s the policy file we have.

clip_image006

6. Save the policy file to “w3c” folder as “privacy_policy.p3p”

clip_image008

7. Choose “File” -> “Save Compact Policy As…”, save the compacted policy to a text file, we say “privacy_policy.txt”, we’ll use its content as http header later.

8. Also in “w3c” folder, create a p3p.xml file, we’ll set this file path in the http header, p3p.xml content:

clip_image010

9. This time I use a aspx file to add an http header, so I change the comptanoo.html to comptanoo.aspx.

clip_image012

10. In the comptanoo.aspx, I set a header:

clip_image014

11. Run the http://www.testaccor.com/accor.html again, we can find that we CAN set/get cookie now in Comptanoo.aspx

clip_image016

12. If we remove the header, cookies will be blocked again:

clip_image018

I attached all the files; also the IBM Privacy Policy Editor is enclosed. Please download here: http://www.jinweijie.com/Images/www_jinweijie_com/files/iframe_cookie_issue_in_ie_p3p.zip

IE在ssl下CacheControl问题

今天碰到一个问题,IE在ssl(https)环境下,下载文件,会出现如下错误信息:

“Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.”

查了一下KB (http://support.microsoft.com/default.aspx?scid=KB;EN-US;q316431&),原来是IE的一个bug,在2007年的时候已经有了,但微软到现在还没修复,唉~

原因大致是这样的:

在ssl下,ie强制no-cache,如果no-cache已经在header里存在了,那么ie就不缓存文件了,所以文件找不到。(好莫名的说法啊)

尝试在下载页面里设置Response.CacheControl, 没有效果。最后,索性调用Response.ClearHeaders();,把Header全部清空,然后再设置Content-Type等属性,问题解决。

ASTreeView 1.4.0 Release Notes

ASTreeView has been updated to version 1.4.0, you may download at http://www.astreeview.com/download/astreeview-1.4.0.zip

New Features:

 

1. Virtical Drag and Drop Nodes


    If you use ASTreeView as a list, you can set EnableHorizontalLock=true, then the end user can only move the nodes up and down, not left or right, screenshot:
    image 
    Visit online demo.  

2. Fixed Drag and Drop depth


    If you want the end user just move the node within the same level as its original level, you may set the property EnableFixedDepthDragDrop=true, then the nodes can only be drag and drop to the same level as its original level, visit online demo.

3. Add OnNodeDragAndDropStartScript Event


    A new event OnNodeDragAndDropStartScript  is now available for developers to execute some js when the end user start to drag nodes. Here’s a usage sample:
    add a property for astreeview:

    OnNodeDragAndDropStartScript="dndStartHandler( elem )"

    the js function to handle start drag drop:


//parameter must be "elem" 
    
functiondndStartHandler( elem ){  
    document.getElementById(
"<%=divConsole.ClientID %>").innerHTML  
    += (
">>drag started. [Node]"+ elem.getAttribute("treeNodeValue")  
    +
" [Parent]:"+ elem.parentNode.parentNode.getAttribute("treeNodeValue")  
    +
"<br />");
}

you may also check the online demo.

Download Now!

Documentation for ASTreeView

A documentation is now available for ASTreeView. Please visit: http://www.astreeview.com/doc/

ASTreeView 1.3.0 Release Notes

Just back from a trip to Santorini, Barcelona and Athens. :)

More photos at: http://www.jinweijie.com/europetrip2009

Back to the topic, the ASTreeView has been updated to 1.3.0, you may download at http://astreeview.googlecode.com/files/astreeview-1.3.0.zip 

New Features:

1. Html as TreeNodeText supported.
    In the new version, you may use html as tree node text, not only plain text.

image

2. Support escape edit/add input. 
    Set the EnableEscapeInput property to enable this feature, default is true.

image

3.Multiline Edit Mode supported.
   Set the EnableMultiLineEdit property to enable this feature, , default is false.

image

4. Drag and drop complete event now is available, sample:

    <script type="text/javascript">
        //parameter must be "elem"
        function dndHandler( elem ){
            document.getElementById( "<%=divConsole.ClientID %>" ).innerHTML 
+= (
">>node dragged:"
+ elem.getAttribute("treeNodeValue")
+
"<br />" ); } </script>

and then set the OnNodeDragAndDropCompleteScript="dndHandler( elem )"

image

5. New property for ASTreeViewNode – EnableChildren

Set this property to false can disable dragging other nodes to the current node as child nodes. please refer sample 1 to see the effect.

ASTreeView 1.2.2 Release Notes

ASTreeView 1.2.2 released. You may download it now from: http://astreeview.googlecode.com/files/astreeview-1.2.2.zip

Here is a list of the new features added and bugs fixed:

New Features:

1. Themes
    ASTreeView now supports themes! Developer can easily create his own theme for the treeview. Check out the demo.
    image

2. Right-To-Left support
    ASTreeView now supports rtl display, thank Mojtaba Vali for the suggestion! Also check out the demo.
    image

3. A performance testing demo page added to demo project.
    See the Demo.

 

Bugs fixed:


1. Drag & drop bug fix, thank fire_birdie for reporting the bug.

2. Dropdown Tree display error after drag and drop. thank 一毛 for reporting the bug.

3. Fix Img Url Property problem. thank tzess for reporting this issue. (fixed in 1.2.2)

 

Download the new version 1.2.2

ASTreeView 1.1.2 What’s New

I registered a domain for ASTreeView: www.astreeview.com

This domain will be only used for ASTreeView, updates, demos, blogs. It can be regarded as the official site. :D

I release ASTreeView 1.1.2 just now. It can be download from: http://astreeview.googlecode.com/files/astreeview-1.1.2.zip

online sample: http://www.astreeview.com

added two new features:

1. Extending ContextMenu
   
Now it is possible to add your customized ContextMenu Items to the menu. A screenshot:
     image 

     Online demo: http://www.astreeview.com/astreeviewdemo/ASTreeViewDemo3.aspx

     To add your customized menu, it’s easy:

/// <summary>
        /// initial controls, bind you events etc. here
        /// </summary>
        private void InitializeComponent()
        {
            this.astvMyTree.ContextMenu.MenuItems.Add( new ASContextMenuItem( 
                "Custom Menu 1", "alert('current value:' + " 
                + this.astvMyTree.ContextMenuClientID
                + ".getSelectedItem().parentNode.getAttribute('treeNodeValue')" 
                + ");return false;", "otherevent" ) );

            this.astvMyTree.ContextMenu.MenuItems.Add( new ASContextMenuItem( 
                "Custom Menu 2", "alert('current text:' + " 
                + this.astvMyTree.ContextMenuClientID 
                + ".getSelectedItem().innerHTML" 
                + ");return false;", "otherevent" ) );
        }


     You can replace the “alert” with your own javascript function.

     The code is also included in the new sample package.

2. Expand node by click node text.
    In version 1.1.2, the end user can open the folder by clicking on the node text. It is useful when only the leaf nodes are clickable, for example, bookmarks.
    image

    To enable this feature, just set the “EnableParentNodeExpand” property of ASTreeView.

 

Downlaod ASTreeView 1.1.2: http://astreeview.googlecode.com/files/astreeview-1.1.2.zip

ASTreeView 1.1.1 Released

I got many feedbacks since the 1.0 release of ASTreeView. Thanks guys for your support!

You can download it now from: http://astreeview.googlecode.com/files/astreeview1.1.1.zip

If you want a sample for connecting sql server, you can also download the sample:

http://astreeview.googlecode.com/files/astreeview1.1.1_sql_server.zip

 

The new version of ASTreeView includes:

 

Some bugs fixed:

  • In DropdownTreeView, the RequiredValidator cannot be disabled.
  • Javascript error when ajax request failed.
  • Tree line does not display correctly after move the last node.
  • Initialization of the treeview may cause js error if in the low bandwidth.

New features:

  • Add Sever-Side ExpandAll, CollapseAll, ExpandTo(depth) Methods. See demo.
  • Add ExpandDepth Property to allow developer set the initial opening depth of the treeview.
  • Add new samples of getting client-side modificatioins( move nodes, add, edit, delete). See the sample code.
  • Optimize the calculation of tree lines after drag & drop nodes.

In the next version, I plan to add new features:

  • Allow developer set if child nodes being checked if their parent be checked.
  • Add theme feature.

ASTreeView: Resolve confliction with jQuery

Thanks xiaot for reporting this issue that if jQuery is included in page, it conflicts with the ASTreeView.

To resolve this issue, we can use the noconflict method of the jQuery:

    <script src="jquery-1.3.2.js"></script>
    <script type="text/javascript">
        var J = jQuery.noConflict();
    </script>

Now $("#foo") will be J("#foo") and it will not conflict with the ASTreeView.

I’ll update the ASTreeView internal methods, make it not conflict with jQuery in the next version.

updated

The new version (1.1.1) does not conflict with jQuery any more, please update if you’re using jQuery in your project.

http://astreeview.googlecode.com/files/astreeview1.1.1.zip

Visual Studio的Solution Explorer 当前文件激活问题

今天在写程序的时候突然发现Visual Studio 2005的Solution Explorer不高亮当前文件了,也就是说不知道当前编辑的文件在Solution Explorer的哪个位置了,之前在VS2003也碰到过这个问题,还以为是VS2003坏了。本文介绍了如何解决这个问题。[Read More...]

在GoDaddy上部署SubText

由于海意互联的恶劣态度,决定把虚拟主机移到GoDaddy上,本文记录了转移过程已经一些问题的解决方案。[Read More...]

ASTreeView 1.0 Released

ASTreeView is a powerful treeview with drag drop, ajax loading, context menu, xml import/export, checkbox, selection, add/editing/deleting nodes with ajax. This is version 1.0.[Read More...]
View posts by date
«February»
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
28123456
78910111213