<%@ Page Language="C#" ContentType="text/html" EnableViewstate="false"%>
<%@ Import Namespace="System.Data" %>
<%@ Import NameSpace="System.Data.OleDb" %>
<%@ Import NameSpace="System.Text.RegularExpressions" %>

<script runat="server">
void mSearch(object sender,EventArgs e){
mGetResult();
}
void mGetResult(){
string strDb=Server.MapPath("db-access/chengyu.mdb");
//Response.Write(strDb);
string strAuth="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=";
OleDbConnection db=new OleDbConnection(strAuth+strDb);

string strKey=Regex.Replace(tbKey.Text,"[=\\s\"\'0-9!,.。，~@#￥……&*(){}`+《》<>/]","",RegexOptions.IgnoreCase);//防止SQL注入

strKey=strKey.Trim();

string strSql="SELECT TOP 200 * FROM LouHome WHERE ChengYu LIKE '%"+strKey+"%' OR DianGu LIKE '%"+strKey+"%' OR ChuChu LIKE '%"+strKey+"%' OR LiZi LIKE '%"+strKey+"%' OR SPingYin='"+strKey+"'"; 

OleDbCommand cmd=new OleDbCommand(strSql,db);
try{
db.Open();
dl.DataSource=cmd.ExecuteReader();
//dg.DataBind();
dl.DataBind();
db.Close();
cmd.Dispose();
db.Dispose();
labCount.Text=dl.Items.Count.ToString();
if(dl.Items.Count==0)
labError.Text="没有找到任何相关单词，请缩短输入再查询！";
}
catch(Exception ee){
labError.Text=ee.ToString();
}
}
string strGet(string strInput){
string strResult=strInput;
string strRex="\\s{2,}";
strResult=Regex.Replace(strResult,strRex,"<br>", RegexOptions.IgnoreCase);
strResult=strResult.Replace("＇",@"""").Replace("｀",@"""");
//strResult=strResult.Replace(tbKey.Text.Trim(),"<font style='background:yellow;color:red'>"+tbKey.Text.Trim()+"</font>");
return strResult;
}
string strTitle(string strInput){
string strResult=strInput;
string strRex=tbKey.Text.Trim();
strResult=Regex.Replace(strResult,strRex,"<FONT STYLE='background:yellow;color:red'>"+strRex+"</FONT>", RegexOptions.IgnoreCase);

return strResult;
}

string strTitleUpper(string strInput){
string strResult=strInput;
string strRex=tbKey.Text.Trim();
strResult=Regex.Replace(strResult,strRex,"<FONT STYLE='background:yellow;color:red'>"+strRex+"</FONT>", RegexOptions.IgnoreCase);

return strResult.ToUpper();
}

string strTitle(string strInput,string strRex){
string strResult=strInput;

strResult=Regex.Replace(strResult,strRex,"<FONT STYLE='background:lightgreen;color:red'>"+strRex+"</FONT>", RegexOptions.IgnoreCase);

return strResult;
}

string fmTitle(string strInput){
string strResult;

strResult="<FONT STYLE='background:lightyellow;color:red'>"+strInput+"</FONT>";

return strResult;
}

void Page_Load(){
if(!Page.IsPostBack){
tbKey.Attributes.Add("onkeydown", "EnterE(this)");
;
}
tbKey.Focus();
}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>楼房网-成语字典</title>

<style type="text/css">
<!--
.STYLE1 {color: #016392}
HTML{font-size:14px;
}
-->
</style>
<script type="text/javascript">
function EnterE()

{

   if(event.keycode==13)

   {
       event.returnValue=false;
       event.cancel=true;
       document.getElementById("btn").click();
   }

}

</script>

</head>
<body><form runat="server" style="width:90%; margin:0px auto;" DefaultButton="btn">
<img src="images/logo.gif" alt="楼房网" width="82" height="29" /><br style="height:8px;font-size:0px"/><br style="height:8px"/>
&nbsp;成 语：
<asp:TextBox ID="tbKey" runat="server" Width="160px" AutoPostBack="false" MaxLength="8"/>
<asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="tbKey" ErrorMessage="*" Display="Dynamic"/>
<asp:Button ID="btn" runat="server" Text="查找" OnClick="mSearch"/><font color="#CCCCCC">可以输入成语，拼音，首字母拼音，成语里的某个字等</font>
<br style="height:8px"/><br style="height:8px"/>
<div style="background:#75CBFF; color:#666666; width:47%; height:20px; padding-top:4px; float:left; text-align:left; vertical-align:middle">&nbsp;&nbsp;将<a href="javascript:window.external.AddFavorite('http://www.louhome.com', '楼房网')">楼房网</a>加入收藏</div>
<div style="background:#75CBFF; color:#666666; width:50%; height:20px; padding-top:4px; float:left; text-align:right">共有<asp:Label ID="labCount" runat="server" Text="0" ForeColor="#FF0000"/>个相关结果&nbsp;&nbsp;</div><br style="height:8px"/>
<asp:Label ID="labError" runat="server"/>
<br style="height:8px"/>
<asp:DataList ID="dl" runat="server" Width="98%">
<itemtemplate>
<div style="background:#016392; color:#FFFFFF; width:80px;"><i>&middot;结果 <%#(Container.ItemIndex+1).ToString()%></i></div>
<div style="width:99%; border:1px solid #016392;"><div style="background:#E2E3D7; font-weight:bold; padding:2px;">
<asp:Label ID="labChenyu" runat="server" Text=<%#strTitle(DataBinder.Eval(Container.DataItem,"ChengYu").ToString()) %> /></div>
<div style=" padding:10px;">
<table border="0" cellpadding="5px" cellpadding="2px">
<tr>
<td valign="top">
<div style="background:#FFFF99; color:#000099; font-weight:bold; width:68px; text-align:center">拼 音</div>
</td>
<td valign="top">
<div style="padding-left:5px"><asp:Label ID="labPY" runat="server" Text=<%#strTitle(DataBinder.Eval(Container.DataItem,"PingYin").ToString())%> />&nbsp;(<asp:Label ID="labSPY" runat="server" Text=<%#strTitleUpper(DataBinder.Eval(Container.DataItem,"SPingYin").ToString().ToUpper())%> />)</div>
</td>
</tr>
<tr>
<td valign="top">
<div style="background:#FFFF99; color:#000099; font-weight:bold; width:68px; text-align:center">释 义</div>
</td>
<td valign="top">
<div style="padding-left:5px"><asp:Label ID="labContent" runat="server" Text=<%#strTitle(DataBinder.Eval(Container.DataItem,"DianGu").ToString())%> /></div>
</td>
</tr>
<tr>
<td valign="top"><div style="background:#FFFF99; color:#000099; font-weight:bold; width:68px; text-align:center">考 源</div>
</td><td valign="top">
<div style="padding-left:5px"><asp:Label ID="labDG" runat="server" Text=<%#strTitle(DataBinder.Eval(Container.DataItem,"ChuChu").ToString(),DataBinder.Eval(Container.DataItem,"ChengYu").ToString())%> /></div>
</td></tr>
<tr>
<td valign="top">
<div style="background:#FFFF99; color:#000099; font-weight:bold; width:68px; text-align:center">用 法</div>
</td><td valign="top">
<div style="padding-left:5px;"><asp:Label ID="labLZ" runat="server" Text=<%#strTitle(DataBinder.Eval(Container.DataItem,"LiZi").ToString().Replace("～",fmTitle(DataBinder.Eval(Container.DataItem,"ChengYu").ToString())))%> /></div>
</td></tr>
</table>
</div></div>
<br />
</itemtemplate>
</asp:DataList>
 <div style="background:#E1FAFF; width:97%; text-align:center;"><a href="http://www.louhome.com" target="_blank">楼房网</a> 版权所有 LouHome.com All right Reserved. Copyright 2009-2012&copy; 粤ICP备09048681</div>

</form>
</body>
</html>
