ordercartaction.java~32~

来自「采用web2.0技术,采用动态标签,sql语句全部存储在数据库里面.开发速度快.」· JAVA~32~ 代码 · 共 183 行

JAVA~32~
183
字号
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 OrderCartAction extends Action {

    public ActionForward execute(ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response) throws
           IOException, ServletException, SQLException {
       ResultSet rs = null, rst = null;
       Statement stmt = null ,state = 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");

           ChoiceType = request.getParameter("choicetype") == null ?
                        "" : request.getParameter("choicetype");
           UserName = request.getParameter("username") == null ?
                      "" : request.getParameter("username");
           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();
           state = conn.createStatement();
           if (ChoiceType.length() > 0 && UserName.length() > 0)
           {
               strSQL =
                       "select a.* from T_Order_Cart a where " +
                       "username='" + UserName + "'";
               rs = stmt.executeQuery(strSQL);
               System.out.println("strSQL[" + strSQL + "]");

               while (rs.next()) {
                  iCount ++;
                  System.out.println("iCount[" + Integer.toString(iCount) + "]");
                  System.out.println("Connection status["+conn.isClosed()+"]");

                   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");
                   ProgramID = rs.getString("programid") == null ? "" :
                               rs.getString("programid");

                   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 + "]");

                       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 + "]");
                       rst = state.executeQuery(strSQL);
                       if (rst.next())
                           OrderID = rst.getString("OrderID") == null ?
                                     "" : rst.getString("OrderID");
                       System.out.println("\n OrderID[" + OrderID + "]\n");
                   }
                   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 ticketid from T_TicketingSeat where " +
                                "programid='" + ProgramID +
                                "'and seatid='" + SeatID + "' ";

                       rst = state.executeQuery(strSQL);
                       if (rst.next())
                           TicketID = rst.getString("ticketid") == null ?
                                      "" : rst.getString("ticketid");
                       strSQLUp =
                               "insert into t_seatsordered(OrderID,ProgramID,TicketID,DiscountID)" +
                               "values(" + OrderID + "," + ProgramID + "," +
                               TicketID + "," + DiscountID + ") ";

                       ModifyData.AddSeatsOrdered(strSQLUp);
                       System.out.println("strSQLUp[" + strSQLUp + "]");
                   }
               }
               if(iCount > 0 )
               {
                   strSQLUp =
                           "delete from  T_Order_Cart where username='" +
                           UserName.trim() + "'";
                   iSuccFlag = stmt.executeUpdate(strSQLUp);
               }
               if(iSuccFlag > 0 || iCount ==0)
                   target = "success";
             }
           } 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();
                   }
                   if(rst != null)
                       rst.close();
               } catch (Exception ex) {
               }
               try {
                   if (stmt != null) {
                       stmt.close();
                   }
                   if(state!= null)
                       state.close();
                   if (conn != null) {
                       conn.close();
                   }
               } catch (Exception ex) {
               }
               rs = null;
               rst = null;
               conn = null;
               stmt = null;
               state = null;
           }
           return (mapping.findForward(target));
       }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?