📄 noticegoodsarriveaction.java
字号:
package com.test.struts.action;
import com.Hibernate.*;
import java.util.*;
import java.io.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.Hibernate.SessionFactory;
public class NoticeGoodsArriveAction extends Action {
private int total=0;
private int page=1;
private int size=10;
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
try{
request.setCharacterEncoding("GB2312");
}catch ( Exception e ){}
this.changePage();
HttpSession session=request.getSession();
Object ob=session.getAttribute("page");
if( ob!=null ){
try{
page = (Integer)ob;
}catch(Exception e){
System.out.println("Error in string.");
}
}
String act=(String)request.getParameter("act");
if( act!=null ){
if( act.equals("next") ){
page=page+1;
}
else if( act.equals("pri") )
page=page-1;
}
if( page<0 ) page=1;
if( page>total ) page=total;
response.setCharacterEncoding("UTF-8");
try {
PrintWriter writer =response.getWriter();
writer.write("<html>");
List goodsList = getGoodsList();
showPrintJS( response , goodsList );
showTalbe(response,goodsList);
writer.write("</html>");
}catch( Exception e ){
e.printStackTrace();
}
return null;
}
public List getGoodsList(){
try {
Session session=SessionFactory.currentSession();
Transaction tx=session.beginTransaction();
Query query=session.createQuery("from GoodsArrive goods order by goods.wtdh ");
query.setFirstResult( size*(page-1) );
query.setMaxResults( size );
List list=query.list();
tx.commit();
return list;
} catch (Exception e) {
System.out.print("Error In NoticeGoodsArriveAction.");
e.printStackTrace();
return null;
}
}
public void changePage(){
Session session=SessionFactory.currentSession();
Transaction tx=session.beginTransaction();
Query query=session.createQuery("from GoodsArrive goods order by goods.wtdh ");
List list=query.list();
tx.commit();
total = list.size();
}
public void showPrintJS(HttpServletResponse response,List goodsList){
response.setCharacterEncoding("UTF-8");
try {
PrintWriter writer =response.getWriter();
writer.println("<head><script language='javascript' type='text/javascript'>");
writer.println("function MakeExcel(){");
writer.println("var exApp = new ActiveXObject('Excel.Application');");
writer.println("var bk=exApp.Workbooks.Open('C:\\\\Program Files\\\\excel\\\\top.xls');");
writer.println("var topsheet = bk.Worksheets(1);");
writer.println("bk=null;");
writer.println("exApp=null;");
writer.write("var i,j;"
+"try {"
+" var xls = new ActiveXObject ( 'Excel.Application' );"
+"}catch(e) {"
+"alert( '要打印该表,您必须安装Excel电子表格软件,同时浏览器须使用“ActiveX 控件”,您的浏览器须允许执行控件。 请点击【帮助】了解浏览器设置方法!');"
+" return '';"
+"}");
writer.println();
writer.write("xls.visible =true;"
+"var xlBook = xls.Workbooks.Add;"
+"var xlsheet = xlBook.Worksheets(1);");
writer.println();
writer.println("xlsheet.Columns(\"A:J\").ColumnWidth =10;");
writer.println("mergesTable( xlsheet , 1 , 1 , 1 , 10 );");
writer.println("mergesTable( xlsheet , 4 , 1 , 7 , 1 );");
writer.println("mergesTable( xlsheet , 6 , 6 , 7 , 10 );");
writer.println("mergesTable( xlsheet , 2 , 2 , 2 , 4 );");
writer.println("mergesTable( xlsheet , 2 , 6 , 2 , 7 );");
writer.println("mergesTable( xlsheet , 2 , 9 , 2 , 10 );");
writer.println("mergesTable( xlsheet , 3 , 2 , 3 , 5 );");
writer.println("mergesTable( xlsheet , 3 , 7 , 3 , 10 );");
writer.println("mergesTable( xlsheet , 4 , 3 , 4 , 5 );");
writer.println("mergesTable( xlsheet , 4 , 7 , 4 , 10 );");
writer.println("mergesTable( xlsheet , 5 , 3 , 5 , 5 );");
writer.println("mergesTable( xlsheet , 5 , 7 , 5 , 10 );");
writer.println("mergesTable( xlsheet , 6 , 3 , 6 , 5 );");
writer.println("mergesTable( xlsheet , 7 , 3 , 7 , 5 );");
writer.println("mergesTable( xlsheet , 8 , 6 , 8 , 7 );");
writer.println("mergesTable( xlsheet , 8 , 8 , 8 , 9 );");
writer.println("mergesTable( xlsheet , 8 , 10 , 23 , 10 );");
writer.println("mergesTable( xlsheet , 9 , 6 , 9 , 7 );");
writer.println("mergesTable( xlsheet , 9 , 8 , 9 , 9 );");
writer.println("mergesTable( xlsheet , 10 , 6 , 10 , 7 );");
writer.println("mergesTable( xlsheet , 10 , 8 , 10 , 9 );");
writer.println("mergesTable( xlsheet , 11 , 6 , 11 , 7 );");
writer.println("mergesTable( xlsheet , 11 , 8 , 11 , 9 );");
writer.println("mergesTable( xlsheet , 12 , 6 , 12 , 7 );");
writer.println("mergesTable( xlsheet , 12 , 8 , 12 , 9 );");
writer.println("mergesTable( xlsheet , 13 , 6 , 13 , 7 );");
writer.println("mergesTable( xlsheet , 13 , 8 , 13 , 9 );");
writer.println("mergesTable( xlsheet , 14 , 6 , 14 , 7 );");
writer.println("mergesTable( xlsheet , 14 , 8 , 14 , 9 );");
writer.println("mergesTable( xlsheet , 15 , 6 , 15 , 7 );");
writer.println("mergesTable( xlsheet , 15 , 8 , 15 , 9 );");
writer.println("mergesTable( xlsheet , 16 , 6 , 16 , 7 );");
writer.println("mergesTable( xlsheet , 16 , 8 , 16 , 9 );");
writer.println("mergesTable( xlsheet , 17 , 6 , 17 , 7 );");
writer.println("mergesTable( xlsheet , 17 , 8 , 17 , 9 );");
writer.println("mergesTable( xlsheet , 18 , 6 , 18 , 7 );");
writer.println("mergesTable( xlsheet , 18 , 8 , 18 , 9 );");
writer.println("mergesTable( xlsheet , 19 , 1 , 19 , 5 );");
writer.println("mergesTable( xlsheet , 19 , 6 , 19 , 7 );");
writer.println("mergesTable( xlsheet , 19 , 8 , 19 , 9 );");
writer.println("mergesTable( xlsheet , 20 , 2 , 20 , 3 );");
writer.println("mergesTable( xlsheet , 21 , 2 , 21 , 3 );");
writer.println("mergesTable( xlsheet , 21 , 4 , 23 , 5 );");
writer.println("mergesTable( xlsheet , 21 , 6 , 23 , 9 );");
writer.println("mergesTable( xlsheet , 22 , 2 , 22 , 3 );");
writer.println("mergesTable( xlsheet , 23 , 2 , 23 , 3 );");
writer.println("mergesTable( xlsheet , 24 , 4 , 24 , 5 );");
writer.println("mergesTable( xlsheet , 24 , 7 , 24 , 8 );");
writer.println("xlsheet.Range(xlsheet.Cells(3,1), xlsheet.Cells(7,10)).BorderAround;");
writer.println("xlsheet.Columns.AutoFit;");
writer.println("xlsheet.Range( xlsheet.Cells(3,1),xlsheet.Cells(23,10)).Borders(3).Weight = 2;");
writer.println("xlsheet.Range( xlsheet.Cells(3,1),xlsheet.Cells(23,10)).Borders(4).Weight = 2;");
writer.println("xlsheet.Range( xlsheet.Cells(3,1),xlsheet.Cells(23,10)).Borders(1).Weight = 2;");
writer.println("xlsheet.Range( xlsheet.Cells(3,1),xlsheet.Cells(23,10)).Borders(2).Weight = 2;");
writer.println("copyStr( xlsheet , topsheet , 1 , 1 );");
writer.println("copyStr( xlsheet , topsheet , 2 , 1 );");
writer.println("copyStr( xlsheet , topsheet , 2 , 5 );");
writer.println("copyStr( xlsheet , topsheet , 2 , 8 );");
writer.println("copyStr( xlsheet , topsheet , 3 , 1 );");
writer.println("copyStr( xlsheet , topsheet , 3 , 6 );");
writer.println("copyStr( xlsheet , topsheet , 4 , 1 );");
writer.println("copyStr( xlsheet , topsheet , 4 , 2 );");
writer.println("copyStr( xlsheet , topsheet , 4 , 6 );");
writer.println("copyStr( xlsheet , topsheet , 5 , 2 );");
writer.println("copyStr( xlsheet , topsheet , 5 , 6 );");
writer.println("copyStr( xlsheet , topsheet , 6 , 2 );");
writer.println("copyStr( xlsheet , topsheet , 6 , 6 );");
writer.println("copyStr( xlsheet , topsheet , 7 , 2 );");
writer.println("copyStr( xlsheet , topsheet , 8 , 1 );");
writer.println("copyStr( xlsheet , topsheet , 8 , 2 );");
writer.println("copyStr( xlsheet , topsheet , 8 , 3 );");
writer.println("copyStr( xlsheet , topsheet , 8 , 4 );");
writer.println("copyStr( xlsheet , topsheet , 8 , 5 );");
writer.println("copyStr( xlsheet , topsheet , 8 , 6 );");
writer.println("copyStr( xlsheet , topsheet , 8 , 8 );");
writer.println("copyStr( xlsheet , topsheet , 8 , 10 );");
writer.println("copyStr( xlsheet , topsheet , 19 , 1 );");
writer.println("copyStr( xlsheet , topsheet , 20 , 1 );");
writer.println("copyStr( xlsheet , topsheet , 20 , 4 );");
writer.println("copyStr( xlsheet , topsheet , 20 , 6 );");
writer.println("copyStr( xlsheet , topsheet , 20 , 8 );");
writer.println("copyStr( xlsheet , topsheet , 21 , 1 );");
writer.println("copyStr( xlsheet , topsheet , 21 , 4 );");
writer.println("copyStr( xlsheet , topsheet , 21 , 6 );");
writer.println("copyStr( xlsheet , topsheet , 22 , 1 );");
writer.println("copyStr( xlsheet , topsheet , 23 , 1 );");
writer.println("copyStr( xlsheet , topsheet , 24 , 1 );");
writer.println("copyStr( xlsheet , topsheet , 24 , 3 );");
writer.println("copyStr( xlsheet , topsheet , 24 , 6 );");
writer.println("copyStr( xlsheet , topsheet , 24 , 9 );");
writer.println("writeData( xlsheet );");
writer.println("xls.UserControl = true;");
writer.println("xls=null;");
writer.println("xlBook=null;");
writer.println("xlsheet=null;");
writer.println("topsheet=null;");
writer.println("}");
writer.println("function copyStr( xlsheet , topsheet , row , col ){");
writer.println("xlsheet.Rows(row).RowHeight=topsheet.Rows(row).RowHeight;");
writer.println("xlsheet.Cells(row,col).HorizontalAlignment = topsheet.Cells(row,col).HorizontalAlignment;");
writer.println("xlsheet.Cells(row,col).VerticalAlignment = topsheet.Cells(row,col).VerticalAlignment;");
writer.println("xlsheet.Cells(row,col).Font.Size=topsheet.Cells(row,col).Font.Size;");
writer.println("xlsheet.Cells(row,col).Font.Name=topsheet.Cells(row,col).Font.Name;");
writer.println("xlsheet.Cells(row,col).Font.Color=topsheet.Cells(row,col).Font.Color;");
writer.println("xlsheet.Cells(row,col).value=topsheet.Cells(row,col).value;");
writer.println("}");
writer.println("function mergesTable( xlsheet , row1 , col1 , row2 , col2 ){");
writer.println("xlsheet.Range(xlsheet.Cells(row1,col1),xlsheet.Cells(row2,col2)).mergecells = true;");
writer.println("}");
writer.println("function writeData( xlsheet ){");
int i;
GoodsArrive goods;
for(i=9;i<19;i++){
if( goodsList.size()<i-8 )
break;
goods=(GoodsArrive)goodsList.get( i-9 );
writer.println();
writer.println("xlsheet.Cells(" + i + ",1).Value='" + goods.getWtdh() + "';");
writer.println("xlsheet.Cells(" + i + ",2).Value='" + goods.getKh() + "';");
writer.println("xlsheet.Cells(" + i + ",3).Value='" + goods.getKhzl() + "';");
writer.println("xlsheet.Cells(" + i + ",4).Value='" + goods.getSljg() + "';");
writer.println("xlsheet.Cells(" + i + ",5).Value='" + goods.getSlrq() + "';");
writer.println("xlsheet.Cells(" + i + ",6).Value='" + "null" + "';");
writer.println("xlsheet.Cells(" + i + ",7).Value='" + "null" + "';");
}
writer.println("}");
writer.println("</script>") ;
writer.println("</head>");
} catch (IOException e) {
e.printStackTrace();
}
}
public void showTalbe(HttpServletResponse response,List goodsList){
try{
response.setCharacterEncoding("UTF-8");
PrintWriter writer =response.getWriter();
writer.write("<body><center><h3>到货入库通知单</h3></center>");
writer.write("<table width=90% height=80% align=center border=0>");
writer.write("<tr>");
writer.write("<td height=10>委托单号</td>");
writer.write("<td>客户</td>");
writer.write("<td>客户指令</td>");
writer.write("<td>受理机构</td>");
writer.write("<td>受理日期</td>");
writer.write("</tr>");
writer.write("<tr><td height=1 bgcolor=black colspan=10></td></tr>");
GoodsArrive goods;
for ( int i=0; i<goodsList.size(); i++ ){
goods=(GoodsArrive)goodsList.get(i);
writer.write("<tr>");
writer.write("<td height=10>" + goods.getWtdh() + "</td>" );
writer.write("<td height=10>" + goods.getKh() + "</td>" );
writer.write("<td height=10>" + goods.getKhzl() + "</td>" );
writer.write("<td height=10>" + goods.getSljg() + "</td>" );
writer.write("<td height=10>" + goods.getSlrq() + "</td>" );
writer.write("</tr>");
writer.write("<tr><td height=1 bgcolor=black colspan=10></td></tr>");
}
response.getWriter().write("<tr><td></td></tr>");
writer.write("</table>");
writer.write("<table align=center>");
writer.write("<tr><td>");
writer.write("<input type='button' value='打印此页' onclick=MakeExcel() />");
writer.write("</td></tr>");
writer.write("</table>");
writer.write("<table>");
writer.write("<tr><td>");
writer.write("共" + total + "条记录 ");
if( page<=1 )
writer.write("上一页");
else
writer.write("<a href=?act=pri>上一页</a>");
if( page*size>=total )
writer.write("下一页");
else
writer.write("<a href=?act=next>下一页</a>");
writer.write("</td></tr>");
writer.write("</table>");
writer.write("<table align=center><tr><td>");
writer.write("<a href=in.jsp target=_blank>添加</a>");
writer.write("</td></tr></table>");
writer.write("</body>");
}catch (Exception e){
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -