package com.ctdw.zk.actions.kj.cjbk;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import org.apache.struts.upload.FormFile;
import com.sun.j2ee.blueprints.util.dao.DAONoRecordException;
import com.sun.j2ee.blueprints.util.dao.DBUtil;
public class CjbkEntity {
// public void saveformfile(HttpServletRequest request,FormFile formfile,String filePath,String fileName) throws Exception{
// if (formfile != null) {
// if (!formfile.getFileName().trim().equals("")) {
//
// InputStream stream = formfile.getInputStream();
//
//
// File f = new File(filePath);
// if (!f.exists()) {
// f.mkdirs();
// }
//
// OutputStream bos = new FileOutputStream(filePath
// + fileName);// 建立一个上传文件的输出流
// 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();
// }
// }
// }
public String insertTxt(FormFile formfile,String kslbdm,String ksq) throws Exception{
InputStream stream = formfile.getInputStream();
StringBuffer s = new StringBuffer();
BufferedReader bufferedreader = null;
try{
bufferedreader = new BufferedReader(new InputStreamReader(stream, "gb2312"));
String s1 = null;
while(null != (s1 = bufferedreader.readLine())){
s.append(s1).append("/r/n");
}
}catch(Exception e) {
e.printStackTrace();
}
StringReader stringreader = new StringReader(s.toString());
bufferedreader = new BufferedReader(stringreader);
String ss = null;
StringBuffer errorBuffer = new StringBuffer();
List sqlList = new ArrayList();
String sql="";
sql = "DELETE FROM CJ_BK_TEMP_JK";
sqlList.add(sql);
int i =1;
while( null != (ss = bufferedreader.readLine()))
{
String as[] = ss.split(",");
if(as.length != 2 ||(as.length == 2 && (as[0].length() != 12 || as[1].length()>10))){
if(errorBuffer.equals("")){
errorBuffer.append("错误数据//r//n");
errorBuffer.append(i+","+ss+"//r//n");
}else{
errorBuffer.append(i+","+ss+"//r//n");
}
}else{
sql = "INSERT INTO CJ_BK_TEMP_JK(ZKZH,KCDM,KSLBDM,KSQ,ZCJ,STATUS) VALUES('"+as[0]+"','10018','"+kslbdm+"','"+ksq+"','"+as[1]+"','99')";
sqlList.add(sql);
}
i++;
}
try{
DBUtil dbutil = new DBUtil();
dbutil.sqlTransactionList(sqlList);
}catch(DAONoRecordException e){
}catch(Exception e){
throw e;
}
return errorBuffer.toString();
}
public String insertXls(FormFile formfile,String kslbdm,String ksq) throws Exception{
//InputStream is = new FileInputStream(formfile.toString());
InputStream stream = formfile.getInputStream();
Workbook rwb = Workbook.getWorkbook(stream);
Sheet rs = rwb.getSheet(0);
int rsRows = rs.getRows();
String[] as = new String[2];
StringBuffer errorBuffer = new StringBuffer();
List sqlList = new ArrayList();
String sql="";
sql = "DELETE FROM CJ_BK_TEMP_JK";
sqlList.add(sql);
for(int i = 0;i<rsRows;i++){
as[0] = "";
as[1] = "";
Cell c0 = rs.getCell(0,i);
as[0] = c0.getContents().trim();
Cell c1 = rs.getCell(1,i);
as[1] = c1.getContents().trim();
if(as[0].equals("") || as[0].length() != 12 || as[1].equals("") || as[1].length()>10){
if(errorBuffer.toString().equals("")){
errorBuffer.append("错误数据//r//n");
errorBuffer.append((i+1)+","+as[0]+","+as[1]+"//r//n");
}else{
errorBuffer.append((i+1)+","+as[0]+","+as[1]+"//r//n");
}
}else{
sql = "INSERT INTO CJ_BK_TEMP_JK(ZKZH,KCDM,KSLBDM,KSQ,ZCJ,STATUS) VALUES('"+as[0]+"','10018','"+kslbdm+"','"+ksq+"','"+as[1]+"','99')";
sqlList.add(sql);
}
}
rwb.close();
try{
DBUtil dbutil = new DBUtil();
dbutil.sqlTransactionList(sqlList);
}catch(DAONoRecordException e){
}catch(Exception e){
throw e;
}
return errorBuffer.toString();
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import org.apache.struts.upload.FormFile;
import com.sun.j2ee.blueprints.util.dao.DAONoRecordException;
import com.sun.j2ee.blueprints.util.dao.DBUtil;
public class CjbkEntity {
// public void saveformfile(HttpServletRequest request,FormFile formfile,String filePath,String fileName) throws Exception{
// if (formfile != null) {
// if (!formfile.getFileName().trim().equals("")) {
//
// InputStream stream = formfile.getInputStream();
//
//
// File f = new File(filePath);
// if (!f.exists()) {
// f.mkdirs();
// }
//
// OutputStream bos = new FileOutputStream(filePath
// + fileName);// 建立一个上传文件的输出流
// 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();
// }
// }
// }
public String insertTxt(FormFile formfile,String kslbdm,String ksq) throws Exception{
InputStream stream = formfile.getInputStream();
StringBuffer s = new StringBuffer();
BufferedReader bufferedreader = null;
try{
bufferedreader = new BufferedReader(new InputStreamReader(stream, "gb2312"));
String s1 = null;
while(null != (s1 = bufferedreader.readLine())){
s.append(s1).append("/r/n");
}
}catch(Exception e) {
e.printStackTrace();
}
StringReader stringreader = new StringReader(s.toString());
bufferedreader = new BufferedReader(stringreader);
String ss = null;
StringBuffer errorBuffer = new StringBuffer();
List sqlList = new ArrayList();
String sql="";
sql = "DELETE FROM CJ_BK_TEMP_JK";
sqlList.add(sql);
int i =1;
while( null != (ss = bufferedreader.readLine()))
{
String as[] = ss.split(",");
if(as.length != 2 ||(as.length == 2 && (as[0].length() != 12 || as[1].length()>10))){
if(errorBuffer.equals("")){
errorBuffer.append("错误数据//r//n");
errorBuffer.append(i+","+ss+"//r//n");
}else{
errorBuffer.append(i+","+ss+"//r//n");
}
}else{
sql = "INSERT INTO CJ_BK_TEMP_JK(ZKZH,KCDM,KSLBDM,KSQ,ZCJ,STATUS) VALUES('"+as[0]+"','10018','"+kslbdm+"','"+ksq+"','"+as[1]+"','99')";
sqlList.add(sql);
}
i++;
}
try{
DBUtil dbutil = new DBUtil();
dbutil.sqlTransactionList(sqlList);
}catch(DAONoRecordException e){
}catch(Exception e){
throw e;
}
return errorBuffer.toString();
}
public String insertXls(FormFile formfile,String kslbdm,String ksq) throws Exception{
//InputStream is = new FileInputStream(formfile.toString());
InputStream stream = formfile.getInputStream();
Workbook rwb = Workbook.getWorkbook(stream);
Sheet rs = rwb.getSheet(0);
int rsRows = rs.getRows();
String[] as = new String[2];
StringBuffer errorBuffer = new StringBuffer();
List sqlList = new ArrayList();
String sql="";
sql = "DELETE FROM CJ_BK_TEMP_JK";
sqlList.add(sql);
for(int i = 0;i<rsRows;i++){
as[0] = "";
as[1] = "";
Cell c0 = rs.getCell(0,i);
as[0] = c0.getContents().trim();
Cell c1 = rs.getCell(1,i);
as[1] = c1.getContents().trim();
if(as[0].equals("") || as[0].length() != 12 || as[1].equals("") || as[1].length()>10){
if(errorBuffer.toString().equals("")){
errorBuffer.append("错误数据//r//n");
errorBuffer.append((i+1)+","+as[0]+","+as[1]+"//r//n");
}else{
errorBuffer.append((i+1)+","+as[0]+","+as[1]+"//r//n");
}
}else{
sql = "INSERT INTO CJ_BK_TEMP_JK(ZKZH,KCDM,KSLBDM,KSQ,ZCJ,STATUS) VALUES('"+as[0]+"','10018','"+kslbdm+"','"+ksq+"','"+as[1]+"','99')";
sqlList.add(sql);
}
}
rwb.close();
try{
DBUtil dbutil = new DBUtil();
dbutil.sqlTransactionList(sqlList);
}catch(DAONoRecordException e){
}catch(Exception e){
throw e;
}
return errorBuffer.toString();
}
}