⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainaction.java

📁 一个完整的网络订餐系统
💻 JAVA
字号:
package com.hao78.main.action;

import org.apache.struts.action.ActionForward;
import com.common.struts.*;
import java.util.List;

import java.sql.*;
import java.util.*;
import com.common.*;



import com.food.dao.FoodDao;
import com.foodset.dao.FoodsetDao;
import com.information.dao.InformationDao;
import com.store.dao.StoreDao;
import com.menubill.dao.MenubillDao;



public class MainAction extends AbstractAction {
  public MainAction() {
  }

  public ActionForward execute(ActionContext actionContext) throws java.lang.Exception {

    String areaID = actionContext.getParameter("areaID");
    actionContext.getSession().setAttribute("areaID",areaID);

    FoodDao foodDao = new FoodDao();
    List foodList = foodDao.getNewFood(areaID);   //推荐菜

    FoodsetDao foodsetDao = new FoodsetDao();
    List foodsetList  = foodsetDao.getNewFoodSet(areaID); //推荐套餐


    InformationDao infoDao = new InformationDao();

    List newsList = infoDao.getNewInformation("cd0506042000000",areaID);  //新闻
    List nurtrationList = infoDao.getNewInformation("cd0506042398493",areaID); //营养
    List techList = infoDao.getNewInformation("cd0506044918497",areaID); //教你几招
    List cateList = infoDao.getNewInformation("cd0506043819136",areaID); //美食


    MenubillDao menuDao = new MenubillDao();
    List menuList = menuDao.getNewMenubillList(areaID);

    StoreDao storeDao = new StoreDao();
    List storeList  = storeDao.getNewStoreList(areaID);



    actionContext.getRequest().setAttribute("newfoodList",foodList);
    actionContext.getRequest().setAttribute("newfoodsetList",foodsetList);
    actionContext.getRequest().setAttribute("newsList",newsList);
    actionContext.getRequest().setAttribute("techList",techList);
    actionContext.getRequest().setAttribute("nurtrationList",nurtrationList);
    actionContext.getRequest().setAttribute("cateList",cateList);
    actionContext.getRequest().setAttribute("menuList",menuList);
    actionContext.getRequest().setAttribute("storeList",storeList);


    int nCounterNum = getCountrNum() + 1;
    updateCounter(nCounterNum);
    actionContext.getRequest().setAttribute("CounterNum",
                                            String.valueOf(nCounterNum));

    return actionContext.getMapping().findForward("main");
 }



  /*  */
  public void updateCounter(int nCount)
  {
    DBConnection dbc = null;
    Connection conn = null;
    Statement stmt = null;
    String strSQL = null;

    try {
      dbc = new DBConnection();
      conn = dbc.getDBConnection();
      stmt = conn.createStatement();

      strSQL = "update Counter set countNum=" + nCount + ", createDate=getdate() where countID=1000";
      stmt.executeUpdate(strSQL);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    finally {
      try {
        if (stmt != null) {
          stmt.close();
        }
        if (conn != null) {
          dbc.closeDBConnection(conn);
        }
      }
      catch (Exception ex) {}
    }
  }


  public int getCountrNum()
  {
    int nCurCount = 0;
    DBConnection dbc = null;
    Connection conn = null;
    Statement stmt = null;
    String strSQL = null;
    ResultSet rs = null;

    try {
      dbc = new DBConnection();
      conn = dbc.getDBConnection();
      stmt = conn.createStatement();

      strSQL = "select countNum from Counter where countID=1000";
      rs = stmt.executeQuery(strSQL);
      if (rs.next()) {
        nCurCount = rs.getInt("countNum");
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    finally {
      try {
        if (stmt != null) {
          stmt.close();
        }
        if (conn != null) {
          dbc.closeDBConnection(conn);
        }
      }
      catch (Exception ex) {}
    }
    return nCurCount;
  }
}

⌨️ 快捷键说明

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