?? admincardsearchaction.java
字號:
/*
* 作者:管磊
* 功能:會員卡的多種條件查詢
* 時間: 12-26-2007
*/
package com.mole.struts.action;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.mole.struts.bean.Page;
import com.mole.struts.dao.MerchantCardDAO;
/**
* MyEclipse Struts Creation date: 12-26-2007
*
* XDoclet definition:
*
* @struts.action validate="true"
*/
public class AdminCardSearchAction extends Action {
/*
* Generated Methods
*/
MerchantCardDAO dao;
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String citylist = request.getParameter("citylist");
String endtime = request.getParameter("endtime");
String starttime = request.getParameter("starttime");
String scid = request.getParameter("scid");
if (dao == null)
dao = new MerchantCardDAO();
String where = null;
if (citylist != null && !"".equals(citylist))// 如果沒有城市限制
where = "cityid='" + citylist + "'";
if (scid != null && !"".equals(scid))// 沒有商家限制
{
if (where != null)
where = where + "and storeid=" + scid;
else
where = " storeid=" + scid;
}
if (starttime != null && !"".equals(starttime)
&& (endtime == null || "".equals(endtime)))// 有發行開始時間限制
{
if (where == null) {
where = " grantdate>" + starttime;
} else
where = where + " and grantdate>'" + starttime + "'";
}
if (endtime != null && !"".equals(endtime)
&& (starttime == null || "".equals(starttime)))// 有截至時間限制的
{
if (where == null) {
where = " grantdate<" + endtime;
} else
where = where + " and grantdate<'" + endtime + "'";
}
if (endtime != null && starttime != null)// 有兩個時間限制都有的。
{
if (where == null)
where = " grantdate<'" + endtime + "' and grantdate>'"
+ starttime + "'";
else
where = where + " and grantdate<'" + endtime
+ "' and grantdate>'" + starttime + "'";
}
if (where != null)
where = " where " + where;
ArrayList al = null;
// a.[ID],a.[CustomerID],a.[OriginID],a.[State],CONVERT(char(20),a.[GrantDate],120)
String sql = "SELECT a.[cardID],a.[ID],a.[OriginID],a.[customerState],CONVERT(char(20),a.[GrantDate],120) "
+ "FROM v_customercard a " + where;
// 分頁查詢的操作
Page page = new Page();
String action = request.getParameter("action");
int pageSize = (request.getParameter("pageSizeSelect") == null ? 10
: Integer.parseInt(request.getParameter("pageSizeSelect")));
int currentPage = (request.getParameter("page") == null ? 1 : Integer
.parseInt(request.getParameter("page")));
if (null == action) {
int count = dao.getPageInfoByWhere(where);
page.setPageSize(pageSize);
page.setRecordCount(count);
page.setPageCount((count + pageSize - 1) / pageSize);
page.setCurrentPage(currentPage);
try {
al = dao.getCards(pageSize, currentPage, where);// DAO操作,查詢數據庫中的卡的信息
request.setAttribute("Page", page);
} catch (Exception e) {
e.printStackTrace();
HttpSession session = request.getSession();
session.setAttribute("title", "錯誤信息");
session.setAttribute("message", "用戶名或密碼錯誤,請重新登陸!");
session.setAttribute("returnUrl", "show.do?action=goLogin");
return mapping.findForward("goMessage");
}
}
request.setAttribute("MerchantCardView", al);// 傳到表現層的卡的集合
return new ActionForward("/adminCardsView.jsp");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -