首页>代码>JSP+Struts2开发免费商品库存后台管理系统源代码下载>/库存管理系统/InventoryManageSystem/src/com/action/InGoodsAction.java
package com.action; import java.io.File; import java.io.FileInputStream; import java.sql.Connection; import java.sql.ResultSet; import java.util.Date; import javax.servlet.http.HttpServletRequest; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.usermodel.Workbook; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; import com.dao.InGoodsDao; import com.dao.SaveGoodsDao; import com.model.InGoods; import com.model.PageBean; import com.util.DateUtil; import com.util.DbUtil; import com.util.ExcelUtil; import com.util.JsonUtil; import com.util.ResponseUtil; import com.util.StringToInt; import com.util.StringUtil; public class InGoodsAction extends ActionSupport{ private InGoods ingoods; private String page; private String rows; private String price; private String intime; private String innumber; private String inothers; HttpServletRequest request; private String delIds; private File ingoodsUploadFile; private String inid; private String idgoods; private String intime2; private String intime1; public String getInnumber() { return innumber; } public String getInid() { return inid; } public void setInid(String inid) { this.inid = inid; } public String getIdgoods() { return idgoods; } public void setInnumber(String innumber) { this.innumber = innumber; } public void setIdgoods(String idgoods) { this.idgoods = idgoods; } public String getPrice() { return price; } public void setPrice(String price) { this.price = price; } public String getIntime() { return intime; } public void setIntime(String intime) { this.intime = intime; } public String getIntime1() { return intime1; } public void setIntime1(String intime1) { this.intime1 = intime1; } public String getIntime2() { return intime2; } public void setIntime2(String intime2) { this.intime2 = intime2; } public HttpServletRequest getRequest() { return request; } public void setRequest(HttpServletRequest request) { this.request = request; } public InGoods getIngoods() { return ingoods; } public void setIngoods(InGoods ingoods) { this.ingoods = ingoods; } public String getPage() { return page; } public void setPage(String page) { this.page = page; } public String getRows() { return rows; } public void setRows(String rows) { this.rows = rows; } public String getDelIds() { return delIds; } public void setDelIds(String delIds) { this.delIds = delIds; } public File getIngoodsUploadFile() { return ingoodsUploadFile; } public void setIngoodsUploadFile(File ingoodsUploadFile) { this.ingoodsUploadFile = ingoodsUploadFile; } public String getInothers() { return inothers; } public void setInothers(String inothers) { this.inothers = inothers; } DbUtil dbUtil = new DbUtil(); InGoodsDao ingoodsdao=new InGoodsDao(); public String execute() throws Exception { PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows)); Connection con = null; if (ingoods == null) { ingoods = new InGoods(); } if (StringUtil.isNotEmpty(idgoods)) { ingoods.setIdgoods(Integer.parseInt(idgoods)); }else{ ingoods.setIdgoods(-1); } if (StringUtil.isNotEmpty(price)) { ingoods.setPrice(Float.valueOf(price)); }else{ ingoods.setPrice(-1); } if (StringUtil.isNotEmpty(innumber)) { ingoods.setInnumber(Integer.parseInt(innumber)); }else{ ingoods.setInnumber(-1); } try{ con=dbUtil.getCon(); JSONObject result=new JSONObject(); JSONArray jsonArray=JsonUtil.formatRsToJsonArray(ingoodsdao.InGoodsList(con, pageBean,ingoods,intime1,intime2)); int total=ingoodsdao.InGoodsCount(con,ingoods,intime1,intime2); result.put("rows", jsonArray); result.put("total", total); ResponseUtil.write(ServletActionContext.getResponse(), result); } catch (Exception e) { e.printStackTrace(); } finally { dbUtil.closeCon(con); } return null; } public String delete() throws Exception { Connection con = null; try { con = dbUtil.getCon(); JSONObject result = new JSONObject(); int delNums = ingoodsdao.InGoodsDelete(con, delIds); if (delNums > 0) { result.put("success", "true"); result.put("delNums", delNums); } else { result.put("errorMsg", "删除失败"); } ResponseUtil.write(ServletActionContext.getResponse(), result); } catch (Exception e) { e.printStackTrace(); } finally { try { dbUtil.closeCon(con); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; } SaveGoodsDao savegoodsdao=new SaveGoodsDao(); public String save() throws Exception { if (StringUtil.isNotEmpty(inid)) { ingoods.setInid(Integer.parseInt(inid)); } Connection con = null; try { con = dbUtil.getCon(); int saveNums = 0; JSONObject result = new JSONObject(); if (StringUtil.isNotEmpty(inid)) { savegoodsdao.updateHaveIdin(con, ingoods); saveNums = ingoodsdao.InGoodsModify(con, ingoods); } else { savegoodsdao.updatetotalin(con, ingoods); saveNums = ingoodsdao.InGoodsAdd(con, ingoods); ingoodsdao.InGoodsAdd1(con, ingoods); } if (saveNums > 0) { result.put("success", "true"); } else { result.put("success", "true"); result.put("errorMsg", "保存失败"); } ResponseUtil.write(ServletActionContext.getResponse(), result); } catch (Exception e) { e.printStackTrace(); } finally { try { dbUtil.closeCon(con); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; } public void setServletRequest(HttpServletRequest request) { // TODO Auto-generated method stub this.request = request; } public String export() throws Exception { Connection con =null; if (ingoods == null) { ingoods = new InGoods(); } if (StringUtil.isNotEmpty(idgoods)) { ingoods.setIdgoods(Integer.parseInt(idgoods)); }else{ ingoods.setIdgoods(-1); } if (StringUtil.isNotEmpty(price)) { ingoods.setPrice(Float.valueOf(price)); }else{ ingoods.setPrice(-1); } if (StringUtil.isNotEmpty(innumber)) { ingoods.setInnumber(Integer.parseInt(innumber)); }else{ ingoods.setInnumber(-1); } try{ con=dbUtil.getCon(); ResultSet rs=ingoodsdao.InGoodsList(con, null, ingoods,intime1,intime2); Workbook wb =ExcelUtil.fillExcelDataWithTemplate(rs, "ingoods.xls"); ResponseUtil.export(ServletActionContext.getResponse(), wb, "利用模板导出exel.xls"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { dbUtil.closeCon(con); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; } public String upload()throws Exception{ POIFSFileSystem fs =new POIFSFileSystem(new FileInputStream(ingoodsUploadFile)); HSSFWorkbook wb =new HSSFWorkbook(fs); HSSFSheet hssfSheet =wb.getSheetAt(0); if(hssfSheet!=null){ for(int rowNum=1;rowNum<=hssfSheet.getLastRowNum();rowNum++){ HSSFRow hssfRow =hssfSheet.getRow(rowNum); if(hssfRow==null){ continue; } InGoods ingoods =new InGoods(); ingoods.setInid(StringToInt.StringToInt(ExcelUtil.formatCell(hssfRow.getCell(0)))); ingoods.setIdgoods(StringToInt.StringToInt(ExcelUtil.formatCell(hssfRow.getCell(1)))); //System.out.println(hssfRow.getCell(2).getDateCellValue()); ingoods.setPrice(Float.valueOf(ExcelUtil.formatCell(hssfRow.getCell(2))));//小米 Date date=hssfRow.getCell(3).getDateCellValue(); //System.out.println(DateUtil.formatDate(date, "yyyy-MM-dd")); ingoods.setIntime(DateUtil.formatString(DateUtil.formatDate(date, "yyyy-MM-dd"),"yyyy-MM-dd")); ingoods.setInnumber(StringToInt.StringToInt(ExcelUtil.formatCell(hssfRow.getCell(4)))); ingoods.setInothers(ExcelUtil.formatCell(hssfRow.getCell(5))); Connection con=null; try{ con=dbUtil.getCon(); int saveNums = 0; JSONObject result = new JSONObject(); savegoodsdao.updatetotalin(con, ingoods); saveNums = ingoodsdao.InGoodsAdd(con, ingoods); ingoodsdao.InGoodsAdd1(con, ingoods); if (saveNums > 0) { result.put("success", "true"); } else { result.put("success", "true"); result.put("errorMsg", "上传失败"); } ResponseUtil.write(ServletActionContext.getResponse(), result); }catch(Exception e){ e.printStackTrace(); }finally{ dbUtil.closeCon(con); } } } JSONObject result =new JSONObject(); result.put("success","true"); ResponseUtil.write(ServletActionContext.getResponse(), result); return null; } }
最近下载更多
微信网友_6442962125967360 LV2
2023年5月9日
teamdragon LV6
2023年4月13日
sandihha LV9
2022年11月10日
WM2020 LV4
2022年6月20日
jwfadacai LV8
2022年4月30日
skook7 LV2
2022年4月20日
邬松桥 LV11
2022年4月5日
yscccc LV1
2022年2月22日
哈哈哈哈哈a LV10
2022年2月15日
wanglinddad LV55
2021年12月12日
最近浏览更多
wangqi_sheng LV1
8月14日
liulian666 LV2
7月22日
ma406805131 LV15
6月29日
王佩琪 LV3
6月14日
lilitu LV6
5月26日
hongdongdong LV14
5月7日
微信网友_6512020493586432 LV2
4月9日
微信网友_6904205432819712 LV1
3月12日
FishYu11
1月19日
暂无贡献等级
hxy19991216 LV4
2023年12月29日