UploadDoc.jsp
7.4 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.conn.ConnStatement" %>
<%@ page import="java.io.Writer" %>
<%@ page import="java.io.File" %>
<%@ page import="weaver.file.FileUpload" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="weaver.conn.ConnectionPool" %>
<%@ page import="java.sql.SQLException" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %> <%@ include file="/systeminfo/init_wev8.jsp" %>
<jsp:useBean id="DocManager" class="weaver.docs.docs.DocManager" scope="page" />
<%!
int id=-1;
int subcompanyid=0;
String mouldname="";
String lastModTime="";
String mouldtext="";
%>
<%!
public void EditMouldInfo() throws Exception {
String sql = "";
RecordSet recordSet=new RecordSet();
boolean isoracle = (recordSet.getDBType()).equals("oracle")&&Util.null2String(recordSet.getOrgindbtype()).equals("oracle");
if (isoracle) {
Connection conn=null;
PreparedStatement stat=null;
ResultSet resultSet=null;
try {
sql = "update CPT_PRINT_Mould set mouldname='"+this.mouldname+"',lastModTime='"+this.lastModTime+"'"+(this.subcompanyid!=0?",subcompanyid='"+this.subcompanyid+"'":"")+",mouldtext=empty_clob() where id='"+this.id+"'";
new RecordSet().executeSql(sql);
conn= ConnectionPool.getInstance().getConnection();
conn.setAutoCommit(false);
// 3.需要使用for update方法来进行更新,
// 但是,特别需要注意,如果原来CLOB字段有值,需要使用empty_clob()将其清空。
// 如果原来是null,也不能更新,必须是empty_clob()返回的结果。
stat = conn.prepareStatement("select mouldtext from CPT_PRINT_Mould where id='-1' for update");
resultSet = stat.executeQuery();
if (resultSet.next()) {
oracle.sql.CLOB clob = (oracle.sql.CLOB) resultSet.getClob("mouldtext");
Writer outStream = clob.getCharacterOutputStream();
char[] c = this.mouldtext.toCharArray();
outStream.write(c, 0, c.length);
outStream.flush();
outStream.close();
}
conn.commit();
} catch (Exception e) {
new BaseBean().writeLog(e.getMessage());
} finally {
if (resultSet!=null) {
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (stat!=null) {
try {
stat.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn!=null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
} else {// For Sql Server
ConnStatement statement = new ConnStatement();
try {
sql = "update CPT_PRINT_Mould set mouldname=?,mouldtext=?,lastModTime=?"+(this.subcompanyid!=0?",subcompanyid=?":"")+" where id=?";
statement.setStatementSql(sql);
statement.setString(1, this.mouldname);
statement.setString(2, this.mouldtext);
statement.setString(3, this.lastModTime);
if(this.subcompanyid!=0){
statement.setInt(4, this.subcompanyid);
statement.setInt(5, this.id);
}else{
statement.setInt(4, this.id);
}
statement.executeUpdate();
} catch (Exception e) {
new BaseBean().writeLog(e.getMessage());
} finally {
try {
statement.close();
} catch (Exception ex) {
}
}
}
}
%>
<%
FileUpload fu=new FileUpload(request);
String operation = Util.null2String(fu.getParameter("operation"));
int languageid=user.getLanguage();
RecordSet rt=new RecordSet();
if (operation.equals("edit")) {
this.id = -1;
this.mouldname = fu.getParameter("mouldname");
this.mouldtext = Util.fromBaseEncoding(
fu.getParameter("mouldtext"), languageid);
int idx=-1;
if ((idx=this.mouldtext.lastIndexOf("<p><br/></p><p><br/></p><p><br/></p><p><br/></p>"))>-1) {
this.mouldtext=this.mouldtext.substring(0,idx);
}
int tmppos = mouldtext
.indexOf("/weaver/weaver.file.FileDownload?fileid=");
while (tmppos != -1) {
int startpos = mouldtext.lastIndexOf("\"", tmppos);
String tmpcontent = mouldtext.substring(0, startpos + 1);
tmpcontent += mouldtext.substring(tmppos);
mouldtext = tmpcontent;
tmppos = mouldtext.indexOf(
"/weaver/weaver.file.FileDownload?fileid=", tmppos + 1);
}
int olddocimagesnum = Util.getIntValue(fu
.getParameter("olddocimagesnum"), 0);
for (int i = 0; i < olddocimagesnum; i++) {
String tmpid = Util.null2String(fu.getParameter("olddocimages"
+ i));
String tmpid1 = "/weaver/weaver.file.FileDownload?fileid="
+ tmpid + "\"";
if (mouldtext.indexOf(tmpid1) == -1) {
String para = "" + tmpid;
rt.executeProc("imagefile_DeleteByDoc", para);
if (rt.next()) {
String filerealpath = Util
.null2String(rt.getString("filerealpath"));
if (!filerealpath.equals("")) {
try {
File file = new File(new String(filerealpath
.getBytes("ISO8859_1"), "UTF-8"));
file.delete();
} catch (Exception e) {
}
}
}
}
}
int docimages_num = Util.getIntValue(fu
.getParameter("docimages_num"), 0);
String[] needuploads = new String[docimages_num];
for (int i = 0; i < docimages_num; i++)
needuploads[i] = "docimages_" + i;
String[] filenames;
String[] fileids;
fileids = fu.uploadFiles(needuploads);
filenames = fu.getFileNames();
for (int i = 0; i < docimages_num; i++) {
int pos = mouldtext.indexOf(DocManager.getImgAltFlag(i));
if (pos != -1) {
String tmpcontent = mouldtext.substring(0, pos);
tmpcontent += " alt=\"" + filenames[i] + "\" ";
pos = mouldtext.indexOf("src=\"", pos);
int endpos = mouldtext.indexOf("\"", pos + 5);
tmpcontent += "src=\"/weaver/weaver.file.FileDownload?fileid="
+ Util.getFileidOut(fileids[i]);
tmpcontent += "\"";
tmpcontent += mouldtext.substring(endpos + 1);
mouldtext = tmpcontent;
} else {
String para = "" + fileids[i];
rt.executeProc("imagefile_DeleteByDoc", para);
if (rt.next()) {
String filerealpath = Util
.null2String(rt.getString("filerealpath"));
if (!filerealpath.equals("")) {
try {
File file = new File(new String(filerealpath
.getBytes("ISO8859_1"), "UTF-8"));
file.delete();
} catch (Exception e) {
}
}
}
}
}
EditMouldInfo();
}
response.sendRedirect("moduleedit.jsp?isclose=1");
%>