field_edit_save.jsp
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" pageEncoding="UTF-8" %>
<%@ include file="../data/conn.jsp"%>
<%@ include file="check.jsp"%>
<%
//获取从文件中传输过来的参数,并利用此参数重新查询数据库获得编辑前数据,并将获取信息转换成INT类型。
int gid=Integer.parseInt(request.getParameter("id"));
String CustomName2 = new String(request.getParameter("CustomName").getBytes("ISO-8859-1"),"utf-8");//名称
String CustomLabel2 = new String(request.getParameter("CustomLabel").getBytes("ISO-8859-1"),"utf-8");//label
String CustomRow2 = new String(request.getParameter("CustomRow").getBytes("ISO-8859-1"),"utf-8");//位置
//String CustomGroup2 = new String(request.getParameter("CustomGroup").getBytes("ISO-8859-1"),"utf-8");
String CustomType2 = new String(request.getParameter("CustomType").getBytes("ISO-8859-1"),"utf-8");//数据类型
int CustomDisplay2=Integer.parseInt(request.getParameter("CustomDisplay"));//是否显示
int CustomBlank2=Integer.parseInt(request.getParameter("CustomBlank"));//是否为空
//int CheckInput2=Integer.parseInt(request.getParameter("CheckInput"));//检测输入
String CheckInput2 = new String(request.getParameter("CheckInput").getBytes("ISO-8859-1"),"utf-8");//检测输入
int CustomInputWay2=Integer.parseInt(request.getParameter("CustomInputWay"));//输入方式
int fenlei2=Integer.parseInt(request.getParameter("fenlei"));//分类
int DisplayWidth2=Integer.parseInt(request.getParameter("DisplayWidth"));//显示宽度
int CustomTypeWidth2=Integer.parseInt(request.getParameter("CustomTypeWidth"));//字段类型长度
//保存编辑前数据 开始
String sql_editid="select * from crm_syscustom where CustomID='"+gid+"'";
ResultSet rs_editid=stmt.executeQuery(sql_editid);
String SEditCustom[]=new String[13];//用数组保存编辑前的信息;
String SClassValue,SClassValue2,SClassValue3;
request.setCharacterEncoding("utf-8"); //新增信息不需要此语句,编辑信息的时候需要添加此语句。
try
{
if(rs_editid.next())
{
SEditCustom[0]=rs_editid.getString("CustomID");//编辑前ID
SEditCustom[1]=rs_editid.getString("CustomName");//编辑前名称
SEditCustom[2]=rs_editid.getString("CustomLabel");//编辑前Label
SEditCustom[3]=rs_editid.getString("CustomGroup");//编辑前选项卡
SEditCustom[4]=rs_editid.getString("CustomType");//编辑前数据类型
SEditCustom[5]=rs_editid.getString("CustomDisplay");//编辑前是否显示
SEditCustom[6]=rs_editid.getString("CustomRow");//编辑前位置
SEditCustom[7]=rs_editid.getString("CustomBlank");//编辑前是否为空
SEditCustom[8]=rs_editid.getString("CheckInput");//编辑前输入
SEditCustom[9]=rs_editid.getString("CustomInputWay");//编辑前输入方式
SEditCustom[10]=rs_editid.getString("InputValue");//编辑前输入字段绑定值
SEditCustom[11]=rs_editid.getString("DisplayWidth");//编辑前显示宽度
SEditCustom[12]=rs_editid.getString("CustomTypeWidth");//编辑前字段宽度
}
}
catch(SQLException ex)
{
System.err.println("执行错误:"+ex.getMessage() );
}
//保存编辑前数据 结束
if(CustomInputWay2==1){
stmt.executeUpdate("UPDATE crm_syscustom SET CustomRow ='"+CustomRow2+"',CustomName ='"+CustomName2+"',CustomLabel = '"+CustomLabel2+"',CustomType = '"+CustomType2+"',CustomDisplay = '"+CustomDisplay2+"',CheckInput = '"+CheckInput2+"',InputValue = '"+fenlei2+"',CustomInputWay = '"+CustomInputWay2+"',DisplayWidth = '"+DisplayWidth2+"',CustomBlank = '"+CustomBlank2+"',CustomTypeWidth = '"+CustomTypeWidth2+"' where CustomID='"+gid+"'");
}else{
stmt.executeUpdate("UPDATE crm_syscustom SET CustomRow ='"+CustomRow2+"',CustomName ='"+CustomName2+"',CustomLabel = '"+CustomLabel2+"',CustomType = '"+CustomType2+"',CustomDisplay = '"+CustomDisplay2+"',CheckInput = '"+CheckInput2+"',CustomInputWay = '"+CustomInputWay2+"',CustomBlank = '"+CustomBlank2+"',DisplayWidth = '"+DisplayWidth2+"',CustomTypeWidth = '"+CustomTypeWidth2+"' where CustomID='"+gid+"'");}
out.print("信息修改成功");
if(CustomName2.equals(SEditCustom[1])){//比较自定义系统名称是否一致 if1
if(CustomType2.equals(SEditCustom[4])){//比对数据类型字段是否一致,一致不做修改。 if2
}
else{//if(CustomType2.equals(SEditCustom[4])){ else 表示数据类型不一致,修改数据类型 else2
String sqlTable="select * from crm_card where id='"+SEditCustom[3]+"'";
ResultSet rsTable=stmt.executeQuery(sqlTable);
if(rsTable.next()){//if 3
SClassValue=rsTable.getString("CardValue");//供下面查询使用
String SType=rsTable.getString("CardName");//供下面查询使用
switch(Integer.parseInt(CustomType2)){
case 0:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" INT( "+CustomTypeWidth2+" ) NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" INT( "+CustomTypeWidth2+" ) NOT NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");}
break;
case 1:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" VARCHAR( "+CustomTypeWidth2+" ) NULL DEFAULT '空' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" VARCHAR( "+CustomTypeWidth2+" ) NOT NULL DEFAULT '空' COMMENT '"+CustomLabel2+"'");}
break;
case 2:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" INT( "+CustomTypeWidth2+" ) NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" INT( "+CustomTypeWidth2+" ) NOT NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");}
break;
case 3://日期时间型
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DATETIME NULL DEFAULT '0000-00-00 00:00:00' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '"+CustomLabel2+"'");}
break;
case 4://备注字段
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TEXT NULL COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TEXT NOT NULL COMMENT '"+CustomLabel2+"'");}
break;
case 5://TINYINT短整型
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TINYINT( "+CustomTypeWidth2+" ) NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TINYINT( "+CustomTypeWidth2+" ) NOT NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");}
break;
case 6://Date日期型
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DATE NULL DEFAULT '0000-00-00' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DATE NOT NULL DEFAULT '0000-00-00' COMMENT '"+CustomLabel2+"'");}
break;
case 7://Time时间型
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TIME NULL DEFAULT '00:00:00' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TIME NOT NULL DEFAULT '00:00:00' COMMENT '"+CustomLabel2+"'");}
break;
case 8://double
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DOUBLE NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DOUBLE NOT NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");}
break;
default:
out.print("错误信息或没有选项");
}
}//if 3 end
}//esle 2 end
}//if 1 end
else{
if(CustomType2.equals(SEditCustom[4])){//比对数据类型字段是否一致,一致不做修改。 if2
String sqlTable3="select * from crm_card where id='"+SEditCustom[3]+"'";
ResultSet rsTable3=stmt.executeQuery(sqlTable3);
if(rsTable3.next()){//if 3
SClassValue3=rsTable3.getString("CardValue");//供下面查询使用
String SType3=rsTable3.getString("CardName");//供下面查询使用
switch(Integer.parseInt(CustomType2)){
case 0:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" INT( "+CustomTypeWidth2+" ) NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" INT( "+CustomTypeWidth2+" ) NOT NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");}
break;
case 1:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" VARCHAR( "+CustomTypeWidth2+" ) NULL DEFAULT '空' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" VARCHAR( "+CustomTypeWidth2+" ) NOT NULL DEFAULT '空' COMMENT '"+CustomLabel2+"'");}
break;
case 2:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" INT( "+CustomTypeWidth2+" ) NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" INT( "+CustomTypeWidth2+" ) NOT NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");}
break;
case 3:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DATETIME NULL DEFAULT '0000-00-00' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DATETIME NOT NULL DEFAULT '0000-00-00' COMMENT '"+CustomLabel2+"'");}
break;
case 4:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TEXT NULL COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TEXT NOT NULL COMMENT '"+CustomLabel2+"'");}
break;
case 5:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TINYINT( "+CustomTypeWidth2+" ) NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TINYINT( "+CustomTypeWidth2+" ) NOT NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");}
break;
case 6://Date日期型
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DATE NULL DEFAULT '0000-00-00' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DATE NOT NULL DEFAULT '0000-00-00' COMMENT '"+CustomLabel2+"'");}
break;
case 7://Time时间型
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TIME NULL DEFAULT '00:00:00' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TIME NOT NULL DEFAULT '00:00:00' COMMENT '"+CustomLabel2+"'");}
break;
case 8://double
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DOUBLE NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue3+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DOUBLE NOT NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");}
break;
default:
out.print("错误信息或没有选项");
}
}//if 3 end
}
else{//if(CustomType2.equals(SEditCustom[4])){ else 表示数据类型不一致,修改数据类型 else2
String sqlTable2="select * from crm_card where id='"+SEditCustom[3]+"'";
ResultSet rsTable2=stmt.executeQuery(sqlTable2);
if(rsTable2.next()){//if 3
SClassValue2=rsTable2.getString("CardValue");//供下面查询使用
String SType2=rsTable2.getString("CardName");//供下面查询使用
switch(Integer.parseInt(CustomType2)){
case 0:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" INT( "+CustomTypeWidth2+" ) NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" INT( "+CustomTypeWidth2+" ) NOT NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");}
break;
case 1:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" VARCHAR( "+CustomTypeWidth2+" ) NULL DEFAULT '空' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" VARCHAR( "+CustomTypeWidth2+" ) NOT NULL DEFAULT '空' COMMENT '"+CustomLabel2+"'");}
break;
case 2:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" INT( "+CustomTypeWidth2+" ) NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" INT( "+CustomTypeWidth2+" ) NOT NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");}
break;
case 3:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DATETIME NULL DEFAULT '0000-00-00' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DATETIME NOT NULL DEFAULT '0000-00-00' COMMENT '"+CustomLabel2+"'");}
break;
case 4:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TEXT NULL COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TEXT NOT NULL COMMENT '"+CustomLabel2+"'");}
break;
case 5:
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TINYINT( "+CustomTypeWidth2+" ) NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TINYINT( "+CustomTypeWidth2+" ) NOT NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");}
break;
case 6://Date日期型
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DATE NULL DEFAULT '0000-00-00' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DATE NOT NULL DEFAULT '0000-00-00' COMMENT '"+CustomLabel2+"'");}
break;
case 7://Time时间型
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TIME NULL DEFAULT '00:00:00' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" TIME NOT NULL DEFAULT '00:00:00' COMMENT '"+CustomLabel2+"'");}
break;
case 8://double
if(CustomBlank2==0){//可以为空
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DOUBLE NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");
}else{
stmt.executeUpdate("ALTER TABLE "+SClassValue2+" CHANGE "+SEditCustom[1]+" "+CustomName2+" DOUBLE NOT NULL DEFAULT '0' COMMENT '"+CustomLabel2+"'");}
break;
default:
out.print("错误信息或没有选项");
}
}//if 3 end
}//esle 2 end
}//比较自定义系统名称是否一致else end
stmt.close();
conn.close();
response.setHeader("refresh","3;url=field_list.jsp");
%>
- 文章导航