- 论坛徽章:
- 0
|
一个页面的代码,自己的。
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 |
|