免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1044 | 回复: 0
打印 上一主题 下一主题

分享一下,希望对大家有帮助 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-11-30 21:22 |只看该作者 |倒序浏览

一个页面的代码,自己的。
BjcsbdxxAction.java
package com.wanlong.dvb.sms.struts.zygl.csgl;
import org.apache.struts.action.*;
import javax.servlet.http.*;
public class BjcsbdxxAction
    extends Action {
  public ActionForward execute(ActionMapping actionMapping,
                               ActionForm actionForm,
                               HttpServletRequest httpServletRequest,
                               HttpServletResponse httpServletResponse) {
    /**@todo: complete the business logic here, this is just a skeleton.*/
    BjcsbdxxActionForm bjcsbdxxActionForm = (BjcsbdxxActionForm) actionForm;
    BjcsbdxxBean bjcsbdxxBean = new BjcsbdxxBean();
    Csbdxx csbdxx = bjcsbdxxActionForm.getCsbdxx();
    String bdbh=bjcsbdxxBean.createBdbh("D","resourcedamage");
    csbdxx = bjcsbdxxActionForm.getCsbdxx();
    try {
      bjcsbdxxBean.bjcsbdxx(csbdxx,bdbh);
      bjcsbdxxBean.bjcsbdxx2(csbdxx,bdbh);
    }
    catch (Exception e) {e.printStackTrace();
    } httpServletRequest.setAttribute("bdbh",bdbh);
    return (actionMapping.findForward("forward"));
  }
}
BjcsbdxxActionForm.java
package com.wanlong.dvb.sms.struts.zygl.csgl;
import org.apache.struts.action.*;
import javax.servlet.http.*;
public class BjcsbdxxActionForm
    extends ActionForm {
  private Csbdxx csbdxx = new Csbdxx();
  public Csbdxx getCsbdxx() {
    return csbdxx;
  }
  public void setCsbdxx(Csbdxx csbdxx) {
    this.csbdxx = csbdxx;
  }
  public ActionErrors validate(ActionMapping actionMapping,
                               HttpServletRequest httpServletRequest) {
    /**@todo: finish this method, this is just the skeleton.*/
    return null;
  }
}
BjcsbdxxBean.java
package com.wanlong.dvb.sms.struts.zygl.csgl;
import java.sql.*;
import java.util.*;
import com.wanlong.dvb.sms.util.*;
import com.wanlong.dvb.sms.db.helper.*;
import java.util.Date.*;
import java.text.*;
public class BjcsbdxxBean {
  public BjcsbdxxBean() {
  }
  private Connection conn;
//从数据库的库房表中取数据
  public Collection getKufang() throws java.sql.SQLException {
    ResultSet rs = null;
    Statement stmt = null;
    Collection ret = null;
    try {
      conn = DatabaseConn.getConnection();
      stmt = conn.createStatement();
      rs = stmt.executeQuery(
          "select id,name from kufang");
      ret = new ArrayList();
      while (rs.next()) {
        Kufang kf = new Kufang();
        kf.setId(rs.getString("id"));
        kf.setName(rs.getString("name"));
        ret.add(kf);
      }
    }
    catch (SQLException e) {
    }
    catch (Exception e) {}
    finally {
      DatabaseConn.closeResultSetSilent(rs);
      DatabaseConn.closeStatementSilent(stmt);
      DatabaseConn.closeConnectionSilent(conn);
    }
    return ret;
  }
//从数据库的处理人表中取数据
  public Collection getChuliren() throws java.sql.SQLException {
    ResultSet rs = null;
    Statement stmt = null;
    Collection ret = null;
    try {
      conn = DatabaseConn.getConnection();
      stmt = conn.createStatement();
      rs = stmt.executeQuery
          ("select id,name from chuliren");
      ret = new ArrayList();
      while (rs.next()) {
        Chuliren chuliren = new Chuliren();
        chuliren.setId(rs.getString("id"));
        chuliren.setName(rs.getString("name"));
        ret.add(chuliren);
      }
    }
    catch (SQLException e) {
    }
    catch (Exception e) {}
    finally {
      DatabaseConn.closeResultSetSilent(rs);
      DatabaseConn.closeStatementSilent(stmt);
      DatabaseConn.closeConnectionSilent(conn);
    }
    return ret;
  }
  //生成表单编号
  public String createBdbh(String prefix, String table_name) {
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    String bdbh = null;
    try {
      conn = DatabaseConn.getConnection();
      stmt = conn.createStatement();
      rs = stmt.executeQuery("select max(formid) from " + table_name +
                             " where formid like '" + prefix +
                             StringDate.getTodaytimeString("yyyyMMdd") + "%'");
      System.out.print("select max(formid) from " + table_name +
                       " where formid like '" + prefix +
                       StringDate.getTodaytimeString("yyyyMMdd") + "%'");
      EntityNumbering entityNumbering1 = new EntityNumbering();
      while (rs.next()) {
        String max_formid = rs.getString(1); //"E20050315002";
        System.out.print(max_formid);
        if (max_formid == null)break;
        bdbh = prefix + StringDate.getTodaytimeString("yyyyMMdd");
        bdbh +=
            entityNumbering1.getStringNum(1 +
                                          Integer.parseInt(max_formid.
            substring(max_formid.length() - 3, max_formid.length())), 3);
        System.out.print(bdbh);
        return bdbh;
      }
      bdbh = prefix + StringDate.getTodaytimeString("yyyyMMdd") + "001";
      System.out.print(bdbh);
      return bdbh;
    }
    catch (SQLException se) {
      se.printStackTrace();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    finally {
      try {
        if (rs != null)
          rs.close();
        if (stmt != null)
          stmt.close();
        if (!conn.isClosed() && conn != null)
          conn.close();
      }
      catch (SQLException ee) {
        ee.printStackTrace();
      }
    }
    return null;
  }
  java.util.Date myDate = new java.util.Date();
  String str = new SimpleDateFormat("yyyy-MM-dd").format(myDate);
//向resourcedamage中写
  public void bjcsbdxx(Csbdxx csbdxx,String bdbh) throws Exception {
    conn = DatabaseConn.getConnection();
    Statement stmt = null;
    stmt = conn.createStatement();
    try {
      stmt.executeUpdate
          ("insert into resourcedamage( formid, storeno ,status, executor, createdate,remark )values('" +
          bdbh
           + "','" + csbdxx.getKf() + "','草稿','" + csbdxx.getClr() + "','" + str +
           "','" +
           csbdxx.getBz() + "')");
    }
    catch (SQLException e) {
      e.printStackTrace();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    finally {
      DatabaseConn.closeStatementSilent(stmt);
      DatabaseConn.closeConnectionSilent(conn);
    }
  }
  //向formquery中写
  public void bjcsbdxx2(Csbdxx csbdxx,String bdbh) throws Exception {
      conn = DatabaseConn.getConnection();
      Statement stmt = null;
      stmt = conn.createStatement();
      try {System.out.print("insert into formquery( formid, storeno ,status, creator, formtype )values('" +
             bdbh
             + "','" + csbdxx.getKf() + "','草稿','" + csbdxx.getClr() + "','残损单')"
);
        stmt.executeUpdate
            ("insert into formquery( formid, storeno ,status, creator, formtype )values('" +
             bdbh
             + "','" + csbdxx.getKf() + "','草稿','" + csbdxx.getClr() + "','残损单')");
      }
      catch (SQLException e) {
        e.printStackTrace();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
      finally {
        DatabaseConn.closeStatementSilent(stmt);
        DatabaseConn.closeConnectionSilent(conn);
      }
    }
}
Bjcsbdxx.jsp
http://java.sun.com/jstl/core
" prefix="c" %>
http://java.sun.com/jstl/core_rt
" prefix="c_rt" %>
编辑残损表单信息
  
   
        编辑残损表单信息(表单编号由系统自动生成)>>
      表单编号
      
      
      表单状态
       草稿
   
      处理人
      
        
         
      库房
      
        
      
        备注
      
   
      
         
        
      
   
  


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/11919/showart_59515.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP