www.gusucode.com > 因特达Access数据库在线管理系统 > 因特达Access数据库在线管理系统\code\access\db_tb_value.asp
<!-- #include file="fun.asp" --> <!-- #include file= "public.asp" --> <!-- #include file="session.asp" --> <% conn=""'不能少,软定义 call openDB dim tbName,idName tbName=request("tb") idName=get_idName(tbName) if idName="" then response.Write("表没有ID,请添加") response.end end if %> <html> <head> <style type="text/css"> <!-- body,td,th { font-size: 13px; } .T { background-image: url(images/zhishi_02.gif); background-repeat: repeat-x; background-position: bottom; } .L { background-image: url(images/zhishi_04.gif); background-repeat: repeat-y; background-position: right; } .R { background-image: url(images/zhishi_04.gif); background-repeat: repeat-y; background-position: right; filter:FlipH; } .B { background-image: url(images/zhishi_03.gif); background-repeat: repeat-x; background-position: top; } .zhishi_LT {filter:FlipV;} .zhishi_RT {filter:FlipV FlipH;} .zhishi_LB {filter:;} .zhishi_RT {filter:FlipH;} body { margin-left: 3px; margin-top: -3px; margin-right: 0px; margin-bottom: 0px; } #tr{ height: 20px; } #tr0 td{ border-top: 1px solid #FFFFFF; border-right: 1px solid #C9C7BA; border-bottom: 1px solid #C9C7BA; border-left: 1px solid #FFFFFF; } a:link { color: #003399; text-decoration: none; } a:visited { text-decoration: none; color: #003399; } a:hover { text-decoration: none; color: #990000; } a:active { text-decoration: none; color: #990000; } --> </style> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head> <body style="overflow-y:hidden"> <iframe name=save_frame width=0 height=0 ></iframe> <% 'On Error Resume Next select case request("operation") case "create" create response.End() case "save_td" save_td response.End() case else show_data end select sub show_data ' on error resume next response.Write("<div style='overflow:auto;height:expression(document.body.offsetHeight-20)' id='divScroll'>") response.write("<table id=oTable STYLE='table-layout:fixed;' cellspacing=0 cellpadding=3 bgColor=#ffffff bordercolordark=#FFFFFF border=1 bordercolor=#E9E6D1 onMouseDown=edit_mouseDown() onMouseUp=edit_mouseUp() onMouseOver='over_bg()'>") response.write("<tr id=tr0 bgColor=#F0EEE1 style=top:expression(document.getElementById('divScroll').scrollTop-2);Left:expression(document.getElementById('divScroll').scrollLeft-1);position:relative;>")'表头 dim rs,sql,MyField if request("orders")<>"" then orders=" order by "&request("orders") end if set rs=server.CreateObject("adodb.recordset") sql="select top 1000 * from "&tbName&orders'只显示1000条 rs.open sql,conn,1,1 i=0 dim arr()'定义数组 For Each MyField In rs.fields a="<a href='?db="&server.urlEncode(request("db"))&"&tb="&server.urlEncode(request("tb"))&"&orders="&server.urlEncode(MyField.name)&"'>" if request("orders")=myField.name then tag="↑" else tag="" end if td_width=get_width(MyField.name)+8'多8个像素,好看。 if td_width<80 then td_width=80 end if'td宽度 if td_width>200 then td_width=200 end if response.write("<td bgcolor=#E7E2CD style='width:"&td_width&"px;' size="&MyField.DefinedSize&">"&tag&a&MyField.name&"</a></td>") redim preserve arr(i)'再次定义动态数组,preserve是为了保证数组中的老值不变 arr(i)=MyField.name'把列名放到数组中 i=i+1 Next response.write("</tr>") '============表头结束 '/////////////再列出所有记录 for j=1 to rs.recordcount if j mod 2=0 then bg="#f9f9f9" else bg="#ffffff" end if response.write("<tr id=tr id2="&rs(idName)&">") for i=0 to ubound(arr)'全部列名 ss="" if len(rs(arr(i)))>0 then'不为空时 ss=replace(rs(arr(i)),"<","<") ss=replace(ss,">",">") ss=replace(ss,"\‘","'") else ss=" "'中文空格 end if response.write("<td>"&ss&"</td>") next response.write("</tr>") rs.movenext next response.write("</table></div>") end sub %> <div id="Layer_edit" style="position:absolute; width:120; height:30px;display:none"> <table width="296" cellpadding="0" cellspacing="0" style="filter:alpha(opacity=96);"> <form method="post" onSubmit="Layer_edit.style.display='none'" target=save_frame> <input type=hidden name=operation value=save_td> <tr> <td width="7" align="right" valign="bottom"><img src="images/zhishi_01.gif"></td> <td colspan="2" class="T" id=td_t><img src="images/zhishi_05.gif" name="zhishiUp" id="zhishiUp" style="filter:FlipV;display:none"></td> <td width="7" valign="bottom"><img src="images/zhishi_01.gif" style="filter:FlipH"></td> </tr> <tr> <td rowspan="3" class="L"> </td> <td width="99%" bgcolor="ffffe1"> <input name="imageField" type="image" src="images/but_save.gif" alt="保存"> </td> <td width="1" align="right" valign="top" bgcolor="ffffe1"><img src="images/close.gif" alt="取消" onClick="Layer_edit.style.display='none'" ></td> <td rowspan="3" class="R"> </td> </tr> <tr> <td colspan="2" bgcolor="#ffffe1"><input name="editBox" style="width:220px"/></td> </tr> <tr> <td colspan="2" bgcolor="ffffe1"><input name="tbName" type="hidden" id="tbName" value="<%=tbName%>"> <input name="edit_id" type="hidden" id="edit_id"> <input name="edit_columnName" type="hidden" id="edit_columnName"> <input name="cur_td" type="hidden" id="cur_td"></td> </tr> <tr> <td align="right" valign="top"><img src="images/zhishi_01.gif" style="filter:FlipV"></td> <td colspan="2" class="B" id=td_b><img src="images/zhishi_05.gif" name="zhishiDown" id="zhishiDown"></td> <td valign="top"><img src="images/zhishi_01.gif" style="filter:FlipV FlipH"></td> </tr> </form> </table> </div> <script> var edit_obj//被编辑的对象 function edit_mouseDown() { oElement=document.elementFromPoint(event.x,event.y) edit_obj=oElement//存储被编辑对象 } function edit_mouseUp() { oElement=document.elementFromPoint(event.x,event.y) if(oElement.tagName=="TD" && oElement.parentElement.id!='tr0') { if(oElement==edit_obj)//鼠标放开的时候看是不是被编辑的对象 { var curTable=oElement.parentElement.parentElement//得到当前tbale tr0_curTd=curTable.rows[0].cells[oElement.cellIndex]//取第一行中的当前列 if(tr0_curTd.size-0>255)//说明是备注型 { document.all.editBox.parentElement.innerHTML="<textarea name=editBox cols=45 rows=3></textarea>" } else { document.all.editBox.parentElement.innerHTML="<input name=editBox size=45>" } Layer_edit.style.display='' var h=Layer_edit.offsetHeight var w=Layer_edit.offsetWidth if (oElement.parentElement.id!="")//tr { document.all.edit_id.value=oElement.parentElement.id2//找到需要修改的记录的ID } document.all.edit_columnName.value=oTable.rows[0].cells[oElement.cellIndex].innerText//取得需要修改的列名 document.all.cur_td.value="rows["+oElement.parentElement.rowIndex+"].cells["+oElement.cellIndex+"]" if (event.y>h)//先确定是在点击的上方还是下方 { document.all.Layer_edit.style.top =event.y-h+document.body.scrollTop//可以放在上方 document.all.zhishiUp.style.display="none" document.all.zhishiDown.style.display="" //document.all.zhishiDown.className.filter=""; } else//只能放在下方 { document.all.Layer_edit.style.top =event.y+document.body.scrollTop document.all.zhishiUp.style.display="" document.all.zhishiUp.style.filter="FlipV" document.all.zhishiDown.style.display="none" } //确定是在点击的左方还是右方 if (event.x+w<document.body.offsetWidth)//不会超出右边窗口 { document.all.Layer_edit.style.left=event.x-6+document.body.scrollLeft//可以放在上方 document.all.zhishiDown.style.filter="" document.all.td_b.align="" document.all.td_t.align="" } else//会超出右边窗口 { document.all.Layer_edit.style.left=event.x-w+6+document.body.scrollLeft document.all.zhishiUp.style.filter="FlipH FlipV" document.all.zhishiDown.style.filter="FlipH" document.all.td_b.align="right" document.all.td_t.align="right" } document.all.editBox.value=oElement.innerText.replace(" ",'')//取掉中文名 document.all.editBox.focus() } } } var cur_td var cur_tr function over_bg()// { var obj=event.srcElement while (obj.parentElement.id!="tr") { obj=obj.parentElement; if (obj.tagName=='BODY')return;//到最顶了 } try{ cur_td.bgColor='';cur_tr.bgColor='' }catch(err){} obj.bgColor="#E7E2CD"; obj.parentElement.bgColor='#F4F2E8' cur_td=obj; cur_tr=obj.parentElement; } </script> </body></html> <% sub save_td 'on error resume next dim tdName,td,rs,id,sql id=sql_id(request("edit_id")) tdName=sql_kill(request("edit_columnName")) td=request("editBox") set rs=server.CreateObject("adodb.recordset") sql="select top 1 "&tdName&" from "&tbName&" where "&idName&"="&id rs.open sql,conn,1,3 if rs.recordcount>0 then rs(tdName)=td rs.update rs.close end if if conn.errors.count>0 then response.Write("<script>alert('") for i=0 to conn.errors.count-1 response.Write("\r\r"&conn.errors.item(i).description) next response.write("\r\r共"&conn.errors.count&"个错误')</script>") response.End() end if %> <textarea id=result><%=td%> </textarea><!--注意:这里有一个中文空格--> <script> parent.document.all.oTable.<%=request("cur_td")%>.innerText=result.value </script> <% end sub sub openDB on error resume next strsql="driver={microsoft access driver (*.mdb)};DBQ="+server.mappath(request("db")) set conn=server.createobject("adodb.connection") conn.open strsql if err<>0 then response.Write("连接数据库失败!您可以试着<a href=../index.asp target=_parent>重新登陆</a>,如果问题依然存在,请联系管理员。") response.End() end if end sub sub create AddTable(tbName) AddColumn tbName,"ID","COUNTER(1,1) CONSTRAINT PK_TVIPLevel26 PRIMARY KEY"'从1开始,递增为1 AddColumn tbName,"userID","int"'用户 AddColumn tbName,"分组","VARCHAR"'类别 AddColumn tbName,"原表列名","VARCHAR"'VARCHAR不会有多余空格,用char就会 AddColumn tbName,"中文名","VARCHAR"' AddColumn tbName,"英文名","VARCHAR"' AddColumn tbName,"宽度","int"'列宽度 AddColumn tbName,"图标","VARCHAR"' AddColumn tbName,"显示方式","int"' AddColumn tbName,"是否显示","int"' AddColumn tbName,"列次序","int"'添加次序 AddColumn tbName,"数据检查","memo"'看录入的数据是否合法 AddColumn tbName,"单页控制","memo"' AddColumn tbName,"单页排序","int"' AddColumn tbName,"text_html","memo"'支持文件,html,图片格式 AddColumn tbName,"系统_用户","memo"' AddColumn tbName,"筛选","VARCHAR"' AddColumn tbName,"搜索","VARCHAR"' AddColumn tbName,"默认值","VARCHAR"' AddColumn tbName,"读写","VARCHAR"' '参考网上资料 'CHAR(size) 字节型 ' DATE 日期型 ' SMALLINT 整形 ' INTEGER 有的系统和SMALLINT相同,有的系统和LONG相同 ' LONG 长整型 ' NUMBER(SIZE) 浮点型 ' VARCHAR() TEXT型 ' BLOB 二进制大对象 '字符型(Text) 字符型(Character) 數值型( 短整型、長整型、單精度、雙精度) 數值型(Numeric) 貨幣型(Currency) 備注型(Memo) 日期時間型(date/Time) 日期型(Date) 邏輯型(Yes/No) 邏輯型(Logical) OLE 對象型(OLE Object) 通用型(General) '''''开始添加记录,记录条数就是被子管理表的列数 For Each MyTable In MyDB.Tables if MyTable.Name =replace(tbName,"_set","") then For Each MyField In MyTable.Columns AddRecord tbName,MyField.name'把列名作为记录添加到_set表中 Next end if Next response.write("<br><br><div align=center>创建成功</div>") end sub function get_width(s) dim i,lens,len_a lens=0 for i=1 to len(s) len_a=asc(mid(s,i,1)) if len_a>256 or len_a<0 then lens=lens+13'汉字点13像数 else lens=lens+7'字母占7,注意css中要用宋体,否则大小写会不一样 end if next get_width=lens end function function get_idName(tbName) on error resume next dim rs,sql sql = "SELECT top 1 * FROM [" & tbName & "] " Set rs = Conn.Execute(sql) if err = 0 then For i = 0 to rs.fields.count-1 if rs(i).Properties("ISAUTOINCREMENT") = True then get_idName=rs(i).name exit function end if next end if end function %>