用戶自定義控件代碼如下: using System; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; using System.IO; namespace EWFS.CL { public struct stuTreeNodes { public string strKey; public string strDispVal; public string strParentKey; public string strJavaScriptCmd; } public struct stuTreeNodesIcons { public string strTreeCaptionIcon; public string strTreeContentOpenIcon; public string strTreeContentCloseIcon; } public struct stuTreePopMenu { public string strMenuItemImg; public string strMenuItemText; public string strMenuItemCmd; } [DefaultProperty("Text"), ToolboxData("<{0}:TreeView runat=server></{0}:TreeView>")] public class TreeView : System.Web.UI.WebControls.WebControl { private string m_TreeCaption; //標(biāo)題 private stuTreeNodes[] m_stuTreeNodes; //節(jié)點(diǎn)內(nèi)容 private stuTreeNodesIcons m_stuTreeNodesIcons; //節(jié)點(diǎn)圖標(biāo) private string m_TreeChangedPostURL; //修改后的樹傳送的地址 private bool m_TreeAddDir; private bool m_TreeRenDir; private bool m_TreeDelDir; private stuTreePopMenu[] m_stuTreePopMenu; private string m_GotoID; private bool m_TreeRootPopMenu; private System.Data.DataSet m_dsTreeNodes; protected System.Web.UI.WebControls.Table TreeTable; public string TreeGotoID //定位ID { get{return m_GotoID;} set{m_GotoID=value;} } [Bindable(true), Category("Appearance"), DefaultValue(true)] public bool TreeRootPopMenu { get{return m_TreeRootPopMenu;} set{m_TreeRootPopMenu=value;} } [Bindable(true), Category("Appearance"), DefaultValue("")] public bool TreeAddDir { get{return m_TreeAddDir;} set{m_TreeAddDir=value;} } public bool TreeRenDir { get{return m_TreeRenDir;} set{m_TreeRenDir=value;} } public bool TreeDelDir { get{return m_TreeDelDir;} set{m_TreeDelDir=value;} } public stuTreePopMenu[] StuTreePopMenu { get{return m_stuTreePopMenu;} set{m_stuTreePopMenu=value;} } public string TreeChangedPostURL { get{return m_TreeChangedPostURL;} set{m_TreeChangedPostURL=value;} } public stuTreeNodesIcons StuTreeNodesIcons { get {return m_stuTreeNodesIcons;} set {m_stuTreeNodesIcons = value;} } public stuTreeNodes[] StuTreeNodes { get { return m_stuTreeNodes; } set { m_stuTreeNodes=value; } } public string TreeCaption { get { return m_TreeCaption; } set { m_TreeCaption = value; } } /// <summary> /// 獲取節(jié)點(diǎn)內(nèi)容 /// </summary> public System.Data.DataSet dsTreeNodes { get{return this.m_dsTreeNodes;} set { this.m_dsTreeNodes=value; SetTreeNodes(); } } private void SetTreeNodes() { this.m_stuTreeNodes =new stuTreeNodes[m_dsTreeNodes.Tables[0].Rows.Count]; for(int i=0;i<m_dsTreeNodes.Tables[0].Rows.Count;i++) { this.m_stuTreeNodes[i].strKey=m_dsTreeNodes.Tables[0].Rows[i][0].ToString(); this.m_stuTreeNodes[i].strParentKey=m_dsTreeNodes.Tables[0].Rows[i][1].ToString()=="0"?"":m_dsTreeNodes.Tables[0].Rows[i][1].ToString(); this.m_stuTreeNodes[i].strDispVal=m_dsTreeNodes.Tables[0].Rows[i][2].ToString(); this.m_stuTreeNodes[i].strJavaScriptCmd=m_dsTreeNodes.Tables[0].Rows[i][3].ToString(); } } /// <summary> /// 將此控件呈現(xiàn)給指定的輸出參數(shù)。 /// </summary> /// <param name="output"> 要寫出到的 HTML 編寫器 </param> protected override void CreateChildControls() { System.Web.UI.WebControls.Table oTB=new Table(); System.Web.UI.WebControls.Table oTB1=new Table(); System.Web.UI.WebControls.TableRow oTR=new TableRow (); System.Web.UI.WebControls.TableCell oTD=new TableCell (); System.Web.UI.WebControls.Unit oU=new Unit("98%"); System.Web.UI.ControlCollection oCC=null; System.Web.UI.Control oC1=null; int i; //輸出JS文件 string scr="";//"<script language=javascript src=BuildTree.js></script>\r\n"; //scr+="<script language=javascript src=PopMenu.js></script>\r\n"; scr+="<script>\r\n"; //設(shè)置右鍵菜單 scr+="var MenuItemArray=new Array( "; if(m_TreeAddDir) { scr+="[‘<img src=images/mycomputer.gif>‘,‘增加目錄‘,‘TreeAddDir()‘],"; } if(m_TreeDelDir) { scr+="[‘<img src=images/mycomputer.gif>‘,‘刪除目錄‘,‘TreeDelDir()‘],"; } if(m_TreeRenDir) { scr+="[‘‘,‘重命名‘,‘TreeRenDir()‘],"; } //通過外部增加菜單內(nèi)容 if(!(m_stuTreePopMenu==null)) { for(i=0;i<m_stuTreePopMenu.Length ;i++) { scr+="[‘"+m_stuTreePopMenu[i].strMenuItemImg +"‘," +"‘"+m_stuTreePopMenu[i].strMenuItemText +"‘," +"‘"+m_stuTreePopMenu[i].strMenuItemCmd.Replace("‘","\\‘") +"‘],"; } } //scr+="[‘‘,‘‘,‘‘]);\n"; scr=scr.Substring(0,scr.Length-1); scr+=");\n"; scr+="var oIMGS=new Array(3);\r\n"; scr+="for(i=0;i<3;i++)\r\n"; scr+="{\r\n"; scr+=" oIMGS[i]=new Image;\r\n"; scr+="}\r\n"; scr+="oIMGS[0].src=‘"+m_stuTreeNodesIcons.strTreeCaptionIcon+"‘\r\n"; //頭部圖形 scr+="oIMGS[1].src=‘"+m_stuTreeNodesIcons.strTreeContentCloseIcon +"‘\r\n"; //未選中 scr+="oIMGS[2].src=‘"+m_stuTreeNodesIcons.strTreeContentOpenIcon +"‘\r\n"; //選中 scr+="document.body.onclick=‘HiddenPopMenu()‘;\r\n"; scr+="function TreeSelectStart(){if(event.srcElement.tagName==‘INPUT‘){return true;}else{return false;}}\n"; scr+=TableTreeMove(); scr+="</script>"; scr+="<script language=vbscript>\r\n"; scr+="call document.body.attachEvent(\"onclick\",getRef(\"TreeViewAddBodyOnClick\"))\r\n"; scr+="sub TreeViewAddBodyOnClick()\r\n"; scr+=" HiddenPopMenu\r\n end sub \r\n</script>\r\n"; scr+="<script>var eISOTreeViewPostAction=‘" +m_TreeChangedPostURL+"‘</script>\r\n"; //指定修改后傳送的URL scr+="</form><iframe src=‘‘ name=‘eISOTreeViewFrame‘ style=\"display:none\"></iframe>\r\n"; scr+="<form name=TreeChangedFORM action=‘"+m_TreeChangedPostURL +"‘ target=‘eISOTreeViewFrame‘ style=\"display:none\"><input type=text name=ChangedValue ></form><from>\r\n"; this.Controls.Add (new LiteralControl(scr)); //this.Parent.Page.Controls[0].Controls.Add //建立根目錄 TreeTable=new Table (); TreeTable.BorderWidth =0; TreeTable.CellPadding =0; TreeTable.CellSpacing =0; TreeTable.ID="TreeTable"; TreeTable.Style.Add ("font-size","12px"); TreeTable.Style.Add ("width","100%"); oTR=new TableRow (); oTR.ID ="TreeViewRoot"; oTD=new TableCell (); oTD.Width =20; oTD.Text ="<img src=‘"+m_stuTreeNodesIcons.strTreeCaptionIcon+"‘ width=16 heigth=16>"; oTR.Cells.Add (oTD); oTD=new TableCell (); oTD.Style.Add ("width","99%"); oTD.Style.Add ("cursor","hand"); oTD.Text ="<span>"+m_TreeCaption+"</span>"; oTD.Style.Add ("padding-left","4px"); oTR.Cells.Add (oTD); TreeTable.Rows.Add (oTR); oTR=new TableRow (); oTD=new TableCell (); oTD.ColumnSpan =2; oTR.Cells.Add (oTD); TreeTable.Rows.Add (oTR); this.Controls.Add (TreeTable); stuTreeNodes[] sTN =m_stuTreeNodes; TreeTable.Attributes.Add ("onclick","TreeNodeClick()"); TreeTable.Attributes.Add ("onselectstart","return TreeSelectStart();"); TreeTable.Attributes.Add ("oncontextmenu","TreePopMenu();return false;"); // TreeTable.Attributes.Add ("onmousemove","TableTreemv()"); // TreeTable.Attributes.Add ("onmousedown","TableTreemd()"); // TreeTable.Attributes.Add ("onmouseup","TableTreemu()"); for(i=0;i<sTN.Length ;i++) { oCC=null; oTR=new TableRow (); oTD=new TableCell (); oTD.Width =20; oTD.Text ="<img src=croend.gif width=20 height=18>"; oTR.Cells.Add(oTD); oTD=new TableCell (); oTD.Width =16; oTD.Text ="<img src="+m_stuTreeNodesIcons.strTreeContentCloseIcon +" width=15 height=15>"; oTD.VerticalAlign =VerticalAlign.Top; oTR.Cells.Add(oTD); oTD.Style.Add ("padding-left","4px"); oTD=new TableCell (); oTD.Width =oU; oTD.Style.Add ("padding-left","4px"); oTD.Text ="<span style=\"cursor:hand\">"+sTN[i].strDispVal+"</span>" ; oTD.Attributes.Add("nowrap",""); oTR.Cells.Add(oTD); oTR.Attributes.Add ("CMD",sTN[i].strJavaScriptCmd); oTB=new Table() ; oTB.Rows.Add(oTR); oTB.CellPadding =0; oTB.CellSpacing =0; oTB.Style.Add ("width","100%"); oTB.Style.Add ("font-size","12px"); oTB.ID =sTN[i].strKey ; if(sTN[i].strParentKey =="") { oCC=TreeTable.Rows[1].Cells[0].Controls; } else { oC1=this.Page.FindControl(sTN[i].strParentKey); oTB1=(Table) oC1; //有子節(jié)點(diǎn)增加一行 if(oTB1.Rows.Count==1) { AddTableRow(oTB1); } oCC=oTB1.Rows[1].Cells[oTB1.Rows[1].Cells.Count -1].Controls; } if(oCC.Count >0) { oTB1=(Table)oCC[oCC.Count-1]; if(oTB1.Rows[0].Cells[0].Text.IndexOf ("croend.gif")>=0) oTB1.Rows[0].Cells[0].Text ="<img src=cro.gif width=20 height=18>"; } oCC.AddAt(oCC.Count,oTB); } //TreeTable.Rows[1].Cells.Add(TreeTable.Rows[0].Cells[0]); for(i=0;i<sTN.Length ;i++) { oC1=Page.FindControl(sTN[i].strKey); oTB1=(Table) oC1; if(oTB1.Rows.Count ==2) { if(oTB1.Rows[0].Cells[0].Text.IndexOf ("end.gif")==-1) { oTB1.Rows[1].Cells[0].Attributes.Add ("background","lin.gif"); } oTB1.Rows[0].Cells[0].Text ="<img src=clo.gif width=20 height=18>"; oTB1.Rows[0].Cells[0].Style.Add ("cursor","hand"); oTB1.Rows[1].Style.Add("display","none"); CreateImages(); } } this.Controls.Add(new LiteralControl (AddTreeJS())); this.Controls.Add(new LiteralControl (AddPopMenuJS())); } #region 增加表行 AddTableRow(Table oTB2) private void AddTableRow(Table oTB2) { System.Web.UI.WebControls.TableRow oTR=new TableRow (); System.Web.UI.WebControls.TableCell oTD=new TableCell (); for(int i=0;i<oTB2.Rows[0].Cells.Count-1;i++) { oTD=new TableCell (); if(i==oTB2.Rows[0].Cells.Count-2) oTD.ColumnSpan =2; oTR.Cells.Add (oTD); } oTB2.Rows.Add (oTR); } #endregion #region 增加右鍵彈出式菜單 AddPopMenuJS() private string AddPopMenuJS() { string strPopMenu="<script language=javascript>\r\n//gdx\r\n"; strPopMenu+="HTMLPopMenu=‘<div id=\"oPopMenu\" style=\"LEFT: 20px; VISIBILITY: hidden; POSITION: absolute; TOP: 30px\">‘;\r\n\r\n"; strPopMenu+="HTMLPopMenu+=‘<TABLE cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<TR>‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<TD height=\"1\" bgcolor=\"white\" style=\"BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px solid; BORDER-BOTTOM: black 1px solid; BACKGROUND-COLOR: #ebf5f7\">‘\r\n"; strPopMenu+="http://Menu Item Area\r\n"; strPopMenu+="HTMLPopMenu+=‘<table id=\"oPopMenuTB\" border=\"0\" style=\"cursor:hand;font-size:12px\" onmousemove=\"DispMenuItem()\" onmouseout=\"if(!(objMenuItem==\\‘\\‘)){objMenuItem.parentElement.style.backgroundColor=\\‘\\‘;objMenuItem.style.color=\\‘\\‘;}\" oncontextmenu=\"return false\" onclick=\"ExecMenuCMD(event.srcElement.parentElement.getAttribute(\\‘CMD\\‘));\" cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">‘\r\n"; strPopMenu+="HTMLPopMenu+=‘</table>‘\r\n"; strPopMenu+="http://Menu Item Area\r\n"; strPopMenu+="HTMLPopMenu+=‘</TD>‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<TD width=\"3\">‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<table width=\"100%\" height=\"100%\" border=\"0\" cellSpacing=\"0\" cellPadding=\"0\" ID=\"Table2\">‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<tr>‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<td height=\"3\"></td>‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<tr>‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<td>‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<div style=\"FILTER: progid:DXImageTransform.Microsoft.BasicImage( Rotation=0,Mirror=0,Invert=0,XRay=0,Grayscale=0,Opacity=0.25);BACKGROUND-COLOR: gray;height:100%; width:3px\">‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<img src=\"\" width=\"1\" height=\"1\">‘\r\n"; strPopMenu+="HTMLPopMenu+=‘</div>‘\r\n"; strPopMenu+="HTMLPopMenu+=‘</td>‘\r\n"; strPopMenu+="HTMLPopMenu+=‘</tr>‘\r\n"; strPopMenu+="HTMLPopMenu+=‘</table>‘\r\n"; strPopMenu+="HTMLPopMenu+=‘</TD>‘\r\n"; strPopMenu+="HTMLPopMenu+=‘</TR>‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<TR style=\"height:3px\">‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<TD colspan=\"2\">‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<table width=\"100%\" height=\"100%\" border=\"0\" cellSpacing=\"0\" cellPadding=\"0\" ID=\"Table3\">‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<tr>‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<td width=\"3\"></td>‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<td><div style=\"FILTER: progid:DXImageTransform.Microsoft.BasicImage( Rotation=0,Mirror=0,Invert=0,XRay=0,Grayscale=0,Opacity=0.25);BACKGROUND-COLOR: gray;height:3px\">‘\r\n"; strPopMenu+="HTMLPopMenu+=‘<img src=\"\" width=\"1\" height=\"1\"></div>‘;\r\n"; strPopMenu+="HTMLPopMenu+=‘</td>‘;\r\n"; strPopMenu+="HTMLPopMenu+=‘</tr>‘;\r\n"; strPopMenu+="HTMLPopMenu+=‘</table>‘;\r\n"; strPopMenu+="HTMLPopMenu+=‘</TD>‘;\r\n"; strPopMenu+="HTMLPopMenu+=‘</TR>‘;\r\n"; strPopMenu+="HTMLPopMenu+=‘</TABLE>‘;\r\n"; strPopMenu+="HTMLPopMenu+=‘</div>‘;\r\n"; strPopMenu+="\r\n"; strPopMenu+="var objMenuItem=‘‘;\r\n"; strPopMenu+="var objBeforePop=‘‘;\r\n"; strPopMenu+="function DispMenuItem()\r\n"; strPopMenu+="{\r\n"; strPopMenu+=" if(event.srcElement.tagName==‘TD‘)\r\n"; strPopMenu+=" {\r\n"; strPopMenu+=" if(!(objMenuItem==‘‘))\r\n"; strPopMenu+=" {\r\n"; strPopMenu+=" objMenuItem.parentElement.style.backgroundColor=‘‘;\r\n"; strPopMenu+=" objMenuItem.style.color=‘black‘;\r\n"; strPopMenu+=" }\r\n"; strPopMenu+=" objMenuItem=event.srcElement;\r\n"; strPopMenu+=" objMenuItem.parentElement.style.backgroundColor=‘blue‘;\r\n"; strPopMenu+=" objMenuItem.style.color=‘white‘;\r\n"; strPopMenu+=" }\r\n"; strPopMenu+="}\r\n"; strPopMenu+="\r\n"; strPopMenu+="function ExecMenuCMD(cmd)\r\n"; strPopMenu+="{\r\n"; strPopMenu+=" if(!cmd==‘‘ && cmd.indexOf(‘(‘)>0 && cmd.indexOf(‘)‘)>0)\r\n"; strPopMenu+=" {\r\n"; strPopMenu+=" eval(cmd);\r\n"; strPopMenu+=" HiddenPopMenu();\r\n"; strPopMenu+=" }\r\n"; strPopMenu+=" HiddenPopMenu();\r\n"; strPopMenu+="}\r\n"; strPopMenu+="\r\n"; strPopMenu+="function DisplayMenu(ArrayMenuItem)\r\n"; strPopMenu+="{\r\n"; strPopMenu+=" //window.oPopMenuTB.removeNode(false);\r\n"; strPopMenu+=" while(oPopMenuTB.rows.length>0)\r\n"; strPopMenu+=" {\r\n"; strPopMenu+=" oPopMenuTB.rows[0].removeNode(true);\r\n"; strPopMenu+=" }\r\n"; strPopMenu+=" for(i=0;i<ArrayMenuItem.length-1;i++)\r\n"; strPopMenu+=" {\r\n"; strPopMenu+=" myrow=window.oPopMenuTB.insertRow();\r\n"; strPopMenu+=" mycel=myrow.insertCell();\r\n"; strPopMenu+=" mycel.height=19\r\n"; strPopMenu+=" mycel.style.paddingLeft=‘4px‘;\r\n"; strPopMenu+=" mycel.style.paddingRight=‘2px‘;\r\n"; strPopMenu+=" mycel.style.paddingTop=‘2px‘;\r\n"; strPopMenu+=" mycel.style.paddingBottom=‘2px‘;\r\n"; strPopMenu+=" mycel.innerHTML=ArrayMenuItem[i][0];\r\n"; strPopMenu+=" mycel=myrow.insertCell();\r\n"; strPopMenu+=" mycel.style.paddingLeft=‘2px‘;\r\n"; strPopMenu+=" mycel.style.paddingRight=‘4px‘;\r\n"; strPopMenu+=" mycel.style.paddingTop=‘2px‘;\r\n"; strPopMenu+=" mycel.style.paddingBottom=‘2px‘;\r\n"; strPopMenu+=" mycel.innerHTML=ArrayMenuItem[i][1];\r\n"; strPopMenu+=" mycel.noWarp=true;\n"; strPopMenu+=" myrow.setAttribute(‘CMD‘,ArrayMenuItem[i][2]); \r\n"; strPopMenu+=" }\r\n"; strPopMenu+="}\r\n"; strPopMenu+="\r\n"; strPopMenu+="function PopMenu()\r\n"; strPopMenu+="{\r\n"; strPopMenu+=" \r\n"; strPopMenu+=" objBeforePop=event.srcElement; //彈出菜單前的對象\r\n"; strPopMenu+=" \r\n"; strPopMenu+=" if((oPopMenu.clientHeight+event.y)>document.body.clientHeight)\r\n"; strPopMenu+=" {\r\n"; strPopMenu+=" oPopMenu.style.posTop =event.y-oPopMenu.clientHeight+document.body.scrollTop;\r\n"; strPopMenu+=" }\r\n"; strPopMenu+=" else\r\n"; strPopMenu+=" {\r\n"; strPopMenu+=" oPopMenu.style.posTop =event.y+document.body.scrollTop;\r\n"; strPopMenu+=" }\r\n"; strPopMenu+=" if((oPopMenu.clientWidth+event.x)>document.body.clientWidth )\r\n"; strPopMenu+=" {\r\n"; strPopMenu+=" oPopMenu.style.posLeft =event.x-oPopMenu.clientWidth+document.body.scrollLeft ;\r\n"; strPopMenu+=" }\r\n"; strPopMenu+=" else\r\n"; strPopMenu+=" {\r\n"; strPopMenu+=" oPopMenu.style.posLeft =event.x+document.body.scrollLeft;\r\n"; strPopMenu+=" }\r\n"; strPopMenu+=" oPopMenu.style.visibility =‘visible‘;\r\n"; strPopMenu+=" //alert(oPopMenu.clientHeight );\r\n"; strPopMenu+="}\r\n"; strPopMenu+="function HiddenPopMenu()\r\n"; strPopMenu+="{\r\n"; strPopMenu+=" oPopMenu.style.visibility =‘hidden‘;\r\n"; strPopMenu+="}\r\n"; strPopMenu+="document.write(HTMLPopMenu);\r\n</script>"; strPopMenu="<script language=javascript src=/eGMS/Web/JS/PopMenu.js></script>"; return strPopMenu; } #endregion private string AddTreeJS() { string strTree="<script language=javascript>\r\n"; strTree+="var strTreeUndeleteDir=‘子目錄不為空,,不能刪除‘;\n"; strTree+="var strTreeNewItem=‘新建目錄‘;\n"; strTree+="TreeHTML1=‘<div id=\"TreeInputParent\" style = \"VISIBILITY: hidden;position:absolute\">‘\r\n"; strTree+="TreeHTML1+=‘<input type=\"text\" name=\"TreeInput\" id=\"TreeInput\" style=\"BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; FONT-SIZE: 12px; Z-INDEX: 9; BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid;\" onkeypress=\"TreeInputKey();\" onblur=\"TreeInputBlur();\">‘\r\n"; strTree+="TreeHTML1+=‘<input type=\"hidden\" id=\"TreeInput1\" id=\"TreeInput1\">‘\r\n"; strTree+="TreeHTML1+=‘</div>‘\r\n"; strTree+="\r\n"; strTree+=" document.write(TreeHTML1);\r\n"; strTree+="\r\n"; strTree+="var objSelected=‘‘\r\n"; //快速定位 strTree+="function tmpGotoID(id)\n"; strTree+="{\n"; strTree+=" obj=document.all.tags(‘TABLE‘);\n"; strTree+=" for(i=0;i<obj.length;i++)\n"; strTree+=" {\n"; strTree+=" if(obj[i].id==id)\n"; strTree+=" {\n"; strTree+=" obj=obj[i];\n"; strTree+=" break;\n"; strTree+=" }\n"; strTree+=" }\n"; strTree+=" obj.rows[0].cells[1].innerHTML=‘<img width=16 height=16 border=0 src=‘+oIMGS[2].src+‘>‘;\n"; strTree+=" //obj.rows[0].cells[2].childNodes[0].style.backgroundColor=‘blue‘;\n"; strTree+=" //obj.rows[0].cells[2].childNodes[0].style.color=‘white‘;\n"; strTree+=" objSelected=obj.rows[0].cells[2].childNodes[0];\n"; strTree+=" \n"; strTree+=" obj=obj.parentElement.parentElement.parentElement.parentElement;\n"; strTree+=" while(!(obj.id==‘TreeTable‘))\n"; strTree+=" {\n"; strTree+=" obj.rows[1].style.display=‘inline‘;\n"; strTree+=" obj.rows[0].cells[0].childNodes[0].src=‘ope.gif‘;\n"; strTree+=" obj=obj.parentElement.parentElement.parentElement.parentElement;\n"; strTree+=" }\n"; strTree+=" \n"; strTree+="}\n"; string mm=m_GotoID+""; if(!(mm.Trim()=="")) //快速定位 strTree+="tmpGotoID(‘"+mm+"‘);\n"; //右鍵彈出菜單 strTree+="function TreePopMenu()\r\n"; strTree+="{\r\n"; strTree+=" if(event.srcElement.tagName==‘SPAN‘)\r\n"; strTree+=" {\r\n"; //根節(jié)點(diǎn)禁止右鍵菜單 if(m_TreeRootPopMenu==false) { strTree+=" if(event.srcElement.parentElement.parentElement.id==‘TreeViewRoot‘)\n"; strTree+=" return;\n"; } strTree+=" if (!(objSelected==‘‘))\r\n"; strTree+=" {\r\n"; strTree+=" loc=objSelected.parentElement.parentElement.cells.length-2\r\n"; strTree+=" objSelected.style.backgroundColor=‘‘;\r\n"; strTree+=" objSelected.style.color=‘‘;\r\n"; strTree+=" if(!(objSelected.parentElement.parentElement.parentElement.parentElement.id==‘TreeTable‘))\n"; strTree+=" objSelected.parentElement.parentElement.cells[loc].innerHTML=oIMGS[1].outerHTML\r\n"; strTree+=" }\r\n"; strTree+=" objSelected=event.srcElement;\r\n"; strTree+=" loc=objSelected.parentElement.parentElement.cells.length-2\r\n"; strTree+=" objSelected.style.backgroundColor=‘blue‘;\r\n"; strTree+=" objSelected.style.color=‘white‘\r\n"; strTree+=" DisplayMenu(MenuItemArray);\r\n"; strTree+=" PopMenu();\r\n"; strTree+=" }\r\n"; strTree+="}\r\n"; strTree+="function TreeNodeClick()\r\n"; strTree+="{\r\n"; strTree+=" \r\n"; strTree+=" if(event.srcElement.tagName==‘SPAN‘)\r\n"; strTree+=" {\r\n"; strTree+=" if (!(objSelected==‘‘))\r\n"; strTree+=" {\r\n"; strTree+=" loc=objSelected.parentElement.parentElement.cells.length-2\r\n"; strTree+=" objSelected.style.backgroundColor=‘‘;\r\n"; strTree+=" objSelected.style.color=‘‘;\r\n"; strTree+=" if(!(objSelected.parentElement.parentElement.parentElement.parentElement.id==‘TreeTable‘))\n"; strTree+=" objSelected.parentElement.parentElement.cells[loc].innerHTML=oIMGS[1].outerHTML\r\n"; strTree+=" }\r\n"; strTree+=" objSelected=event.srcElement;\r\n"; strTree+=" loc=objSelected.parentElement.parentElement.cells.length-2\r\n"; strTree+=" objSelected.style.backgroundColor=‘blue‘;\r\n"; strTree+=" objSelected.style.color=‘white‘\r\n"; strTree+=" if(!(objSelected.parentElement.parentElement.parentElement.parentElement.id==‘TreeTable‘))\n"; strTree+=" objSelected.parentElement.parentElement.cells[loc].innerHTML=oIMGS[2].outerHTML\r\n"; strTree+=" cmdstr=objSelected.parentElement.parentElement.CMD;\r\n"; strTree+=" if(!(cmdstr==‘‘))\r\n"; strTree+=" eval(cmdstr);\r\n"; strTree+=" return;\r\n"; strTree+=" }\r\n"; strTree+=" \r\n"; strTree+=" if(event.srcElement.tagName==‘IMG‘)\r\n"; strTree+=" {\r\n"; strTree+=" obj=event.srcElement;\r\n"; strTree+=" if(obj.src.indexOf(‘clo.gif‘)>0)\r\n"; strTree+=" {\r\n"; strTree+=" obj.src=\"ope.gif\"\r\n"; strTree+=" obj.parentElement.parentElement.parentElement.rows[1].style.display=‘inline‘;\r\n"; strTree+=" return\r\n"; strTree+=" }\r\n"; strTree+=" if(obj.src.indexOf(‘ope.gif‘)>0)\r\n"; strTree+=" {\r\n"; strTree+=" obj.src=\"clo.gif\"\r\n"; strTree+=" obj.parentElement.parentElement.parentElement.rows[1].style.display=‘none‘;\r\n"; strTree+=" return;\r\n"; strTree+=" }\r\n"; strTree+=" }\r\n"; strTree+="}\r\n"; strTree+="function TreePostChange(v1){" ; strTree+=" document.TreeChangedFORM.ChangedValue.value=v1;"; strTree+=" document.TreeChangedFORM.submit();}\n"; //刪除目錄 strTree+="function TreeDelDir(){\n"; strTree+=" objNode=objBeforePop.parentElement.parentElement.parentElement.parentElement;\r\n"; strTree+=" objNodeParent=objNode.parentElement;\r\n"; strTree+=" if(objNode.rows.length>1)\r\n"; strTree+=" {\r\n"; strTree+=" objNode.rows[1].style.display=‘inline‘;\r\n"; strTree+=" objNode.rows[0].cells[0].childNodes[0].src=‘ope.gif‘\r\n"; strTree+=" objNode.rows[0].cells[1].childNodes[0].src=oIMGS[2].src;\r\n"; strTree+=" alert(strTreeUndeleteDir)\r\n"; strTree+=" return;\r\n"; strTree+=" }\r\n"; strTree+=" TreePostChange(‘DELETE?‘+objNode.id);}\n"; strTree+="function TreeDelDirEnabled()\r\n"; strTree+="{\r\n"; strTree+=" objNode=objBeforePop.parentElement.parentElement.parentElement.parentElement;\r\n"; strTree+=" objNodeParent=objNode.parentElement;\r\n"; strTree+=" if(objNode.rows.length>1)\r\n"; strTree+=" {\r\n"; strTree+=" objNode.rows[1].style.display=‘inline‘;\r\n"; strTree+=" objNode.rows[0].cells[0].childNodes[0].src=‘ope.gif‘\r\n"; strTree+=" objNode.rows[0].cells[1].childNodes[0].src=oIMGS[2].src;\r\n"; strTree+=" alert(strTreeUndeleteDir)\r\n"; strTree+=" return;\r\n"; strTree+=" }\r\n"; strTree+=" TreePostChange(‘DEL?‘+objNode.id);"; strTree+=" objNodeParent.removeChild(objNode);\r\n"; strTree+=" if(objNodeParent.childNodes.length==0)\r\n"; strTree+=" {\r\n"; strTree+=" //空子目錄\r\n"; strTree+=" obj1=objNodeParent.parentElement.parentElement.parentElement\r\n"; strTree+=" obj1.deleteRow(1);\r\n"; strTree+="obj1.rows[0].cells[0].childNodes[0].src=‘cro.gif‘;\r\n"; strTree+=" obj1p=obj1.parentElement;\r\n"; strTree+=" \r\n"; strTree+=" if(obj1p.childNodes[obj1p.childNodes.length-1]==obj1)\r\n"; strTree+=" {\r\n"; strTree+=" //目錄底部\r\n"; strTree+=" obj1.rows[0].cells[0].childNodes[0].src=‘croend.gif‘;\r\n"; strTree+=" obj1.rows[0].cells[0].style.cursor=‘‘;\r\n"; strTree+=" }\r\n"; strTree+=" return\r\n"; strTree+=" }\r\n"; strTree+=" \r\n"; strTree+=" //設(shè)置上層目錄類型\r\n"; strTree+=" obj1=objNodeParent.childNodes[objNodeParent.childNodes.length-1];\r\n"; strTree+=" if(obj1.rows.length==2)\r\n"; strTree+=" {\r\n"; strTree+=" obj1.rows[1].cells[0].background=‘‘;\r\n"; strTree+=" }\r\n"; strTree+=" else\r\n"; strTree+=" {\r\n"; strTree+=" obj1.rows[0].cells[0].childNodes[0].src=‘croend.gif‘;\r\n"; strTree+=" }\r\n"; strTree+="}\r\n"; //重命名 strTree+="http://重命名\r\n"; strTree+="var oTreeInpt=TreeInputParent.childNodes[0];\r\n"; strTree+="var oTreeInpt1=TreeInputParent.childNodes[1];\r\n"; //查詢是否能夠Rename strTree+="function TreeRenDir()\r\n"; strTree+="{\r\n"; strTree+=" objRen=objBeforePop;\r\n"; strTree+=" TreePostChange(‘RENAME?‘+objRen.parentElement.parentElement.parentElement.parentElement.id);}\n"; strTree+="function TreeRenDirEnabled()\r\n"; strTree+="{\r\n"; strTree+=" objRen=objBeforePop;\r\n"; strTree+=" if(objRen.parentElement.parentElement.parentElement.parentElement.id==‘TreeTable‘)\n"; strTree+=" return;\n"; strTree+=" oTreeInpt.value =objRen.innerText;\r\n"; strTree+=" oTreeInpt1.value =objRen.innerText;\r\n"; strTree+=" objRen.innerText=‘‘;\r\n"; strTree+=" objRen.appendChild (oTreeInpt);\r\n"; strTree+=" oTreeInpt=objRen.childNodes[0];\r\n"; strTree+=" oTreeInpt.focus();\r\n"; strTree+="}\r\n"; strTree+="\r\n"; strTree+="var NewItem=0;\r\n"; strTree+="var lNewItem=false;\n"; strTree+="function TreeAddDir()\r\n"; strTree+="{\r\n"; strTree+=" objNode=objBeforePop.parentElement.parentElement.parentElement.parentElement;\r\n"; strTree+=" objBeforePop.style.backgroundColor=‘‘;\r\n"; strTree+=" objBeforePop.style.color=‘‘;\r\n"; strTree+=" TreeCreatTable(‘NewItem‘+NewItem,objNode.id);\r\n"; strTree+=" TreePostChange(‘NEWITEM?‘+objNode.id);}\n"; strTree+="function TreeAddDirEnabled()\r\n"; strTree+="{\r\n"; strTree+=" objNode=objBeforePop.parentElement.parentElement.parentElement.parentElement;\r\n"; strTree+=" objBeforePop.style.backgroundColor=‘‘;\r\n"; strTree+=" objBeforePop.style.color=‘‘;\r\n"; strTree+=" TreeCreatTable(‘NewItem‘+NewItem,objNode.id);\r\n"; strTree+=" NewItem++;\r\n"; strTree+=" \r\n"; strTree+=" if(objNode.rows.length==1)\r\n"; strTree+=" {\r\n"; strTree+=" //建立下一行\(zhòng)r\n"; strTree+=" oTr=objNode.insertRow();\r\n"; strTree+=" for(m=0;m<objNode.rows[0].cells.length-1;m++)\r\n"; strTree+=" {\r\n"; strTree+=" oTd=oTr.insertCell();\r\n"; strTree+=" }\r\n"; strTree+=" oTd.colSpan=2\r\n"; strTree+="\r\n"; strTree+=" if(!(objNode.parentElement.childNodes[objNode.parentElement.childNodes.length-1]==objNode))\r\n"; strTree+=" {\r\n"; strTree+=" objNode.rows[1].cells[0].background=‘lin.gif‘;\r\n"; strTree+=" }\r\n"; strTree+=" objNode.rows[0].cells[0].innerHTML=\"<img src=ope.gif width=20 height=18>\";\r\n"; strTree+=" objNode.rows[0].cells[0].style.cursor=‘hand‘;\r\n"; strTree+=" }\r\n"; strTree+=" else\r\n"; strTree+=" {\r\n"; strTree+=" if(!(objNode.id==‘TreeTable‘)){\n"; strTree+=" objNode.rows[1].style.display=‘inline‘;\r\n"; strTree+=" objNode.rows[0].cells[0].innerHTML=\"<img src=ope.gif width=20 height=18>\";\r\n"; strTree+=" if(!(objNode.parentElement.childNodes[objNode.parentElement.childNodes.length-1]==objNode))\r\n"; strTree+=" objNode.childNodes[objNode.childNodes.length-1].rows[1].cells[0].background=‘lin.gif‘;\r\n"; strTree+=" }\n}\r\n"; strTree+=" \r\n"; strTree+=" obj1=objNode.rows[1].cells[objNode.rows[1].cells.length-1];\r\n"; strTree+=" if(obj1.childNodes.length>0)\r\n"; strTree+=" {\r\n"; strTree+=" obj=obj1.childNodes[obj1.childNodes.length-1];\r\n"; strTree+=" if(obj.rows[0].cells[0].innerHTML.indexOf(‘croend.gif‘)>-1)\r\n"; strTree+=" obj.rows[0].cells[0].innerHTML=\"<img src=cro.gif>\";\r\n"; strTree+=" else\r\n"; strTree+=" obj.rows[1].cells[0].background=‘lin.gif‘;\r\n"; strTree+=" \r\n"; strTree+=" }\r\n"; strTree+=" obj1.insertAdjacentElement(‘beforeEnd‘,oTb);\r\n"; strTree+=" objBeforePop=oTb.rows[0].cells[2].childNodes[0];\r\n"; strTree+=" lNewItem=true;\n TreeRenDirEnabled();\r\n"; strTree+="}\r\n"; strTree+="\r\n"; strTree+="function TreeCreatTable(ID,ParID)\r\n"; strTree+="{\r\n"; strTree+=" oTb=document.createElement (\"TABLE\")\r\n"; strTree+=" oTb.width=‘100%‘;\r\n"; strTree+=" oTb.border=0;\r\n"; strTree+=" oTb.cellPadding =0;\r\n"; strTree+=" oTb.cellSpacing =0;\r\n"; strTree+=" oTb.id=ID;\r\n"; strTree+=" oTb.style.fontSize=‘12px‘;\r\n"; strTree+=" \r\n"; strTree+=" oTr=oTb.insertRow();\r\n"; strTree+=" oTr.setAttribute(‘CMD‘,\"\");\r\n"; strTree+=" \r\n"; strTree+=" oTd=oTr.insertCell();\r\n"; strTree+=" oTd.width=20;\r\n"; strTree+=" oTd.height=18;\r\n"; strTree+=" oTd.innerHTML=\"<img src=croend.gif width=20 height=18>\"\r\n"; strTree+=" \r\n"; strTree+=" oTd=oTr.insertCell();\r\n"; strTree+=" oTd.width=16;\r\n"; strTree+=" oTd.innerHTML=oIMGS[1].outerHTML;\r\n"; strTree+=" oTd.align=‘center‘\r\n"; strTree+=" oTd.style.paddingLeft=‘4px‘;\r\n"; strTree+=" \r\n"; strTree+=" oTd=oTr.insertCell();\r\n"; strTree+=" oTd.width=‘98%‘\r\n"; strTree+=" oTd.innerHTML=‘<span>‘+strTreeNewItem +NewItem+‘</span>‘;\r\n"; strTree+=" oTd.style.cursor=‘hand‘;\r\n"; strTree+=" oTd.style.paddingLeft=‘4px‘;\r\n"; strTree+="}\r\n"; strTree+="\r\n"; strTree+="http://重命名鍵判斷\r\n"; strTree+="function TreeInputKey()\r\n"; strTree+="{\r\n"; strTree+=" if(event.keyCode==13)\r\n"; strTree+=" {\r\n"; strTree+=" TreeInputBlur();\r\n"; strTree+=" }\r\n"; strTree+=" if(event.keyCode==27)\r\n"; strTree+=" {\r\n"; strTree+=" o1=oTreeInpt.parentElement;\r\n"; strTree+=" TreeInputParent.appendChild (oTreeInpt);\r\n"; strTree+=" o1.innerText =oTreeInpt1.value;\r\n"; strTree+=" }\r\n"; strTree+="}\r\n"; strTree+="\r\n"; strTree+="http://判斷新內(nèi)容\r\n"; strTree+="function TreeInputBlur()\r\n"; strTree+="{\r\n"; strTree+=" if(oTreeInpt.value==‘‘)\r\n"; strTree+=" {\r\n"; strTree+=" alert(‘名稱不能為空‘);\r\n"; strTree+=" oTreeInpt.focus ();\r\n"; strTree+=" return;\r\n"; strTree+=" }\r\n"; strTree+=" o3=oTreeInpt.parentElement.parentElement.parentElement.parentElement.parentElement\r\n"; strTree+=" o2=o3.parentElement\r\n"; strTree+=" for(i=0;i<o2.childNodes.length;i++)\r\n"; strTree+=" {\r\n"; strTree+=" //alert(o2.childNodes[i].rows[0].cells[2].innerText)\r\n"; strTree+=" if(o2.childNodes[i].rows[0].cells[2].innerText==oTreeInpt.value)\r\n"; strTree+=" {\r\n"; strTree+=" alert(‘名稱重復(fù)‘);\r\n"; strTree+=" oTreeInpt.focus ();\r\n"; strTree+=" return;\r\n"; strTree+=" }\r\n"; strTree+=" }\r\n"; strTree+="if(!lNewItem){"; strTree+="TreePostChange(‘REN?‘+o3.id+‘?‘+oTreeInpt.value);}\n"; strTree+="else{\n"; strTree+="TreePostChange(‘NEW?‘+o3.id+‘?‘+oTreeInpt.value+‘?‘+o2.parentElement.parentElement.parentElement.id);lNewItem=false;}\n"; strTree+=" o1=oTreeInpt.parentElement;\r\n"; strTree+=" TreeInputParent.appendChild (oTreeInpt);\r\n"; strTree+=" o1.innerText =oTreeInpt.value;\r\n"; strTree+="}\r\n</script>"; return strTree; } private void CreateImages() { string fp=this.Parent.Page.Server.MapPath(".")+"\\"; string strOPE="R0lGODlhFAASAJECAAAAAICAgP///wAAACH5BAEAAAIALAAAAAAUABIAAAInlI+pK8EPY5MUhotxdIo/j4CLaJCJA6Tp5LTnuMGW/GVZhXf5rj8FADs="; SaveImage(strOPE,fp+"ope.gif"); string strCRO ="R0lGODlhFAASAIABAICAgP///yH5BAEAAAEALAAAAAAUABIAAAIcjI+pG8APY5O0uorfzRy5P4EdtI1caWJoSq1IAQA7"; SaveImage(strCRO,fp+"cro.gif"); string strCROEND="R0lGODlhFAASAIABAICAgP///yH5BAEAAAEALAAAAAAUABIAAAIYjI+pG8APY5O0uorfzRy5P4HdSJbmiUoFADs="; SaveImage(strCROEND,fp+"croend.gif"); string strLIN="R0lGODlhFAASAIABAICAgP///yH5BAEAAAEALAAAAAAUABIAAAIYjI+pG8APY5O0uorfzRzt3n1gJo6WGUIFADs="; SaveImage(strLIN,fp+"lin.gif"); string strCLO="R0lGODlhFAASAJECAAAAAICAgP///wAAACH5BAEAAAIALAAAAAAUABIAAAIqlI+pK8EPY5MUhotxdIo/DxweA4qbAKTp5LRJaYwLPFnzlmXV3vF+/ygAADs="; SaveImage(strCLO,fp+"clo.gif"); } private void SaveImage(string strFileB64,string strFileName) { FileStream oFS=new FileStream (strFileName,FileMode.Create); byte[] bDes=Convert.FromBase64String (strFileB64); oFS.Write(bDes,0,bDes.Length ); oFS.Close (); } /// <summary> /// 生成目錄移動(dòng)腳本 /// </summary> /// <returns></returns> private string TableTreeMove() { return "var lmousedown=false;\n" +"var createspan=‘‘;\n" +"var redobj=‘‘;\n" +"var selectednode=‘‘\n" +"function TableTreemv()\n" +"{\n" +" if(lmousedown==false)\n" +" return;\n" +" createspan.style.left=event.x;\n" +" createspan.style.top=event.y;\n" +" if(event.srcElement.tagName==‘SPAN‘ && event.srcElement.style.cursor==‘hand‘)\n" +" {\n" +" event.srcElement.style.color=‘red‘;\n" +" if(redobj!=‘‘ && redobj!=event.srcElement && redobj.style.color==‘red‘ )\n" +" {\n" +" redobj.style.color=‘‘;\n" +" \n" +" }\n" +" redobj=event.srcElement;\n" +" \n" +" }\n" +"}\n" +"function TableTreemu()\n" +"{\n" +" if(lmousedown==false)\n" +" return;\n" +" lmousedown=false;\n" +" if(createspan !=‘‘)\n" +" {\n" +" document.body.removeChild(createspan);\n" +" createspan=‘‘;\n" +" }\n" +" if(event.srcElement.tagName==‘SPAN‘ && event.srcElement.style.cursor==‘hand‘)\n" +" {\n" +" if(event.srcElement.parentElement.parentElement.parentElement.parentElement.rows.length==1)\n" +" {\n" +" tr=event.srcElement.parentElement.parentElement.parentElement.parentElement.insertRow();\n" +" tr.insertCell();\n" +" td=tr.insertCell();td.colSpan=2;\n" +" }\n" +" event.srcElement.parentElement.parentElement.parentElement.parentElement.rows[1].cells[1].appendChild(selectednode);\n" +" }\n" +"}\n" +"function TableTreemd()\n" +"{\n" +" if(event.srcElement.tagName==‘SPAN‘ && event.srcElement.style.cursor==‘hand‘)\n" +" {\n" +" lmousedown=true;\n" +" //event.srcElement.innerHTML=‘a(chǎn)aa‘;\n" +" selectednode=event.srcElement.parentElement.parentElement.parentElement.parentElement;\n" +" TableTreeCreateObject();\n" +" }\n" +"}\n" +"function TableTreeCreateObject()\n" +"{\n" +" o1=document.createElement(‘SPAN‘);\n" +" o1.innerText=selectednode.innerText;\n" +" //\n" +" //o1.style.position=‘a(chǎn)bsloute‘;\n" +" o1.style.top=event.y;\n" +" o1.style.left =event.x;\n" +" document.body.appendChild(o1);\n" +" o1.style.position=‘a(chǎn)bsolute‘;\n" +" createspan=o1;\n" +"}\n"; } } } |
|