OutPrint.java
上传用户:u_thks
上传日期:2022-07-31
资源大小:1910k
文件大小:12k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

Java

  1. /*
  2.  * Created on 2005-7-6
  3.  * Made In GamVan
  4.  */
  5. package com.gamvan.html;
  6. import java.text.ParseException;
  7. import com.gamvan.tools.FormatDateTime;
  8. /**
  9.  * @author GamVan by 我容易么我
  10.  * Powered by GamVan.com
  11.  */
  12. public class OutPrint {
  13.     /**
  14.      * 带CSS居中打印文字提示信息
  15.      * @param txt
  16.      * @param urls
  17.      * @param i
  18.      * @return
  19.      * 2005-11-7 6:28:24 Made In GamVan
  20.      * com.gamvan.html
  21.      */
  22.     public static String prtCenter(String txt, String urls, int i){
  23.         String temp;
  24.         temp = "<SCRIPT type=text/javascript>function doTrans(filterCode){imgObj.filters[0].apply();oImg.style.filter = filterCode;imgObj.filters[0].play();}</SCRIPT>";
  25.         temp =  temp + "<br><br><center> ";
  26.         switch(i){ 
  27.             case 1:
  28.                 temp = temp + "<a href="+ urls +">";
  29.                 break;
  30.             case 2:
  31.                 temp = temp + "<a href=javascript:history.back()>";
  32.                 break;
  33.         }
  34.         temp = temp + "<span style="font-size:14px; font-family:Verdana, Arial, 宋体; line-height: 19px;" >";
  35.         temp = temp + txt + "</span>";
  36.         if(i > 0){
  37.             temp = temp + "</a>";
  38.         }
  39.         
  40.         temp = temp + "<br>"+
  41.         "<span id="imgObj" onmouseleave='doTrans("gray")'  style="FILTER: progid:DXImageTransform.Microsoft.Fade(Overlap=1.00); WIDTH: 100% ""+
  42.         "  onmouseenter='doTrans("")'>"+
  43.         "<a href=# target=_blank><img id="oImg" style="FILTER: gray" alt="技术支持" src="/club/GVimgs/gamvan.gif" border=0></a>"+
  44.         "</span></center><br><br>";
  45.         return temp;
  46.     }
  47.     
  48.     /**
  49.      * 网页文本框
  50.      * @param formName
  51.      * @param cols
  52.      * @param rows
  53.      * @param txt
  54.      * @return
  55.      * 2005-11-7 6:28:10 Made In GamVan
  56.      * com.gamvan.html
  57.      */
  58.     public static String textArea(String formName, int cols, int rows, String txt){
  59.         StringBuffer sb = new StringBuffer();
  60.         sb.append("<textarea name=""+ formName +"" id=""+ formName +"" cols=""+ cols +"" rows=""+ rows +"" onkeydown="keyForm();">");
  61.         sb.append(txt);
  62.         sb.append("</textarea><script language="javascript">gv_textarea(""+ formName +"","+ cols +","+ rows +");</script>");
  63.         return sb.toString();
  64.     }
  65.     
  66.     
  67.     /**
  68.      * 分页Html
  69.      * @param totalCount 数据总数
  70.      * @param pageNum 每页显示数量
  71.      * @param iPage 当前页
  72.      * @param url 
  73.      * @return
  74.      */
  75.     public static String pageJump(int totalCount, int pageNum, int iPage, String url){
  76.         if(iPage<1){
  77.             iPage = 1;
  78.         }
  79.         if(totalCount<=0){
  80.             return "";
  81.         }
  82.         int iPage1=0, iPage2=0;
  83.         int totalPage = 0; //总页数
  84.         if(totalCount%pageNum!=0){
  85.             totalPage = totalCount/pageNum + 1;
  86.         }else{
  87.             totalPage = totalCount/pageNum;
  88.         }
  89.         StringBuffer sb = new StringBuffer();
  90.         sb.append("<table height="25" border="0" cellpadding="2" cellspacing="1" class="tab"><tr class="tab1">");
  91.         sb.append("<td class="tab">&nbsp;<strong>");
  92.         sb.append(totalPage);
  93.         sb.append("</strong>&nbsp;</td>");  
  94.         sb.append("<td align="center">");
  95.         sb.append("&nbsp;<a title="返回首页" href="" + url + "iPage=1">&lt;&lt;</a>&nbsp;");
  96.         sb.append("</td>");
  97.         sb.append("<td align="center">");
  98.         sb.append("<a title="返回上一页" href="" + url + "iPage=" + (iPage-1) + "">&lt;</a>&nbsp;");
  99.         sb.append("</td>");
  100.         if(iPage>=10){
  101.             iPage2=iPage+8;
  102.             iPage1=iPage-1;
  103.             if(iPage2>totalPage){
  104.                 iPage2=totalPage;
  105.                 iPage1=totalPage-9;
  106.             }
  107.         }else{
  108.             if(totalPage>10){
  109.                 iPage2=10;
  110.             }else{
  111.                 iPage2=totalPage;
  112.             }
  113.             iPage1=1;
  114.         }
  115.         for(int i=iPage1;i<=iPage2;i++){
  116.             if(i==iPage){
  117.             sb.append("<td align="center" class="tab3">");
  118.                 sb.append("&nbsp;<a href="" + url + "iPage=" + i + "">");
  119.                 sb.append("<span style=color:#bb0000><strong>"+ i +"</strong></span></a>&nbsp;");
  120.                 sb.append("</td>");
  121.             }else{
  122.                 sb.append("<td align="center"> ");
  123.                 sb.append("&nbsp;<a href="" + url + "iPage=" + i + "">");
  124.                 sb.append("<strong>" + i + "</strong></a>&nbsp; ");
  125.                 sb.append("</td>");
  126.             }
  127.         }
  128.         sb.append("<td align="center">");
  129.         sb.append("&nbsp;<a title="跳到下一页" href="" + url + "iPage=" + (iPage+1) + "">&gt;</a>");
  130.         sb.append("</td>");
  131.         sb.append("<td align="center">");
  132.         sb.append("&nbsp;<a title="跳到尾页" href="" + url + "iPage=" + totalPage + "">&gt;&gt;</a>");
  133.         sb.append("</td>");
  134.         sb.append("</table>");
  135.         return sb.toString();
  136.         }
  137.     
  138.    public static String pageJump2(int totalPage, int pageNum, int iPage, String url){
  139.         
  140.         if(totalPage<=0){
  141.             return "";
  142.         }
  143.         int iPage1=0, iPage2=0;
  144.         
  145.         StringBuffer sb = new StringBuffer();
  146.         sb.append("<table height="25" border="0" cellpadding="2" cellspacing="1" class="tab"><tr class="tab1">");
  147.         sb.append("<td class="tab">&nbsp;<strong>");
  148.         sb.append(totalPage);
  149.         sb.append("</strong>&nbsp;</td>");  
  150.         sb.append("<td align="center">");
  151.         sb.append("&nbsp;<a title="返回首页" href="" + url + "iPage=1">&lt;&lt;</a>&nbsp;");
  152.         sb.append("</td>");
  153.         sb.append("<td align="center">");
  154.         sb.append("<a title="返回上一页" href="" + url + "iPage=" + (iPage-1) + "">&lt;</a>&nbsp;");
  155.         sb.append("</td>");
  156.         if(iPage>=10){
  157.             iPage2=iPage+8;
  158.             iPage1=iPage-1;
  159.             if(iPage2>totalPage){
  160.                 iPage2=totalPage;
  161.                 iPage1=totalPage-9;
  162.             }
  163.         }else{
  164.             if(totalPage>10){
  165.                 iPage2=10;
  166.             }else{
  167.                 iPage2=totalPage;
  168.             }
  169.             iPage1=1;
  170.         }
  171.         for(int i=iPage1;i<=iPage2;i++){
  172.             if(i==iPage){
  173.             sb.append("<td align="center" class="tab3">");
  174.                 sb.append("&nbsp;<a href="" + url + "iPage=" + i + "">");
  175.                 sb.append("<span style=color:#bb0000><strong>"+ i +"</strong></span></a>&nbsp;");
  176.                 sb.append("</td>");
  177.             }else{
  178.                 sb.append("<td align="center"> ");
  179.                 sb.append("&nbsp;<a href="" + url + "iPage=" + i + "">");
  180.                 sb.append("<strong>" + i + "</strong></a>&nbsp; ");
  181.                 sb.append("</td>");
  182.             }
  183.         }
  184.         sb.append("<td align="center">");
  185.         sb.append("&nbsp;<a title="跳到下一页" href="" + url + "iPage=" + (iPage+1) + "">&gt;</a>");
  186.         sb.append("</td>");
  187.         sb.append("<td align="center">");
  188.         sb.append("&nbsp;<a title="跳到尾页" href="" + url + "iPage=" + totalPage + "">&gt;&gt;</a>");
  189.         sb.append("</td>");
  190.         sb.append("</table>");
  191.         return sb.toString();
  192.         }
  193.     
  194.    
  195.    /**
  196.     * 定制页面时间输出格式
  197.     * @param sb
  198.     * @return
  199.     * 2005-11-7 5:59:25 Made In GamVan
  200.     * com.gamvan.html
  201.     */
  202.     public static String isDateHtml(String sb){
  203.         if(sb==null || sb.equals("")){
  204.             return "";
  205.         }
  206.         String d = "";
  207.         String t = "";
  208.         sb = sb.replace(".0","");
  209.         d = sb.substring(0, sb.indexOf(" ")); /*取年月*/
  210.         t = sb.substring(sb.indexOf(" ")+1, sb.length()-3); /*取时间去掉秒数*/
  211.         String ts=""; 
  212.         boolean isAfter;
  213.         try{
  214.          String now = FormatDateTime.formatDateTime("yyyy-MM-dd");
  215.          isAfter = FormatDateTime.dateCompare(d, now);
  216.             if(!isAfter){ /* 今天 */
  217.              d = d.substring(2, d.length());
  218.                 ts=("<span style="font-size: 12px; color:#cc0000;font-weight: bold;">今天</span> ");
  219.                 ts+=(" <span style="color:#990066">"+t);  
  220.                 ts+=("</span>"); 
  221.              }else{
  222.               /* 计算昨天 */
  223.               ts = FormatDateTime.dateAdd("d",-1); /* 返回间隔一天后的时候 */
  224.               ts = ts.substring(0, 11); /* 取年月日 */
  225.               isAfter = FormatDateTime.dateCompare(d, ts);
  226.               if(!isAfter){
  227.                     d = d.substring(2, d.length());
  228.                     ts=("<span style="font-size: 12px; color:#006600;font-weight: bold;">昨天</span> ");
  229.                     ts+=(" <span style="color:#990066">"+t);  
  230.                     ts+=("</span>");  
  231.               }else{
  232.                      /* 计算前天 */
  233.                   ts = FormatDateTime.dateAdd("d",-2); /* 返回间隔两天后的时候 */
  234.                   ts = ts.substring(0, 11); /* 取年月日 */
  235.                   isAfter = FormatDateTime.dateCompare(d, ts);
  236.                   if(!isAfter){
  237.                         d = d.substring(2, d.length());
  238.                         ts=("<span style="font-size: 12px; color:#2A00FF;font-weight: bold;">前天</span> ");
  239.                         ts+=(" <span style="color:#990066">"+t);  
  240.                         ts+=("</span>");  
  241.                   }else{
  242.                  d = d.substring(2, d.length());
  243.                  ts=(d+ " <span style="color:#990066">" + t);
  244.           ts+=("</span>");
  245.                   }
  246.               }
  247.             }
  248.         }catch(Exception e){
  249.             
  250.         }
  251.         return ts;       
  252.     }
  253.     
  254.     public static String isDateHtml2(String sb, String format){
  255.         if(sb==null || sb.equals("")){
  256.             return "";
  257.         }
  258.         String d = "";
  259.         String t = "";
  260.         sb = sb.replace(".0","");
  261.         d = sb.substring(0, sb.indexOf(" "));
  262.         t = sb.substring(sb.indexOf(" ")+1, sb.length());
  263.         String ts=""; 
  264.         boolean isAfter;
  265.         try{
  266.             java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format);
  267.             String isDate = sdf.format(new java.util.Date());   
  268.             java.util.Date date1 ;
  269.             java.util.Date date0 ;
  270.             ts= (d);
  271.             date1 = sdf.parse(ts);
  272.             date0 = sdf.parse(isDate);
  273.             isAfter = date0.after(date1);   
  274.             if(!isAfter){
  275.                 ts=("<span style="font-size: 12px; color:#cc0000;font-weight: bold;">今天</span> ");
  276.                 ts+=(" <span style=color:#990066>"+t);  
  277.                 ts=(ts.substring(0,(ts.length()-3)));
  278.                 ts+=("</span>");                
  279.             }else{
  280.                ts+=(" <span style=color:#990066>"+t);
  281.                ts=(ts.substring(2,(ts.length()-3)));
  282.                ts+=("</span>");
  283.             }
  284.             //this.isAfter = isAfter;
  285.         }catch(ParseException e){
  286.             
  287.         }
  288.         return ts;       
  289.     }
  290.     
  291.     /**
  292.      * 不显示时间
  293.      * @param sb
  294.      * @param format
  295.      * @return
  296.      * 2005-11-7 6:29:48 Made In GamVan
  297.      * com.gamvan.html
  298.      */
  299.     public static String isDateHtml3(String sb, String format){
  300.         if(sb==null || sb.equals("")){
  301.             return "";
  302.         }
  303.         String d = "";
  304.         String t = "";
  305.         sb = sb.replace(".0","");
  306.         d = sb.substring(0, sb.indexOf(" "));
  307.         t = sb.substring(sb.indexOf(" ")+1, sb.length());
  308.         String ts=""; 
  309.         boolean isAfter;
  310.         try{
  311.             java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format);
  312.             String isDate = sdf.format(new java.util.Date());   
  313.             java.util.Date date1 ;
  314.             java.util.Date date0 ;
  315.             ts= (d);
  316.             date1 = sdf.parse(ts);
  317.             date0 = sdf.parse(isDate);
  318.             isAfter = date0.after(date1);   
  319.             if(!isAfter){
  320.                 ts=("<span style="font-size: 12px;color:#cc0000;font-weight: bold;">今天</span> ");
  321.             }else{
  322.                 ts=d;
  323.             }
  324.         }catch(ParseException e){
  325.             
  326.         }
  327.         return ts;       
  328.     }
  329. }