package park.jsp.reportfill;
import javax.servlet.http.HttpServletRequest;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.SQLException;
import park.jsp.main.ConnectDB;
import park.jsp.common.TableNewId;
import javax.servlet.http.HttpSession;
import java.util.Date;
import park.jsp.common.DateHandle;
/**
* <p>Title: </p>
* <p>Description:修改和存储登记卡相关信息 </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author 熊炼
* @version 1.0
*/
public class Register_Refer
{
/**
* 此程序需要在scope中额外获取的参数有:type(对象类型)、message(操作类型)、f_emp_name(用户名)
* 特别:1.操作类型为modify,需要旧的t_bas_*表中所有可更改参数 2.对象类型为动植物,则需要f_k,f_s,f_classno,f_py
* @param request
* @return String(操作信息字段)
*/
public static String main(HttpServletRequest request,HttpSession session)
{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
//连接数据库
conn=ConnectDB.connect();
stmt=conn.createStatement();
// String f_name, f_k_classname,f_s_classname,f_s_ldm,f_j_classname,f_xx,f_cd,f_layer,
// f_ldm,f_bhc,f_fzcs,f_szxz ,f_ms,f_yt,f_area,f_yy,v_message,v_type,v_tablename;
String f_name, f_k,f_s,f_classno,f_xx,f_cd,f_layer,f_py,
f_ldm,f_bhc,f_fzcs,f_szxz ,f_ms,f_yt,f_area,f_yy,v_message,v_type,v_tablename;
v_message = request.getParameter("message"); //判断消息字段,modify修改,create创建,delete删除
v_type=(String)request.getAttribute("type");//判断类型(plant植物,animal是动物...)
//植物不同字段
f_ms=request.getParameter("t_ms");
f_yt=request.getParameter("t_yt");
f_area=request.getParameter("t_area");
f_yy=request.getParameter("t_yy");
//执行数据库操作
String rrSql="";
int v_flag=0;//v_flag为数据操作是否成功的标志,1为成功,0为失败
StringBuffer sb=null;
//判断对象类型
if("animal".equals(v_type))
{
//获取t_bas_animal表中的所有字段(除f_id)
//获得不能更改的字段
f_name=request.getParameter("t_name");
f_k=(String)request.getAttribute("f_k");
f_s=(String)request.getAttribute("f_s");
f_classno=(String) request.getAttribute("f_j");
f_py=(String)request.getAttribute("f_py");
f_ldm = request.getParameter("t_ldm");
f_xx = request.getParameter("t_xx");
f_cd = request.getParameter("t_cd");
f_layer = request.getParameter("t_layer");
//从form中获取可以更改的字段,为字段新内容
f_bhc = request.getParameter("t_bch");
f_fzcs = request.getParameter("t_fzcs");
f_szxz = request.getParameter("t_szxz");
float animal_f_id=0;
//判断操作类型
if("create".equals(v_message))
{
//获取t_rpt_modify报表操作表中的相关字段
String f_rpt_no,f_rpt_pid,f_emp_name,f_type,f_new_value,f_ref_date;
//获取表中f_pid字段
float rpt_f_id=0;
try
{
rpt_f_id = TableNewId.getTableNewId(stmt,1,"t_rpt_modi",
"f_pid");
if(rpt_f_id==0)
{
return "<script language=javascript>window.alert('系统错误,创建失败!');window.close();</script>";
}
}
catch(SQLException ex)
{
ex.printStackTrace();
}
//其余相关字段
f_emp_name=(String) session.getAttribute("f_emp_name");
f_type="0";
//以逗号分割连接所有属性值
f_new_value=sb.append(f_name+","+f_k+","+f_s+","+f_classno+","+f_xx+","+f_cd+","+f_layer+","+f_py+","+f_ldm+","+f_bhc+","+f_fzcs+","+f_szxz).toString();
f_ref_date=new DateHandle().getDate();
//*************************************还有一些字段未获取***************
rrSql="";//插入t_rpt_modi表中的sql语句
v_flag=stmt.executeUpdate(rrSql);
}
else if("modify".equals(v_message))
{
//获取t_bas_animal中的f_id
animal_f_id=Integer.parseInt((String)request.getAttribute("animal_f_id"));
//获取t_rpt_modify报表操作表中的相关字段
String f_rpt_no,f_rpt_pid,f_emp_name,f_type,f_old_value,f_new_value,f_ref_date,f_old_bhc,f_old_fzcs,f_old_szxz;
float rpt_f_id=0;
try
{
rpt_f_id = park.jsp.common.TableNewId.getTableNewId(stmt, 1, "t_rpt_modi",
"f_pid");
if (rpt_f_id == 0) {
return "<script language=javascript>window.alert('系统错误,创建失败!');window.close();</script>";
}
}
catch (SQLException ex) {
ex.printStackTrace();
}
f_emp_name=(String) session.getAttribute("f_emp_name");
f_type="1";
//以逗号分割连接所有属性值
f_new_value=sb.append(animal_f_id+","+f_name+","+f_k+","+f_s+","+f_classno+","+f_xx+","+f_cd+","+f_layer+","+f_py+","+f_ldm+","+f_bhc+","+f_fzcs+","+f_szxz).toString();
f_ref_date=new DateHandle().getDate();
//获取旧动物对应的t_bas_animal表中对应的所有值,并以逗号分割连接,作为f_old_value字段
f_old_bhc=(String) request.getAttribute("f_bhc");
f_old_fzcs=(String)request.getAttribute("f_fzcs");
f_old_szxz=(String) request.getAttribute("f_szxz");
f_old_value=sb.append(animal_f_id+","+f_name+","+f_k+","+f_s+","+f_classno+","+f_xx+","+f_cd+","+f_layer+","+f_py+","+f_ldm+","+f_old_bhc+","+f_old_fzcs+","+f_old_szxz).toString();
//*************************************还有一些字段未获取***************
rrSql = ""; //插入t_rpt_modi表中的sql语句
v_flag = stmt.executeUpdate(rrSql);
}
}
else if("plant".equals(v_type))
{
}
v_flag=stmt.executeUpdate(rrSql);
conn.commit();
if(v_flag==1)
{
return "<script language=javascript>window.alert('保存操作成功!');window.close();</script>";
}
else
{
return
"<script language=javascript>window.alert('保存操作改失败!');window.close();</script>";
}
}
catch(SQLException ex)
{
try
{
conn.rollback();
}
catch(SQLException ex1)
{}
return "<script language=javascript>window.alert('系统错误,不能修改!');</script>";
}
finally
{
try
{
if(rs != null)
{
rs.close();
rs = null;
}
}
catch(Exception ignore)
{}
try
{
if(stmt != null)
{
stmt.close();
stmt = null;
}
}
catch(Exception ignore)
{}
try
{
if(conn != null)
{
conn.rollback();
conn.close();
conn = null;
}
}
catch(Exception ignore)
{}
}
}
}