package com.z2sci.crms.action;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.z2sci.crms.manager.CustomerManager;
import com.z2sci.crms.manager.UploadFileManager;
import com.z2sci.crms.manager.UserManager;
import com.z2sci.crms.po.Customerinfo;
import com.z2sci.crms.po.PageBean;
import com.z2sci.crms.po.UploadFiles;
import com.z2sci.crms.po.Userinfo;
public class CustomerAction extends ActionSupport implements Serializable {
private static final long serialVersionUID = -4680744653859844642L;
private int customerId;
private String username;
private String customername;
private String telephone;
private String loginname;
private String address;
private String company;
private String description;
private Date createTime;
private int page = 1;
private PageBean pageBean;
private String selectUser;
private String searchContent;
private String password;
private String position;
private File file;
private String fileFileName;
private String fileContextType;
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileFileName() {
return fileFileName;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public String getFileContextType() {
return fileContextType;
}
public void setFileContextType(String fileContextType) {
this.fileContextType = fileContextType;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getLoginname() {
return loginname;
}
public void setLoginname(String loginname) {
this.loginname = loginname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
private CustomerManager customerManager;
public CustomerManager getCustomerManager() {
return customerManager;
}
public void setCustomerManager(CustomerManager customerManager) {
this.customerManager = customerManager;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getSearchContent() {
return searchContent;
}
public void setSearchContent(String searchContent) {
this.searchContent = searchContent;
}
public String getSelectUser() {
return selectUser;
}
public void setSelectUser(String selectUser) {
this.selectUser = selectUser;
}
public int getPage() {
return page;
}
public int getCustomerId() {
return customerId;
}
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
public UserManager getUserManager() {
return userManager;
}
public void setUserManager(UserManager userManager) {
this.userManager = userManager;
}
@Override
public String execute() throws Exception {
Userinfo userInfo = new Userinfo();
userInfo.setLoginname(loginname);
userInfo.setPassword(password);
if (customerManager.checkUserExist(userInfo)) {
Userinfo userInfo1 = userManager.findUser(loginname);
HttpServletRequest request = ServletActionContext.getRequest();
request.getSession().setAttribute("username",
userInfo1.getUsername());
// session.setAttribute("username",
// java.url.Encoder.encode(userInfo1.getUsername(),"utf-8"));
request.getSession().setAttribute("username",
userInfo1.getUsername());
request.getSession().setAttribute("loginname", loginname);
request.getSession().setAttribute("username",
userInfo1.getUsername());
this.pageBean = customerManager.queryForPage(15, page, loginname);
return "customerinfoList";
}
return "fail";
}
public void setPage(int page) {
this.page = page;
}
public PageBean getPageBean() {
return pageBean;
}
public void setPageBean(PageBean pageBean) {
this.pageBean = pageBean;
}
private UserManager userManager;
// public String getUsername() {
// return username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
public int getUserId() {
return customerId;
}
public void setUserId(int customerId) {
this.customerId = customerId;
}
public String getCustomername() {
return customername;
}
public void setCustomername(String customername) {
this.customername = customername;
}
public String openaddcustomer() {
// HttpServletRequest request = ServletActionContext.getRequest();
// List<Userinfo> userlist = userManager.searchUsers();
// request.setAttribute("userlist", userlist);
return "customeradd";
}
UploadFileManager uploadFileManager;
public UploadFileManager getUploadFileManager() {
return uploadFileManager;
}
public void setUploadFileManager(UploadFileManager uploadFileManager) {
this.uploadFileManager = uploadFileManager;
}
public String[] getUploadRealName() {
return uploadRealName;
}
public void setUploadRealName(String[] uploadRealName) {
this.uploadRealName = uploadRealName;
}
public String add() {
Customerinfo c = new Customerinfo();
System.out.println(loginname);
c.setCustomername(customername);
c.setUsername(username);
c.setLoginname(loginname);
c.setTelephone(telephone);
c.setCompany(company);
c.setAddress(address);
c.setPosition(position);
// u.setCreateTime(new Date());
c.setDescription(description);
customerManager.addOrUpdateCustomer(c);
this.pageBean = customerManager.queryForPage(15, page, loginname);
return "customerinfoList";
}
public String delCustomer() {
System.out.print("id=" + customerId);
customerManager.delCustomer(customerId);
this.pageBean = customerManager.queryForPage(15, page, loginname);
return "customerinfoList";
}
public String delCustomers() {
HttpServletRequest request = ServletActionContext.getRequest();
String[] customerId = request.getParameterValues("selectFlag");
String customerIds = "";
if (customerId != null) {
for (int i = 0; i < customerId.length; i++) {
customerIds = customerIds + customerId[i] + ",";
}
customerIds = customerIds.substring(0, customerIds.length() - 1);
customerManager.delCustomers(customerIds);
}
this.pageBean = customerManager.queryForPage(15, page, loginname);
return "customerinfoList";
}
public String searchCustomers() {
HttpServletRequest request = ServletActionContext.getRequest();
// for(Iterator ite = users.iterator(); ite.hasNext();){
// Userinfo userInfo = (Userinfo) ite.next();
// System.out.println(userInfo.getUserName());
// }
// request.setAttribute("list",users
- 1
- 2
- 3
- 4
- 5
- 6
前往页