<!--
whilvydy 新闻发布系统
-->

<%@ page contentType="text/html; charset=GB2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*" %> 
<%@ page import="java.util.*" %>

<%@ include file="function/parameter.jsp" %>

<jsp:useBean id="NewsBean" scope="page" class="net.jspcn.db.DbConnect" />
<jsp:useBean id='StrTool' scope='page' class='net.jspcn.tool.StringProcess' />

<%
int intPageCount,intPageSize,intCurrentPage,intRowCount,i;
intPageSize = param[3];

String strSearchWord;
if(request.getParameter("strSearchWord")==null||"".equals(request.getParameter("strSearchWord")))
	strSearchWord = " ";
else
	strSearchWord = request.getParameter("strSearchWord");

String strSearchType;
if(request.getParameter("strSearchType")==null||"".equals(request.getParameter("strSearchType")))
	strSearchType = "titleSearch";
else
	strSearchType = request.getParameter("strSearchType");

ResultSet rs;
String sql;

NewsBean.openConnection();
%>

<%@ include file = "function/header1.jsp" %>
<%=strSearchWord%>Search ...
<%@ include file = "function/header3.jsp" %>
<br><span class=typename><%=strSearchWord%>&nbsp;Search ...</span><br><br>
<table width="600"  border="1" cellspacing="0" cellpadding="0"  bordercolor="#00CC66"  borderColorDark="#FFFFFF" borderColorLight="#00CC66">
      <tr> 
    <td width="7%"> 
      <div align="center">编号</div>
    </td>
    <td width="35%"> 
      <div align="center">新闻标题</div>
    </td>
    <td width="15%"> 
      <div align="center">新闻作者</div>
    </td>
    <td width="15%"> 
      <div align="center">新闻来源</div>
    </td>
    <td width="10%"> 
      <div align="center">访问次数</div>
    </td>
    <td width="18%"> 
      <div align="center">新闻时间</div>
    </td>
   </tr>
<%
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(" ".equals(strSearchWord))
{
		sql = "select * from "+news_table+" order by news_id desc";
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
else if("keywordSearch".equals(strSearchType))
{
	sql = "select a.news_id,news_title,news_author,news_source,news_time,news_hits from "+news_table+" a,"+keyword_table+" b where keyword_value like '%"+strSearchWord+"%' and a.news_id = b.news_id  order by a.news_id desc";
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
else if("titleSearch".equals(strSearchType))
{
		sql = "select * from "+news_table+" where news_title like '%"+strSearchWord+"%'  order by news_id desc";
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
else if("contentSearch".equals(strSearchType))
{
	sql = "select a.news_id,news_title,news_author,news_source,news_time,news_hits from "+news_table+" a,"+newsdetail_table+" b where newsdetail_content like '%"+strSearchWord+"%' and a.news_id = b.news_id  order by a.news_id desc";
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
else
{
	sql = "select * from "+news_table+" order by news_id desc";
}





		if(request.getParameter("page")==""||request.getParameter("page")==null)
			intCurrentPage = 1;
		else
		{
			intCurrentPage = Integer.parseInt(request.getParameter("page"));
			if(intCurrentPage<1) intCurrentPage = 1;
		}
	
		
		rs = NewsBean.executeQuery(sql);
		rs.last();
		intRowCount = rs.getRow();
		intPageCount = (intRowCount+intPageSize-1)/intPageSize;
		if(intCurrentPage>intPageCount) intCurrentPage=intPageCount;		//对当前页数的控制
		
		if(intPageCount>0)
		{	
			rs.absolute((intCurrentPage-1)*intPageSize+1);	
			//for(color=0,i=0;i<intPageSize&&!rs.isAfterLast();color++,i++)		
			i=0;
	
			do {
			%>
  			<tr> 
    			<td width="7%"> 
      			<div align="center"><%=rs.getString("news_id")%></div>
    			</td>
    			<td width="35%"> 
      			<div align="center"><a href="newsdetail.jsp?news_id=<%=rs.getString("news_id")%>" target=_blank><%=rs.getString("news_title")%></a></div>
    			</td>
    			<td width="15%"> 
      			<div align="center"><%=rs.getString("news_author")%></div>
    			</td>
    			<td width="15%"> 
      			<div align="center"><%=rs.getString("news_source")%>&nbsp;</div>
    			</td>
    			<td width="10%"> 
      			<div align="center"><%=rs.getString("news_hits")%></div>
    			</td>
    			<td width="18%"> 
      			<div align="center"><%=rs.getString("news_time").substring(0,10)%></div>
    			</td>
   			</tr>
			<%	
				i++;
			}
			while(rs.next()&&i<intPageSize);
		}
		%>
		</table>
		<br>
		<%
		if(intCurrentPage == 1) { 
			%> 首页 前页 <% }
		else

			out.println("<a href='search.jsp?page=1&strSearchType="+strSearchType+"&strSearchWord="+strSearchWord+"'>首页</a> <a href='search.jsp?page="+(intCurrentPage-1)+"&strSearchType="+strSearchType+"&strSearchWord="+strSearchWord+"'>前页</a> ");
	
		if(intCurrentPage==intPageCount) {
			%>后页 末页<% }
		else
			out.println("<a href='search.jsp?page="+(intCurrentPage+1)+"&strSearchType="+strSearchType+"&strSearchWord="+strSearchWord+"'>后页</a> <a href='search.jsp?page="+intPageCount+"&strSearchType="+strSearchType+"&strSearchWord="+strSearchWord+"'>末页</a> ");



  NewsBean.close();
%>

<%@ include file = "function/feeder.jsp" %>