<%
guidedisplay=1
copyrightend=1
%>

<!--#include file="admin_start.asp" -->
<!--#include file="edit/active_frame.asp" -->
<%
Session("FB_EM_1_ACC_c")=request.form("c")

function gettable()
   
	dim rsSchema
	set rsSchema=Conn.openSchema(20)
	rsSchema.movefirst
	do while not rsSchema.eof 
		if rsSchema("TABLE_TYPE")="TABLE" then 
			if rsSchema("DESCRIPTION")<>"" then 
			response.write "<option value='"&rsSchema("TABLE_NAME")&"'>"&rsSchema("DESCRIPTION")&"</option>"
			else
			response.write "<option value='"&rsSchema("TABLE_NAME")&"'>"&rsSchema("TABLE_NAME")&"</option>"
			end if
		end if
		rsSchema.movenext
	loop
	set rsSchema=nothing

end function
%>

<body style="background-color:#EBE9ED ;margin: 0px;" onmousemove="changew(2,-1)">
<form name=edit_sql target=admin_edit_sql method=post><input type=hidden name=c value=''><input type=hidden name=formname value=''><input type=hidden name=inputname value=''></form>
<form name='makesql' method="post"  target='_self'>
<table cellpadding="0" cellspacing="0"  border="0" id=label_show width="28%" height=100% align=left >
    <tr> 
      <td valign=top style='padding:0' colspan="10" bgcolor="#ffffff" >
		<table id="label_show_public" cellpadding="0" cellspacing="0"  border="0" width="100%" height=100% >
			<tr> 
			  <td valign=top style='padding:0' colspan="10" bgcolor="#ffffff" >
			<iframe id=f_label_show_public  style='border:solid #b0b0b0 0px' marginheight=0 marginwidth=0 frameborder=0  scrolling="no"  align=middle height=100% width=100% src='admin_edit_label_public.asp' ></iframe>
			  </td>
			</tr>
		</table>
      </td>
    </tr>
</table>

<table cellpadding="0" cellspacing="0"  border="0"  height=100% width="15" align=left>
    <tr> 
      <td align=right style="cursor:e-resize;" height="47%" width='50%'  background="images/bg_a.gif" onmouseup="changew(1,-1)"  onMousedown="changew(0,-1)"  ></td>
      <td align=right height="47%" width='50%'></td>
    </tr>
    <tr> 
      <td align=right  width='50%'  ><img src="images/d_0.gif" onMouseOver='changei(this)'; onMouseOut='changei(this)'; onMouseDown='changeii(this)'></td>
      <td align=right  width='50%'></td>
    </tr>
    <tr> 
      <td align=right style="cursor:e-resize;"  height="47%" width='50%'  background="images/bg_a.gif"  onmouseup="changew(1,-1)"  onMousedown="changew(0,-1)" ></td>
      <td align=right height="47%" width='50%'></td>
    </tr>
</table>

<table cellpadding="0" cellspacing="0"  border="0" width="68%"  id=sql_show>
    <tr> 
      <td  colspan=10  height=20>
	  &nbsp
	  </td>
    </tr>
    <tr> 
      <td align=right height="21" width='1%'><img src="images/bg_di_l.gif"></td>
      <td  valign=bottom background="images/bg_di_m.gif" align=center><nobr> 数据库查询 </nobr></td>
      <td align=left width='1%' ><img src="images/bg_di_r.gif"></td>
      <td style='border-bottom:1px solid #808080;' width=90% >
	  &nbsp
	  </td>
    </tr>
    <tr> 
      <td style='border:1px solid #808080; border-top:0px;padding:5' colspan="10" background="images/bg_di.gif" >
	  <table cellpadding="3" cellspacing="0" >
		  <tr> 
			  <td width=20% align=right > 从数据表 </td >
			  <td width=80% align=left style='padding-left:5px'> 
			   <select name="table_get"  id="table_get"  style='width:300px; border:1px solid #f7f7f7' onchange="getfield()">
			   <option value="" selected >请选择数据表</option>
			   <%gettable()%>
			   </select> 中
			  </td>
		  </tr>
		  <tr> 
			  <td width=20% align=right valign=top> 取出字段 </td >
			  <td width=80% align=left style='padding-left:5px'> 
			   <iframe  style='border:solid #b0b0b0 1px' marginheight=0 marginwidth=0 frameborder=0 scrolling=no align=middle height=156 width=300 src='about:blank' id='field_get'></iframe>
			   <input name="field_get"  type=hidden >
			  </td>
		  </tr>
		  <tr> 
			  <td width=20% align=right > 取出前 </td >
			  <td width=80% align=left style='padding-left:5px'>
			   <input name="num_get"  id="num_get"   value=10  size=48 ONSELECT="storeCaret(this);" ONCLICK="storeCaret(this);" ONKEYUP="storeCaret(this);">
			    条记录
			  </td>
		  </tr>
		  <tr> 
			  <td width=20% align=right> 其中字段 </td >
			  <td width=80% align=left style='padding-left:5px'> 
			   <iframe  style='border:solid #b0b0b0 1px' marginheight=0 marginwidth=0 frameborder=0 scrolling=no align=middle height=21 width=300 src='about:blank' id='field_verify'></iframe>
			   <input name="field_verify"  type=hidden >
			  </td>
		  </tr>
		  <tr> 
			  <td width=20% align=right valign=top> 满足条件 </td >
			  <td width=80% align=left valign="baseline" style='padding-left:5px'> 
	          <textarea name="method_verify" cols="40" rows="5" id="method_verify" style="font:Arial;font-size:13px" ONSELECT="storeCaret(this);" ONCLICK="storeCaret(this);" ONKEYUP="storeCaret(this);">=</textarea>
			<a title='点击在新窗口编辑sql语句！' href="javascript:openedit_sql('makesql','method_verify');" >
			<img border=0 src="Images/sql.gif"  align="top" alt='点击在新窗口编辑sql语句！'>
			</a>
			  </td>
		  </tr>
		  <tr> 
			  <td width=20% align=right > 按照字段 </td >
			  <td width=80% align=left style='padding-left:5px'> 
			   <iframe  style='border:solid #b0b0b0 1px' marginheight=0 marginwidth=0 frameborder=0 scrolling=no align=top height=21 width=300 src='about:blank' id='field_order'></iframe>
			   <input name="field_order"  type=hidden >
			    的
			   <select name="action_order"  id="action_order" style='border:1px solid #f7f7f7'>
			   <option value="desc" >降序</option>
			   <option value="" >升序</option>
			   </select> 排列
			  </td>
		  </tr>
		  <tr> 
			  <td width=20% align=right valign=top colspan=2 > <hr align="center" width="98%" size="1">		      </td >
		  </tr>
		  <tr> 
			  <td width=20% align=right valign=top > 	  
			  <input type=button value='生成！' align=left onclick='makes()'><br>
			  <input type="button" value="提交！" onclick='send()'><br>
			  <input type="reset" value="重置！">
		    </td >
			  <td width=80% align=left style='padding-left:5px'> 
	          <textarea name="c" cols="58" rows="12" id="content" style="font:Arial;font-size:13px" ONSELECT="storeCaret(this);" ONCLICK="storeCaret(this);" ONKEYUP="storeCaret(this);"><%=request("c")%></textarea>
			  </td>
		  </tr>
	  </table>
      </td>
    </tr>
</table>

<input name=target_window type=hidden>
<input name=opener_window type=hidden value=<%=request("opener_window")%>>
</form>
<script language="javascript" >
    var i_n=0;
	var ff=new Array("label_show_public")
	var h_ff=new Array(document.getElementById("label_show_public").scrollHeight)

	function InsertLabel(s){
	s=CutHtml(s)
	if(object_now)
	insertAtCaret (object_now, s)
    }
</script>
<script language="vbscript" >
	function CutHtml(str) 
		Dim re 
		Set re=new RegExp 
		re.IgnoreCase =True 
		re.Global=true 
		re.Pattern="<([^<>]*?)>" 
	
		Do while re.Test(str) 
			str=re.Replace(str,"") 
		Loop 
		set re=Nothing 
	
		CutHtml=str
	
	End Function
</script>
<script language="javascript" >
	
	function getfield(){
	document.getElementById("field_get").src='admin_edit_sql_field.asp?table='+document.makesql.table_get.value+'&field_get=field_get&type=0';
	document.getElementById("field_order").src='admin_edit_sql_field.asp?table='+document.makesql.table_get.value+'&field_get=field_order&type=1';
	document.getElementById("field_verify").src='admin_edit_sql_field.asp?table='+document.makesql.table_get.value+'&field_get=field_verify&type=1';
    document.getElementById("field_get").style.border='0px'
    document.getElementById("field_order").style.border='0px'
    document.getElementById("field_verify").style.border='0px'
	}
	getfield()
	function send(){
	    //var dd;
		//alert(makesql.source.value);
		//makes();
		opener.document.<%=request("formname")%>.<%=request("inputname")%>.value=document.makesql.c.value;
		opener.focus();
		opener.document.<%=request("formname")%>.<%=request("inputname")%>.focus();
		window.close();
	}
	function makes(){
	    //var dd;
		//alert(makesql.source.value);
		
		var t_g=document.makesql.table_get.value;
		var f_g=document.makesql.field_get.value;
		var n_g=document.makesql.num_get.value;
		var f_v=document.makesql.field_verify.value;
		var m_v=document.makesql.method_verify.value;
		var f_o=document.makesql.field_order.value;
		var a_o=document.makesql.action_order.value;
		
		if (t_g=='') {
		alert('请选择数据表！');
		return false;
		}
		
		if (f_v!='' && m_v=='') {
		alert('请输入字段的满足条件！');
		return false;
		}
		
		/*if (f_o=='' && a_o!='') {
		alert('请选择需要排序的字段！');
		return false;
		}*/
		
		var cc;
		cc="SELECT ";
		if (n_g!='')cc=cc+" TOP "+n_g;
		if (f_g!='')cc=cc+" "+f_g; else  cc=cc+" * ";
		if (t_g!='')cc=cc+"\n FROM "+t_g; else alert('请选择数据表');
		if (f_v!='' && m_v!='')cc=cc+"\n WHERE "+ f_v + m_v ;
		if (f_v=='' && m_v!='')cc=cc+"\n WHERE "+ m_v ;
		
		if (f_o!='')cc=cc+"\n ORDER BY "+ f_o + " "+ a_o ;
		
		document.makesql.c.value=cc;
		//alert(cc)
	}
	var key_d=0
	var x_m_o=document.getElementById("label_show").scrollWidth
	function changew(nn,xx){
	
	    if(xx==-1)xx=event.x
		
		if (nn==0&&key_d==0){
			
			key_d=1
			x_m_o=xx-document.getElementById("label_show").scrollWidth
			
		}else if (nn==1&&key_d==1){
		
			key_d=0
		
		}
		else if (nn==2&&key_d==1){
		
			var x_m=xx
			var x_n=document.getElementById("label_show").scrollWidth
			document.getElementById("label_show").style.width=x_m-x_m_o;
			document.getElementById("sql_show").style.width=document.body.scrollWidth-document.getElementById("label_show").scrollWidth-15-20;
		
		}
	}
</script>
</body>
<!--#include file="admin_end.asp" -->