预览模式: 普通 | 列表

倾听王菲网站关闭的通知

不好意思,各位,倾听王菲(www.ofaye.com)因为种种原因要暂时关闭一段时间,在此本人向所有支持倾听王菲的网友表示抱歉。

开放时间另行通知,希望大家能够谅解!谢谢大家~

倾听王菲QQ群号码:58213709    8966464

Windows 下也能创建硬链接和符号(软)链接

首先简单理解一下硬链接和符号(软)链接的区别(此文中的符号链接和软链接指同一概念):

硬连接指向的是节点(inode),而软连接指向的是路径(path) 。

最初的文件名与所有的硬链接地位是对等的,比如为文件 a 建立了硬链接 b、c、d。那么a、b、c、d之中只要有一个文件未删除,这个文件就可通未删除的名称访问的。你也可以认为每个文件都可认为至少有一个硬链接,就是说 a 也是一个硬链接。

软链接特性上有些类似于快捷方式,比如为原文件 a 建立了软链接 b、c、d。删除b、c 或 d 访问到 a,但是只要删除了 a,软链接就不可用了。但是 windows 下的快捷方式只能在资源管理器中有用,它只是一个 lnk 文件,如果是一个目录的快捷方式,它是不能通过 cd 命令或路径进入。

硬链接文件有两个限制(Unix/Linux 和 Windows 也都如此)

  1、不允许给目录创建硬链接;
  2、只有在同一文件系统中的文件之间才能创建链接。

更详细区别请见:硬链结和符号链接的区别 ,具体不多述,本文的内容关键在 Windows 下如何建立软硬链接。

熟悉过 Unix/Linux 都应该知道,Unix/Linux 用 ln 建立硬链接,ln -s 建立软链接,那么 Windows 下是如何做到的呢?

一: Windows 下创建硬链接,只能适用于 NTFS 文件系统。使用命令 fsutil hardlink

语法
fsutil hardlink create NewFileName ExistingFileName

参数
create 建立现有文件和新文件之间的 NTFS 硬链接。NTFS 硬链接与 POSIX 硬链接相似。

NewFileName 指定要将创建硬链接的文件。

ExistingFileName 指定要从中创建硬链接的文件。

当然,如果你想在自己的程序里创建硬链接,那也是很容易的,只需要一个很简单的 API 函数:

BOOL CreateHardLink(
    LPCTSTR lpFileName,
    LPCTSTR lpExistingFileName,
    LPSECURITY_ATTRIBUTES lpSecurityAttributes
);

适用于 Win2000 及以上版本的系统,前两个参数的意思就不用解释了,最后一个参数的用途暂时保留,必须为 NULL。

二:Windows 下创建软链接,NTFS 只支持对目录的软链接,微软把它称作 junction。但是对于文件的软链接,微软也有提供解决方案,那就是快捷方式(Shortcut,.lnk 文件)。不过软链接和快捷方式不是一个层次上的东西,前者是底层文件系统的功能,后者是应用层的功能。Windows 下目录的快捷方式用 dir 看起来是个文件。

http://www.microsoft.com/technet/sysinternals/FileAndDisk/Junction.mspx 下载 junction.exe。junction 的命令语是:

junction  LinkDirectory ExistingDirectory

例如:
junction d:\link c:\winnt

将为c:\winnt 建立一个链接目录 d:\link,C和D分区都要是 NTFS 格式,在资源管理器和 dir 列示中 d:\link 都以目录的面目存在的。d:\link 就像是 c:\winnt 的一个引用一般,删除 d:\link 目录中的内容也就是删除了 c:\winnt 中的内容,但删除 d:\link 本身是不会影响到 c:\winnt 的。

相应的,在程序中也有一个 API 函数 CreateSymbolicLink 支持创建软链接,不过来得太晚了,要 Windows VISTA 和 Windows Server 2008 那样的版本才支持,先还是别想了,API 原型是:

BOOL WINAPI CreateSymbolicLink(
  __in  LPCWSTR lpSymlinkFileName,
  __in  LPCWSTR lpTargetFileName,
  __in  DWORD dwFlags
);

参数:
lpSymlinkFileName 要创建的符号链接名称.

lpTargetFileName 符号链接所对应目标的名称.

dwFlags 标识目标是文件还是目录. 取值0x0 代表是文件,SYMBOLIC_LINK_FLAG_DIRECTORY或0x1 代表是目录

三:其他方法

也可以使用 GNU utilities for Win32 中的 ln 来创建硬链接。这是一些 GNU 工具的 Win32 移植版本,非常好用。另外 Cygwin 里的 ln 不但可以创建硬链接也可以创建符号链接(在 Windows 里就是快捷方式 .lnk 文件)。

实际需求引出:Web 应用中上传文到 WEB 下的某个子目录中,这样可以直接通过网页链接的方式访问到这些文件。但是会出现的问题就是,每当完全重新部署应用时,如果忘了把存上传文件的目录进行备份,那么原有上传文件就全没了。原来项目部署在 Unix 下的做法是,把那个上传目录作为另一个目录的符号链接,实际存储文件的目录不在 WEB 应用目录下,重新部署时只要重建这个符号链接即可,不会有覆盖文件的危险。当然在 Unix/Linux 是好解决,只要用 ln -s 命令就行,然而对于 Windows 系统却要想点办法,为目录建立快捷的方式是行不通的,目录的链接只会当 lnk 文件对待,在 Explorer 中可以双击打开,但对于网页链接或者 cd 命令是无法正确定位的。于是思考起如何在 Windows 下创建符号连接的问题,才有了上文。

题外:对于以上的需求,可以在 Web 应用外部事先建立好一个目录,赋上相应的权限。然后在应用的配置文件中记下这个目录的绝对路径,上传时往其中写文件没问题,关键浏览时,因为文件在应用之后,不能直接通过网址浏览到,就需要通过一个程序去读取相应的文件,发送到浏览器之前必须设置根据文件类型设置响应 MINE 类型,这个 MINE 类型可以在上传时记载在库的。

现在觉得这种方法还优于用符号链接的方式,至为无需每次完整发布后重创建符号链接,而且实际中也出现过完全重部署后,目标目录中文件完全丢失的情况。

参考:1. NTFS 下的硬链接(hard link)与符号链接(symbolic link)
        2. 原来Windows下面也有硬链接
        3. Windows上创建硬链接
        4. MSDN CreateSymbolicLink Function
        5. MSDN CreateHardLink Function
        6. ln命令详细用法

有固定宽度页面的背景广告JS代码

以下是已经封装的JS类,点击这里查看效果。 

JavaScript代码
  1. /*  
  2.     Powered By CMSDream Copyright © All rights reserved.  
  3. */  
  4. var backgroundAd = {   
  5.     Div: null,   
  6.     IE: 10, /*IE版本*/  
  7.     CD: new Array(1),   
  8.     AD: new Array(1),   
  9.     Config: {   
  10.         adTime: {   
  11.             begin: "2009/7/15 00:00:00",    /*开始时间*/  
  12.             end: "2009/7/16 23:59:59"   /*结束时间*/  
  13.         },   
  14.         Type: 0,        /*0-IE6 背景固定  不等于0-IE6背景浮动*/  
  15.         minWidth: 930,  /*页面最小宽度*/  
  16.         totalWidth: 0,   
  17.         adWidth: 283,   /*广告宽度*/  
  18.         adImage:{   
  19.             left: 'l.gif',    
  20.             right: 'r.gif'  
  21.         },   
  22.         adURL: 'http://get.766.com/go.php?id=2303'/*广告连接地址*/  
  23.         adClick: 0, /*是否允许点击*/  
  24.         bgImage: 'bg.jpg'/*广告背景图片*/  
  25.         bgColor: '#6EE6FE',     /*广告背景颜色*/  
  26.         oldBackground: '',  /*页面原背景*/  
  27.         /*关闭按钮*/  
  28.         closeImage: {   
  29.             src: 'close.jpg',   
  30.             width: 13,   
  31.             height: 13   
  32.         }   
  33.     },   
  34.   
  35.     createAd: function(u){   
  36.         var self = this;   
  37.         var h = document.body.clientHeight;   
  38.         var div = document.createElement('div');   
  39.         with(div.style){   
  40.             if(this.Config.adClick){   
  41.                 cursor = 'pointer';   
  42.             }   
  43.             position = 'absolute';   
  44.             width = this.Config.adWidth + 'px';   
  45.             height = h + 'px';   
  46.             backgroundImage = "url(" + this.Config.adImage[u] + ")";   
  47.             backgroundRepeat = 'no-repeat';   
  48.             backgroundPosition = u + ' 0';   
  49.             backgroundAttachment = 'fixed';   
  50.             top = 0;   
  51.             zIndex = 0;   
  52.             eval(u + ' = '' + (-this.Config.adWidth) + 'px'');   
  53.         }   
  54.         if(this.Config.adClick){   
  55.             div.onclick = function(){   
  56.                 window.open(self.Config.adURL, '_blank');   
  57.             };   
  58.         }   
  59.            
  60.         return div;   
  61.     },   
  62.        
  63.     createClose: function(u){   
  64.         var self = this;   
  65.         var a = document.createElement('a');   
  66.         a.href = '#close';   
  67.         with(a.style){   
  68.             position = 'absolute';   
  69.             width = self.Config.closeImage.width + 'px';   
  70.             height = self.Config.closeImage.height + 'px';   
  71.             top = 0;   
  72.             zIndex = 0;   
  73.             eval(u + ' = '' + (-this.Config.adWidth) + 'px'');   
  74.         }   
  75.         a.onclick = function(){   
  76.             var pp = self.Div.parentNode;   
  77.             pp.removeChild(self.Div);   
  78.             if(self.Config.oldBackground.length > 0)   
  79.             document.body.style.background = self.Config.oldBackground;   
  80.             return false;   
  81.         };   
  82.         a.innerHTML = '<img src="'+this.Config.closeImage.src+'" '+   
  83.             'style="border:0;width:'+this.Config.closeImage.width+'px;height:'+this.Config.closeImage.height+'px;" />';   
  84.         return a;   
  85.     },   
  86.        
  87.     Resize: function(){   
  88.         var w = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.scrollWidth;   
  89.         var c = w - this.Config.totalWidth;   
  90.         c = c < 0 ? 0 : c;   
  91.         var w1 = (w - this.Config.minWidth - c) / 2 - 2;   
  92.         var w2 = w1 + 2;   
  93.            
  94.         this.AD[0].style.left = (-w1) + 'px';   
  95.         this.AD[0].style.backgroundPosition = - (this.Config.adWidth - w2) + 'px 0';   
  96.         this.AD[1].style.right = (-w1) + 'px';   
  97.         if(this.IE <= 6)   
  98.         this.AD[1].style.backgroundPosition = (this.Config.adWidth - w2) + 'px 0';   
  99.         else  
  100.         this.AD[1].style.backgroundPosition = (w2 + this.Config.minWidth) + 'px 0';   
  101.            
  102.         this.CD[0].style.left = (-w1) + 'px';   
  103.         this.CD[1].style.right = (-w1) + 'px';   
  104.     },   
  105.        
  106.     Scroll: function(){   
  107.         var t = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;   
  108.         if(this.IE <= 6 && this.Config.Type > 0){   
  109.             this.AD[0].style.backgroundPosition = '0 ' + t + 'px';   
  110.             this.AD[1].style.backgroundPosition = 'right ' + t + 'px';   
  111.         }   
  112.         this.CD[0].style.top = t + 'px';   
  113.         this.CD[1].style.top = t + 'px';   
  114.         this.Resize();   
  115.     },   
  116.   
  117.     Init: function(){   
  118.         var nd = new Date();   
  119.         var bd = new Date(Date.parse(this.Config.adTime.begin));   
  120.         var ed = new Date(Date.parse(this.Config.adTime.end));   
  121.         if(!(nd.getTime()>bd.getTime() && nd.getTime()<ed.getTime()))return;       
  122.   
  123.         document.body.style.backgroundColor = this.Config.bgColor;   
  124.         document.body.style.background = 'url('+this.Config.bgImage+') fixed';   
  125.         if(navigator.appName == "Microsoft Internet Explorer"){   
  126.             var userAgent = navigator.userAgent;   
  127.             var s = 'MSIE';   
  128.             this.IE = parseFloat(userAgent.substr(userAgent.indexOf(s) + s.length));       
  129.         }   
  130.         this.Config.totalWidth = this.Config.minWidth + this.Config.adWidth * 2;   
  131.            
  132.         this.Div = document.createElement('div');   
  133.         with(this.Div.style){   
  134.             position = 'relative';   
  135.             width = (this.Config.minWidth + 2) + 'px';   
  136.             margin = 'auto';   
  137.             top = '0';   
  138.             zIndex = '0';   
  139.         }   
  140.         document.body.insertBefore(this.Div, document.body.childNodes[0]);     
  141.         this.AD[0] = this.createAd('left');        
  142.         this.AD[1] = this.createAd('right');   
  143.         this.CD[0] = this.createClose('left');   
  144.         this.CD[1] = this.createClose('right');   
  145.         this.Div.appendChild(this.AD[0]);   
  146.         this.Div.appendChild(this.AD[1]);   
  147.         this.Div.appendChild(this.CD[0]);   
  148.         this.Div.appendChild(this.CD[1]);   
  149.   
  150.         var self = this;   
  151.            
  152.         if(document.all){   
  153.             window.attachEvent("onscroll"function(){self.Scroll();});   
  154.             window.attachEvent("onresize"function(){self.Resize();});   
  155.         }else{   
  156.             window.addEventListener("scroll"function(){self.Scroll();},true);   
  157.             window.addEventListener("resize"function(){self.Resize();},true);   
  158.         }   
  159.            
  160.         this.Scroll();   
  161.     }   
  162. };  

 调用方法:

JavaScript代码
  1. if(document.all){   
  2.     window.attachEvent("onload"function(){backgroundAd.Init();});   
  3. }else{   
  4.     window.addEventListener("load"function(){backgroundAd.Init();}, true);   
  5. }  
标签: 背景广告

纯CSS解决DIV垂直居中的样式

XML/HTML代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  5. <title>无标题文档</title>  
  6. <style type="text/css">  
  7. .a {width:200px;height:200px;border:1px solid #333;display:table;vertical-align:middle;}   
  8. .a p {position:relative;left:0;top:50%;width:100%;text-align:center;display:table-cell;vertical-align:middle;}   
  9. .a img {height:50px;border:1px solid #f30;position:relative;top:-50%;}   
  10. </style>  
  11. </head>  
  12. <div  
  13. <body>  
  14. <div class="a"><p><img src="http://www.google.com/intl/en/images/logo.gif" /></p></div>  
  15. </body>  
  16. </html>  
标签: CSS 垂直居中

获取字符串长度的函数(ASP/VB/JS)

 

JavaScript代码
  1. function strLen(str){      
  2.     var len=0;      
  3.     for(var i=0;i<str.length;i++){      
  4.         var intCode=str.charCodeAt(i);      
  5.         if(intCode>=0 && intCode<=128){      
  6.             len = len + 1;      
  7.         }else{      
  8.             len = len + 2;      
  9.         }      
  10.     }      
  11.     return len;      
  12. }    

 

ASP/Visual Basic代码
  1. Private Function Length(iTxt)   
  2.     Dim txt: txt = Trim(iTxt)   
  3.     Dim x: x = Len(txt)   
  4.     Dim y: y = 0   
  5.     Dim ii, chrA   
  6.     For ii = 1 To x   
  7.         chrA = Mid(txt, ii, 1)   
  8.         If Asc(chrA) >= 0 And Asc(chrA) <= 255 Then  
  9.         y = y + 1   
  10.         Else    
  11.         y = y + 2   
  12.         End If    
  13.     Next  
  14.     Length = y   
  15. End Function  

PHP的MSSql的操作类

PHP代码
  1. <?php   
  2. /*MSSql的操作类*/  
  3. class MSSql {   
  4.     var $link;   
  5.     var $querynum = 0;   
  6.   
  7.     /*连接MSSql数据库,参数:dbsn->数据库服务器地址,dbun->登陆用户名,dbpw->登陆密码,dbname->数据库名字*/  
  8.     function Connect($dbsn$dbun$dbpw$dbname) {   
  9.         if($this->link = @mssql_connect($dbsn$dbun$dbpw, true)) {   
  10.             $query = $this->Query('SET TEXTSIZE 2147483647');   
  11.             if (@mssql_select_db($dbname$this->link)) {   
  12.             } else {   
  13.                 $this->halt('Can not Select DataBase');   
  14.             }   
  15.         } else {   
  16.             $this->halt('Can not connect to MSSQL server');   
  17.         }   
  18.     }   
  19.   
  20.     /*执行sql语句,返回对应的结果标识*/  
  21.     function Query($sql) {   
  22.         if($query = @mssql_query($sql$this->link)) {   
  23.             $this->querynum++;   
  24.             return $query;   
  25.         } else {   
  26.             $this->querynum++;   
  27.             $this->halt('MSSQL Query Error'$sql);   
  28.         }   
  29.     }   
  30.   
  31.     /*执行Insert Into语句,并返回最后的insert操作所产生的自动增长的id*/  
  32.     function Insert($table$iarr) {   
  33.         $value = $this->InsertSql($iarr);   
  34.         $query = $this->Query('INSERT INTO ' . $table . ' ' . $value . '; SELECT SCOPE_IDENTITY() AS [insertid];');   
  35.         $record = $this->GetRow($query);   
  36.         $this->Clear($query);   
  37.         return $record['insertid'];   
  38.     }   
  39.   
  40.     /*执行Update语句,并返回最后的update操作所影响的行数*/  
  41.     function Update($table$uarr$condition = '') {   
  42.         $value = $this->UpdateSql($uarr);   
  43.         if ($condition) {   
  44.             $condition = ' WHERE ' . $condition;   
  45.         }   
  46.         $query = $this->Query('UPDATE ' . $table . ' SET ' . $value . $condition . '; SELECT @@ROWCOUNT AS [rowcount];');   
  47.         $record = $this->GetRow($query);   
  48.         $this->Clear($query);   
  49.         return $record['rowcount'];   
  50.     }   
  51.   
  52.     /*执行Delete语句,并返回最后的Delete操作所影响的行数*/  
  53.     function Delete($table$condition = '') {   
  54.         if ($condition) {   
  55.             $condition = ' WHERE ' . $condition;   
  56.         }   
  57.         $query = $this->Query('DELETE ' . $table . $condition . '; SELECT @@ROWCOUNT AS [rowcount];');   
  58.         $record = $this->GetRow($query);   
  59.         $this->Clear($query);   
  60.         return $record['rowcount'];   
  61.     }   
  62.   
  63.     /*将字符转为可以安全保存的mssql值,比如a'a转为a''a*/  
  64.     function EnCode($str) {   
  65.         return str_replace('''''''str_replace(''''$str));   
  66.     }   
  67.   
  68.     /*将可以安全保存的mssql值转为正常的值,比如a''a转为a'a*/  
  69.     function DeCode($str) {   
  70.         return str_replace('''''''$str);   
  71.     }   
  72.   
  73.     /*将对应的列和值生成对应的insert语句,如:array('id' => 1, 'name' => 'name')返回([id], [name]) VALUES (1, 'name')*/  
  74.     function InsertSql($iarr) {   
  75.         if (is_array($iarr)) {   
  76.             $fstr = '';   
  77.             $vstr = '';   
  78.             foreach ($iarr as $key => $val) {   
  79.                 $fstr .= '[' . $key . '], ';   
  80.                 $vstr .= ''' . $val . '', ';   
  81.             }   
  82.             if ($fstr) {   
  83.                 $fstr = '(' . substr($fstr, 0, -2) . ')';   
  84.                 $vstr = '(' . substr($vstr, 0, -2) . ')';   
  85.                 return $fstr . ' VALUES ' . $vstr;   
  86.             } else {   
  87.                 return '';   
  88.             }   
  89.         } else {   
  90.             return '';   
  91.         }   
  92.     }   
  93.   
  94.     /*将对应的列和值生成对应的insert语句,如:array('id' => 1, 'name' => 'name')返回[id] = 1, [name] = 'name'*/  
  95.     function UpdateSql($uarr) {   
  96.         if (is_array($uarr)) {   
  97.             $ustr = '';   
  98.             foreach ($uarr as $key => $val) {   
  99.                 $ustr .= '[' . $key . '] = '' . $val . '', ';   
  100.             }   
  101.             if ($ustr) {   
  102.                 return substr($ustr, 0, -2);   
  103.             } else {   
  104.                 return '';   
  105.             }   
  106.         } else {   
  107.             return '';   
  108.         }   
  109.     }   
  110.   
  111.     /*返回对应的查询标识的结果的一行*/  
  112.     function GetRow($query$result_type = MSSQL_ASSOC) {   
  113.         return mssql_fetch_array($query$result_type);   
  114.     }   
  115.   
  116.     /*清空查询结果所占用的内存资源*/  
  117.     function Clear($query) {   
  118.         return mssql_free_result($query);   
  119.     }   
  120.   
  121.     /*关闭数据库*/  
  122.     function Close() {   
  123.         return mssql_close($this->link);   
  124.     }   
  125.   
  126.     function halt($message = ''$sql = '') {   
  127.         $message .= '<br />MSSql Error:' . mssql_get_last_message();   
  128.         if ($sql) {   
  129.             $sql = '<br />sql:' . $sql;   
  130.         }   
  131.         exit("DataBase Error.<br />Message:$message $sql");   
  132.     }   
  133. }   
  134. ?>  

在下的照片(密码是我的手机号)

该日志已被加密
SQL代码
  1. --====================================/=======================================   
  2. --Powered By CMSDream Copyright © 2007-2008 All rights reserved.   
  3. --13:32 2008-12-26   
  4. --通用获取父节点/子节点/子节点下所有节点ID的存储过程   
  5. --====================================/=======================================   
  6. create proc [dbo].[cmsdream_SP_Navigate](   
  7.     @Type varchar(20),      -- parent/sub/all   
  8.     @TableName varchar(50),     --表名   
  9.     @PrimaryField varchar(50),  --数据表的主ID字段   
  10.     @ParentField varchar(50),   --数据表中的父ID字段   
  11.     @CurrentID int,         --表中当前主ID   
  12.     @OutputField varchar(1000) = '',   
  13.     @OrderField varchar(50) = ''  
  14. )AS  
  15. begin  
  16.     if @CurrentID <= 0 return  
  17.     set @Type = lower(@Type)   
  18.     if @OutputField = '' set @OutputField = '*'  
  19.     declare @sql nvarchar(4000)   
  20.     declare @IDList nvarchar(2000)   
  21.   
  22.     if @Type = 'all'  
  23.     begin  
  24.         set @IDList = cast(@CurrentID As nvarchar(12))   
  25.   
  26.         declare @IDTemp1 nvarchar(2000) set @IDTemp1 = @IDList   
  27.         declare @IDTemp2 nvarchar(2000) set @IDTemp2 = ''  
  28.         declare @SubCount int set @SubCount = 1   
  29.   
  30.         while @SubCount > 0   
  31.         begin  
  32.             set @IDTemp2 = ''  
  33.             if len(@IDTemp1) > 0   
  34.             begin  
  35.                 set @sql = 'select @IDTemp2 = @IDTemp2 + '','' + cast([' + @PrimaryField + '] As nvarchar(12)) from ' + @TableName + ' where [' + @ParentField + '] IN (' + @IDTemp1 + ')'  
  36.                 exec sp_executesql @sql,N'@IDTemp2 nvarchar(2000) output',@IDTemp2 output  
  37.             end  
  38.   
  39.             if len(@IDTemp2) > 1   
  40.             begin  
  41.                 set @IDTemp2 = substring(@IDTemp2,2,len(@IDTemp2)-1)   
  42.                 set @IDList = @IDList + ',' + @IDTemp2   
  43.             end  
  44.             set @IDTemp1 = @IDTemp2   
  45.   
  46.             set @SubCount = 0   
  47.             if len(@IDTemp2) > 1   
  48.             begin  
  49.                 set @sql = 'select @SubCount = count(*) from ' + @TableName + ' where [' + @ParentField + '] IN (0' + @IDTemp2 + ')'  
  50.                 exec sp_executesql @sql,N'@SubCount int output',@SubCount output  
  51.             end  
  52.         end  
  53.         if @OrderField = ''  
  54.             exec('select ' + @OutputField + ' from ' + @TableName + ' where [' + @PrimaryField + '] IN (' + @IDList + ')')   
  55.         else  
  56.             exec('select ' + @OutputField + ' from ' + @TableName + ' where [' + @PrimaryField + '] IN (' + @IDList + ') Order BY ' + @OrderField)   
  57.     end  
  58.   
  59.     if @Type = 'parent'  
  60.     begin  
  61.         set @IDList = cast(@CurrentID As nvarchar(12)) + ','  
  62.         declare @ParentID int set @ParentID = 0   
  63.            
  64.         set @sql = 'select @ParentID = [' + @ParentField + '] from ' + @TableName + ' where [' + @PrimaryField + '] = ' + cast(@CurrentID As nvarchar(12))   
  65.         exec sp_executesql @sql,N'@ParentID int output',@ParentID output  
  66.   
  67.         while @ParentID > 0   
  68.         begin  
  69.             set @IDList = @IDList + cast(@ParentID As nvarchar(12)) + ','  
  70.             set @sql = 'select @ParentID = [' + @ParentField + '] from ' + @TableName + ' where [' + @PrimaryField + '] = ' + cast(@ParentID As nvarchar(12))   
  71.             exec sp_executesql @sql,N'@ParentID int output',@ParentID output  
  72.         end  
  73.         set @IDList = substring(@IDList,1,len(@IDList)-1)   
  74.         if @OrderField = ''  
  75.             exec('select ' + @OutputField + ' from ' + @TableName + ' where [' + @PrimaryField + '] IN (' + @IDList + ')')   
  76.         else  
  77.             exec('select ' + @OutputField + ' from ' + @TableName + ' where [' + @PrimaryField + '] IN (' + @IDList + ') Order BY ' + @OrderField)   
  78.     end  
  79.   
  80.            
  81.     if @Type = 'sub'  
  82.     begin  
  83.         if @OrderField = ''  
  84.             exec('select ' + @OutputField + ' from ' + @TableName + ' where [' + @ParentField + '] = ' + @CurrentID + ' OR [' + @PrimaryField + '] = ' + @CurrentID)   
  85.         else  
  86.             exec('select ' + @OutputField + ' from ' + @TableName + ' where [' + @ParentField + '] = ' + @CurrentID + ' OR [' + @PrimaryField + '] = ' + @CurrentID + ' Order BY ' + @OrderField)   
  87.     end  
  88. end  
  89.   
  90.   
  91. /*   
  92.     --测试   
  93.     exec cmsdream_SP_Navigate 'parent','cmsdream_Nodes','NodeID','ParentID',116,'NodeID,Name','NavSort Desc'  
  94.     exec cmsdream_SP_Navigate 'sub','cmsdream_Nodes','NodeID','ParentID',76,'NodeID,Name'  
  95.     exec cmsdream_SP_Navigate 'all','cmsdream_Nodes','NodeID','ParentID',4,'NodeID,Name'  
  96. */