📄 replaceenginelogin.java
字号:
import java.io.*;
import java.text.*;
import java.util.*;
import java.sql.*;
public class ReplaceEngineLogin extends ReplaceEngine
{
int nPage = 0;
int nAllPage=1;
String name;
public void setPage(int nP ){
nPage = nP;
}
public boolean replace(TemplateList tempList,
Person person,HtmlOut servlet )
{
//get all page now;
nAllPage=1;
name=person.getName();
DBOperater DB = new DBOperater ("userchannel");
ResultSet rs = DB.executeQuery ("select pagenum from person where username = '"
+CommonMethods.DealWithSQLParameter (person.getName ())+"'");
if(rs!=null){
try{
if( rs.next () )
nAllPage = rs.getInt (1);
}
catch(Exception e){
}
}
DB.close ();
setTemplateList(tempList);
setHtmlOuter (servlet);
setPerson(person);
SingleTemplate templateRoot;
templateRoot= tempList.searchTemplate ("ROOT");
if( templateRoot==null ){
return false;
}
int i;
for(i=0;i<templateRoot.getKeyNum();i++)
{
htmlOut.addString(templateRoot.getStringAt(i));
if( getKeyString( templateRoot.getKeyAt(i) )==false )
continue;
}
htmlOut.addString(templateRoot.getEndString());
return true;
}
public boolean getKeyString( String keyword )
{
if(keyword.compareTo("cgi-path")==0){
htmlOut.addString(CommonMethods.sHostNameCGI);
}
if(keyword.compareTo("username")==0){
htmlOut.addString ( person.getName () );
return true;
}
if(keyword.compareTo("userpass")==0){
htmlOut.addString ( person.getPassword () );
return true;
}
if(keyword.compareTo("page")==0){
htmlOut.addString ( Integer.toString (nPage) );
return true;
}
if(keyword.compareTo("allpage")==0){
//out put page link;
for( int i=0;i<nAllPage;i++ ){
if(i!= nPage)
htmlOut.addString ("<a href=Login?p="+i+"> 第"+(i+1)+"页 </a>");
else
htmlOut.addString (" 第"+(i+1)+"页 ");
}
htmlOut.addString ("<a href=ChangeUserChannel?p="+nAllPage+"> 增加页</a>");
return true;
}
if(keyword.compareTo("彩票")==0){
DBOperater DB = new DBOperater ("userchannel");
String sQr = "select * from user_cp where username='"+name+"'";
ResultSet rs=DB.executeQuery(sQr);
try{
if( rs.next () ){
htmlOut.addString( "取消彩票信息" ) ;
}else{
htmlOut.addString( "订阅彩票信息" ) ;
}
DB.close();
}catch(Exception e){
}
}
if(keyword.compareTo("频道左")==0)
{
//find user's all channel ;
DBOperater DB = new DBOperater ("userchannel");
String queryString;
queryString = "select channelid from userchannel where username='"
+ CommonMethods.DealWithSQLParameter (person.getName())
+ "' and pagenumber=" +nPage
+" and type = '1'"
+" ORDER BY userchannel.orderid";
ResultSet rs;
try {
rs = DB.executeQuery(queryString);
if( rs!=null ){
while(rs.next())
{
//for each channel , make channel;
String sChannel = rs.getString("channelid");
Channel userChannel=CommonMethods.FindChannel(sChannel);
if( userChannel==null ){
continue;
}
userChannel.makeChannel(person,tempList,htmlOut);
//userChannel.makeChannelContents (person,tempList,htmlOut);
}
}
}catch(Exception ex) {
System.err.println("SQLException: " + ex.getMessage());
htmlOut.addString( "SQLException" ) ;
DB.close();
return false;
}
DB.close();
}
if(keyword.compareTo("频道右")==0)
{
//find user's all channel ;
DBOperater DB = new DBOperater ("userchannel");
String queryString;
queryString = "select channelid from userchannel where username='"
+ CommonMethods.DealWithSQLParameter (person.getName()) + "' and pagenumber=" +nPage
+" and type = '2'"
+" ORDER BY userchannel.orderid";
ResultSet rs;
try {
rs = DB.executeQuery(queryString);
if(rs!=null){
while(rs.next())
{
//for each channel , make channel;
String sChannel = rs.getString("channelid");
Channel userChannel=CommonMethods.FindChannel(sChannel);
if( userChannel==null ){
continue;
}
userChannel.makeChannel(person,tempList,htmlOut);
//userChannel.makeChannelContents (person,tempList,htmlOut);
}
}
}catch(Exception ex) {
System.err.println("SQLException: " + ex.getMessage());
htmlOut.addString( "SQLException" ) ;
DB.close();
return false;
}
DB.close();
}
return true;
}
public boolean replaceMakeFirst(TemplateList tempList,
Person person,HtmlOut servlet )
{
//get all page now;
nAllPage=1;
setTemplateList(tempList);
setHtmlOuter (servlet);
setPerson(person);
SingleTemplate templateRoot;
templateRoot= tempList.searchTemplate ("ROOT");
if( templateRoot==null ){
return false;
}
int i;
for(i=0;i<templateRoot.getKeyNum();i++)
{
htmlOut.addString(templateRoot.getStringAt(i));
if( getKeyString( templateRoot.getKeyAt(i) )==false )
continue;
}
htmlOut.addString(templateRoot.getEndString());
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -