cptFieldOperation.jsp
21.5 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="weaver.general.Util" %>
<%@ include file="/systeminfo/init_wev8.jsp" %>
<%@ page import="java.util.*,java.util.regex.*" %>
<jsp:useBean id="rs2" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="CptFieldManager" class="weaver.cpt.util.CptFieldManager" scope="page"/>
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="rs1" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="LabelComInfo" class="weaver.systeminfo.label.LabelComInfo" scope="page" />
<jsp:useBean id="RecordSetTrans" class="weaver.conn.RecordSetTrans" scope="page" />
<jsp:useBean id="BrowserComInfo" class="weaver.workflow.field.BrowserComInfo" scope="page" />
<jsp:useBean id="CptFieldComInfo" class="weaver.cpt.util.CptFieldComInfo" scope="page" />
<%
/**
if(!HrmUserVarify.checkUserRight("DeptDefineInfo1:DeptMaintain1", user)){
response.sendRedirect("/notice/noright.jsp");
return;
}**/
boolean isoracle = (RecordSet.getDBType()).equals("oracle") ;
boolean isdb2 = (RecordSet.getDBType()).equals("db2") ;
boolean issqlserver = (RecordSet.getDBType()).equals("sqlserver") ;
String ajax=Util.null2String(request.getParameter("ajax"));
String src = Util.null2String(request.getParameter("src"));
if(src.equals("addfieldbatch")){//批量添加字段
char flag=2;
RecordSetTrans.setAutoCommit(false);
try{
int formid = Util.getIntValue((request.getParameter("formid")),0);//表单id
String maintablename = "cptcapital";//主表名
int recordNum = Util.getIntValue(Util.null2String(request.getParameter("recordNum")),0);//字段行数
String delids = Util.null2String(request.getParameter("delids"));//删除行id集
String changeRowIndexs = Util.null2String(request.getParameter("changeRowIndexs"));//有改变的行id集
String labelidsCache = ",";//更新缓存用
//主字段 开始
ArrayList delidsArray = Util.TokenizerString(delids,",");
for(int i=0;i<delidsArray.size();i++){//删除指定的字段
String fieldnameForDel = "";
String delFieldId = (String)delidsArray.get(i);
RecordSetTrans.executeSql("select fieldname from cptDefineField where id="+delFieldId);
if(RecordSetTrans.next()) fieldnameForDel = RecordSetTrans.getString("fieldname");//取得字段名
RecordSetTrans.executeSql("alter table "+maintablename+" drop column "+fieldnameForDel);//修改表结构
RecordSetTrans.executeSql("delete from cptDefineField where id="+delFieldId);//删除字段
RecordSetTrans.executeSql("delete from cpt_SelectItem where fieldid="+delFieldId);//删除表workflow_SelectItem中该字段对应数据
RecordSetTrans.executeSql("delete from cpt_specialfield where fieldid="+delFieldId);//删除表workflow_specialfield中该字段对应数据
}
ArrayList changeRowIndexsArray = Util.TokenizerString(changeRowIndexs,",");
//for(int i=0;i<changeRowIndexsArray.size();i++){//修改有改变的行(包括新增行和编辑行)
//String index = (String)changeRowIndexsArray.get(i);
for(int i=0;i<recordNum;i++){//修改有改变的行(包括新增行和编辑行)
String index = ""+i;
String new_OR_modify = Util.null2String(request.getParameter("modifyflag_"+index));
if(!new_OR_modify.equals("")){//不为空表示是编辑字段,为空表示新添加字段。
//对编辑字段先删除,再添加
RecordSetTrans.executeSql("delete from cpt_SelectItem where fieldid="+new_OR_modify);//删除表workflow_SelectItem中该字段对应数据
RecordSetTrans.executeSql("delete from cpt_specialfield where fieldid="+new_OR_modify);//删除表workflow_specialfield中该字段对应数据
}
String fieldname = "";//数据库字段名称
int fieldlabel = 0;//字段显示名标签id
String fielddbtype = "";//字段数据库类型
String _fielddbtype = "";//字段数据库类型
String fieldhtmltype = "";//字段页面类型
String type = "";//字段详细类型
String dsporder = "";//显示顺序
String viewtype = "0";//viewtype="0"表示主表字段,viewtype="1"表示明细表字段
String detailtable = "";//明细表名
int textheight = 0;//多行文本框的高度
String isopen = "";//启用
String ismand = "";//必填
String groupid = "";//组
isopen = ""+Util.getIntValue(request.getParameter("isopen_"+index),0);
ismand = ""+Util.getIntValue(request.getParameter("ismand_"+index),0);
groupid = ""+Util.getIntValue(request.getParameter("group_"+index),0);
fieldname = Util.null2String(request.getParameter("itemDspName_"+index));
if(fieldname.equals("")) continue;//先添加后删除的
int imgwidth = Util.getIntValue(request.getParameter("imgwidth_"+index),0);
int imgheight = Util.getIntValue(request.getParameter("imgheight_"+index),0);
String fieldlabelname = Util.null2String(request.getParameter("itemFieldName_"+index));
fieldlabelname = Util.StringReplace(fieldlabelname, "\"", "");//TD10108 表单字段显示名不可以含有半角双引号“"”
if(issqlserver) RecordSetTrans.executeSql("select indexid from HtmlLabelInfo where labelname='"+fieldlabelname+"' collate Chinese_PRC_CS_AI and languageid="+Util.getIntValue(""+user.getLanguage(),7));
else RecordSetTrans.executeSql("select indexid from HtmlLabelInfo where labelname='"+fieldlabelname+"' and languageid="+Util.getIntValue(""+user.getLanguage(),7));
if(RecordSetTrans.next()) fieldlabel = RecordSetTrans.getInt("indexid");//如果字段名称在标签库中存在,取得标签id
else{
fieldlabel = CptFieldManager.getNewIndexId(RecordSetTrans);//生成新的标签id
if(fieldlabel!=-1){//更新标签库
labelidsCache+=fieldlabel+",";
RecordSetTrans.executeSql("delete from HtmlLabelIndex where id="+fieldlabel);
RecordSetTrans.executeSql("delete from HtmlLabelInfo where indexid="+fieldlabel);
RecordSetTrans.executeSql("INSERT INTO HtmlLabelIndex values("+fieldlabel+",'"+fieldlabelname+"')");
RecordSetTrans.executeSql("INSERT INTO HtmlLabelInfo values("+fieldlabel+",'"+fieldlabelname+"',7)");
RecordSetTrans.executeSql("INSERT INTO HtmlLabelInfo values("+fieldlabel+",'"+fieldlabelname+"',8)");
RecordSetTrans.executeSql("INSERT INTO HtmlLabelInfo values("+fieldlabel+",'"+fieldlabelname+"',9)");
}
}
fieldhtmltype = Util.null2String(request.getParameter("itemFieldType_"+index));
if(fieldhtmltype.equals("1")){
int decimaldigits = Util.getIntValue(request.getParameter("decimaldigits_"+index),2);
type = Util.null2String(request.getParameter("documentType_"+index));
if(type.equals("1")){
String strlength = Util.null2String(request.getParameter("itemFieldScale1_"+index));
if(Util.getIntValue(strlength,1)<=1) strlength = "1";
if(isoracle) fielddbtype="varchar2("+strlength+")";
else fielddbtype="varchar("+strlength+")";
if(!new_OR_modify.equals("")){
String oldfielddbtype = "";
RecordSetTrans.executeSql("select fielddbtype from cptDefineField where id="+new_OR_modify);
if(RecordSetTrans.next()) oldfielddbtype = RecordSetTrans.getString("fielddbtype");
if(!fielddbtype.equals(oldfielddbtype)){
if(isoracle) RecordSetTrans.executeSql("ALTER TABLE "+maintablename+" MODIFY "+fieldname+" "+fielddbtype);
else RecordSetTrans.executeSql("ALTER TABLE "+maintablename+" ALTER COLUMN "+fieldname+" "+fielddbtype);
}
}
}
if(type.equals("2")){
if(isoracle) fielddbtype="integer";
else fielddbtype="int";
}
if(type.equals("3")){
if(isoracle) fielddbtype="number(15,"+decimaldigits+")";
else fielddbtype="decimal(15,"+decimaldigits+")";
}
if(type.equals("4")){
if(isoracle) fielddbtype="number(15,2)";
else fielddbtype="decimal(15,2)";
}
if(type.equals("5")){
if(isoracle) fielddbtype="varchar2(30)";
else fielddbtype="varchar(30)";
}
}
if(fieldhtmltype.equals("2")){
String htmledit = Util.null2String(request.getParameter("htmledit_"+index));
if(htmledit.equals("")) type="1";
else type=htmledit;
if(isoracle) fielddbtype="varchar2(4000)";
else if(isdb2) fielddbtype="varchar(2000)";
else fielddbtype="text";
textheight = Util.getIntValue(Util.null2String(request.getParameter("textheight_"+index)),4);
}
if(fieldhtmltype.equals("3")){
int temptype = Util.getIntValue(Util.null2String(request.getParameter("broswerType_"+index)),0);
type = ""+temptype;
if(temptype>0)
fielddbtype=BrowserComInfo.getBrowserdbtype(type+"");
if(temptype==118){
if(isoracle) fielddbtype="varchar2(200)";
else fielddbtype="varchar(200)";
}
if(temptype==161||temptype==162){
fielddbtype=Util.null2String(request.getParameter("definebroswerType_"+index));
if(temptype==161){
if(isoracle) _fielddbtype="varchar2(1000)";
else if(isdb2) _fielddbtype="varchar(1000)";
else _fielddbtype="varchar(1000)";
}else{
if(isoracle) _fielddbtype="varchar2(4000)";
else if(isdb2) _fielddbtype="varchar(2000)";
else _fielddbtype="text";
}
}
if(temptype==224||temptype==225){
fielddbtype=Util.null2String(request.getParameter("sapbrowser_"+index));
if(temptype==224){
if(isoracle) _fielddbtype="varchar2(1000)";
else if(isdb2) _fielddbtype="varchar(1000)";
else _fielddbtype="varchar(1000)";
}else{
if(isoracle) _fielddbtype="varchar2(4000)";
else if(isdb2) _fielddbtype="varchar(2000)";
else _fielddbtype="text";
}
}
if(temptype==165||temptype==166||temptype==167||temptype==168)
textheight=Util.getIntValue(Util.null2String(request.getParameter("decentralizationbroswerType_"+index)),0);
}
if(fieldhtmltype.equals("4")){
type = "1";
fielddbtype="char(1)";
}
if(fieldhtmltype.equals("5")) {
type = "1";
if(isoracle) fielddbtype="integer";
else fielddbtype="int";
}
if(fieldhtmltype.equals("6")) {
type = "" + Util.getIntValue(Util.null2String(request.getParameter("uploadtype_"+index)), 1);
if(isoracle) fielddbtype="varchar2(4000)";
else if(isdb2) fielddbtype="varchar(2000)";
else fielddbtype="text";
textheight = Util.getIntValue(Util.null2String(request.getParameter("strlength_"+index)), 0);
}
if(fieldhtmltype.equals("7")) {
type = Util.null2String(request.getParameter("specialfield_"+index));
if(isoracle) fielddbtype="varchar2(4000)";
else if(isdb2) fielddbtype="varchar(2000)";
else fielddbtype="text";
}
dsporder = Util.null2String(request.getParameter("itemDspOrder_"+index));
//dsporder = ""+i;
//if(dsporder.equals("")) dsporder="0";
dsporder = ""+Util.getDoubleValue(dsporder,0.0);
int childfieldid_tmp = Util.getIntValue(request.getParameter("childfieldid_"+index), 0);
if(!new_OR_modify.equals("")){//不为空表示是编辑字段,为空表示新添加字段。
String oldfieldname = "";
String oldfielddbtype = "";
String issystem_t = "";
RecordSetTrans.executeSql("select fieldname,issystem,fielddbtype from cptDefineField where id="+new_OR_modify);
if(RecordSetTrans.next()){
oldfieldname = RecordSetTrans.getString("fieldname");
oldfielddbtype = RecordSetTrans.getString("fielddbtype");
issystem_t = RecordSetTrans.getString("issystem");
}
RecordSetTrans.executeSql("update cptDefineField set groupid='"+groupid+"',isopen='"+isopen+"',ismand='"+ismand+"',billid="+formid+",fieldname='"+fieldname+"',fieldlabel="+fieldlabel+",fielddbtype='"+fielddbtype+"',fieldhtmltype="+fieldhtmltype+",type="+type+",dsporder="+dsporder+",viewtype="+viewtype+",detailtable='"+detailtable+"',textheight="+textheight+",childfieldid="+childfieldid_tmp+",imgwidth="+imgwidth+",imgheight="+imgheight+" where id="+new_OR_modify);
if(!fieldname.equals(oldfieldname)||(!fielddbtype.equals(oldfielddbtype) && !"1".equals(fieldhtmltype) && !"".equals(type))||(fieldhtmltype.equals("3")&&(type.equals("161")||type.equals("162")))){//修改了数据库字段名称或类型
if(!"1".equals(issystem_t)){
RecordSetTrans.executeSql("alter table "+maintablename+" drop column "+oldfieldname);
if(fieldhtmltype.equals("3")&&(type.equals("161")||type.equals("162"))){
RecordSetTrans.executeSql("alter table "+maintablename+" add "+fieldname+" "+_fielddbtype);
}else if(fieldhtmltype.equals("3")&&(type.equals("224")||type.equals("225"))){
RecordSetTrans.executeSql("alter table "+maintablename+" add "+fieldname+" "+_fielddbtype);
}else{
RecordSetTrans.executeSql("alter table "+maintablename+" add "+fieldname+" "+fielddbtype);
}
}
}
}else{
//插入字段信息
RecordSetTrans.executeSql("INSERT INTO cptDefineField(groupid,isopen,ismand,billid,fieldname,fieldlabel,fielddbtype,fieldhtmltype,type,dsporder,viewtype,detailtable,textheight,childfieldid,imgwidth,imgheight) "+
" VALUES ('"+groupid+"','"+isopen+"','"+ismand+"',"+formid+",'"+fieldname+"',"+fieldlabel+",'"+fielddbtype+"',"+fieldhtmltype+","+type+","+dsporder+","+viewtype+",'"+detailtable+"',"+textheight+","+childfieldid_tmp+","+imgwidth+","+imgheight+")");
}
if(new_OR_modify.equals("")){//新添加字段
//更新主表结构
if(fieldhtmltype.equals("3")&&(type.equals("161")||type.equals("162"))){
RecordSetTrans.executeSql("alter table "+maintablename+" add "+fieldname+" "+_fielddbtype);
}else if(fieldhtmltype.equals("3")&&(type.equals("224")||type.equals("225"))){
RecordSetTrans.executeSql("alter table "+maintablename+" add "+fieldname+" "+_fielddbtype);
}else{
RecordSetTrans.executeSql("alter table "+maintablename+" add "+fieldname+" "+fielddbtype);
}
}
//如果是选择框,更新表workflow_SelectItem
String curfieldid = "";
if(new_OR_modify.equals("")){
RecordSetTrans.executeSql("select max(id) as id from cptDefineField");
if(RecordSetTrans.next()) curfieldid = RecordSetTrans.getString("id");
}else{
curfieldid = new_OR_modify;
}
if(fieldhtmltype.equals("5")){
//System.out.println("==========fieldhtmltype.equals(5)==========");
int rowsum = Util.getIntValue(Util.null2String(request.getParameter("choiceRows_"+index)));
//System.out.println("rowsum:"+rowsum);
int curvalue=0;
for(int temprow=1;temprow<=rowsum;temprow++){
String curname = Util.null2String(request.getParameter("field_"+index+"_"+temprow+"_name"));
//System.out.println("curname:"+curname);
if(curname.equals("")) continue;
String curorder = Util.null2String(request.getParameter("field_count_"+index+"_"+temprow+"_name"));
String isdefault = "n";
String checkValue = Util.null2String(request.getParameter("field_checked_"+index+"_"+temprow+"_name"));
String cancel = Util.null2String(request.getParameter("cancel_"+index+"_"+temprow+"_name"));
if(cancel!=null && !cancel.equals("") && cancel.equals("1")){
cancel = "1";
}else{
cancel = "0";
}
if(checkValue.equals("1")) isdefault="y";
int isAccordToSubCom_tmp = Util.getIntValue(request.getParameter("isAccordToSubCom"+index+"_"+temprow), 0);
//System.out.println("isAccordToSubCom_tmp:"+isAccordToSubCom_tmp);
String doccatalog = Util.null2String(request.getParameter("maincategory_"+index+"_"+temprow));
String docPath = Util.null2String(request.getParameter("pathcategory_"+index+"_"+temprow));
String childItem_tmp = Util.null2String(request.getParameter("childItem_"+index+"_"+temprow));
String para=curfieldid+flag+"1"+flag+""+curvalue+flag+curname+flag+curorder+flag+isdefault+flag+cancel;
//System.out.println("para:"+para);
RecordSetTrans.executeProc("cpt_selectitem_insert_new",para);//更新表workflow_SelectItem
RecordSetTrans.executeSql("update cpt_selectitem set docpath='"+docPath+"', docCategory='"+doccatalog+"',childitemid='"+childItem_tmp+"',isAccordToSubCom='"+isAccordToSubCom_tmp+"' where fieldid="+curfieldid+" and selectvalue="+curvalue);
//System.out.println("sql:"+"update cpt_selectitem set docpath='"+docPath+"', docCategory='"+doccatalog+"',childitemid='"+childItem_tmp+"',isAccordToSubCom='"+isAccordToSubCom_tmp+"' where fieldid="+curfieldid+" and selectvalue="+curvalue);
curvalue++;
}
}
if(fieldhtmltype.equals("7")){
String displayname = Util.null2String(request.getParameter("displayname_"+index));//显示名
String linkaddress = Util.null2String(request.getParameter("linkaddress_"+index));//链接地址
String descriptivetext = Util.null2String(request.getParameter("descriptivetext_"+index));//描述性文字
descriptivetext = Util.spacetoHtml(descriptivetext);
String specialfield = Util.null2String(request.getParameter("specialfield_"+index));//类型
//String sql = "select max(id) from workflow_billfield";
//RecordSetTrans.executeSql(sql);
//RecordSetTrans.next();
//String curfieldid=RecordSetTrans.getString(1);
//if(!new_OR_modify.equals("")) curfieldid = new_OR_modify;
String sql = "";
if(specialfield.equals("1")){
sql = "insert into cpt_specialfield(fieldid,displayname,linkaddress,isform,isbill) values("+curfieldid+",'"+displayname+"','"+linkaddress+"',0,1)";
}else{
sql = "insert into cpt_specialfield(fieldid,descriptivetext,isform,isbill) values("+curfieldid+",'"+descriptivetext+"',0,1)";
}
RecordSetTrans.executeSql(sql);
}
}
//主字段 结束
RecordSetTrans.commit();
ArrayList labelidsArray = Util.TokenizerString(labelidsCache,",");
for(int i=0;i<labelidsArray.size();i++){//添加标签id到缓存
LabelComInfo.addLabeInfoCache((String)labelidsArray.get(i));
}
CptFieldManager.syncFields();
}catch(Exception e){
RecordSetTrans.rollback();
}
CptFieldComInfo.removeFieldCache();
response.sendRedirect("/cpt/ffield/editCptFieldBatch.jsp?ajax=1");
}else if(src.equals("editfieldlabel")){
String formid = Util.null2String(request.getParameter("formid"));
String changefieldids = Util.null2String(request.getParameter("changefieldids"));
ArrayList<String> labelids=new ArrayList<String>();
RecordSetTrans.setAutoCommit(false);
try{
ArrayList changefieldidsArray = Util.TokenizerString(changefieldids,",");
for(int i=0;i<changefieldidsArray.size();i++){
String fieldid = (String)changefieldidsArray.get(i);
String fieldnameCN = Util.null2String(request.getParameter("field_"+fieldid+"_CN"));
String fieldnameEn = Util.null2String(request.getParameter("field_"+fieldid+"_En"));
String fieldnameTW = Util.null2String(request.getParameter("field_"+fieldid+"_TW"));
fieldnameCN = Util.StringReplace(fieldnameCN, "\"", "");//TD10108 表单字段显示名不可以含有半角双引号“"”
fieldnameEn = Util.StringReplace(fieldnameEn, "\"", "");//TD10108 表单字段显示名不可以含有半角双引号“"”
fieldnameTW = Util.StringReplace(fieldnameTW, "\"", "");//TD10108 表单字段显示名不可以含有半角双引号“"”
int lableid = 0;
String mysql=""+
" select distinct t2.indexid from HtmlLabelInfo t2 where "+
" exists (select 1 from HtmlLabelInfo t1 where t1.indexid=t2.indexid and t1.labelname='"+fieldnameCN+"' and t1.languageid=7) "+
" and exists (select 1 from HtmlLabelInfo t1 where t1.indexid=t2.indexid and t1.labelname='"+fieldnameEn+"' and t1.languageid=8) "+
" and exists (select 1 from HtmlLabelInfo t1 where t1.indexid=t2.indexid and t1.labelname='"+fieldnameTW+"' and t1.languageid=9) " ;
RecordSetTrans.executeSql(mysql);
if(!RecordSetTrans.next()){
lableid = CptFieldManager.getNewIndexId(RecordSetTrans);
labelids.add(""+lableid);
RecordSetTrans.executeSql("delete from HtmlLabelIndex where id="+lableid);
RecordSetTrans.executeSql("delete from HtmlLabelInfo where indexid="+lableid);
RecordSetTrans.executeSql("INSERT INTO HtmlLabelIndex values("+lableid+",'"+fieldnameCN+"')");
RecordSetTrans.executeSql("INSERT INTO HtmlLabelInfo values("+lableid+",'"+fieldnameCN+"',7)");//中文
RecordSetTrans.executeSql("INSERT INTO HtmlLabelInfo values("+lableid+",'"+fieldnameEn+"',8)");//英文
RecordSetTrans.executeSql("INSERT INTO HtmlLabelInfo values("+lableid+",'"+fieldnameTW+"',9)");//繁体
}else{
lableid=RecordSetTrans.getInt("indexid");
}
RecordSetTrans.executeSql("update cptDefineField set fieldlabel="+lableid+" where id="+fieldid);
}
RecordSetTrans.commit();
int newlabelsize=labelids.size();
for(int j=0;j<newlabelsize;j++){
LabelComInfo.addLabeInfoCache(labelids.get(j));//更新缓存
}
}catch(Exception exception){
RecordSetTrans.rollback();
}
CptFieldComInfo.removeFieldCache();
response.sendRedirect("/cpt/ffield/addCptFieldlabel.jsp?ajax=1");
}
%>