ticketssubmitaction.java~196~
来自「采用web2.0技术,采用动态标签,sql语句全部存储在数据库里面.开发速度快.」· JAVA~196~ 代码 · 共 240 行
JAVA~196~
240 行
package com.sztheater.biz.order;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable up-and-up
* @version 1.0
*/
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import java.sql.*;
import com.sztheater.framework.web.*;
import com.sztheater.framework.util.*;
import java.util.*;
import javax.servlet.http.*;
public class TicketsSubmitAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
IOException, ServletException {
ResultSet rs = null;
Statement stmt = null;
Connection conn = null;
HttpSession _httpsession = null;
_httpsession = request.getSession();
String strSQL = "", strSQLUp = "";
String strMsg = null, target = "error";
int iSuccFlag = 0, ileftCount = 0, iID = 0;
String ChoiceType = null, UserName = null, ProgramID = null, SeatsID = null,
SeatID = null;
String ClassID = null, DiscountID = null;
String HallID = null, FloorID = null, OrderID = null, TicketID = null;
String strCols[] = null;
try {
request.removeAttribute("ErrMsg");
HallID = request.getParameter("hallid") == null ?
"0" : request.getParameter("hallid");
FloorID = request.getParameter("floorid") == null ?
"0" : request.getParameter("floorid");
ChoiceType = request.getParameter("choicetype") == null ?
"" : request.getParameter("choicetype");
UserName = request.getParameter("username") == null ?
"" : request.getParameter("username");
ProgramID = request.getParameter("programid") == null ?
"0" : request.getParameter("programid");
try {
conn = DbFunc.getConnection(false);
} catch (Exception e) {
iSuccFlag = -90102;
if (conn != null) {
DbFunc.free(conn, iSuccFlag);
}
conn = null;
strMsg = "服务取数据库连接异常" + e.getMessage();
}
stmt = conn.createStatement();
if (ChoiceType.length() > 0 && UserName.length() > 0 &&
ProgramID.length() > 0) {
strSQL =
"select a.*,(ticketnum-OrCount) as leftCount from Tsm_OrderCart a where " +
"username='" + UserName + "' and programID='" +ProgramID +
"' and OrderFlag='0' and hallid="+HallID;
rs = stmt.executeQuery(strSQL);
if (rs.next()) {
DiscountID = rs.getString("discount") == null ? "" :
rs.getString("discount");
SeatsID = rs.getString("OrSeatID") == null ? "" :
rs.getString("OrSeatID");
ClassID = rs.getString("ClassID") == null ? "0" :
rs.getString("ClassID");
System.out.println("DiscountID[" + DiscountID + "]");
System.out.println("SeatsID[" + SeatsID + "]");
System.out.println("ClassID[" + ClassID + "]");
if (SeatsID.length() > 1) {
SeatsID = SeatsID.replaceFirst(",", "");
strCols = SeatsID.split(",");
if (ChoiceType.compareToIgnoreCase("success") == 0) {
strSQLUp =
"update T_TicketingSeat set StatusID = 3 where SeatID in(" +
SeatsID + ") ";
ModifyData.ModifyTicketingSeat(strSQLUp);
System.out.println("strSQLUp[" + strSQLUp + "]");
strSQLUp =
" update T_seat set StatusID = 3 where SeatID in(" +
SeatsID + ") ";
ModifyData.ModifySeat(strSQLUp);
System.out.println("strSQLUp[" + strSQLUp + "]");
strSQL =" select top 1 OrderID from T_Order where " +
"customerid=(select customerid from t_netcustomer where loginname='" +
UserName.trim() + "') " +
"and retrievetypeid='" + ClassID +
"' order by OrderID desc";
rs = stmt.executeQuery(strSQL);
System.out.println("strSQL[" + strSQL + "]");
if (rs.next())
OrderID = rs.getString("OrderID") == null ?
"" : rs.getString("OrderID");
else
{
strSQLUp =
" insert into T_Order(customerid,retrievetypeid) " +
"select customerid,'" + ClassID +
"' from t_netcustomer where loginname='" +
UserName.trim() + "' ";
ModifyData.AddOrder(strSQLUp);
System.out.println("strSQLUp[" + strSQLUp + "]");
strSQL =" select top 1 OrderID from T_Order where " +
"customerid=(select customerid from t_netcustomer where loginname='" +
UserName.trim() + "') " +
"and retrievetypeid='" + ClassID +
"' order by OrderID desc";
System.out.println("strSQL[" + strSQL + "]");
rs = stmt.executeQuery(strSQL);
if (rs.next())
OrderID = rs.getString("OrderID") == null ?
"" : rs.getString("OrderID");
}
System.out.println("\n\n\n OrderID[" + OrderID + "]\n\n\n");
for (int i = 0; i < strCols.length; i++) {
SeatID = strCols[i];
if (SeatID == null || SeatID.length() == 0)
continue;
else {
strSQL =
" select ticketid from T_TicketingSeat where " +
"programid='" + ProgramID +
"'and seatid='" + SeatID + "' ";
rs = stmt.executeQuery(strSQL);
if (rs.next())
TicketID = rs.getString("ticketid") == null ?
"" : rs.getString("ticketid");
strSQLUp =
" insert into t_seatsordered(OrderID,ProgramID,TicketID,DiscountID)" +
"values(" + OrderID + "," +
ProgramID +
"," + TicketID + "," + DiscountID +
") ";
ModifyData.ModifySeatsOrdered(strSQLUp);
System.out.println("strSQLUp[" + strSQLUp + "]");
}
}
strSQLUp = " update Tsm_OrderCart set OrderFlag=1 where username='" +
UserName + "' and programID='" +ProgramID +
"' and OrderFlag=0 and hallid="+HallID;
iSuccFlag = stmt.executeUpdate(strSQLUp);
}
else {
strSQLUp =
" update Tsm_OrderCart set OrCount = 0,OrSeatID='' where username='" +
UserName + "' and programID='" +ProgramID +
"' and OrderFlag=0 ";
iSuccFlag = stmt.executeUpdate(strSQLUp);
strSQLUp =
"update T_TicketingSeat set StatusID = 0 where SeatID in(" +
SeatsID + ") and programid=" +
ProgramID;
ModifyData.ModifyTicketingSeat(strSQLUp);
System.out.println("strSQLUp[" + strSQLUp + "]");
strSQLUp =
" update T_seat set StatusID = 0 where SeatID in(" +
SeatsID + ") ";
ModifyData.ModifySeat(strSQLUp);
System.out.println("strSQLUp[" + strSQLUp + "]");
}
if(iSuccFlag >0 )
target = "success";
else
strMsg = "数据库执行错误!重新操作!";
}
else
{
if(ChoiceType.compareToIgnoreCase("success") == 0)
strMsg = "您还没有选座位!请选择座位!";
}
}
else
{
strMsg = "您还没有选择票数跟折扣!请返回上一步选择票数跟折扣!";
}
System.out.println("strSQLUp[" + strSQLUp + "]");
System.out.println("UserName[" + UserName + "]");
System.out.println("ProgrameID[" + ProgramID + "]");
}
else
strMsg = "用户名,电影ID和折扣ID不能为空!";
} catch (Exception ex) {
strMsg = "程序执行异常!";
ex.printStackTrace();
} finally {
request.setAttribute("hallid", HallID);
request.setAttribute("floorid", FloorID);
request.setAttribute("username", UserName);
request.setAttribute("programid", ProgramID);
if (target.compareToIgnoreCase("error") == 0) {
_httpsession.setAttribute("ErrMsg", strMsg);
}
try {
if (rs != null) {
rs.close();
}
} catch (Exception ex) {
}
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (Exception ex) {
}
}
System.out.println("target["+target+"]");
return (mapping.findForward(target));
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?