surveyTempSave.jsp
3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<%@ page language="java" contentType="application/json;charset=UTF-8" %>
<%@page import="weaver.general.Util,
weaver.hrm.*,java.util.*,
java.text.SimpleDateFormat"%>
<%@page import="org.json.JSONObject"%>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<%
User user = HrmUserVarify.getUser (request , response) ;
if(user == null){
return;
}
JSONObject returnObject = new JSONObject();
//参数异常
String votingid = Util.null2String(request.getParameter("votingId"));
if(votingid.isEmpty()){
returnObject.put("flag","-2");
out.print(returnObject.toString());
return;
}
//用户不一致,防止session覆盖
String formUserid = Util.null2String(request.getParameter("formUserid"));
String userid=Util.null2String(user.getUID());
if(!formUserid.equals(userid)){
returnObject.put("flag","-3");
out.print(returnObject.toString());
return;
}
String qid = Util.null2String(request.getParameter("qid"));
String oid = Util.null2String(request.getParameter("oid"));
String remark = Util.null2String(request.getParameter("remark"));
String type = Util.null2String(request.getParameter("type")); //checkbox-多选 。radio-单选。select-下拉
String operate = Util.null2String(request.getParameter("operate")); // 1-选中。0-取消 。-1-其他输入
String questiontype = Util.null2String(request.getParameter("questiontype")); //0-选择题,1-组合题,2-填空题,-1-选择题其他输入
//参数异常
if(qid.isEmpty()){
returnObject.put("flag","-2");
out.print(returnObject.toString());
return;
}
Date date = new Date();
String dateString = new SimpleDateFormat("yyyy-MM-dd").format(date);
String timeString = new SimpleDateFormat("HH:mm:ss").format(date);
if(type.equals("radio") || type.equals("select") || questiontype.equals("2")){//单选,下拉,填空
if(questiontype.equals("1")){//组合单选
String rowOpid = oid.contains("_") ? oid.substring(0,oid.indexOf("_")) : oid;
rs.executeUpdate("delete from VotingResourceTemp where votingid=" + votingid + " and questionid=" + qid + " and resourceid=" + user.getUID() + " and optionid like '" + rowOpid + "_%'");
}else{
rs.executeUpdate("delete from VotingResourceTemp where votingid=" + votingid + " and questionid=" + qid + " and resourceid=" + user.getUID());
}
}else if(type.equals("checkbox") && operate.equals("0")){//多选 取消选中
rs.executeUpdate("delete from VotingResourceTemp where votingid=" + votingid + " and questionid=" + qid + " and resourceid=" + user.getUID() +
(oid.isEmpty() ? " and optionid is null" : (" and optionid='" + oid + "'")));
}
if("-100".equals(oid)){
remark = remark.replaceAll("'","''");
}else{
remark = remark.replaceAll("'","''");
}
returnObject.put("flag","0");
if(operate.equals("1") || questiontype.equals("2")){//选中,填空
if(questiontype.equals("2") && remark.trim().isEmpty()){
}else{
rs.executeUpdate("insert into VotingResourceTemp(votingid,questionid,optionid,resourceid,operatedate,operatetime,remark) " +
" values(" + votingid + "," + qid + "," + (oid.isEmpty() ? null : ("'" + oid + "'")) + "," + user.getUID() + ",'" + dateString +"','" + timeString + "','" + remark + "') ");
}
returnObject.put("flag","1");
}else if(operate.equals("-1")){
rs.executeUpdate("update VotingResourceTemp set remark='" + remark + "' where votingid=" + votingid + " and questionid=" + qid + " and resourceid=" + user.getUID());
returnObject.put("flag","1");
}else if(operate.equals("0")){
returnObject.put("flag","1");
}
out.print(returnObject.toString());
%>