/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.accp.struts.action;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.accp.biz.AccountinfoBiz;
import com.accp.biz.MovieinfoBiz;
import com.accp.biz.TicketBiz;
import com.accp.entity.Accountinfo;
import com.accp.entity.Movieinfo;
import com.accp.entity.Ticket;
import com.accp.struts.form.MovieinfoForm;
import com.accp.util.page.PageInfo;
/**
* MyEclipse Struts
* Creation date: 05-11-2009
*
* XDoclet definition:
* @struts.action path="/confirmTicket" name="movieinfoForm" parameter="operate" scope="request" validate="true"
* @struts.action-forward name="movieinfo" path="/admin/movieinfo.jsp"
*/
public class ConfirmTicketAction extends DispatchAction {
private MovieinfoBiz movieinfoBiz;
private TicketBiz ticketBiz;
private AccountinfoBiz accountinfoBiz;
/*
* Generated Methods
*/
public AccountinfoBiz getAccountinfoBiz() {
return accountinfoBiz;
}
public void setAccountinfoBiz(AccountinfoBiz accountinfoBiz) {
this.accountinfoBiz = accountinfoBiz;
}
public TicketBiz getTicketBiz() {
return ticketBiz;
}
public void setTicketBiz(TicketBiz ticketBiz) {
this.ticketBiz = ticketBiz;
}
public MovieinfoBiz getMovieinfoBiz() {
return movieinfoBiz;
}
public void setMovieinfoBiz(MovieinfoBiz movieinfoBiz) {
this.movieinfoBiz = movieinfoBiz;
}
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward disp(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
MovieinfoForm movieinfoForm = (MovieinfoForm) form;// TODO Auto-generated method stub
PageInfo pageInfo = new PageInfo();
pageInfo.setRecList(movieinfoBiz.getAllMovieinfo());
request.setAttribute("pageInfo", pageInfo);
return mapping.findForward("movieinfo");
}
public ActionForward setMovieToSe(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
MovieinfoForm movieinfoForm = (MovieinfoForm) form;// TODO Auto-generated method stub
PageInfo pageInfo = new PageInfo();
String idStr = request.getParameter("id");
if(null == idStr && "".equals(idStr)) {
return mapping.findForward("movieErr");
}
Long id = new Long(-1);
try {
id = Long.parseLong(idStr);
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return mapping.findForward("movieErr");
}
Movieinfo movieinfo = movieinfoBiz.getMovieinfoById(id);
pageInfo.setMovieinfo(movieinfo);
List list = ticketBiz.getTicketByMovieId(movieinfo.getId());
pageInfo.setRecList(list);
request.setAttribute("pageInfo", pageInfo);
return mapping.findForward("confirmTicket");
}
public ActionForward toRealTicket(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
MovieinfoForm movieinfoForm = (MovieinfoForm) form;// TODO Auto-generated method stub
PageInfo pageInfo = new PageInfo();
String idStr = request.getParameter("id");
if(null == idStr && "".equals(idStr)) {
return mapping.findForward("movieErr");
}
Long id = new Long(-1);
try {
id = Long.parseLong(idStr);
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return mapping.findForward("movieErr");
}
Movieinfo movieinfo = movieinfoBiz.getMovieinfoById(id);
pageInfo.setMovieinfo(movieinfo);
String seatStr = request.getParameter("seatStr");
if(null == seatStr || "".equals(seatStr)) {
return mapping.findForward("seatNoErr");
}
pageInfo.setSeatStr(seatStr);
pageInfo.setTicketType(request.getParameter("tickettype"));
request.setAttribute("pageInfo", pageInfo);
return mapping.findForward("realTicket");
}
public ActionForward addTicket(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
MovieinfoForm movieinfoForm = (MovieinfoForm) form;// TODO Auto-generated method stub
List<Ticket> list = new ArrayList<Ticket>();
String ticketStr = request.getParameter("ticketList");
Accountinfo accountinfo = accountinfoBiz.getAccountinfo(movieinfoForm.getAccountinfo());
if(accountinfo == null) {
return mapping.findForward("AccountOrPswErr");
}
String[] ticketStrArr = ticketStr.split("/");
String seatNo = "";
String ticketType = "";
Long movieId = null;
for (int i = 0; i < ticketStrArr.length; i++) {
String[] tempStr = ticketStrArr[i].split(",");
if("一大厅".equals(tempStr[0])) {
seatNo = "1-"+tempStr[1];
} else if("二大厅".equals(tempStr[0])) {
seatNo = "2-"+tempStr[1];
} else {
seatNo = "3-"+tempStr[1];
}
ticketType = tempStr[2];
movieId = Long.parseLong(tempStr[3]);
System.out.println(tempStr);
Ticket ticket = new Ticket();
ticket.setSeatno(seatNo);
ticket.setTickettype(ticketType);
Movieinfo movieinfo = new Movieinfo();
movieinfo.setId(movieId);
ticket.setMovieinfo(movieinfo);
ticket.setAccountinfo(accountinfo);
list.add(ticket);
}
int ret = ticketBiz.addTickets(list);
if(ret <= 0) {
return mapping.findForward("ConfirmTicketErr");
}
return mapping.findForward("index");
}
}