liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
public with sharing class ISO_DemandOperAndDemonsController {
 
    
 
    //公共变量:list
    public List<IS_Opportunity_Demand_Operating__c> pageQueryoDoList{get;set;}
    public List<IS_Opportunity_Demand_Demonstration__c> pageQueryoDDList{get;set;}
    //公共变量:对象数据
    public IS_Opportunity_Demand_Operating__c pageShwoElement{get;set;}
    public String ISodcIdStr {get;set;}
    public String OpporIdStr {get;set;}
    public String abortCode {get;set;}
    public IS_Opportunity_Demand__c ISOhead {get;set;}
    public ISOpportunityDemandInfo pageShowSet{get;set;}
    public ISOpportunityDemandInfo pageShowSetClone{get;set;}
    public List<IS_Opportunity_Demand__c> ISOheadList{get;set;}
    public List<MailEle> initMail{get;set;}
    //公共变量: 数据类型
    public Id thePageIdStr{get;set;}
    public Integer indexOpr{get;set;}
    public Integer indexDom{get;set;}
    public String nowDateShow{get;set;}
    public String ErrorMsg{get;set;}
    public String StatusMsg{get;set;}
    public String Brand_of_Laparoscopy_Tower{get;set;}
    public boolean NewOrNot {get;set;}
    public boolean EditAble {get;set;}
    public String TargetName{get;set;}
    public Integer OprNumCnt{get;set;}
    public Integer DomNumCnt{get;set;}
    public boolean UnableToEdit{get;set;}
    public String MailTarget{get;set;}
    public String Cc {get;set;}
    public String Ccid {get;set;}
    public String MailDetail {get;set;}
    public String CopyIDStr {get;set;}
    public String PDFfileName {get;set;}//为打印PDF提供名字
    public String isReturn{get;set;} //判断保存之后是否返回
    /**
    追加了一个字符串,把需要变色的id压进去,传到前台
    */
    public String ErrorColorChangeStr  {get;set;}
    public String ErrorColorChangeStrShow {get;set;}
    //公共变量:集合变量
    public List<String> CcList{get;set;}
    //公共变量:Flg控制标签
    //
        public String ErrorHead{get;set;}
        public String ErrorTitle{get;set;}
        public String ErrorElements{get;set;}
        public boolean ifCtrlUtil{get;set;}
    //
 
    public ISO_DemandOperAndDemonsController() {
        ifCtrlUtil = false;
        nowDateShow = Date.today().year()+'年' +Date.today().month()+'月'+Date.today().day()+'日';
            ISodcIdStr = ApexPages.currentPage().getParameters().get('id');
            CopyIDStr = ApexPages.currentPage().getParameters().get('CopyID');
            system.debug(OpporIdStr+'::::::::OppoerID');
            abortCode = ApexPages.currentPage().getParameters().get('abortID');
        if(ISodcIdStr==''|ISodcIdStr==null){
            OpporIdStr = ApexPages.currentPage().getParameters().get('OppoerID');
            NewOrNot = false;
            EditAble = true;
        }else{
            NewOrNot = true;
            EditAble = false;
        }
        pageQueryoDoList = new List<IS_Opportunity_Demand_Operating__c>();
        pageQueryoDDList = new List<IS_Opportunity_Demand_Demonstration__c>();
        pageShwoElement = new IS_Opportunity_Demand_Operating__c();
        pageShowSetClone = new ISOpportunityDemandInfo();
        pageShowSet = new ISOpportunityDemandInfo();
        ISOheadList = new List<IS_Opportunity_Demand__c>();
        initMail = new List<MailEle>();
        CcList = new List<String>();
        //ErrorElements = new List<String>();
        ErrorElements='ErrorHead,ErrorHead,ErrorHead,ErrorHead';
        //system.debug('Test$$$$$00002'+ErrorElements);
        this.ErrorHead = 'ErrorHead';
        this.ErrorTitle = 'ErrorTitle';
        indexOpr = 0;
        indexDom = 0;
    }
    //*******************************************************************************************/
    //                      外部使用的方法            Start
    //*******************************************************************************************/
    public static String synchronousSodWithOppor(List<String> oppoidList){
        //对于询价新增的需求表,通过这个方法进行必要的参数同步,一般用于同步状态,日期
        List<Opportunity> ThisOpporList = [select id,S_Install_Date__c,SI_FinishedPorj_Date__c from Opportunity 
                                    where
                                        id = : oppoidList];
        Map<String,String> opporidMap = new Map<String,String>();
        Map<String,Date> opporDateInsMap = new Map<String,Date>();
        Map<String,Date> opporDateProMap = new Map<String,Date>();
        for(Opportunity ops : ThisOpporList){
            opporDateInsMap.put(ops.Id, ops.S_Install_Date__c);
            opporDateProMap.put(ops.Id, ops.SI_FinishedPorj_Date__c);
        }
        List<IS_Opportunity_Demand__c> updateISO = [select id, Program_Finished_Date__c,Install_Date__c,Opportunity_ID__c from IS_Opportunity_Demand__c
                                                    where
                                                         Opportunity_ID__c = :oppoidList
                                                    and
                                                        Abort_Date__c = null];
        for(IS_Opportunity_Demand__c iso : updateISO){
            opporidMap.put(iso.id, iso.Opportunity_ID__c);
        }
        for(IS_Opportunity_Demand__c iso : updateISO){
            iso.Program_Finished_Date__c = opporDateProMap.get(opporidMap.get(iso.id));
            iso.Install_Date__c = opporDateInsMap.get(opporidMap.get(iso.id));
        }
        Savepoint sp = Database.setSavepoint();
        try{
            update updateISO;
            return 'Fin';
        }catch(Exception o){
            Database.rollback(sp);
            return 'DDL Error';
        }
 
    }
    public static String SetQuoteDecide(String oppoid){
        List<IS_Opportunity_Demand__c> setDecideDate =  [SELECT Quote_Locked_Date__c from IS_Opportunity_Demand__c where Opportunity_ID__c = :oppoid];
        for(IS_Opportunity_Demand__c iso: setDecideDate){
            iso.Quote_Locked_Date__c = Date.today();
        }
        Savepoint sp = Database.setSavepoint();
        try{
            update setDecideDate;
            }catch(Exception o){
                return o+'';
                DataBase.rollback(sp);
            }
        return 'Fin';
    }
    public static Map<id,Integer> setNameForNew(List<IS_Opportunity_Demand__c> newList){
        Map<id,Integer> isoCount = new Map<id,Integer>();
        Set<id> OppoIDset = new Set<id>();
 
        for(IS_Opportunity_Demand__c NewISO : newList){
            OppoIDset.add(NewISO.Opportunity_ID__c);
        }
        //
 
        List<AggregateResult> ISOList  = [  select 
                                                count(id) isoID,
                                                Opportunity_ID__c oppoID
                                            from
                                                IS_Opportunity_Demand__c
                                            where
                                                Opportunity_ID__c = :OppoIDset
                                            group by 
                                                Opportunity_ID__c];
 
        for(AggregateResult ar : ISOList){
            system.debug('$$$$$$$$$$$$$$$$$$'+Integer.valueOf(ar.get('isoID')));
            isoCount.put((id)ar.get('oppoID'), Integer.valueOf(ar.get('isoID')));
        }
        
        return isoCount;
    }
    public static boolean UpdateMotherOpportunity(List<IS_Opportunity_Demand__c> oldList,List<IS_Opportunity_Demand__c> newList){
        List<id> oldIdList = new List<id>();
        Map<id,id> NewIdMap = new Map<id,id>();
        Map<id,id> OppToSODIdMap = new Map<id,id>();
        List<id> updateOppor = new List<id>();
        for(IS_Opportunity_Demand__c iso : oldList){
            if(iso.Approval_Date__c == null &&iso.Submit_Date__c !=null){
                oldIdList.add(iso.id);
            }
        }
        for(IS_Opportunity_Demand__c iso : newList){
            if(iso.Approval_Date__c !=null){
                NewIdMap.put(iso.id, iso.Opportunity_ID__c);
                OppToSODIdMap.put(iso.Opportunity_ID__c, iso.id);
            }
        }
        for(id idc : oldIdList){
            if(NewIdMap.containsKey(idc)){
                updateOppor.add(NewIdMap.get(idc));
            }
        }
        List<Opportunity> OppList = [select id,SI_Decide_ID__c,Opportunity_No__c from Opportunity where id in:updateOppor];
        for(Opportunity Op : OppList){
            Op.SI_Decide_ID__c = OppToSODIdMap.get(Op.Id);
        }
        Savepoint sp = Database.setSavepoint();
        boolean Flg;
        try{
            update OppList;
            Flg = true;
            }catch (Exception o){
                Database.rollback(sp);
                Flg = false;
            }
        return Flg;
    }
    public static String SetStockDate(id isoID){
        List<IS_Opportunity_Demand__c> updateList = new List<IS_Opportunity_Demand__c>();
        updateList = [SELECT id,Stock_Comfirm_Date__c,Equipment_Confirm_Date__c from IS_Opportunity_Demand__c where id = :isoID];
        return 'Fin';
    }
    public static String Abort_SI(id isoID,String AbortReason){
        List<IS_Opportunity_Demand__c> updateList = new List<IS_Opportunity_Demand__c>();
        if(AbortReason==null||String.isBlank(AbortReason)){
            return '请输入终止SI需求原因';
        }else{
            
            updateList = [SELECT id,Abort_SI_Reason__c,Abort_Date__c from IS_Opportunity_Demand__c where id = :isoID];
            for(IS_Opportunity_Demand__c iso : updateList){
                iso.Abort_SI_Reason__c = AbortReason;
                iso.Abort_Date__c = Date.today();
            }
            Savepoint sp = Database.setSavepoint();
            try{
                update updateList;
                return 'Fin';
            }catch (Exception o){
                Database.rollback(sp);
                return 'DataBase is Crashed,Connect with the Developer PLEASE';
            }
        }
    }
    public static String CopyFunc(String ISodcIdStr){
 
            IS_Opportunity_Demand__c  isoHead = new  IS_Opportunity_Demand__c() ;
            List<IS_Opportunity_Demand_Operating__c> isoODO = new List<IS_Opportunity_Demand_Operating__c>();
            List<IS_Opportunity_Demand_Demonstration__c> isoODD = new List<IS_Opportunity_Demand_Demonstration__c>();
            isoODD        =        [ SELECT 
                                    Id,
                                    IsDeleted,
                                    Name,
                                    Other_Relative_Position__c,
                                    IS_Opportunity_Demand__c,
                                    Demand_Demonstration_Area_Sum__c,
                                    Display_Separate_TF__c,
                                    Mobile_Equip_Controller_TF__c,
                                    Display_Equipment_List__c,
                                    HD_Camera_Panorama_TF__c,
                                    Microphone_Type_List__c,
                                    Position_To_Operating_Room_List__c,
                                    Share_With_Other_Firm_TF__c,
                                    Other_Require_Text__c,
                                    Microphone_Number__c,
                                    Microphone_Exsit_TF__c,
                                    Brand_Name__c 
                                FROM 
                                    IS_Opportunity_Demand_Demonstration__c
                                where
                                    IS_Opportunity_Demand__c =:ISodcIdStr
                                ];
            isoHead   = [SELECT 
                                    Id,
                                    Name,
                                    Name_Index__c ,
                                    Response__c,
                                    Opportunity_ID__c,
                                    Mail_Tar_Selector__c,
                                    Phone_Of_Nuers__c,
                                    Phone_Of_HDOA__c,
                                    Phone_of_ImfD__c,
                                    Phone_of_GAD__c,
                                    Phone_of_EDC__c,
                                    Phone_of_CCD__c,
                                    Lead_Of_Nurses__c,
                                    Lead_Of_Department_Of_Anesthesia__c,
                                    Lead_Of_Information_Department__c,
                                    Lead_of_General_Affairs_Department__c,
                                    Lead_of_Equipment_Department__c,
                                    Lead_of_Capital_Construction_Department__c,
                                    Public_Hospital_TF__c,
                                    Private_Hospital_TF__c,
                                    Other_Hospital_TF__c,
                                    Operating_Room_Sum__c,
                                    Demand_Demonstration_Cnt__c,
                                    OperatingCnt__c,
                                    Demonstration_Area_Sum__c,
                                    Preparation_Stage_TF__c,
                                    Building_Phase_Stage_TF__c,
                                    Purification_Construction_Stage_TF__c,
                                    Other_Stage_Text__c,
                                    Operating_Room_Plane_Graph_TF__c,
                                    Head_Mast_Position_Graph_TF__c,
                                    Operating_Room_Clear_Graph_TF__c,
                                    Demonstration_Area_Plane_Graph_TF__c,
                                    Buliding_Plane_Graph_TF__c,
                                    Other_Enginee_List_Text__c,
                                    Func_SOD_Status__c
                            FROM 
                                    IS_Opportunity_Demand__c
                            where
                                    Id  =:  ISodcIdStr
            ];
            isoODO             = [SELECT Id,
                                    Name,
                                    IS_Opportunity_Demand__c,
                                    Operating_Room_Num_or_Name__c,
                                    Operating_Room_Position_Area__c,
                                    Operating_Room_Position_Building__c,
                                    Operating_Room_Position_Stage__c,
                                    Operating_Room_Length__c,
                                    Operating_Room_Width__c,
                                    Operating_Room_Build_Heigth__c,
                                    Operating_Room_Top_heigth__c,
                                    isChirurgery_TF__c,
                                    isGynaecology_TF__c,
                                    isUrological_TF__c,
                                    isOrthopedics_TF__c,
                                    isENT_TF__c,
                                    isPlanned_TF__c,
                                    isAural_Sursery_TF__c,
                                    isGastroenterology_TF__c,
                                    isRespirationDept_TF__c,
                                    isInvasive_Technology_TF__c,
                                    Wall_Mounting_Type_TF__c,
                                    Dept_Others_Text__c,
                                    Centre_Air_Support_System_TF__c,
                                    Purify_Operating_Room_TF__c,
                                    Lamp_Panel_Type_List__c,
                                    Lamp_Panel_Sum__c,
                                    Planning_Blue_Room_TF__c,
                                    Need_to_Transform_TF__c,
                                    Centralized_Control_TF__c,
                                    Shadowless_And_Carm_Ctrl1_TF__c,
                                    Shadowless_And_Carm_Ctrl2_TF__c,
                                    Shadowless_And_Carm_Ctrl3_TF__c,
                                    Reform_Lamp_Plane_List__c,
                                    Reform_Lamp_Plane_Sum__c,
                                    Equipment_Centralized_Control_TF__c,
                                    Equipment_Center_Crtl_Minor_TF__c,
                                    OTV_S190_TF__c,
                                    OTV_S7_Pro_TF__c,
                                    T3D_System_TF__c,
                                    CV_180_TF__c,
                                    CV_190_TF__c,
                                    Olympus_Endoscope_Other_Text__c,
                                    UHI_4_TF__c,
                                    UHI_3_TF__c,
                                    UHI_3_TF_add__c,
                                    Other_3D_Displayer__c ,
                                    Pneumoperitoneum_Other__c,
                                    Storz_Main__c,
                                    Storz_Main_Model__c,
                                    Stryker_Main__c,
                                    Stryker_Main_Model__c,
                                    Compatible_Signal_TF__c,
                                    Compatible_Signal_Format_Text__c,
                                    Compatible_Signal_Sum__c,
                                    Party_a_Purchase_TF__c,
                                    Olympus_Package_Purchase_TF__c,
                                    Party_A_Hold_TF__c,
                                    Laparoscopy_Tower_TF__c,
                                    Anesthesia_Tower_TF__c,
                                    Surgical_Tower_TF__c,
                                    Display_Tower_Radiation_TF__c,
                                    Other_Tower_TF__c,
                                    Brand_of_Laparoscopy_Tower_List__c,
                                    Other_Brand_Laparoscopy_Text__c,
                                    Laparoscopy_Tower_Type_List__c,
                                    Install_Type_FullHD_List_Display__c,
                                    Laparoscopy_Tower_Model_Desciption_Text__c,
                                    Brand_Surgical_Tower_List__c,
                                    Surgical_Tower_Model_Or_Decription_Text__c,
                                    Brand_Of_Display_Tower_Radiation_List__c,
                                    Display_Tower_Model_Or_Description__c,
                                    Other_Tower_Brand__c,
                                    Performanc_60inch_Display__c,
                                    Other_FullHD_Display__c,
                                    Other_Tower_Brand_List__c,
                                    Other_Tower_Model_Description__c,
                                    Purchase_Plan_SpringArm_List__c,
                                    Brand_Of_SpringArm__c,
                                    Other_Medic_Displayer__c,
                                    HIS_TF__c,PASC_TF__c,
                                    Hand_Anaesthesia_SYS_TF__c,
                                    Other_IMF_Interface__c,
                                    SpringArm_AC2000_Sum__c,
                                    SpringArm_AC3000_Sum__c,
                                    SpringArm_Other_Name__c,
                                    Shadowless_Lamp_Procurement_Plan__c,
                                    Other_Main_And_Model_Text__c,
                                    Equipment_Centralized_Control_List__c,
                                    Brand_Of_Shadowless_Lamp_List__c,
                                    ShadowlessLamp_Model_Or_Description_Text__c,
                                    Shadowless_Lamp_Type_List__c,
                                    Brand_Of_Mid_Camera_List__c,
                                    Mid_Camera_Model_Or_Descirption_Text__c,
                                    Mid_Camera_Signal_Type_List__c,
                                    Side_Camera_Procurement_Plan__c,
                                    Brand_Of_Side_Camera__c,
                                    Side_Camera_Model_Or_Description_Text__c,
                                    Side_Camera_Signal_Type_List__c,
                                    Endoscopic_Other_Video_Src_ListM__c,
                                    OEV_262_2D_Sum__c,
                                    Other_2D_Sum__c,
                                    Other_2D_Name__c,
                                    Dept_Others_TF__c,
                                    Olympus_Endoscope_2_Model_List__c,
                                    Other_Main_And_Model_TF__c,
                                    Energy_Portable_ESG_400_TF__c,
                                    Energy_Portable_USG_400_TF__c,
                                    Energy_Portable_UES_40_TF__c,
                                    Energy_Portable_SSG_2_TF__c,
                                    Energy_Portable_Other_Text__c,
                                    Covidien_Brand_TF__c,
                                    Force_FX_C_Brand_TF__c,
                                    Force_Triad_Brand_TF__c,
                                    ERBE_Brand_TF__c,
                                    VIO300D_Brand_TF__c,
                                    Anesthesia_Tower_Text_Description__c,
                                    Brand_Of_Anesthesia_Tower_List__c,
                                    Operating_Room_Plan__c,
                                    Brand_Of_Operating_Bed_List__c,
                                    Operating_Bed_Model_Or_Description_Text__c,
                                    Operating_Equipment_Ctrl_TF__c,
                                    Other_Vs_Arm_Type_C_TF__c,
                                    Other_Vs_DSA_TF__c,
                                    Other_Vs_EUS_TF__c,
                                    Other_Vs_Type_B_ultrasonic_TF__c,
                                    Other_Vs_Other_Text__c,
                                    LMD_2451TC_Sum__c,
                                    LMD_3251TC_Sum__c,
                                    Other_3D_Displayer_Sum__c,
                                    Size60_3D_Displayer_Sum__c,
                                    Sony_42_3D_Displayer_Pro_Sum__c,
                                    In_Cell_InstallType_TF__c,
                                    Display_60_Install_TF__c,
                                    IMF_IO_System__c,
                                    IMH_20_Model_TF__c,
                                    IMH_10_Model_TF__c,
                                    Install_Type_60Display_List__c,
                                    MultiTouch_Display_Equip_Ctrl_TF__c,
                                    Wireless_Music_Input_Ctrl_TF__c,
                                    Reserved_Video_Channels_Sum__c,
                                    Reserved_Audio_Channels_Sum__c,
                                    Remarks_Text__c 
                            FROM 
                                    IS_Opportunity_Demand_Operating__c
                            where
                                    IS_Opportunity_Demand__c =: ISodcIdStr
                                ];
        isoHead.id =null;
        isoHead.name='*';
        insert isoHead;
        for(IS_Opportunity_Demand_Operating__c odo: isoODO){
            odo.id= null;
            odo.IS_Opportunity_Demand__c = isoHead.id;
        }
        for(IS_Opportunity_Demand_Demonstration__c odd: isoODD){
            odd.id= null;
            odd.IS_Opportunity_Demand__c = isoHead.id;
        }
        insert isoODO; 
        insert isoODD;
        return isoHead.id;
    }
    //*******************************************************************************************/
    //                      外部使用的方法              END
    //*******************************************************************************************/
    public ISO_DemandOperAndDemonsController(ApexPages.StandardController controller) {
        //this.targetEstimateId = (String)(ApexPages.currentPage().getParameters().get('id'));
        nowDateShow = Date.today().year()+'年' +Date.today().month()+'月'+Date.today().day()+'日';
        ISodcIdStr = ApexPages.currentPage().getParameters().get('id');
        OpporIdStr = ApexPages.currentPage().getParameters().get('OppoerID');
        system.debug(OpporIdStr+'::::::::OppoerID');
        abortCode = ApexPages.currentPage().getParameters().get('abortID');
        if(ISodcIdStr==''|ISodcIdStr==null){
            NewOrNot = false;
            EditAble = true;
        }else{
            NewOrNot = true;
            EditAble = false;
        }
        pageQueryoDoList = new List<IS_Opportunity_Demand_Operating__c>();
        pageQueryoDDList = new List<IS_Opportunity_Demand_Demonstration__c>();
        pageShwoElement = new IS_Opportunity_Demand_Operating__c();
        pageShowSetClone = new ISOpportunityDemandInfo();
        pageShowSet = new ISOpportunityDemandInfo();
        ISOheadList = new List<IS_Opportunity_Demand__c>();
        initMail = new List<MailEle>();
        CcList = new List<String>();
        //ErrorElements = new List<String>();
        ErrorElements='ErrorHead,ErrorHead,ErrorHead,ErrorHead';
        //system.debug('Test$$$$$00002'+ErrorElements);
        this.ErrorHead = 'ErrorHead';
        this.ErrorTitle = 'ErrorTitle';
        indexOpr = 0;
        indexDom = 0;
    }
    public void init(){ 
        OprNumCnt = 0;
        DomNumCnt = 0;
        pageQueryoDoList = new List<IS_Opportunity_Demand_Operating__c>();
        pageQueryoDDList = new List<IS_Opportunity_Demand_Demonstration__c>();
        if(abortCode!=null&&abortCode!=''){
            //更新需求表:终止之前的需求表,然后创建新的
            List<IS_Opportunity_Demand__c> ODCLIST = new List<IS_Opportunity_Demand__c>();
            ODCLIST = [SELECT id,Abort_Date__c from IS_Opportunity_Demand__c where Opportunity_ID__c =:abortCode and Abort_Date__c=null];
            for(IS_Opportunity_Demand__c Od : ODCLIST){
                Od.Abort_Date__c = Date.today();
            }
            update ODCLIST;
        }
        ISOhead = new IS_Opportunity_Demand__c();
        if(ISodcIdStr!=''&&ISodcIdStr!=null){
            pageQueryoDDList = [ SELECT 
                                    Id,
                                    IsDeleted,
                                    Name,
                                    Other_Relative_Position__c,
                                    IS_Opportunity_Demand__c,
                                    Demand_Demonstration_Area_Sum__c,
                                    Display_Separate_TF__c,
                                    Mobile_Equip_Controller_TF__c,
                                    Display_Equipment_List__c,
                                    HD_Camera_Panorama_TF__c,
                                    Microphone_Type_List__c,
                                    Position_To_Operating_Room_List__c,
                                    Share_With_Other_Firm_TF__c,
                                    Other_Require_Text__c,
                                    Microphone_Number__c,
                                    Microphone_Exsit_TF__c,
                                    Brand_Name__c 
                                FROM 
                                    IS_Opportunity_Demand_Demonstration__c
                                where
                                    IS_Opportunity_Demand__c =:ISodcIdStr
                                ];
            ISOheadList = [SELECT 
                                    Id,
                                    OwnerId,
                                    IsDeleted,
                                    Name,
                                    Name_Index__c ,
                                    Submit_Date__c,
                                    Response__c,
                                    Mail_Tar_Selector__c,
                                    Approval_Date__c,
                                    Phone_Of_Nuers__c,
                                    Phone_Of_HDOA__c,
                                    Phone_of_ImfD__c,
                                    Phone_of_GAD__c,
                                    Phone_of_EDC__c,
                                    Phone_of_CCD__c,
                                    Opportunity_ID__c,
                                    Lead_Of_Nurses__c,
                                    Lead_Of_Department_Of_Anesthesia__c,
                                    Lead_Of_Information_Department__c,
                                    Lead_of_General_Affairs_Department__c,
                                    Lead_of_Equipment_Department__c,
                                    Lead_of_Capital_Construction_Department__c,
                                    Table_Create_Date__c,
                                    Public_Hospital_TF__c,
                                    Private_Hospital_TF__c,
                                    Other_Hospital_TF__c,
                                    Operating_Room_Sum__c,
                                    Demand_Demonstration_Cnt__c,
                                    OperatingCnt__c,
                                    Demonstration_Area_Sum__c,
                                    Preparation_Stage_TF__c,
                                    Building_Phase_Stage_TF__c,
                                    Purification_Construction_Stage_TF__c,
                                    Other_Stage_Text__c,
                                    Operating_Room_Plane_Graph_TF__c,
                                    Head_Mast_Position_Graph_TF__c,
                                    Operating_Room_Clear_Graph_TF__c,
                                    Demonstration_Area_Plane_Graph_TF__c,
                                    Buliding_Plane_Graph_TF__c,
                                    Other_Enginee_List_Text__c,
                                    Func_SOD_Status__c
                            FROM 
                                    IS_Opportunity_Demand__c
                            where
                                    Id  =:  ISodcIdStr
            ];
            if(ISOheadList.size()==1){
                ISOhead = ISOheadList[0];
                ISOhead.Operating_Room_Sum__c = ISOhead.OperatingCnt__c;
                ISOhead.Demonstration_Area_Sum__c = ISOhead.Demand_Demonstration_Cnt__c;
                String oppoIDs = ISOhead.Opportunity_ID__c;
                Opportunity OppList = [select id,SI_Decide_ID__c,Opportunity_No__c from Opportunity where id =:oppoIDs];
                PDFfileName = OppList.Opportunity_No__c;
 
            }else{
                ISOhead = new IS_Opportunity_Demand__c(Operating_Room_Sum__c = 1,Demonstration_Area_Sum__c = 1,Response__c='');
            }
            pageQueryoDoList = [SELECT Id,
                                    Name,
                                    IS_Opportunity_Demand__c,
                                    Operating_Room_Num_or_Name__c,
                                    Operating_Room_Position_Area__c,
                                    Operating_Room_Position_Building__c,
                                    Operating_Room_Position_Stage__c,
                                    Operating_Room_Length__c,
                                    Operating_Room_Width__c,
                                    Operating_Room_Build_Heigth__c,
                                    Operating_Room_Top_heigth__c,
                                    isChirurgery_TF__c,
                                    isGynaecology_TF__c,
                                    isUrological_TF__c,
                                    isOrthopedics_TF__c,
                                    isENT_TF__c,
                                    isPlanned_TF__c,
                                    isAural_Sursery_TF__c,
                                    isGastroenterology_TF__c,
                                    isRespirationDept_TF__c,
                                    isInvasive_Technology_TF__c,
                                    Wall_Mounting_Type_TF__c,
                                    Dept_Others_Text__c,
                                    Centre_Air_Support_System_TF__c,
                                    Purify_Operating_Room_TF__c,
                                    Lamp_Panel_Type_List__c,
                                    Lamp_Panel_Sum__c,
                                    Planning_Blue_Room_TF__c,
                                    Need_to_Transform_TF__c,
                                    Centralized_Control_TF__c,
                                    Shadowless_And_Carm_Ctrl1_TF__c,
                                    Shadowless_And_Carm_Ctrl2_TF__c,
                                    Shadowless_And_Carm_Ctrl3_TF__c,
                                    Reform_Lamp_Plane_List__c,
                                    Reform_Lamp_Plane_Sum__c,
                                    Equipment_Centralized_Control_TF__c,
                                    Equipment_Center_Crtl_Minor_TF__c,
                                    OTV_S190_TF__c,
                                    OTV_S7_Pro_TF__c,
                                    T3D_System_TF__c,
                                    CV_180_TF__c,
                                    CV_190_TF__c,
                                    Olympus_Endoscope_Other_Text__c,
                                    UHI_4_TF__c,
                                    UHI_3_TF__c,
                                    UHI_3_TF_add__c,
                                    Other_3D_Displayer__c ,
                                    Pneumoperitoneum_Other__c,
                                    Storz_Main__c,
                                    Storz_Main_Model__c,
                                    Stryker_Main__c,
                                    Stryker_Main_Model__c,
                                    Compatible_Signal_TF__c,
                                    Compatible_Signal_Format_Text__c,
                                    Compatible_Signal_Sum__c,
                                    Party_a_Purchase_TF__c,
                                    Olympus_Package_Purchase_TF__c,
                                    Party_A_Hold_TF__c,
                                    Laparoscopy_Tower_TF__c,
                                    Anesthesia_Tower_TF__c,
                                    Surgical_Tower_TF__c,
                                    Display_Tower_Radiation_TF__c,
                                    Other_Tower_TF__c,
                                    Brand_of_Laparoscopy_Tower_List__c,
                                    Other_Brand_Laparoscopy_Text__c,
                                    Laparoscopy_Tower_Type_List__c,
                                    Install_Type_FullHD_List_Display__c,
                                    Laparoscopy_Tower_Model_Desciption_Text__c,
                                    Brand_Surgical_Tower_List__c,
                                    Surgical_Tower_Model_Or_Decription_Text__c,
                                    Brand_Of_Display_Tower_Radiation_List__c,
                                    Display_Tower_Model_Or_Description__c,
                                    Other_Tower_Brand__c,
                                    Performanc_60inch_Display__c,
                                    Other_FullHD_Display__c,
                                    Other_Tower_Brand_List__c,
                                    Other_Tower_Model_Description__c,
                                    Purchase_Plan_SpringArm_List__c,
                                    Brand_Of_SpringArm__c,
                                    Other_Medic_Displayer__c,
                                    HIS_TF__c,PASC_TF__c,
                                    Hand_Anaesthesia_SYS_TF__c,
                                    Other_IMF_Interface__c,
                                    SpringArm_AC2000_Sum__c,
                                    SpringArm_AC3000_Sum__c,
                                    SpringArm_Other_Name__c,
                                    Shadowless_Lamp_Procurement_Plan__c,
                                    Other_Main_And_Model_Text__c,
                                    Equipment_Centralized_Control_List__c,
                                    Brand_Of_Shadowless_Lamp_List__c,
                                    ShadowlessLamp_Model_Or_Description_Text__c,
                                    Shadowless_Lamp_Type_List__c,
                                    Brand_Of_Mid_Camera_List__c,
                                    Mid_Camera_Model_Or_Descirption_Text__c,
                                    Mid_Camera_Signal_Type_List__c,
                                    Side_Camera_Procurement_Plan__c,
                                    Brand_Of_Side_Camera__c,
                                    Side_Camera_Model_Or_Description_Text__c,
                                    Side_Camera_Signal_Type_List__c,
                                    Endoscopic_Other_Video_Src_ListM__c,
                                    OEV_262_2D_Sum__c,
                                    Other_2D_Sum__c,
                                    Other_2D_Name__c,
                                    Dept_Others_TF__c,
                                    Olympus_Endoscope_2_Model_List__c,
                                    Other_Main_And_Model_TF__c,
                                    Energy_Portable_ESG_400_TF__c,
                                    Energy_Portable_USG_400_TF__c,
                                    Energy_Portable_UES_40_TF__c,
                                    Energy_Portable_SSG_2_TF__c,
                                    Energy_Portable_Other_Text__c,
                                    Covidien_Brand_TF__c,
                                    Force_FX_C_Brand_TF__c,
                                    Force_Triad_Brand_TF__c,
                                    ERBE_Brand_TF__c,
                                    VIO300D_Brand_TF__c,
                                    Anesthesia_Tower_Text_Description__c,
                                    Brand_Of_Anesthesia_Tower_List__c,
                                    Operating_Room_Plan__c,
                                    Brand_Of_Operating_Bed_List__c,
                                    Operating_Bed_Model_Or_Description_Text__c,
                                    Operating_Equipment_Ctrl_TF__c,
                                    Other_Vs_Arm_Type_C_TF__c,
                                    Other_Vs_DSA_TF__c,
                                    Other_Vs_EUS_TF__c,
                                    Other_Vs_Type_B_ultrasonic_TF__c,
                                    Other_Vs_Other_Text__c,
                                    LMD_2451TC_Sum__c,
                                    LMD_3251TC_Sum__c,
                                    Other_3D_Displayer_Sum__c,
                                    Size60_3D_Displayer_Sum__c,
                                    Sony_42_3D_Displayer_Pro_Sum__c,
                                    In_Cell_InstallType_TF__c,
                                    Display_60_Install_TF__c,
                                    IMF_IO_System__c,
                                    IMH_20_Model_TF__c,
                                    IMH_10_Model_TF__c,
                                    Install_Type_60Display_List__c,
                                    MultiTouch_Display_Equip_Ctrl_TF__c,
                                    Wireless_Music_Input_Ctrl_TF__c,
                                    Reserved_Video_Channels_Sum__c,
                                    Reserved_Audio_Channels_Sum__c,
                                    Remarks_Text__c 
                            FROM 
                                    IS_Opportunity_Demand_Operating__c
                            where
                                    IS_Opportunity_Demand__c =: ISodcIdStr
                                ];
        }else{
            String TestJson = '';
            //String TestJson = '{ "MailEle": [{ "To":"AppleTest", "Fromer": "Applier", "Cc":"McLaughlin", "Details": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" },{ "To":"AppleTest", "Fromer": "SI", "Cc":"Hunter", "Details": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"},{ "To":"AppleTest", "Fromer": "SI", "Cc":"Harold", "Details": "cccc" },{ "To":"AppleTest", "Fromer": "Applier", "Cc":"Harold", "Details": "cccc" },{ "To":"AppleTest", "Fromer": "SI", "Cc":"Harold", "Details": "cccc" }]}';
            ISOhead = new IS_Opportunity_Demand__c(Operating_Room_Sum__c = 1,Demonstration_Area_Sum__c = 0,Response__c=TestJson);
            pageQueryoDoList.add(new IS_Opportunity_Demand_Operating__c(name='*'));
            //pageQueryoDDList.add(new IS_Opportunity_Demand_Demonstration__c(name='*'));
            pageShowSet = new ISOpportunityDemandInfo(ISOhead,pageQueryoDoList,pageQueryoDDList);
        }
        
        if(pageQueryoDoList.size()==1){
            pageShwoElement = pageQueryoDoList[0];
        }else if(pageQueryoDoList.size()==0){
            pageQueryoDoList.add(new IS_Opportunity_Demand_Operating__c(name='*'));
        }
        if(pageQueryoDDList.size()==0){
            //pageQueryoDDList.add(new IS_Opportunity_Demand_Demonstration__c(name='*'));
        }
        System.debug('ididididid'+ISOhead);
        System.debug('ddddd'+pageQueryoDoList.size());
        pageShowSet = new ISOpportunityDemandInfo(ISOhead,pageQueryoDoList,pageQueryoDDList);
        if(pageShowSet!=null){
            StatusMsg = 'Normal'; 
        }else{
            StatusMsg = 'Empty';
        }
        if(ISOhead.Submit_Date__c!=null||ISOhead.Approval_Date__c!=null){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '数据已提交审批,不能再进行编辑了'));
            UnableToEdit = false;
        }else{
            UnableToEdit = true;
        }
        if(ISOhead.Response__c!=null){
            system.debug('开始解析');
            initMail = ISO_DemandOperAndDemonsController.JSONtoMailElement(ISOhead.Response__c);
            system.debug('结束解析'+initMail);
        }
        OprNumCnt = pageQueryoDoList.size();
        DomNumCnt = pageQueryoDDList.size();
        //system.debug('开始解析id'+pageQueryoDDList[0].id);
    }
    /**
    页面交互功能,用于刷新相关负责人的联系方式
    */
    public void SearchPhone(){
 
        Map<String,String> ContactMap  = new Map<String,String>();
        ContactMap.put(pageShowSet.ISOdcInfoHead.Lead_Of_Nurses__c, '');
        ContactMap.put(pageShowSet.ISOdcInfoHead.Lead_Of_Department_Of_Anesthesia__c, '');
        ContactMap.put(pageShowSet.ISOdcInfoHead.Lead_Of_Information_Department__c, '');
        ContactMap.put(pageShowSet.ISOdcInfoHead.Lead_of_General_Affairs_Department__c, '');
        ContactMap.put(pageShowSet.ISOdcInfoHead.Lead_of_Equipment_Department__c, '');
        ContactMap.put(pageShowSet.ISOdcInfoHead.Lead_of_Capital_Construction_Department__c, '');
        List<Contact> ConPhoneList = [
                            SELECT
                                id,
                                name,
                                MobilePhone,
                                Phone
                            FROM
                                Contact
                            where
                                id in: ContactMap.keySet()
                            ];
        for(Contact Co : ConPhoneList){
            if(Co.MobilePhone!=null &&  Co.MobilePhone!=''){
                ContactMap.put(Co.id, Co.MobilePhone);
            }else if(Co.Phone!=null &&  Co.Phone!=''){
                ContactMap.put(Co.id, Co.Phone);
            }
        }
        if(pageShowSet.ISOdcInfoHead.Phone_Of_Nuers__c==null||pageShowSet.ISOdcInfoHead.Phone_Of_Nuers__c==''){
            pageShowSet.ISOdcInfoHead.Phone_Of_Nuers__c = ContactMap.get(pageShowSet.ISOdcInfoHead.Lead_Of_Nurses__c);
        }
        
        if(pageShowSet.ISOdcInfoHead.Phone_Of_HDOA__c==null||pageShowSet.ISOdcInfoHead.Phone_Of_HDOA__c=='')pageShowSet.ISOdcInfoHead.Phone_Of_HDOA__c = ContactMap.get(pageShowSet.ISOdcInfoHead.Lead_Of_Department_Of_Anesthesia__c);
        if(pageShowSet.ISOdcInfoHead.Phone_of_ImfD__c==null||pageShowSet.ISOdcInfoHead.Phone_of_ImfD__c=='')pageShowSet.ISOdcInfoHead.Phone_of_ImfD__c = ContactMap.get(pageShowSet.ISOdcInfoHead.Lead_Of_Information_Department__c);
        if(pageShowSet.ISOdcInfoHead.Phone_of_GAD__c==null||pageShowSet.ISOdcInfoHead.Phone_of_GAD__c=='')pageShowSet.ISOdcInfoHead.Phone_of_GAD__c = ContactMap.get(pageShowSet.ISOdcInfoHead.Lead_of_General_Affairs_Department__c);
        if(pageShowSet.ISOdcInfoHead.Phone_of_EDC__c==null||pageShowSet.ISOdcInfoHead.Phone_of_EDC__c=='')pageShowSet.ISOdcInfoHead.Phone_of_EDC__c = ContactMap.get(pageShowSet.ISOdcInfoHead.Lead_of_Equipment_Department__c);
        if(pageShowSet.ISOdcInfoHead.Phone_of_CCD__c==null||pageShowSet.ISOdcInfoHead.Phone_of_CCD__c=='')pageShowSet.ISOdcInfoHead.Phone_of_CCD__c = ContactMap.get(pageShowSet.ISOdcInfoHead.Lead_of_Capital_Construction_Department__c);
 
    }
    public void refreshDetail() {
        
        system.debug(indexOpr+'####'+indexDom );
        for(integer i = 0 ; i < indexOpr ; i++){
            pageQueryoDoList.add(new IS_Opportunity_Demand_Operating__c(name='*'));
        }
        for(integer i = 0 ; i < indexDom ; i++){
            pageQueryoDDList.add(new IS_Opportunity_Demand_Demonstration__c(name='*'));
        }
        //return null;
    }
    //public void refreshDetail(integer i,integer j){
    //  system.debug(indexOpr+'===='+indexDom );
    //}
    public Pagereference renturn(){
        if(OpporIdStr==null){
            OpporIdStr ='';
        }
           PageReference ref  = new Pagereference('/'+(OpporIdStr!=''?OpporIdStr:ISodcIdStr));
        ref.setRedirect(true);
        return ref;
    }
    public PageReference Save(){
            //insert
            System.debug('==========Test999'+pageShowSet.ISodoc_InfoList.size());
            System.debug('==========Test888'+pageShowSet.ISOdd_InfoList.size());
            system.debug('Test0001');
            PageReference ref = new Pagereference('/');
            //******************************************************************************
            //Pneumoperitoneum_Other__c 整理数据
            //******************************************************************************
 
            //******************************************************************************
            //Pneumoperitoneum_Other__c 整理数据
            //******************************************************************************
            if(ISodcIdStr==null||ISodcIdStr==''){
                ErrorColorChangeStr = this.CheckRules(pageShowSet.ISOdcInfoHead,pageShowSet.ISodoc_InfoList,pageShowSet.ISOdd_InfoList);
                system.debug('Test0002');
                IS_Opportunity_Demand__c insertODC = new IS_Opportunity_Demand__c();
                List<IS_Opportunity_Demand_Operating__c> insertOperatingList = new List<IS_Opportunity_Demand_Operating__c>();
                List<IS_Opportunity_Demand_Demonstration__c> insertDemonstration = new List<IS_Opportunity_Demand_Demonstration__c>();
                insertODC = pageShowSet.ISOdcInfoHead;
                insertODC.Table_Create_Date__c = Date.today();
                //insertOperatingList = pageShowSet.ISodoc_InfoList;
                //insertDemonstration = pageShowSet.ISOdd_InfoList;
                //if(insertODC.Operating_Room_Length__c == '无效'
                //  ||insertODC.Operating_Room_Width__c == '无效'
                //      ||insertODC.Operating_Room_Build_Heigth__c == '无效'
                //          ||insertODC.Operating_Room_Top_heigth__c = '无效'){
                //  ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '请修正无效的数据'));
                //  return null;
                //}
                if(insertODC.Operating_Room_Sum__c>0 ){
                    system.debug('Test0003');
                    Savepoint sp = Database.setSavepoint();
                    try{
                        insertODC.Id = null;
                        system.debug('Test0003====OpporIdStr'+OpporIdStr);
                        if(OpporIdStr!=null&&OpporIdStr!=''){
                            insertODC.Opportunity_ID__c = OpporIdStr;
                            insert insertODC;
                            system.debug('Test0003===TestInsert');
                        }else if(abortCode!=null && abortCode!=''){
                            insertODC.Opportunity_ID__c = abortCode;
                            insert insertODC;
                            OpporIdStr = abortCode;
                            } else{
                            system.debug('Test0003===TestInsert');
                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '未能锁定询价'));
                            return null;
                        }
                        system.debug('Test0003===2');
                        if(pageShowSet.ISodoc_InfoList.size()>0){
                            for(IS_Opportunity_Demand_Operating__c ODO : pageShowSet.ISodoc_InfoList){
                                if( ODO.IS_Opportunity_Demand__c    ==  null){
                                    ODO.IS_Opportunity_Demand__c = insertODC.id;
                                }
                                ODO.id = null;
                                if(ODO.Equipment_Centralized_Control_List__c=='控制无影灯'){
                                    if(ODO.Brand_Of_Shadowless_Lamp_List__c ==''
                                        ||ODO.ShadowlessLamp_Model_Or_Description_Text__c == ''
                                            ||ODO.Shadowless_Lamp_Type_List__c ==''){
                                        system.debug(ODO.Brand_Of_Shadowless_Lamp_List__c+'###'+ODO.ShadowlessLamp_Model_Or_Description_Text__c+'###'+ODO.Shadowless_Lamp_Type_List__c);
                                            ODO.Equipment_Centralized_Control_List__c.addError('请补全所选控制设备的相关信息');
                                            //ApexPages.addMessages('请补全无影灯相关控制设备信息');
                                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '请补全无影灯相关控制设备信息'));
                                            return null;
                                    }
                                }
                                if(ODO.Equipment_Centralized_Control_List__c=='控制术野摄像机'){
                                    if(ODO.Mid_Camera_Model_Or_Descirption_Text__c==''
                                        ||ODO.Mid_Camera_Signal_Type_List__c == ''
                                            ||ODO.Brand_Of_Mid_Camera_List__c ==''){
                                            ODO.Equipment_Centralized_Control_List__c.addError('请补全所选控制设备的相关信息');
                                            system.debug(ODO.Mid_Camera_Signal_Type_List__c+'###'+ODO.Brand_Of_Mid_Camera_List__c+'###'+ODO.Mid_Camera_Model_Or_Descirption_Text__c);
                                        
                                            //ApexPages.addMessages('请补中置术野摄像机相关控制设备信息');
                                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '请补中置术野摄像机相关控制设备信息'));
                                            return null;
                                    }
                                }
                                insertOperatingList.add(ODO);
                            }
                            insert insertOperatingList;
                        }
                        if(pageShowSet.ISOdd_InfoList.size()>0){
                            system.debug('检测InsertDemon数量'+pageShowSet.ISOdd_InfoList.size());
                            for(IS_Opportunity_Demand_Demonstration__c ODD : pageShowSet.ISOdd_InfoList){
                                if( ODD.IS_Opportunity_Demand__c    ==  null){
                                    ODD.IS_Opportunity_Demand__c = insertODC.id;
                                }
                                ODD.id = null;
                                insertDemonstration.add(ODD);
                            }
                            system.debug('检测InsertDemon数量'+insertDemonstration.size());
                            insert insertDemonstration;
                        }
                    }catch(Exception e){
                        system.debug('Test0004');
                        Database.rollback(sp);
                        ApexPages.addMessages(e);
                        return null;
                        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'e'));
                    }
                }else{
                    system.debug('Test0005');
                    String Error = '';
                    if(insertODC.Operating_Room_Sum__c  ==  0 ||insertODC.Operating_Room_Sum__c  == null){
                        Error = Error + '手术间数量为零   ';
                    }
                    //if(insertODC.Demonstration_Area_Sum__c    ==  0||insertODC.Demonstration_Area_Sum__c    ==  null){
                    //    Error = Error + '示教点数量为零   ';
                    //}
                    Error = Error + '不可保存';
                    system.debug('Test0005'+Error);
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, Error));
                    return null;
                }
            ref = new Pagereference('/'+OpporIdStr);
            }else if(CopyIDStr!=''&&CopyIDStr!=null){
 
                pageShowSet.ISOdcInfoHead.id=null;
                insert pageShowSet.ISOdcInfoHead;
                for(IS_Opportunity_Demand_Operating__c odo: pageShowSet.ISodoc_InfoList){
                    odo.id=null;
                    odo.IS_Opportunity_Demand__c = pageShowSet.ISOdcInfoHead.id;
                }
                for(IS_Opportunity_Demand_Demonstration__c odd: pageShowSet.ISOdd_InfoList){
                    odd.id=null;
                    odd.IS_Opportunity_Demand__c = pageShowSet.ISOdcInfoHead.id;
                }
                insert pageShowSet.ISodoc_InfoList;
                insert pageShowSet.ISOdd_InfoList;
            }else{
                if(UnableToEdit){
                    ErrorColorChangeStr = this.CheckRules(pageShowSet.ISOdcInfoHead,pageShowSet.ISodoc_InfoList,pageShowSet.ISOdd_InfoList);
                    system.debug('Anydatatype_msg'+pageShowSet.ISodoc_InfoList.size());
                    Savepoint sp = Database.setSavepoint();
                    system.debug('Test0009');
                    try{
                        update pageShowSet.ISOdcInfoHead;
                         for(IS_Opportunity_Demand_Operating__c isodo : pageShowSet.ISodoc_InfoList){
                            if(isodo.IS_Opportunity_Demand__c==null){
                                isodo.IS_Opportunity_Demand__c = pageShowSet.ISOdcInfoHead.id;
                            }
                            if(isodo.Name==null){
                                isodo.Name ='*';
                            }
                        }
                        system.debug('Test0010'+pageShowSet.ISOdd_InfoList.size());
                        for(IS_Opportunity_Demand_Demonstration__c isddd : pageShowSet.ISOdd_InfoList){
                            if(isddd.IS_Opportunity_Demand__c==null){
                                isddd.IS_Opportunity_Demand__c = pageShowSet.ISOdcInfoHead.id;
                            }
                             if(isddd.Name==null){
                                isddd.Name ='*';
                            }
                        }
                        List<IS_Opportunity_Demand_Operating__c> insertList = new List<IS_Opportunity_Demand_Operating__c>();
                        List<IS_Opportunity_Demand_Operating__c> updateList = new List<IS_Opportunity_Demand_Operating__c>();
                        List<IS_Opportunity_Demand_Demonstration__c> insertListODD = new List<IS_Opportunity_Demand_Demonstration__c>();
                        List<IS_Opportunity_Demand_Demonstration__c> updateListODD = new List<IS_Opportunity_Demand_Demonstration__c>();
                        for(IS_Opportunity_Demand_Operating__c isodo : pageShowSet.ISodoc_InfoList){
                            if(isodo.id==null){
                                insertList.add(isodo);
                            }else{
                                updateList.add(isodo);
                            }
                        }
                        for(IS_Opportunity_Demand_Demonstration__c isoDD : pageShowSet.ISOdd_InfoList){
                            if(isoDD.id==null){
                                insertListODD.add(isoDD);
                            }else{
                                updateListODD.add(isoDD);
                            }
                        }
                        if(insertList.size()>0){
                            insert insertList;
                        }
                        if(insertListODD.size()>0){
                            if(pageShowSet.ISOdcInfoHead.Demonstration_Area_Sum__c!=0){
                                insert insertListODD;
                            }
                            
                        }
                        if(updateList.size()>0){
                            update updateList;
                        }
                        if(updateListODD.size()>0){
                            update updateListODD;
                        }
                        ref = new Pagereference('/'+pageShowSet.ISOdcInfoHead.id);
                        }catch(Exception IO){
                            Database.rollback(sp);
                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, ''+IO));
                            return null;
                        }
                }else{
                    ref = new Pagereference('/'+pageShowSet.ISOdcInfoHead.id);
                }
                
                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '已存在的需求表'));
                system.debug('Test0006');
                //return null;
            }
            if(ErrorColorChangeStr!='Fin'){
                if(isReturn == 'false'){
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO , '以上数据不完整,请及时修正'));
                }else{
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '数据不完整,请修正'));
                }
                
                //return null;
            }
            ref.setRedirect(true);
            if(isReturn == 'true'){
                return ref;
                }else{
                    ISodcIdStr = pageShowSet.ISOdcInfoHead.id;
                    return null;
                }
            
        }
    public void completenessCheck(){
        ErrorColorChangeStr = this.CheckRules(pageShowSet.ISOdcInfoHead,pageShowSet.ISodoc_InfoList,pageShowSet.ISOdd_InfoList);
        if(ErrorColorChangeStr !='Fin')ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '需求表未填写完整,请修正'));
        
        system.debug('ErrorColorChangeStr'+ErrorColorChangeStr );
    }
    public String CheckRules(IS_Opportunity_Demand__c checkSOD,List<IS_Opportunity_Demand_Operating__c> checkoDoList,List<IS_Opportunity_Demand_Demonstration__c> checkoDDList){
        String ErrorStr = '';
        ErrorColorChangeStrShow = '';
        //提交的时候才验证
        if(true){
            /**
            工程文件清单(必须提供)
            */
            //if(checkSOD.Operating_Room_Plane_Graph_TF__c==false
            //    &&checkSOD.Head_Mast_Position_Graph_TF__c == false
            //        &&checkSOD.Operating_Room_Clear_Graph_TF__c == false
            //            &&checkSOD.Demonstration_Area_Plane_Graph_TF__c == false
            //                &&checkSOD.Buliding_Plane_Graph_TF__c == false
            //                    &&( checkSOD.Other_Enginee_List_Text__c == '' || checkSOD.Other_Enginee_List_Text__c == null    )){
            //                        ErrorStr += 'ProgramFileList,';
            //                        ErrorColorChangeStrShow +='工程文件清单(必须提供);';
            //                    }
            /**
            循环检索oDo内部的错误数据
            */
            for(integer i   =   0;i <   checkoDoList.size() ;   i++ ){
                if(checkoDoList[i].isChirurgery_TF__c   ==  false
                        &&checkoDoList[i].isGynaecology_TF__c   ==  false
                            &&checkoDoList[i].isUrological_TF__c    ==  false
                                &&checkoDoList[i].isOrthopedics_TF__c   ==  false
                                    &&checkoDoList[i].isENT_TF__c   ==  false
                                        &&checkoDoList[i].isAural_Sursery_TF__c ==  false
                                            &&checkoDoList[i].isGastroenterology_TF__c  ==  false
                                                &&checkoDoList[i].isRespirationDept_TF__c   ==  false
                                                    &&checkoDoList[i].isInvasive_Technology_TF__c   ==false
                                                        &&checkoDoList[i].Dept_Others_TF__c ==  false
                                                            ){
                                        ErrorStr    +=  'DeptForUse'+i+',';
                                        ErrorColorChangeStrShow += i+':使用科室;';
                }else   if(checkoDoList[i].Dept_Others_TF__c    ==  true
                            &&( checkoDoList[i].Dept_Others_Text__c ==  ''  ||  checkoDoList[i].Dept_Others_Text__c==   null)){
                    ErrorStr    +=  'DeptForUse'+i+',';
                }
                if(    checkoDoList[i].Operating_Room_Position_Area__c ==null || 
                        checkoDoList[i].Operating_Room_Position_Area__c ==''){
                    ErrorStr    +=  'ErrorPosition'+i+',';
                    ErrorColorChangeStrShow += i+':院区;';
                }else if(    checkoDoList[i].Operating_Room_Position_Building__c ==null || 
                        checkoDoList[i].Operating_Room_Position_Building__c ==''){
                    ErrorStr    +=  'ErrorPosition'+i+',';
                    ErrorColorChangeStrShow += i+':楼;';
                }else if(    checkoDoList[i].Operating_Room_Position_Stage__c ==null || 
                        checkoDoList[i].Operating_Room_Position_Stage__c ==''){
                    ErrorStr    +=  'ErrorPosition'+i+',';
                    ErrorColorChangeStrShow += i+':层;';
                }
                if(checkoDoList[i].Equipment_Center_Crtl_Minor_TF__c== true
                    &&checkoDoList[i].OTV_S190_TF__c   ==  false
                        &&  checkoDoList[i].OTV_S7_Pro_TF__c    ==  false
                            &&  checkoDoList[i].T3D_System_TF__c    ==  false
                                &&  checkoDoList[i].CV_180_TF__c    ==  false
                                    &&  checkoDoList[i].CV_190_TF__c    ==  false
                                        &&  (checkoDoList[i].Olympus_Endoscope_Other_Text__c    ==''    ||  checkoDoList[i].Olympus_Endoscope_Other_Text__c ==  null)){
                                            ErrorStr    +=  'olympusMainMirrorOne'+i+',';
                                            ErrorColorChangeStrShow +=i+':奥林巴斯内镜主机1型号;';
                }
                system.debug('FFFFFFFFFF'+checkoDoList[i].Equipment_Centralized_Control_TF__c+checkoDoList[i].OTV_S190_TF__c+checkoDoList[i].Olympus_Endoscope_Other_Text__c);
                if(checkoDoList[i].Energy_Portable_ESG_400_TF__c    ==  false
                        &&  checkoDoList[i].Energy_Portable_USG_400_TF__c   ==  false
                            &&  checkoDoList[i].Energy_Portable_UES_40_TF__c    ==  false
                                &&  checkoDoList[i].Energy_Portable_SSG_2_TF__c ==  false
                                    &&  (checkoDoList[i].Energy_Portable_Other_Text__c==null    ||  checkoDoList[i].Energy_Portable_Other_Text__c   =='')){
                    ErrorStr    +=  'OlympusEnergy'+i+',';
                    ErrorColorChangeStrShow +=i+':奥林巴斯能量平台;';
                }
                if(checkoDoList[i].Compatible_Signal_TF__c == true
                    &&(checkoDoList[i].Compatible_Signal_Format_Text__c == '' ||checkoDoList[i].Compatible_Signal_Format_Text__c == null)){
                    ErrorStr    +=  'Compatible_Signal_TF__c'+i+',';
                    ErrorColorChangeStrShow +=i+':兼容其信号;';
                }
                /**
                这里是吊塔配置判断
                */
                system.debug(checkoDoList[i].Laparoscopy_Tower_TF__c);
                system.debug(checkoDoList[i].Brand_of_Laparoscopy_Tower_List__c);
                system.debug(checkoDoList[i].Brand_of_Laparoscopy_Tower_List__c ==null);
                if(checkoDoList[i].Party_A_Hold_TF__c == true
                    &&checkoDoList[i].Laparoscopy_Tower_TF__c ==false
                        &&checkoDoList[i].Anesthesia_Tower_TF__c ==false
                            &&checkoDoList[i].Surgical_Tower_TF__c ==false
                                &&checkoDoList[i].Display_Tower_Radiation_TF__c ==false
                                    &&checkoDoList[i].Other_Tower_TF__c ==false){
                    ErrorStr    +=  'SetOfTower'+i+',';
                    ErrorColorChangeStrShow +=i+':吊塔配置;';
                }
                if(checkoDoList[i].Purchase_Plan_SpringArm_List__c == '甲方已有'
                    &&(checkoDoList[i].Brand_Of_SpringArm__c == ''||checkoDoList[i].Brand_Of_SpringArm__c == null)){
                    ErrorStr    +=  'Brand_Of_SpringArm'+i+',';
                    ErrorColorChangeStrShow +=i+':补全弹簧臂品牌;';
                }
                if(checkoDoList[i].Shadowless_Lamp_Procurement_Plan__c == '甲方已有'
                    &&(checkoDoList[i].Brand_Of_Shadowless_Lamp_List__c == ''||checkoDoList[i].Brand_Of_Shadowless_Lamp_List__c == null)
                        &&(checkoDoList[i].Brand_Of_Mid_Camera_List__c == ''||checkoDoList[i].Brand_Of_Mid_Camera_List__c == null)){
                    ErrorStr    +=  'Brand_Of_Mid_Camera_List'+i+',';
                    ErrorStr    +=  'Brand_Of_Shadowless_Lamp_List'+i+',';
                    ErrorColorChangeStrShow +=i+':无影灯及中置术野摄像机补全无影灯品牌;';
                }
                if(checkoDoList[i].Side_Camera_Procurement_Plan__c == '甲方已有'
                    &&(checkoDoList[i].Brand_Of_Side_Camera__c == ''||checkoDoList[i].Brand_Of_Side_Camera__c == null)){
                    ErrorStr    +=  'Brand_Of_Side_Camera__cTitle'+i+',';
                    ErrorColorChangeStrShow +=i+':补全旁置术野摄像机品牌;';
                }
                if(checkoDoList[i].Operating_Room_Plan__c == '甲方已有'
                    &&(checkoDoList[i].Brand_Of_Operating_Bed_List__c == ''||checkoDoList[i].Brand_Of_Operating_Bed_List__c == null)){
                    ErrorStr    +=  'Brand_Of_Operating_Bed'+i+',';
                    ErrorColorChangeStrShow +=i+':补全手术床品牌;';
                }
                if( checkoDoList[i].Laparoscopy_Tower_TF__c ==  true
                    &&  (checkoDoList[i].Brand_of_Laparoscopy_Tower_List__c  ==  ''||checkoDoList[i].Brand_of_Laparoscopy_Tower_List__c  ==  null )){
                    ErrorStr    +=  'Brand_of_Laparoscopy_Tower'+i+',';
                    ErrorColorChangeStrShow +=i+':腔镜塔品牌;';
                    }
                        if(checkoDoList[i].Anesthesia_Tower_TF__c   ==  true
                            &&  (checkoDoList[i].Brand_Of_Anesthesia_Tower_List__c   ==  ''||checkoDoList[i].Brand_Of_Anesthesia_Tower_List__c   ==  null)){
                        ErrorStr    +=  'Brand_Of_Anesthesia_Tower'+i+',';
                        ErrorColorChangeStrShow +=i+':麻醉塔品牌;';
                        }
                            if(checkoDoList[i].Surgical_Tower_TF__c ==  true
                                &&  (checkoDoList[i].Brand_Surgical_Tower_List__c    ==  ''||checkoDoList[i].Brand_Surgical_Tower_List__c    ==  null)){
                                ErrorStr    +=  'Brand_Surgical_Tower'+i+',';
                                ErrorColorChangeStrShow +=i+':外科塔品牌;';
                            }
                                if(checkoDoList[i].Display_Tower_Radiation_TF__c    ==  true
                                    &&  (checkoDoList[i].Brand_Of_Display_Tower_Radiation_List__c    ==  ''||checkoDoList[i].Brand_Of_Display_Tower_Radiation_List__c    ==  null)){
                                        ErrorStr    +=  'Brand_Of_Display_Tower_Radiation'+i+',';
                                        ErrorColorChangeStrShow +=i+':显示塔品牌;';
                                }
                                    if(checkoDoList[i].Other_Tower_TF__c    ==  true
                                        &&  (checkoDoList[i].Other_Tower_Brand_List__c   ==  ''||checkoDoList[i].Other_Tower_Brand_List__c   ==  null||
                                                checkoDoList[i].Other_Tower_Model_Description__c == '' ||checkoDoList[i].Other_Tower_Model_Description__c == null)){
                                                ErrorStr    +=  'Other_Tower_Brand'+i+',';
                                                    ErrorColorChangeStrShow +=i+':其他塔品牌;';
                                    }
                                        if(    checkoDoList[i].Laparoscopy_Tower_TF__c ==  true && 
                                                (checkoDoList[i].Laparoscopy_Tower_Model_Desciption_Text__c == '' ||checkoDoList[i].Laparoscopy_Tower_Model_Desciption_Text__c == null)){
                                            ErrorStr    +=  'Laparoscopy_Tower_Model_Desciption_Text__c'+i+',';
                                            ErrorColorChangeStrShow +=i+':腔镜塔型号或描述;';
                                        }
                                        if(    checkoDoList[i].Anesthesia_Tower_TF__c   ==  true &&
                                                (checkoDoList[i].Anesthesia_Tower_Text_Description__c == '' ||checkoDoList[i].Anesthesia_Tower_Text_Description__c == null)){
                                            ErrorStr    +=  'Anesthesia_Tower_Text_Description__c'+i+',';
                                            ErrorColorChangeStrShow +=i+':麻醉塔型号或描述;';
                                        }
                                        if(    checkoDoList[i].Surgical_Tower_TF__c ==  true && 
                                                (checkoDoList[i].Surgical_Tower_Model_Or_Decription_Text__c == '' ||checkoDoList[i].Surgical_Tower_Model_Or_Decription_Text__c == null)){
                                            ErrorStr    +=  'Surgical_Tower_Model_Or_Decription_Text__c'+i+',';
                                            ErrorColorChangeStrShow +=i+':外科塔型号或描述;';
                                        }
                                        if(    checkoDoList[i].Display_Tower_Radiation_TF__c    ==  true && 
                                                (checkoDoList[i].Display_Tower_Model_Or_Description__c == '' ||checkoDoList[i].Display_Tower_Model_Or_Description__c == null)){
                                            ErrorStr    +=  'Display_Tower_Model_Or_Description__c'+i+',';
                                            ErrorColorChangeStrShow +=i+':显示塔(放射)型号或描述;';
                                        }
                                        if(    checkoDoList[i].Other_Tower_TF__c    ==  true && 
                                                (checkoDoList[i].Other_Tower_Model_Description__c == '' ||checkoDoList[i].Other_Tower_Model_Description__c == null)){
                                            ErrorStr    +=  'Other_Tower_Model_Description__c'+i+',';
                                            ErrorColorChangeStrShow +=i+':其他塔品牌型号或描述;';
                                        }
                if( checkoDoList[i].Brand_Of_SpringArm__c   ==  null){
                    ErrorStr    +=  'Brand_Of_SpringArm'+i+',';
                    ErrorColorChangeStrShow +=i+':弹簧臂;';
                }
                if( checkoDoList[i].Brand_Of_Mid_Camera_List__c ==  null    &&  checkoDoList[i].Equipment_Centralized_Control_List__c=='控制术野摄像机'){
                    ErrorStr    +=  'Brand_Of_Mid_Camera_List'+i+',';
                    ErrorColorChangeStrShow +=i+':中置显示器;';
                }
                if( checkoDoList[i].Brand_Of_Operating_Bed_List__c  ==  null){
                    ErrorStr    +=  'Brand_Of_Operating_Bed'+i+',';
                    ErrorColorChangeStrShow +=i+':手术床;';
                }
                if( checkoDoList[i].Brand_Of_Shadowless_Lamp_List__c    ==  null    &&  checkoDoList[i].Equipment_Centralized_Control_List__c=='控制无影灯'){
                    ErrorStr    +=  'Brand_Of_Shadowless_Lamp_List'+i+',';
                    ErrorColorChangeStrShow +=i+':无影灯;';
                }
            }
            Integer j = 0;
            for(IS_Opportunity_Demand_Demonstration__c odd : checkoDDList){
                System.debug('Brand_Name__c'+odd.Brand_Name__c+'===Microphone_Exsit_TF__c'+odd.Microphone_Exsit_TF__c);
                if(odd.Microphone_Exsit_TF__c == true 
                    &&    (odd.Brand_Name__c =='' ||odd.Brand_Name__c == null)){
                    ErrorStr += 'Brand_Name__c'+j+',';
                    ErrorColorChangeStrShow +=j+':麦克风品牌;';
                }
                j++;
            }
        }
        system.debug(ErrorStr+'ErrorStr=======');
        if(ErrorColorChangeStrShow!=''){
            if(isReturn == 'false'){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '已保存,但以下字段存在问题:'+ErrorColorChangeStrShow));
                }else{
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '以下字段存在问题:'+ErrorColorChangeStrShow));
                }
        }else{
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '已填写完整'));
        }
        ErrorStr    +=  'Fin';
        if(ErrorStr == 'Fin' && checkSOD.Id!=null && checkSOD.Submint_TF__c ==false){
            IS_Opportunity_Demand__c updateISO = new IS_Opportunity_Demand__c(id =checkSOD.Id,Data_Check_TF__c= true );
            update updateISO;
        }
        return ErrorStr;
    }
    public void SetDetailSum(){
        //刷新表格数量
        //如果数字比以前小,要在这里执行删除
        this.ErrorHead = '测试ErrorHead';
        this.ErrorTitle = '测试ErrorTitle';
        //this.ErrorElements = ErrorList;
        //this.SetErrorMsg('测试ErrorHead','测试ErrorTitle',ErrorList);
        List<IS_Opportunity_Demand_Operating__c> EmptyoDoList = new List<IS_Opportunity_Demand_Operating__c>();
        List<IS_Opportunity_Demand_Demonstration__c> EmptyoDDList =new List<IS_Opportunity_Demand_Demonstration__c>();
        /**
        System.debug('==========1');
        System.debug('==========1ODO'+pageShowSet.ISOdcInfoHead.Operating_Room_Sum__c);
        System.debug('==========1ODD'+pageShowSet.ISOdcInfoHead.Demonstration_Area_Sum__c);
        System.debug('==========1'+TargetName);
        */
        if(TargetName =='Operating_Room'){
            if(pageShowSet.ISOdcInfoHead.Operating_Room_Sum__c!=null){
                if(pageShowSet.ISOdcInfoHead.Operating_Room_Sum__c>0){
                    //重定义,如果刷新数据大于原本
                    if( pageShowSet.ISOdcInfoHead.Operating_Room_Sum__c >   pageShowSet.ISodoc_InfoList.size()  ){
                        Decimal addCly =  pageShowSet.ISOdcInfoHead.Operating_Room_Sum__c - pageShowSet.ISodoc_InfoList.size();
                        System.debug('==========1');
                        for(Decimal i = 0; i<addCly ; i++ ){
                            pageShowSet.ISodoc_InfoList.add(new IS_Opportunity_Demand_Operating__c(name='*'));
                            System.debug('==========1^'+i);
                        }
                    }else if(   pageShowSet.ISOdcInfoHead.Operating_Room_Sum__c <   pageShowSet.ISodoc_InfoList.size()  ){
                        List<IS_Opportunity_Demand_Operating__c> rebuildList = pageShowSet.ISodoc_InfoList.clone();
                        List<IS_Opportunity_Demand_Operating__c> deleteListoDo = new List<IS_Opportunity_Demand_Operating__c>();
                        Decimal minCly = pageShowSet.ISodoc_InfoList.size() - pageShowSet.ISOdcInfoHead.Operating_Room_Sum__c;
                        for( Decimal i = 0; i<minCly ; i++ ){
                            deleteListoDo.add(rebuildList.get(rebuildList.size()-1));
                            rebuildList.remove(rebuildList.size()-1);
                        }
                        pageShowSet.ISodoc_InfoList = rebuildList;
                        if(deleteListoDo.size()>0){
                            delete deleteListoDo;
                        }
                    }
                }else if(pageShowSet.ISOdcInfoHead.Operating_Room_Sum__c==0){
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '手术间数量不能为零'));
                }
            }
        
        }else if(TargetName =='Demonstration'){
            for(IS_Opportunity_Demand_Demonstration__c isodd : pageShowSet.ISOdd_InfoList){
            System.debug('Head确认ID::::::::'+isoDD.Id);
        }
            if(pageShowSet.ISOdcInfoHead.Demonstration_Area_Sum__c!=null){
                if(pageShowSet.ISOdcInfoHead.Demonstration_Area_Sum__c >0){
                System.debug('################1');
                    for(integer i = 0;i<pageShowSet.ISOdcInfoHead.Demonstration_Area_Sum__c;i++){
                        EmptyoDDList.add(new IS_Opportunity_Demand_Demonstration__c(name='*'));
                    }
                    System.debug('==========2');
                    if(pageShowSet.ISOdd_InfoList==null){
                        pageShowSet.ISOdd_InfoList = EmptyoDDList;
                        System.debug('==========3='+pageShowSet.ISOdd_InfoList.size());
                    }else if(pageShowSet.ISOdd_InfoList.size()==0){
                        pageShowSet.ISOdd_InfoList = EmptyoDDList;
                        System.debug('==========4='+pageShowSet.ISOdd_InfoList.size());
                    }else if(pageShowSet.ISOdd_InfoList.size()<=pageShowSet.ISOdcInfoHead.Demonstration_Area_Sum__c){
                        Decimal CountODD = (pageShowSet.ISOdcInfoHead.Demonstration_Area_Sum__c-pageShowSet.ISOdd_InfoList.size());
                        for(integer i = 0;
                                i<CountODD;
                                    i++){
                            pageShowSet.ISOdd_InfoList.add(new IS_Opportunity_Demand_Demonstration__c(name='*'));
                            System.debug('==========5####'+pageShowSet.ISOdd_InfoList);
                            System.debug('==========5=i '+i+'####'+CountODD);
                            System.debug('==========5=Minu '+(pageShowSet.ISOdcInfoHead.Demonstration_Area_Sum__c-pageShowSet.ISOdd_InfoList.size()));
                        }
                        for(IS_Opportunity_Demand_Demonstration__c isodd : pageShowSet.ISOdd_InfoList){
                            System.debug('Midd确认ID::::::::'+isoDD.Id);
                        }
                        //pageShowSet.ISOdd_InfoList = EmptyoDDList;
                        System.debug('==========5='+pageShowSet.ISOdd_InfoList.size());
                        System.debug('==========5='+EmptyoDDList.size());
                    }else{
                        System.debug('==========6');
                        //pageShowSet.ISOdcInfoHead.Demonstration_Area_Sum__c.addError('已有'+pageShowSet.ISOdd_InfoList.size()+'条记录');
                        List<IS_Opportunity_Demand_Demonstration__c> rebuildListODD = pageShowSet.ISOdd_InfoList.clone();
                        List<IS_Opportunity_Demand_Demonstration__c> deleteListODD = new List<IS_Opportunity_Demand_Demonstration__c>();
                        Decimal minClyOdd = pageShowSet.ISOdd_InfoList.size() - pageShowSet.ISOdcInfoHead.Demonstration_Area_Sum__c;
                        for( Decimal i = 0; i<minClyOdd ; i++ ){
                            System.debug('==========6_'+i+'***'+deleteListODD.size());
                            deleteListODD.add(rebuildListODD.get(rebuildListODD.size()-1));
                            System.debug('==========7_'+i+'***'+deleteListODD.size()); 
                            rebuildListODD.remove(rebuildListODD.size()-1);
                        }
                        pageShowSet.ISOdd_InfoList = rebuildListODD;
                        System.debug('==========7'+deleteListODD);
                        System.debug('==========8'+pageShowSet.ISOdcInfoHead.Demonstration_Area_Sum__c);
                        if(deleteListODD.size()>0){
                            System.debug('执行删除'+deleteListODD.size());
                            delete deleteListODD;
                        }
                    }
                }else if(pageShowSet.ISOdcInfoHead.Demonstration_Area_Sum__c == 0){
                    System.debug('==========设置为零');
                    Savepoint sp = Database.setSavepoint();
                    try{
                        System.debug('执行删除'+ pageShowSet.ISOdd_InfoList.size());
                        delete pageShowSet.ISOdd_InfoList;
                        pageShowSet.ISOdd_InfoList = new List<IS_Opportunity_Demand_Demonstration__c>();
                    }catch (Exception ex ){
                        Database.rollback(sp);
                        ApexPages.addMessages(ex);
                    }
                }
            }
        }
        OprNumCnt = pageShowSet.ISodoc_InfoList.size();
        DomNumCnt = pageShowSet.ISOdd_InfoList.size();
        for(IS_Opportunity_Demand_Demonstration__c isodd : pageShowSet.ISOdd_InfoList){
            System.debug('确认ID::::::::'+isoDD.Id);
            System.debug('确认Name::::::::'+isoDD.Name);
        }
        System.debug('==========19'+pageShowSet.ISodoc_InfoList.size());
        System.debug('==========18'+pageShowSet.ISOdd_InfoList.size());
        
    } 
    public void sendMail(){
        if(MailTarget == 'Applyer'){
 
            }else if(MailTarget == 'SIoppor'){
 
            }
        Datetime dt = Datetime.now();
        String temp = '';
        temp += '****** '  + ' ' + dt.format() + ' ******\n';
        temp += '*** To:' + MailTarget + '\n';
        temp += '*** Cc:' + Cc + '\n';
        temp += MailDetail;
        MailEle me = new MailEle();
        me.Fromer=MailTarget;
        me.Cc=Cc;
        me.To=MailTarget;
        me.Details=MailDetail;
        initMail.add(me);
        String response = MailImfParseToJson(initMail);
        pageShowSet.ISOdcInfoHead.Response__c = response;
 
        try{
            update pageShowSet.ISOdcInfoHead;
            Messaging.SingleEmailMessage messageNEW= new Messaging.SingleEmailMessage();
            //get the bode from above dummy instance and set it to your actual email
            //messageNEW.HTMLBody = message.getHtmlBody();
            //messageNEW.Subject = '备品借出申请' + ra.Name + '' + '应答沟通';
            messageNEW.Subject = 'SI询价需求表 ' + pageShowSet.ISOdcInfoHead.Name + ' \n' + 'SI术间:';
            for(IS_Opportunity_Demand_Operating__c odo: pageShowSet.ISodoc_InfoList){
                messageNEW.Subject += odo.name +' ';
            }
            messageNEW.Subject += '\n SI示教点:';
            for(IS_Opportunity_Demand_Demonstration__c odd:  pageShowSet.ISOdd_InfoList){
                messageNEW.Subject += odd.name +' ';
            }
            
            messageNEW.PlainTextBody = temp;
            //set desired email addresses
            messageNEW.setCharset('UTF-8');
            List<String> idList = Ccid.split(',');
            List<user> UserEmail = [SELECT Id, Name, Email from user where id in :idList];
            List<String> MailCc = new List<String>();
            for(User us : UserEmail){
                MailCc.add(us.Email);
            }
            //messageNEW.toAddresses = toMailList;
            messageNEW.ccAddresses = MailCc;
            //send the mail
            Messaging.SendEmailResult[] results = messaging.sendEmail(new Messaging.SingleEmailMessage[] {messageNEW});
            if(!results[0].success){
                system.debug('=====' + results[0].errors[0].message);
                //MailDetail.addError('邮件发送失败。');
                //hasError=true;
            }else{
                //邮件发送成功
                //hasError=false;
            }
        } catch (Exception ex) {
            system.debug('=====' + ex.getMessage());
            //hasError = true;
            ApexPages.addMessages(ex);
        }
    }
    class ISOpportunityDemandInfo{
        //主题数据组
        public IS_Opportunity_Demand__c ISOdcInfoHead{get;set;}
        public List<IS_Opportunity_Demand_Operating__c> ISodoc_InfoList {get;set;}
        public List<IS_Opportunity_Demand_Demonstration__c> ISOdd_InfoList{get;set;}
        //验证关系
        boolean isCheckPass{get;set;}
        public ISOpportunityDemandInfo(){
            isCheckPass =false;
        }
        public ISOpportunityDemandInfo(IS_Opportunity_Demand__c ISHead,List<IS_Opportunity_Demand_Operating__c> ISodocInfoList,List<IS_Opportunity_Demand_Demonstration__c> ISOddInfoList){
            isCheckPass = false;
            this.ISOdcInfoHead = ISHead;
            this.ISodoc_InfoList = ISodocInfoList;
            this.ISOdd_InfoList =ISOddInfoList;
            if(ISOdcInfoHead!=null){
                if(ISOdcInfoHead.Demonstration_Area_Sum__c!=ISOdd_InfoList.size()
                    ||ISOdcInfoHead.Operating_Room_Sum__c!=ISodoc_InfoList.size()
                        ||ISOdd_InfoList.size()==0
                            ||ISodoc_InfoList.size()==0){
                }else{
                    isCheckPass = true;
                }
            }
        }
 
    }
    public static String MailImfParseToJson(List<MailEle> imfList){
        String JsonString; 
        JSONGenerator CreateJson = JSON.createGenerator(true); 
        CreateJson.writeStartObject();
        for(MailEle Mail : imfList){
            CreateJson.writeFieldName('MailEle');
            CreateJson.writeObject(Mail);
        }
        CreateJson.writeEndObject();
        JsonString = CreateJson.getAsString();
        return JsonString;
    }
    public static List<MailEle> JSONtoMailElement(String JsonStr){
        JSONParser parser = JSON.createParser(JsonStr);
        List<MailEle> OutputList = new List<MailEle>();
        while(parser.nextToken()!=null){
            system.debug('23333333333');
                while(parser.nextToken() != null){
                    if(parser.getCurrentToken() == JSONToken.START_OBJECT){
                    MailEle Me = (MailEle)parser.readValueAs(MailEle.class);
                    OutputList.add(Me);
                    system.debug('==++==Me++==++'+Me);
                    }
                }
            }
        return OutputList;
    }
    public class MailEle{
        public String Fromer {get;set;}
        public String Cc{get;set;}
        public String To{get;set;}
        public String Details{get;set;}
        public MailEle(){
 
        }
    }
}