content: package com.cy.action;
  
  import java.util.List;
  import java.util.Map;
  
  import javax.annotation.Resource;
  
  import org.apache.struts2.interceptor.RequestAware;
  import org.apache.struts2.interceptor.SessionAware;
  
  import com.cy.entity.Account;
  import com.cy.entity.Admin;
  import com.cy.entity.Personinfo;
  import com.cy.entity.Status;
  import com.cy.service.interfaces.PersoninfoServiceInter;
  import com.cy.service.interfaces.UserServiceInter;
  import com.opensymphony.xwork2.ActionSupport;
  
  public class AdminAction extends ActionSupport implements RequestAware,SessionAware {
  
  	//ʹResourceעעUserServiceInterPersoninfoServiceInterԣʡȥset
  	@Resource private UserServiceInter userServiceInter;
  	@Resource private PersoninfoServiceInter personinfoServiceInter; 
  	Map<String, Object> request;
  	Map<String, Object> session;
  	public void setRequest(Map<String, Object> request) {
  		this.request = request;
  	}
  	public void setSession(Map<String, Object> session) {
  		this.session = session;
  	}
  	//AdminڷװԱ¼ҳ
  	private Admin admin;
  	public Admin getAdmin() {
  		return admin;
  	}
  	public void setAdmin(Admin admin) {
  		this.admin = admin;
  	}
  	//statuslistUsers()ʹ
  	private Status status;
  	public Status getStatus() {
  		return status;
  	}
  	public void setStatus(Status status) {
  		this.status = status;
  	}
  	//personinfosearch()ʹ
  	private Personinfo personinfo;
  	public Personinfo getPersoninfo() {
  		return personinfo;
  	}
  	public void setPersoninfo(Personinfo personinfo) {
  		this.personinfo = personinfo;
  	}
  	
  	private int id;
  	public int getId() {
  		return id;
  	}
  	public void setId(int id) {
  		this.id = id;
  	}
  	
  	private Account account;
  	public Account getAccount() {
  		return account;
  	}
  	public void setAccount(Account account) {
  		this.account = account;
  	}
  	//Ե¼ҳ֤ûǷȷ
  	public void validateLogin() {
  		Admin a = userServiceInter.getAdmin(admin.getUsername());
  		if(a == null) {
  			this.addFieldError("username", "ûڣ");
  		} else {
  			if(!admin.getPassword().equals(a.getPassword())) {
  				this.addFieldError("password", "벻ȷ");
  			}
  		}
  		admin = a;
  	}
  	//¼
  	public String login() {
  		if(admin != null) {
  			session.put("admin", admin);
  			return "success";
  		}
  		return "login";
  	}
  	
  	//Աѯ˻
  	public String listUsers() {
  		//System.out.println(""+status.getId());
  		List users = personinfoServiceInter.searchPersoninfo(status);
  		request.put("users", users);
  		return "users";
  	}
  	
  	//ʵѯ˻
  	public String search() {
  		List users = personinfoServiceInter.searchPersoninfo(personinfo);
  		request.put("users", users);
  		return "users";
  	}
  	
  	//˻
  	public String enabled() {
  		userServiceInter.enabled(id);
  		return "list";
  	}
  	//˻
  	public String locking() {
  		userServiceInter.locking(id);
  		return "list";
  	}
  	//ɾ˻
  	public String del() {
  		userServiceInter.delAccount(id);
  		return "list";
  	}
  	
  	//Կҳ֤֤ûǷڡһֻ֤ӵһ˻
  	public void validateOpenAccount() {
  		if(userServiceInter.getAccount(account.getUsername()) != null ) {
  			request.put("message", "ûѴڣ");
  		}
  		//
  		
  	}
  	//
  	public String openAccount() {
  		//account˻
  		userServiceInter.addAccount(account);
  		//personinfoӸϢ
  		account = userServiceInter.getAccount(account.getUsername());
  		personinfo.setAccount(account);
  		personinfoServiceInter.add(personinfo);
  		request.put("message", "ɹ");
  		return "message";
  	}
  	
  }
  