<%@page import="java.io.FileOutputStream"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@ page contentType="text/html;charset=GBK"%>


String filename = application.getRealPath("/" + "importfile/OamPart_list.xls");
  HSSFWorkbook workbook = new HSSFWorkbook();
  HSSFSheet sheet = workbook.createSheet("OamPart");
  OamPartApp newOamPartApp = new OamPartApp();
  OamPart newOamPart = new OamPart();
  String whereClause=BuildSQL.getWhere(request); 
  newOamPartApp.setWhereClause(whereClause);
  ArrayList ar = newOamPartApp.getOamPartList(dbi,0,0,"");
   if(ar.size()==0)
  {
   out.println("<script language='javascript'> alert('没有符合条件的记录可到导'); history.go(-1); </script>");
  }
  else
  {  
   HSSFRow row = sheet.createRow((short)0);
   HSSFCell cell = row.createCell((short)0);
   cell.setCellType(HSSFCell.CELL_TYPE_STRING);
   cell.setCellValue("零件号");
      cell = row.createCell((short)1);
   cell.setCellValue("计划代码");
      cell = row.createCell((short)2);
   cell.setCellValue("机型代码");
      cell = row.createCell((short)3);
   cell.setCellValue("采购人代码");
      cell = row.createCell((short)4);
   cell.setCellValue("LocationFrom");
      cell = row.createCell((short)5);
   cell.setCellValue("LocationTo");
      cell = row.createCell((short)6);
   cell.setCellValue("ReceiveFrom");
      cell = row.createCell((short)7);
   cell.setCellValue("ReceiveTo");
      cell = row.createCell((short)8);
   cell.setCellValue("LOCCLASS");
   for(int i = 1 ; i<ar.size(); i++){
    newOamPart = (OamPart)ar.get(i);
       row = sheet.createRow((short)i);
       cell = row.createCell((short)0);
    cell.setCellValue(newOamPart.getPartNo());
    cell = row.createCell((short)1);
    cell.setCellValue(newOamPart.getPlanCode());
    cell = row.createCell((short)2);
    cell.setCellValue(newOamPart.getMachineCode());
    cell = row.createCell((short)3);
    cell.setCellValue(newOamPart.getPurCode());
    cell = row.createCell((short)4);
    cell.setCellValue(newOamPart.getLocationFrom());
    cell = row.createCell((short)5);
    cell.setCellValue(newOamPart.getLocationTo());
    cell = row.createCell((short)6);
    cell.setCellValue(newOamPart.getReceiveFrom());
    cell = row.createCell((short)7);
    cell.setCellValue(newOamPart.getReceiveTo());
    cell = row.createCell((short)8);
    cell.setCellValue(newOamPart.getLOCCLASS());
   }
   FileOutputStream fOut = new FileOutputStream(filename);
   workbook.write(fOut);
   fOut.flush();
   fOut.close();
      pageContext.forward("DownLoadFile.jsp?fileName=" + filename);
   //response.setContentType("application/x-msdownload");
   //response.setHeader("Content-Disposition","attachment; filename=\"OAMEximport.xls\"");
  }