ticketssubmitaction.java~74~
来自「采用web2.0技术,采用动态标签,sql语句全部存储在数据库里面.开发速度快.」· JAVA~74~ 代码 · 共 184 行
JAVA~74~
184 行
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 = null, strSQLUp = null;
String strMsg = null, target = "failure";
int iSuccFlag = 0, ileftCount = 0, iID = 0;
String ChoiceType = null, UserName = null, ProgrameID = null, SeatsID = null,
SeatID = null;
String ClassID = null, DiscountID = null;
String HallID = null, FloorID = null, OrderID = null, TicketID = null;
String strCols[] = null;
try {
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");
ProgrameID = request.getParameter("programeid") == null ?
"0" : request.getParameter("programeid");
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 &&
ProgrameID.length() > 0) {
strSQL =
"select a.*,(ticketnum-OrCount) as leftCount from Tsm_OrderCart a where " +
"username='" + UserName + "' and programID='" +
ProgrameID +
"'";
rs = stmt.executeQuery(strSQL);
if (rs.next()) {
DiscountID = rs.getString("DiscountID") == null ? "" :
rs.getString("DiscountID");
SeatsID = rs.getString("OrSeatID") == null ? "" :
rs.getString("OrSeatID");
ClassID = rs.getString("ClassID") == null ? "0" :
rs.getString("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 + ") ";
strSQLUp +=
" update T_seat set StatusID = 3 where SeatID in(" +
SeatsID + ") ";
strSQLUp +=
" update T_seat set StatusID = 3 where SeatID in(" +
SeatsID + ") ";
for (int i = 0; i < strCols.length; i++) {
SeatID = strCols[i];
if (SeatID == null || SeatID.length() == 0)
continue;
else {
strSQLUp +=
"insert into T_Order(customerid,retrievetypeid) " +
"select customerid,'" + ClassID +
"' from t_netcustomer where loginname='" +
UserName + "' ";
strSQL =
"select OrderID from T_Order where " +
"customerid=(select customerid from t_netcustomer where loginname='xiaohai133') " +
"and retrievetypeid='" + ClassID +
"'";
rs = stmt.executeQuery(strSQL);
if (rs.next())
OrderID = rs.getString("OrderID") == null ?
"" : rs.getString("OrderID");
strSQL =
"select ticketid from T_TicketingSeat where " +
"programid='" + ProgrameID +
"'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 + "," +
ProgrameID +
"," + TicketID + "," + DiscountID +
") ";
}
}
}
else {
strSQLUp =
"update Tsm_OrderCart set OrCount = 0,OrSeatID='' where username='" +
UserName + "'";
strSQLUp =
"update T_TicketingSeat set StatusID = 0 where SeatID='" +
SeatID + "' and programid=" +
ProgrameID;
strSQLUp +=
" update T_seat set StatusID = 0 where SeatID=" +
SeatID;
}
}
}
System.out.println("strSQLCount[" + strSQL + "]");
System.out.println("UserName[" + UserName + "]");
System.out.println("ProgrameID[" + ProgrameID + "]");
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
request.setAttribute("hallid", HallID);
request.setAttribute("floorid", FloorID);
request.setAttribute("username", UserName);
request.setAttribute("programeid", ProgrameID);
if (target.compareToIgnoreCase("failure") == 0) {
request.setAttribute("resultid", "0");
request.setAttribute("resultinfo", strMsg);
}
try {
if (rs != null) {
rs.close();
}
} catch (Exception ex) {
}
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (Exception ex) {
}
}
return (mapping.findForward(target));
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?