OutReportItemOperation_back.jsp 19.8 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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.*" %>
<%@ page language="java" contentType="text/html; charset=GBK" %> <%@ include file="/systeminfo/init.jsp" %>
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="ConditionComInfo" class="weaver.datacenter.ConditionComInfo" scope="page" />

<%


String operation = Util.null2String(request.getParameter("operation"));
String itemid = Util.null2String(request.getParameter("itemid"));
String outrepid = Util.null2String(request.getParameter("outrepid"));
String itemrow = Util.null2String(request.getParameter("itemrow"));
String itemcolumn = Util.null2String(request.getParameter("itemcolumn"));
String itemtype = Util.null2String(request.getParameter("itemtype"));


String itemexpress = Util.fromScreen(request.getParameter("itemexpress"),user.getLanguage());

String itemdesc = Util.fromScreen(request.getParameter("itemdesc"),user.getLanguage());
String itemexpresstype = Util.null2String(request.getParameter("itemexpresstype"));
String itemmodtype = Util.null2String(request.getParameter("itemmodtype"));
String picstatbudget = ""+ Util.getIntValue(request.getParameter("picstatbudget"),0);
String picstatlast = ""+ Util.getIntValue(request.getParameter("picstatlast"),0);
String picstat = ""+ Util.getIntValue(request.getParameter("picstat"),0);
int totaldetail1 = Util.getIntValue(request.getParameter("totaldetail1"),0);
int totaldetail2 = Util.getIntValue(request.getParameter("totaldetail2"),0);
int totaldetail3 = Util.getIntValue(request.getParameter("totaldetail3"),0);


String fromitem = Util.null2String(request.getParameter("fromitem"));
String toitems[] = request.getParameterValues("toitem");
int outrepcolumn = Util.getIntValue(request.getParameter("outrepcolumn"),0);
int outreprow = Util.getIntValue(request.getParameter("outreprow"),0);

String deletetype = Util.null2String(request.getParameter("deletetype"));

String sqlfrom = "" ;
String sqlcondition = "" ;


if(operation.equals("edit")){


    char separator = Util.getSeparator() ;

	String para = itemid + separator + outrepid
		+ separator + itemrow + separator + itemcolumn + separator + itemtype + separator + itemexpress + separator + itemdesc + separator + itemexpresstype + separator + picstatbudget + separator + picstatlast + separator + picstat + separator + itemmodtype;

	RecordSet.executeProc("T_OutReportItem_Insert",para);
    RecordSet.next() ;
    
    itemid = RecordSet.getString(1) ;

    if(itemtype.equals("2")) {
        
        ArrayList tables = new ArrayList() ;
        ArrayList tablenames = new ArrayList() ;
        ArrayList conditionids = new ArrayList() ;
        ArrayList conditionvalues = new ArrayList() ;

        for(int i=0 ; i< totaldetail1 ; i++) {
            String itemtable = Util.null2String(request.getParameter("itemtable"+i));
            String itemtablealter = Util.null2String(request.getParameter("itemtablealter"+i));
            
            if(!itemtable.equals("") && !itemtablealter.equals("")) {
                para = itemid + separator + itemtable + separator + itemtablealter ;
                RecordSet.executeProc("T_OutReportItemTable_Insert",para);
                tables.add(itemtablealter) ;
                tablenames.add(itemtable) ;
            }
        }


        for(int i=0 ; i< totaldetail2 ; i++) {
            String conditionid = Util.null2String(request.getParameter("conditionid"+i));
            String conditionvalue = Util.fromScreen(request.getParameter("conditionvalue"+i),user.getLanguage());

            if(!conditionid.equals("") && !conditionvalue.equals("")) {
                para = itemid + separator + conditionid + separator + conditionvalue ;
                RecordSet.executeProc("T_OutRItemCondition_Insert",para);
                conditionids.add(conditionid) ;
                conditionvalues.add(conditionvalue) ;
            }
        }


        for(int i=0 ; i< totaldetail3 ; i++) {
            String coordinatename = Util.fromScreen(request.getParameter("coordinatename"+i),user.getLanguage());
            String coordinatevalue = Util.fromScreen(request.getParameter("coordinatevalue"+i),user.getLanguage());

            if(!coordinatename.equals("") && !coordinatevalue.equals("")) {
                para = itemid + separator + coordinatename + separator + coordinatevalue ;
                RecordSet.executeProc("T_OutReportICoordinate_Insert",para);
            }
        }


    
        String fromyear = "1960" ;
        String frommonth = "01" ;
        String fromday = "01" ;
        String toyear = "3000" ;
        String tomonth = "12" ;
        String today = "31" ;


        if(tables.size() != 0) {

            for(int j=0 ; j<conditionids.size() ; j++) {
                String tempconditionid = (String)conditionids.get(j) ;
                String tempconditionvalue = (String)conditionvalues.get(j) ;

                if(tempconditionvalue.indexOf("-") > 0) {
                    tempconditionvalue = Util.StringReplaceOnce(tempconditionvalue,"-","@-") ;
                }

                if(tempconditionvalue.indexOf("+") > 0) {
                    tempconditionvalue = Util.StringReplaceOnce(tempconditionvalue,"+","@+") ;
                }

                if(tempconditionvalue.indexOf("*") > 0) {
                    tempconditionvalue = Util.StringReplaceOnce(tempconditionvalue,"*","@*") ;
                }

                if(tempconditionvalue.indexOf("/") > 0) {
                    tempconditionvalue = Util.StringReplaceOnce(tempconditionvalue,"/","@/") ;
                }

                
                if(tempconditionid.equals("1") || tempconditionvalue.equalsIgnoreCase("$crm_code") ) {
                    if(sqlcondition.equals("")) {
                        if(tempconditionvalue.equalsIgnoreCase("$crm")) {
                            sqlcondition = " where CRM_CustomerInfo.id=" ;
                            for(int i=0;i<tables.size();i++) {
                                String temptable = (String)tables.get(i) ;
                                if(i==0) sqlcondition += temptable+".crmid " ;
                                else sqlcondition += " and CRM_CustomerInfo.id="+ temptable+".crmid " ;
                            }
                            sqlcondition += " and CRM_CustomerInfo.id in("+tempconditionvalue+") " ;
                        }
                        else {
                            if(tempconditionvalue.equalsIgnoreCase("$crm_code")) tempconditionvalue = "$crm" ;
                            sqlcondition = " where CRM_CustomerInfo.id=" ;
                            for(int i=0;i<tables.size();i++) {
                                String temptable = (String)tables.get(i) ;
                                if(i==0) sqlcondition += temptable+".crmid " ;
                                else sqlcondition += " and CRM_CustomerInfo.id="+ temptable+".crmid " ;
                            }
                            sqlcondition += " and CRM_CustomerInfo.engname like ''"+tempconditionvalue+"'' " ;
                        }
                    }
                    else {
                        if(tempconditionvalue.equalsIgnoreCase("$crm")) {
                            sqlcondition += " and CRM_CustomerInfo.id=" ;
                            for(int i=0;i<tables.size();i++) {
                                String temptable = (String)tables.get(i) ;
                                if(i==0) sqlcondition += temptable+".crmid " ;
                                else sqlcondition += " and CRM_CustomerInfo.id="+ temptable+".crmid " ;
                            }
                            sqlcondition += " and CRM_CustomerInfo.id in("+tempconditionvalue+") " ;
                        }
                        else {
                            if(tempconditionvalue.equalsIgnoreCase("$crm_code")) tempconditionvalue = "$crm" ;
                            sqlcondition += " and CRM_CustomerInfo.id=" ;
                            for(int i=0;i<tables.size();i++) {
                                String temptable = (String)tables.get(i) ;
                                if(i==0) sqlcondition += temptable+".crmid " ;
                                else sqlcondition += " and CRM_CustomerInfo.id="+ temptable+".crmid " ;
                            }
                            sqlcondition += " and CRM_CustomerInfo.engname like ''"+tempconditionvalue+"'' " ;
                        }
                    }
                }

                else if(tempconditionid.equals("2")) fromyear = tempconditionvalue ;
                else if(tempconditionid.equals("3")) {
                    if(tempconditionvalue.indexOf("$") ==0) frommonth = tempconditionvalue ;
                    else frommonth = Util.add0(Util.getIntValue(tempconditionvalue,0),2) ;
                }
                else if(tempconditionid.equals("4")) {
                    if(tempconditionvalue.indexOf("$") ==0) fromday = tempconditionvalue ;
                    else fromday = Util.add0(Util.getIntValue(tempconditionvalue,0),2) ;
                }
                else if(tempconditionid.equals("5")) toyear = tempconditionvalue ;
                else if(tempconditionid.equals("6")) {
                    if(tempconditionvalue.indexOf("$") ==0) tomonth = tempconditionvalue ;
                    else tomonth = Util.add0(Util.getIntValue(tempconditionvalue,0),2) ;
                }
                else if(tempconditionid.equals("7")) {
                    if(tempconditionvalue.indexOf("$") ==0) today = tempconditionvalue ;
                    else today = Util.add0(Util.getIntValue(tempconditionvalue,0),2) ;
                }
                else {
                    String tempfieldname = ConditionComInfo.getConditionitemfieldnames(tempconditionid) ;
                    String temptable1 = "" ;
                    
                    if(sqlcondition.equals("")) {
                        for(int i=0;i<tables.size();i++) {
                            String temptable = (String)tables.get(i) ;
                            
                            if(i==1) sqlcondition = " where "+temptable1+"."+tempfieldname+" = "+temptable +"."+tempfieldname ;
                            
                            if(i>1) sqlcondition += " and "+temptable1+"."+tempfieldname+" = "+temptable +"."+tempfieldname ;

                            temptable1 = temptable ;
                        }
                        
                        if(sqlcondition.equals("")) sqlcondition = " where "+ temptable1+"."+tempfieldname+" = ''"+tempconditionvalue+"'' " ;
                        else sqlcondition += " and "+ temptable1+"."+tempfieldname+" = ''"+tempconditionvalue+"'' " ;
                    }
                    else {
                        for(int i=0;i<tables.size();i++) {
                            String temptable = (String)tables.get(i) ;
                            
                            if(i>=1) sqlcondition += " and "+temptable1+"."+tempfieldname+" = "+temptable +"."+tempfieldname ;

                            temptable1 = temptable ;
                        }
                        
                        sqlcondition += " and "+ temptable1+"."+tempfieldname+" = ''"+tempconditionvalue+"'' " ;
                    }
                }
            }

            String fromdate = fromyear+"-" + frommonth + "-" + fromday ;
            String todate = toyear+"-" + tomonth + "-" + today ;
            String temptable1 = "" ;

            if(sqlcondition.equals("")) {
                for(int i=0;i<tables.size();i++) {
                    String temptable = (String)tables.get(i) ;
                    
                    if(i==1) sqlcondition = " where "+temptable1+".reportdate = "+temptable +".reportdate" ;
                    
                    if(i>1) sqlcondition += " and "+temptable1+".reportdate = "+temptable +".reportdate" ;

                    temptable1 = temptable ;
                }
                
                if(sqlcondition.equals("")) sqlcondition = " where "+ temptable1+".reportdate >= ''"+fromdate+"'' and " + temptable1+".reportdate <= ''"+todate+"'' ";
                else sqlcondition += " and "+ temptable1+".reportdate >= ''"+fromdate+"' and " + temptable1+".reportdate <= ''"+todate+"'' ";
            }
            else {
                for(int i=0;i<tables.size();i++) {
                    String temptable = (String)tables.get(i) ;
                    
                    if(i>=1) sqlcondition += " and "+temptable1+".reportdate = "+temptable +".reportdate" ;
                    
                    temptable1 = temptable ;
                }
                
                sqlcondition += " and "+ temptable1+".reportdate >= ''"+fromdate+"'' and " + temptable1+".reportdate <= ''"+todate+"'' ";
            }

            String inputstatus = "$inputstatus" ;

            if(sqlcondition.equals("")) {
                for(int i=0;i<tables.size();i++) {
                    String temptable = (String)tables.get(i) ;

                    if(i==0) sqlcondition = " where "+temptable+".inputstatus >= ''"+inputstatus +"'' " ;
                    
                    if(i>0) sqlcondition += " and "+temptable+".inputstatus >= ''"+inputstatus +"'' " ;
                }
            }
            else {
                for(int i=0;i<tables.size();i++) {
                    String temptable = (String)tables.get(i) ;
                    sqlcondition += " and "+temptable+".inputstatus >= ''"+inputstatus +"'' " ;

                }
                
            }


            for(int i=0 ; i< tables.size() ; i++ ) {
                if(sqlfrom.equals("")) sqlfrom = "from " + (String)tablenames.get(i) +" "+  (String)tables.get(i) ;
                else sqlfrom += " , " + (String)tablenames.get(i) +" "+ (String)tables.get(i) ;
            }

            for(int i=0 ; i<conditionids.size() ; i++) {
                String tempconditionid = (String)conditionids.get(i) ;
                if(!tempconditionid.equals("1")) continue ;
                sqlfrom += " , CRM_CustomerInfo " ;
            }
            
            RecordSet.executeSql("update T_OutReportItem set itemtable ='"+sqlfrom+"' where itemid="+itemid);

            RecordSet.executeSql("update T_OutReportItem set itemcondition ='"+Util.fromBaseEncoding2(sqlcondition,7)+"' where itemid="+itemid);

        } 
    }

    response.sendRedirect("OutReportItemDetail.jsp?haspost=1&desc="+itemdesc); 
}

if(operation.equals("delete")){


    char separator = Util.getSeparator() ;
  	
	String para = itemid  ;

	RecordSet.executeProc("T_OutReportItem_Delete",para);
    
    response.sendRedirect("OutReportItemDetail.jsp?haspost=2");
}


if(operation.equals("copy")){ 

    if(!fromitem.equals(""))  {
        if(toitems != null) {

            char separator = Util.getSeparator() ;

            int toitemcount = toitems.length ;

            if(fromitem.indexOf("row_") == 0 ) {
                String fromrow = fromitem.substring(4) ;

                for(int countindex =0 ; countindex < toitemcount ; countindex++) {
                    String toitemvalue = toitems[countindex] ;
                    if(toitemvalue.indexOf("row_") != 0 ) continue ;
                    String torow = toitemvalue.substring(4) ;
                    
                    if(fromrow.equals(torow)) continue ;

                    for(int i= 1 ; i <= outrepcolumn ; i++) {
                        
                        String para = outrepid + separator + torow
                            + separator + ""+i + separator + fromrow + separator + ""+i  ;
                        RecordSet.executeProc("T_OutReportItem_Copy",para);
                    }
                }
            }

            if(fromitem.indexOf("col_") == 0 ) {
                String fromcol = fromitem.substring(4) ;

                for(int countindex =0 ; countindex < toitemcount ; countindex++) {
                    String toitemvalue = toitems[countindex] ;
                    if(toitemvalue.indexOf("col_") != 0 ) continue ;
                    String tocol = toitemvalue.substring(4) ;
                    
                    if(fromcol.equals(tocol)) continue ;

                    for(int i= 1 ; i <= outreprow ; i++) {
                        
                        String para = outrepid + separator + ""+i
                            + separator + tocol + separator + ""+i + separator + fromcol  ;
                        RecordSet.executeProc("T_OutReportItem_Copy",para);
                    }
                }
            }

            if(fromitem.indexOf("rowcol_") == 0 ) {
                String fromrowcol[] = Util.TokenizerString2(fromitem,"_") ;
                String fromrow = fromrowcol[1] ;
                String fromcol = fromrowcol[2] ;

                for(int countindex =0 ; countindex < toitemcount ; countindex++) {
                    String toitemvalue = toitems[countindex] ;
                    
                    if(toitemvalue.indexOf("col_") == 0 ) {
                        String tocol = toitemvalue.substring(4) ;
                    
                        for(int i= 1 ; i <= outreprow ; i++) {
                            String torow = "" +i ;
                            if(fromrow.equals(torow) && fromcol.equals(tocol)) continue ;

                            String para = outrepid + separator + torow
                                + separator + tocol + separator + fromrow + separator + fromcol  ;
                            RecordSet.executeProc("T_OutReportItem_Copy",para);
                        }
                    }

                    if(toitemvalue.indexOf("row_") == 0 ) {
                        String torow = toitemvalue.substring(4) ;
                    
                        for(int i= 1 ; i <= outrepcolumn ; i++) {
                            String tocol = "" +i ;
                            if(fromrow.equals(torow) && fromcol.equals(tocol)) continue ;

                            String para = outrepid + separator + torow
                                + separator + tocol + separator + fromrow + separator + fromcol  ;
                            RecordSet.executeProc("T_OutReportItem_Copy",para);
                        }
                    }

                    if(toitemvalue.indexOf("rowcol_") == 0 ) {
                        String torowcol[] = Util.TokenizerString2(toitemvalue,"_") ;
                        String torow = torowcol[1] ;
                        String tocol = torowcol[2] ;
                    
                        if(fromrow.equals(torow) && fromcol.equals(tocol)) continue ;

                        String para = outrepid + separator + torow
                            + separator + tocol + separator + fromrow + separator + fromcol  ;
                        RecordSet.executeProc("T_OutReportItem_Copy",para);
                    }
                }
            }
        }
    }

    response.sendRedirect("OutReportItem.jsp?outrepid="+outrepid);
}


if(operation.equals("deletebatch")){

    char separator = Util.getSeparator() ;

    if(deletetype.equals("1")) {

        for(int j= 1 ; j<= outrepcolumn ; j++ ) {
                String para = outrepid + separator + itemrow + separator + ""+j   ;
                RecordSet.executeProc("T_OutReportItem_DeleteByRowCol",para);
        }
    }

    else if(deletetype.equals("2")) {

        for(int j= 1 ; j<= outreprow ; j++ ) {
                String para = outrepid + separator + ""+j + separator + itemcolumn   ;
                RecordSet.executeProc("T_OutReportItem_DeleteByRowCol",para);
        }
    }
    
    response.sendRedirect("OutReportItem.jsp?outrepid="+outrepid);
}

if(operation.equals("editrow")){

    RecordSet.executeSql(" select rowid from T_OutReportItemRow where outrepid="+outrepid+" and itemrow="+itemrow );

    if(RecordSet.next()) {
        RecordSet.executeSql(" delete from T_OutReportItemRow where outrepid="+outrepid+" and itemrow="+itemrow );
    }
    else {
        RecordSet.executeSql(" insert into T_OutReportItemRow(outrepid,itemrow) values("+outrepid+","+itemrow +")");
    }
    
    response.sendRedirect("OutReportItem.jsp?outrepid="+outrepid);
}


%>