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

📄 addgatheringaction.java

📁 完整的合同管理信息系统
💻 JAVA
字号:
package com.ICT.AFC.contractmoney.gathering;

import org.apache.struts.action.*;
import java.io.*;
import javax.servlet.http.*;
import com.ICT.AFC.DB.*;
import javax.servlet.http.*;
import javax.servlet.ServletContext;
import javax.sql.*;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.struts.upload.*;

public class addGatheringAction extends Action
{
  public ActionForward execute(ActionMapping actionMapping,
                               ActionForm actionForm,
                               HttpServletRequest httpServletRequest,
                               HttpServletResponse httpServletResponse)
  {
    /**@todo: complete the business logic here, this is just a skeleton.*/
    addGatheringActionForm addGatheringActionForm=(addGatheringActionForm)
      actionForm;
    String PageForward="addGatheringResult";
    //httpServletResponse.setContentType("text/html; charset=gb2312");
    HttpSession session=httpServletRequest.getSession();
    ServletContext context=servlet.getServletContext();
    DataSource dataSource=(DataSource)context.getAttribute("contract");
    DB db=new DB(dataSource);
    int ii=0;
    String filePath="";
    String aa=httpServletRequest.getParameter("checkbox1");
    aa=aa+"on";
    if (aa.equals("onon"))
      ii=1;
    else
      ii=0;
    try
    {
      boolean addResult=addOperate(db,addGatheringActionForm,filePath,ii,httpServletRequest);
      if(addResult)
      {
        session.setAttribute("addResult","1");
      }
      else
      {
        session.setAttribute("addResult","0");

      }
    }
    catch(Exception e)
    {
    }
    finally
    {
      //throw new java.lang.UnsupportedOperationException("Method perform() not yet implemented.");
      return(actionMapping.findForward(PageForward));
    }
  }

  public boolean addOperate(DB db,addGatheringActionForm addGatheringActionForm,
                            String filePath,int ii,HttpServletRequest httpServletRequest) throws
    Exception
  { if (ii!=1)
    {FormFile file=addGatheringActionForm.getGatheringFile(); //取得上传的文件
    try
    {
      InputStream stream=file.getInputStream(); //把文件读入
      //ByteArrayOutputStream baos=new ByteArrayOutputStream();
      String aa=httpServletRequest.getRealPath("/");
      OutputStream bos=new FileOutputStream(aa+"upload/gathering/"+file.getFileName()); //建立一个上传文件的输出流
      filePath=aa+"upload/gathering/"+file.getFileName();
      //System.out.println(filePath+"/"+file.getFileName());
      int bytesRead=0;
      byte[] buffer=new byte[8192];
      while((bytesRead=stream.read(buffer,0,8192))!=-1)
      {
        bos.write(buffer,0,bytesRead); //将文件写入服务器
      }
      bos.close();
      stream.close();
    }
    catch(Exception e)
    {
      System.err.print(e);
    }
    }
    else
      {filePath="nullnull";}
    String conditions = "select seq_contractmoney.nextval from dual";
    ResultSet rs = db.OpenSql(conditions);
    rs.next();
    int contractMoneyID = rs.getInt(1); //提取id
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
    String contractID=httpServletRequest.getParameter("contractID");
    addGatheringActionForm.setGatheringContractID(contractID);
    String strSql=
      "INSERT INTO M_MONEY VALUES("+
      addGatheringActionForm.getGatheringContractID()+",'"+
      addGatheringActionForm.getGatheringMoney()+
      "','"+addGatheringActionForm.getGatheringDate()+
      "','"+
      addGatheringActionForm.getGatheringRemark()+"','asddf','"+
      sdf.format(new Date())+
      "','"+filePath+"'"+
      ","+contractMoneyID+",'"+"收款"+
      "')";

    if(db.ExecSql(strSql)==0)
    {
      rs.close();
      db.close();
      return false;
    }
    else
    {
      rs.close();
      db.close();
      return true;
    }
  }

}

⌨️ 快捷键说明

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