package com.luo.ssherp.action;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.luo.ssherp.model.Member;
import com.luo.ssherp.model.Member;
import com.luo.ssherp.service.IMemberService;
import com.luo.ssherp.util.Page;
import com.luo.ssherp.util.PageUtil;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
@Component("memberAction")
@Scope("prototype")
public class MemberAction extends ActionSupport implements ModelDriven<Member>{
private Member member;
private IMemberService memberService;
private int currentPage;
public int getCurrentPage(){
return currentPage;
}
public void setCurrentPage(int currentPage){
this.currentPage=currentPage;
}
public IMemberService getMemberService(){
return memberService;
}
@Resource(name="memberService")
public void setMemberService(IMemberService memberService){
this.memberService=memberService;
}
@Override
public Member getModel(){
if(member==null){
return member=new Member();
}
return member;
}
public String list()throws Exception{
Page page=new Page();
page.setEveryPage(15);
page.setCurrentPage(currentPage);
if(memberService.queryMemberCount()==0){
return "noResult";
}
page=PageUtil.createPage(page.getEveryPage(),memberService.queryMemberCount(),page.getCurrentPage());
List<Member> memberList=memberService.queryMember(page);
HttpSession httpSession=ServletActionContext.getRequest().getSession();
httpSession.setAttribute("memberPage",page);
if(memberList.size()==0){
httpSession.setAttribute("memberFlag","noResult");
}else{
httpSession.setAttribute("memberFlag","result");
httpSession.setAttribute("memberScanList",memberList);
}
httpSession.setAttribute("memberScanList",memberList);
return "list";
}
public String scoreList()throws Exception{
Page page=new Page();
page.setEveryPage(15);
page.setCurrentPage(currentPage);
if(memberService.queryMemberCount()==0){
return "noResult";
}
page=PageUtil.createPage(page.getEveryPage(),memberService.queryMemberCount(),page.getCurrentPage());
List<Member> memberList=memberService.queryMember(page);
HttpSession httpSession=ServletActionContext.getRequest().getSession();
httpSession.setAttribute("memberPage",page);
if(memberList.size()==0){
httpSession.setAttribute("memberFlag","noResult");
}else{
httpSession.setAttribute("memberFlag","result");
httpSession.setAttribute("memberScanList",memberList);
}
httpSession.setAttribute("memberScanList",memberList);
return "scoreList";
}
public String add() throws Exception{
boolean bool=false;
bool=memberService.save(member);
if(bool){
return SUCCESS;
}
else {
return "fail";
}
}
public String updateQuery()throws Exception{
String strQuery="from Member mem where mem.id='"+member.getId()+"'";
Member mem=memberService.query(strQuery);
if(mem==null){
return "noResult";
}else{
HttpSession httpSession=ServletActionContext.getRequest().getSession();
httpSession.setAttribute("updateMember",mem);
return "update";
}
}
public String query() throws Exception{
String strQuery="from Member as mem where mem.id= '"+member.getId()+"'";
Member mem=memberService.query(strQuery );
if(mem==null){
return "noResult";
}
HttpSession session=ServletActionContext.getRequest().getSession();
session.setAttribute("memberQuery",mem);
return "showQueryResult";
}
public void ajaxQuery()throws Exception{
String strQuery="from Member mem where mem.id='"+member.getId()+"'";
Member mem=memberService.query(strQuery);
PrintWriter out=ServletActionContext.getResponse().getWriter();
if(mem!=null){
out.print("true");
}else{
out.print("false");
}
}
public String queryScore()throws Exception{
String strQuery="from Member mem where mem.id='"+member.getId()+"'";
Member mem=memberService.query(strQuery);
if(mem!=null){
HttpSession session=ServletActionContext.getRequest().getSession();
session.setAttribute("queryScore",mem);
return "queryScore";
}
return "noResult";
}
public String queryTimes()throws Exception{
String strQuery="from Member mem where mem.id='"+member.getId()+"'";
Member mem=memberService.query(strQuery);
if(mem!=null){
HttpSession session=ServletActionContext.getRequest().getSession();
session.setAttribute("queryTimes",mem);
return "queryTimes";
}
return "noResult";
}
//会员注销
public String delete() throws Exception{
String strDelete="delete from Member mem where mem.id='"+member.getId()+"'";
int i=memberService.delete(strDelete);
if(i==0){
return "noResult";
}
return SUCCESS;
}
public String lost()throws Exception{
boolean bool=memberService.lost(member);
if(bool==true){
return SUCCESS;
}else{
return "noResult";
}
}
public String active()throws Exception{
boolean bool=memberService.active(member);
if(bool==true){
return SUCCESS;
}else{
return "noResult";
}
}
public String update()throws Exception{
int i=memberService.update(member);
if(i!=0){
return SUCCESS;
}
return "fail";
}
}