ticketssubmitaction.java~309~
来自「采用web2.0技术,采用动态标签,sql语句全部存储在数据库里面.开发速度快.」· JAVA~309~ 代码 · 共 191 行
JAVA~309~
191 行
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, SQLException {
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,iCount = 0;
String ChoiceType = null, UserName = null, ProgramID = 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.* from T_Order_Cart a where " +
"username='" + UserName + "' and programID='" +ProgramID +
"' and hallid="+HallID;
rs = stmt.executeQuery(strSQL);
while (rs.next()) {
iCount ++;
if(iCount ==1 && ChoiceType.compareToIgnoreCase("success") == 0)
{
strSQLUp =
"insert into T_Order(customerid,retrievetypeid) " +
"select customerid,'1' from t_netcustomer where loginname='" +
UserName.trim() + "' ";
ModifyData.AddOrder(strSQLUp);
System.out.println("strSQLUp[" + strSQLUp + "]");
}
DiscountID = rs.getString("discount") == null ? "" :
rs.getString("discount");
SeatID = rs.getString("SeatID") == null ? "" :
rs.getString("SeatID");
ClassID = rs.getString("ClassID") == null ? "0" :
rs.getString("ClassID");
if (ChoiceType.compareToIgnoreCase("success") == 0) {
strSQLUp = "update T_TicketingSeat set StatusID = 3 where SeatID =" + SeatID +
" and programid="+ProgramID;
ModifyData.ModifyTicketingSeat(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() + "') " +
"' 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 OrderID[" + OrderID + "]\n");
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 + "]");
target = "addsuccess";
}
else
{
strSQLUp =
"update T_TicketingSeat set StatusID=0 where SeatID=" + SeatID +
" and programid= '" + ProgramID +"'";
ModifyData.ModifyTicketingSeat(strSQLUp);
System.out.println("strSQLUp[" + strSQLUp + "]");
}
}
if(iCount > 0)
{
strSQLUp =
"delete from T_Order_Cart where username='" +
UserName.trim() + "' and programid=" + ProgramID +
" and hallid = " + HallID + " and floorid =" +
FloorID + "";
iSuccFlag = stmt.executeUpdate(strSQLUp);
}
if(iSuccFlag > 0 || iCount == 0)
target = "success";
else
strMsg = "数据库执行错误!重新操作!";
}
} catch (Exception ex)
{
strMsg = "程序执行异常!";
ex.printStackTrace();
} finally {
DbFunc.free(conn, iSuccFlag);
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 + -
显示快捷键?