高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
public with sharing class ISO_DemandOperAndDemonsNewController {
    // Is需求表id
    public String ISodcIdStr {get;set;}
    public String OpporIdStr {get;set;}
    public String PDFfileName {get;set;}//为打印PDF提供名字
    public String ErrorColorChangeStr{get;set;}
    public Boolean returnNew {get;set;}
    public Boolean saveAndReturnB {get;set;}
    // si询价需求表
    public IS_Opportunity_Demand__c ISOppDemandList{ get; set; }
    public List<IS_Opportunity_Demand__c> ISOpptunityDemandList{ get; set; }
    // si询价手术室
    public List<IS_Opportunity_Demand_Operating__c> ISOppDemandOperList{ get; set; }
    public IS_Opportunity_Demand_Operating__c ISOppDemandOper1{ get; set; }
    public IS_Opportunity_Demand_Operating__c ISOppDemandOper2{ get; set; }
    public IS_Opportunity_Demand_Operating__c ISOppDemandOper3{ get; set; }
    public IS_Opportunity_Demand_Operating__c ISOppDemandOperMore{ get; set; }
    // si询价示教点
    public List<IS_Opportunity_Demand_Demonstration__c> ISOppDemandDemonList{ get; set; }
    public IS_Opportunity_Demand_Demonstration__c ISOppDemandDemon1{ get; set; }
    public IS_Opportunity_Demand_Demonstration__c ISOppDemandDemon2{ get; set; }
    public IS_Opportunity_Demand_Demonstration__c ISOppDemandDemonMore{ get; set; }
    // si询价配置单
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate11{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate12{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate13{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate14{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate21{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate22{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate23{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate24{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate31{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate32{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate33{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate34{get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguateList{ get; set; }
    public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguateListStandard{ get; set; }
    // 判断是否显示标准配置单
    // public Boolean ISOppDemandConfiguateStand11 = false;
    // public Boolean ISOppDemandConfiguateStand12 = false;
    // public Boolean ISOppDemandConfiguateStand13 = false;
    // public Boolean ISOppDemandConfiguateStand14 = false;
    // public Boolean ISOppDemandConfiguateStand21 = false;
    // public Boolean ISOppDemandConfiguateStand22 = false;
    // public Boolean ISOppDemandConfiguateStand23 = false;
    // public Boolean ISOppDemandConfiguateStand24 = false;
    // public Boolean ISOppDemandConfiguateStand31 = false;
    // public Boolean ISOppDemandConfiguateStand32 = false;
    // public Boolean ISOppDemandConfiguateStand33 = false;
    // public Boolean ISOppDemandConfiguateStand34 = false;
    // public List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguateListStandard{ get; set; }
    // 默认值显示
    public Boolean oddNeed {get;set;}
    public Boolean odoNeed {get;set;}
    // 控制术间及示教点的显示
    public Boolean showISOdo1 { get; set; }
    public Boolean showISOdo2 { get; set; }
    public Boolean showISOdo3 { get; set; }
    public Boolean showISOdoMore { get; set; }
    public Boolean showISOdd1 { get; set; }
    public Boolean showISOdd2 { get; set; }
    public Boolean showISOddMore { get; set; }
    // 控制配置单的显示
    public Boolean showISOdc11 { get; set; }
    public Boolean showISOdc12 { get; set; }
    public Boolean showISOdc13 { get; set; }
    public Boolean showISOdc14 { get; set; }
    public Boolean showISOdc21 { get; set; }
    public Boolean showISOdc22 { get; set; }
    public Boolean showISOdc23 { get; set; }
    public Boolean showISOdc24 { get; set; }
    public Boolean showISOdc31 { get; set; }
    public Boolean showISOdc32 { get; set; }
    public Boolean showISOdc33 { get; set; }
    public Boolean showISOdc34 { get; set; }
    // 控制是否新建需求表
    public String Operating_Room_Count { get; set; }
    public String Operating_Room_Type1 { get; set; }
    public String Operating_Room_Type2 { get; set; }
    public String Operating_Room_Type3 { get; set; }
    public String Demonstration_Number { get; set; }
    public String Demonstration_Type1 { get; set; }
    public String Demonstration_Type2 { get; set; }
    public String Demand_DemonstrationType { get; set; }
    public Boolean insertOrNot { get; set; }
    public ISO_DemandOperAndDemonsNewController(){
        // if(ISodcIdStr=='' || ISodcIdStr==null){
            OpporIdStr = ApexPages.currentPage().getParameters().get('OppoerID');
            system.debug(OpporIdStr+'========');
            // OpporIdStr = '006p0000007IQvq';
        // }
    }
 
    public ISO_DemandOperAndDemonsNewController(ApexPages.StandardController controller){
 
    }
    public void init(){
        returnNew = false;
        saveAndReturnB = false;
        OpporIdStr = ApexPages.currentPage().getParameters().get('OppoerID');
        ISodcIdStr = ApexPages.currentPage().getParameters().get('Id');
        System.debug(ISodcIdStr+'======ISodcIdStr');
        if(ISodcIdStr == '' || ISodcIdStr == null){
            returnNew = true;
        }
        if(ISodcIdStr != '' && ISodcIdStr != null){
            returnNew = false;
        }
        System.debug(returnNew+'======returnNew');
        system.debug(OpporIdStr+'========111');
        // OpporIdStr = '006p0000007IQvq';
        String idstr = ISodcIdStr;
        ISOppDemandConfiguate11 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguate12 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguate13 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguate14 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguate21 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguate22 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguate23 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguate24 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguate31 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguate32 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguate33 = new List<IS_Opportunity_Demand_Configuration__c>();
        ISOppDemandConfiguate34 = new List<IS_Opportunity_Demand_Configuration__c>();
        showISOdc11 = false;
        showISOdc12 = false;
        showISOdc13 = false;
        showISOdc14 = false;
        showISOdc21 = false;
        showISOdc22 = false;
        showISOdc23 = false;
        showISOdc24 = false;
        showISOdc31 = false;
        showISOdc32 = false;
        showISOdc33 = false;
        showISOdc34 = false;
        showISOdo1 = false;
        showISOdo2 = false;
        showISOdo3 = false;
        showISOdoMore = false;
        showISOdd1 = false;
        showISOdd2 = false;
        showISOddMore = false;
 
        odoNeed = false;
        oddNeed = false;
        // 查询si询价需求表的信息
        // ISOpptunityDemandList = [select id,Demonstration_Number__c,Opportunity_ID__c,Transmission_Mode__c,Operating_Room_Count__c,Demand_DemonstrationType__c,OperatingRoomName__c,Operating_Room_Position_Area__c,Operating_Room_Position_Building__c,Operating_Room_Position_Stage__c from IS_Opportunity_Demand__c where Opportunity_ID__c = :OpporIdStr and Func_SOD_Status__c != '00 已终止'];
        ISOpptunityDemandList = [select id,Demonstration_Number__c,Opportunity_ID__c,Transmission_Mode__c,Operating_Room_Count__c,Demand_DemonstrationType__c,OperatingRoomName__c,Operating_Room_Position_Area__c,Operating_Room_Position_Building__c,Operating_Room_Position_Stage__c from IS_Opportunity_Demand__c where id = :ISodcIdStr ];
        if(ISOpptunityDemandList.size() <= 0){
            ISOppDemandList = new IS_Opportunity_Demand__c();
            // ISOppDemandList.Operating_Room_Count__c = '1';
            // ISOppDemandList.Demonstration_Number__c = '0';
            ISOppDemandList.Opportunity_ID__c = OpporIdStr;
            System.debug('默认是空的');
            // insert ISOppDemandList;
        }else{
            ISOppDemandList = ISOpptunityDemandList[0];
        }
        idstr = ISOppDemandList.Id;
        // 获取PDF的名称
        String oppoIDs = ISOppDemandList.Opportunity_ID__c;
        Opportunity OppList = [select id,SI_Decide_ID__c,Opportunity_No__c from Opportunity where id =:oppoIDs];
        PDFfileName = OppList.Opportunity_No__c;
        // 查询si询价手术间
        ISOppDemandOperList = [select id,Project_Information__c,Name,Name__c,IS_Opportunity_Demand__c,Operating_Room_Area__c,Remarks_Text__c,Operating_Room_Type__c,Olympus_LightSource_Host__c,Olympus_CD_Writer__c,Olympus_Ultrasound_Knife__c,Olympus_Insufflator__c,Olympus_Camera_Host__c,Olympus_Electric_Knife__c,ThirdParty_OperatingTable__c,ThirdParty_OperationLamp__c,ThirdParty_Camera__c from IS_Opportunity_Demand_Operating__c where IS_Opportunity_Demand__c = :idstr];
        // 查询si询价示教点
        ISOppDemandDemonList = [select id,Name,IS_Opportunity_Demand__c,Teaching_Needs__c,Other_Require_Text__c,Demonstration_Type__c,Other_Relative_Position__c,Name__c from IS_Opportunity_Demand_Demonstration__c where IS_Opportunity_Demand__c = :idstr];
        // 查询si询价配置单
        ISOppDemandConfiguateList = [select id,name,Configuration_Type__c,Selection__c,Matching__c,SerialNumber__c,Number__c,Standard_Configuration__c,IS_Opportunity_Demand_Operating__c,Brand__c,Company__c,IS_Opportunity_Demand_Operating__r.Name__c from IS_Opportunity_Demand_Configuration__c where IS_Opportunity_Demand_Operating__c = :ISOppDemandOperList or Standard_Configuration__c = true order by SerialNumber__c];
        // insert ISOppDemandConfiguate11;
        
        // 用来控制术间页面的初始显示
        if(ISOppDemandList.Operating_Room_Count__c == '1'){
            showISOdo1 = true;
        }
        if(ISOppDemandList.Operating_Room_Count__c == '2'){
            showISOdo1 = true;
            showISOdo2 = true;
        }
        if(ISOppDemandList.Operating_Room_Count__c == '3'){
            showISOdo1 = true;
            showISOdo2 = true;
            showISOdo3 = true;
        }
        if(ISOppDemandList.Operating_Room_Count__c == '>3'){
            showISOdoMore = true;
        }
        // 用来控制示教点页面的初始显示
        if(ISOppDemandList.Demonstration_Number__c == '1'){
            showISOdd1 = true;
        }
        if(ISOppDemandList.Demonstration_Number__c == '2'){
            showISOdd1 = true;
            showISOdd2 = true;
        }
        if(ISOppDemandList.Demonstration_Number__c == '>2'){
            showISOddMore = true;
        }
        for(IS_Opportunity_Demand_Operating__c isOdo : ISOppDemandOperList){
            if(isOdo.Name__c == '手术间1'){
            ISOppDemandOper1 = isOdo;
            }
            if(isOdo.Name__c == '手术间2'){
                ISOppDemandOper2 = isOdo;
            }
            if(isOdo.Name__c == '手术间3'){
                ISOppDemandOper3 = isOdo;
            }
            if(isOdo.Name__c == '术间数量>3间'){
                ISOppDemandOperMore = isOdo;
                // System.debug('=====Project_Information__c'+ISOppDemandOperMore.Project_Information__c+'===');
                if(ISOppDemandOperMore.Project_Information__c == '' || ISOppDemandOperMore.Project_Information__c == null){
                    odoNeed = true;
                }
            }
        }
        // 判断手术间是否已存在
        Map<String,IS_Opportunity_Demand_Operating__c> isOdoMap = new Map<String,IS_Opportunity_Demand_Operating__c>();
        if(ISOppDemandOper1 == null){
            ISOppDemandOper1 = new IS_Opportunity_Demand_Operating__c();
            ISOppDemandOper1.Name__c = '手术间1';
            // ISOppDemandOper1.IS_Opportunity_Demand__c = idstr;
            isOdoMap.put('1', ISOppDemandOper1);
        }
        if(ISOppDemandOper2 == null){
            ISOppDemandOper2 = new IS_Opportunity_Demand_Operating__c();
            ISOppDemandOper2.Name__c = '手术间2';
            // ISOppDemandOper2.IS_Opportunity_Demand__c = idstr;
            isOdoMap.put('2', ISOppDemandOper2);
        }
        if(ISOppDemandOper3 == null){
            ISOppDemandOper3 = new IS_Opportunity_Demand_Operating__c();
            ISOppDemandOper3.Name__c = '手术间3';
            // ISOppDemandOper3.IS_Opportunity_Demand__c = idstr;
            isOdoMap.put('3', ISOppDemandOper3);
        }
        if(ISOppDemandOperMore == null){
            ISOppDemandOperMore = new IS_Opportunity_Demand_Operating__c();
            ISOppDemandOperMore.Name__c = '术间数量>3间';
            odoNeed = true;
            // ISOppDemandOperMore.IS_Opportunity_Demand__c = idstr;
            isOdoMap.put('more', ISOppDemandOperMore);
        }
        // insert isOdoMap.values();
 
        for(IS_Opportunity_Demand_Demonstration__c isOdd : ISOppDemandDemonList){
            if(isOdd.Name__c == '示教点1'){
                ISOppDemandDemon1 = isOdd;
            }
            if(isOdd.Name__c == '示教点2'){
                ISOppDemandDemon2 = isOdd;
            }
            if(isOdd.Name__c == '示教点数量>2'){
                ISOppDemandDemonMore = isOdd;
                if(isOdd.Teaching_Needs__c == '' || isOdd.Teaching_Needs__c == null){
                    oddNeed = true;
                }
            }
        }
        // 判断示教点是否存在
        Map<String,IS_Opportunity_Demand_Demonstration__c> isOddMap = new Map<String,IS_Opportunity_Demand_Demonstration__c>();
        if(ISOppDemandDemon1 == null){
            ISOppDemandDemon1 = new IS_Opportunity_Demand_Demonstration__c();
            ISOppDemandDemon1.Name__c = '示教点1';
            // ISOppDemandDemon1.IS_Opportunity_Demand__c = idstr;
            isOddMap.put('1', ISOppDemandDemon1);
        }
        if(ISOppDemandDemon2 == null){
            ISOppDemandDemon2 = new IS_Opportunity_Demand_Demonstration__c();
            ISOppDemandDemon2.Name__c = '示教点2';
            // ISOppDemandDemon2.IS_Opportunity_Demand__c = idstr;
            isOddMap.put('2', ISOppDemandDemon2);
        }
        if(ISOppDemandDemonMore == null){
            ISOppDemandDemonMore = new IS_Opportunity_Demand_Demonstration__c();
            ISOppDemandDemonMore.Name__c = '示教点数量>2';
            oddNeed = true;
            // ISOppDemandDemonMore.IS_Opportunity_Demand__c = idstr;
            isOddMap.put('more', ISOppDemandDemonMore);
        }
        // insert isOddMap.values();
 
        for(IS_Opportunity_Demand_Configuration__c isOdc : ISOppDemandConfiguateList){
            // 判断是否是第一次创建,还是查看
            if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c != null){
                // 经过保存了查看si询价页面信息
                if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间1' && isodc.Configuration_Type__c == '01 _ HD整体手术间配置单'){
                    ISOppDemandConfiguate11.add(isOdc);
                    showISOdc11 = true;
                }
                if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间1' && isodc.Configuration_Type__c == '02 _ 3D整体手术间配置单'){
                    ISOppDemandConfiguate12.add(isOdc);
                    showISOdc12 = true;
                }
                if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间1' && isodc.Configuration_Type__c == '03 _ 4K整体手术间配置单'){
                    ISOppDemandConfiguate13.add(isOdc);
                    showISOdc13 = true;
                }
                if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间1' && isodc.Configuration_Type__c == '04 _ 3D/4K整体手术间配置单'){
                    ISOppDemandConfiguate14.add(isOdc);
                    showISOdc14 = true;
                }
                if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间2' && isodc.Configuration_Type__c == '01 _ HD整体手术间配置单'){
                    ISOppDemandConfiguate21.add(isOdc);
                    showISOdc21 = true;
                }
                if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间2' && isodc.Configuration_Type__c == '02 _ 3D整体手术间配置单'){
                    ISOppDemandConfiguate22.add(isOdc);
                    showISOdc22 = true;
                }
                if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间2' && isodc.Configuration_Type__c == '03 _ 4K整体手术间配置单'){
                    ISOppDemandConfiguate23.add(isOdc);
                    showISOdc23 = true;
                }
                if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间2' && isodc.Configuration_Type__c == '04 _ 3D/4K整体手术间配置单'){
                    ISOppDemandConfiguate24.add(isOdc);
                    showISOdc24 = true;
                }
                if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间3' && isodc.Configuration_Type__c == '01 _ HD整体手术间配置单'){
                    ISOppDemandConfiguate31.add(isOdc);
                    showISOdc31 = true;
                }
                if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间3' && isodc.Configuration_Type__c == '02 _ 3D整体手术间配置单'){
                    ISOppDemandConfiguate32.add(isOdc);
                    showISOdc32 = true;
                }
                if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间3' && isodc.Configuration_Type__c == '03 _ 4K整体手术间配置单'){
                    ISOppDemandConfiguate33.add(isOdc);
                    showISOdc33 = true;
                }
                if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == '手术间3' && isodc.Configuration_Type__c == '04 _ 3D/4K整体手术间配置单'){
                    ISOppDemandConfiguate34.add(isOdc);
                    showISOdc34 = true;
                }
            }
        }
        System.debug(ISOppDemandConfiguate11.size()+'==='+showISOdc11);
        
        if(ISOppDemandConfiguate11.size() <= 0){
            System.debug('等于空格');
        }
        for(IS_Opportunity_Demand_Configuration__c isOdc : ISOppDemandConfiguateList){
            if(isOdc.IS_Opportunity_Demand_Operating__r.Name__c == null){
                // 第一次打开,显示标准的配置单
                if(isodc.Configuration_Type__c == '01 _ HD整体手术间配置单'){
                    System.debug('===='+isOdc);
                    if(!showISOdc11){
                        IS_Opportunity_Demand_Configuration__c isOdc11 = new IS_Opportunity_Demand_Configuration__c();
                        isOdc11 = makeISOdc(ISOppDemandOper1,isOdc);
                        ISOppDemandConfiguate11.add(isOdc11);
                    }
                    if(!showISOdc21){
                        IS_Opportunity_Demand_Configuration__c isOdc11 = new IS_Opportunity_Demand_Configuration__c();
                        isOdc11 = makeISOdc(ISOppDemandOper2,isOdc);
                        ISOppDemandConfiguate21.add(isOdc11);
                    }
                    if(!showISOdc31){
                        IS_Opportunity_Demand_Configuration__c isOdc11 = new IS_Opportunity_Demand_Configuration__c();
                        isOdc11 = makeISOdc(ISOppDemandOper3,isOdc);
                        ISOppDemandConfiguate31.add(isOdc11);
                    }
                    
                }
                if(isodc.Configuration_Type__c == '02 _ 3D整体手术间配置单'){
                    if(!showISOdc12){
                        IS_Opportunity_Demand_Configuration__c isOdc11 = new IS_Opportunity_Demand_Configuration__c();
                        isOdc11 = makeISOdc(ISOppDemandOper1,isOdc);
                        ISOppDemandConfiguate12.add(isOdc11);
                    }
                    if(!showISOdc22){
                        IS_Opportunity_Demand_Configuration__c isOdc11 = new IS_Opportunity_Demand_Configuration__c();
                        isOdc11 = makeISOdc(ISOppDemandOper2,isOdc);
                        ISOppDemandConfiguate22.add(isOdc11);
                    }
                    if(!showISOdc32){
                        IS_Opportunity_Demand_Configuration__c isOdc11 = new IS_Opportunity_Demand_Configuration__c();
                        isOdc11 = makeISOdc(ISOppDemandOper3,isOdc);
                        ISOppDemandConfiguate32.add(isOdc11);
                    }
                }
                if(isodc.Configuration_Type__c == '03 _ 4K整体手术间配置单'){
                    if(!showISOdc13){
                        IS_Opportunity_Demand_Configuration__c isOdc11 = new IS_Opportunity_Demand_Configuration__c();
                        isOdc11 = makeISOdc(ISOppDemandOper1,isOdc);
                        ISOppDemandConfiguate13.add(isOdc11);
                    }
                    if(!showISOdc23){
                        IS_Opportunity_Demand_Configuration__c isOdc11 = new IS_Opportunity_Demand_Configuration__c();
                        isOdc11 = makeISOdc(ISOppDemandOper2,isOdc);
                        ISOppDemandConfiguate23.add(isOdc11);
                    }
                    if(!showISOdc33){
                        IS_Opportunity_Demand_Configuration__c isOdc11 = new IS_Opportunity_Demand_Configuration__c();
                        isOdc11 = makeISOdc(ISOppDemandOper3,isOdc);
                        ISOppDemandConfiguate33.add(isOdc11);
                    }
                }
                if(isodc.Configuration_Type__c == '04 _ 3D/4K整体手术间配置单'){
                    if(!showISOdc14){
                        IS_Opportunity_Demand_Configuration__c isOdc11 = new IS_Opportunity_Demand_Configuration__c();
                        isOdc11 = makeISOdc(ISOppDemandOper1,isOdc);
                        ISOppDemandConfiguate14.add(isOdc11);
                    }
                    if(!showISOdc24){
                        IS_Opportunity_Demand_Configuration__c isOdc11 = new IS_Opportunity_Demand_Configuration__c();
                        isOdc11 = makeISOdc(ISOppDemandOper2,isOdc);
                        ISOppDemandConfiguate24.add(isOdc11);
                    }
                    if(!showISOdc34){
                        IS_Opportunity_Demand_Configuration__c isOdc11 = new IS_Opportunity_Demand_Configuration__c();
                        isOdc11 = makeISOdc(ISOppDemandOper3,isOdc);
                        ISOppDemandConfiguate34.add(isOdc11);
                    }
                }
            }
        }
        // if(ISOppDemandConfiguate11 != null && showISOdc11 == false){
        //     insert ISOppDemandConfiguate11;
        // }
        // if(ISOppDemandConfiguate12 != null && showISOdc12 == false){
        //     insert ISOppDemandConfiguate12;
        // }
        // if(ISOppDemandConfiguate13 != null && showISOdc13 == false){
        //     insert ISOppDemandConfiguate13;
        // }
        // if(ISOppDemandConfiguate14 != null && showISOdc14 == false){
        //     insert ISOppDemandConfiguate14;
        // }
        // if(ISOppDemandConfiguate21 != null && showISOdc21 == false){
        //     insert ISOppDemandConfiguate21;
        // }
        // if(ISOppDemandConfiguate22 != null && showISOdc22 == false){
        //     insert ISOppDemandConfiguate22;
        // }
        // if(ISOppDemandConfiguate23 != null && showISOdc23 == false){
        //     insert ISOppDemandConfiguate23;
        // }
        // if(ISOppDemandConfiguate24 != null && showISOdc24 == false){
        //     insert ISOppDemandConfiguate24;
        // }
        // if(ISOppDemandConfiguate31 != null && showISOdc31 == false){
        //     insert ISOppDemandConfiguate31;
        // }
        // if(ISOppDemandConfiguate32 != null && showISOdc32 == false){
        //     insert ISOppDemandConfiguate32;
        // }
        // if(ISOppDemandConfiguate33 != null && showISOdc33 == false){
        //     insert ISOppDemandConfiguate33;
        // }
        // if(ISOppDemandConfiguate34 != null && showISOdc34 == false){
        //     insert ISOppDemandConfiguate34;
        // }
 
        // 在控制一遍
        if(ISOppDemandOper1.Name__c == '手术间1'){
            if(ISOppDemandOper1.Operating_Room_Type__c == 'HD整体手术间'){
                showISOdc11 = true;
                showISOdc12 = false;
                showISOdc13 = false;
                showISOdc14 = false;
            }else if(ISOppDemandOper1.Operating_Room_Type__c == '3D整体手术间'){
                showISOdc11 = false;
                showISOdc12 = true;
                showISOdc13 = false;
                showISOdc14 = false;
            }else if(ISOppDemandOper1.Operating_Room_Type__c == '4K整体手术间'){
                showISOdc11 = false;
                showISOdc12 = false;
                showISOdc13 = true;
                showISOdc14 = false;
            }else if(ISOppDemandOper1.Operating_Room_Type__c == '3D/4K整体手术间'){
                showISOdc11 = false;
                showISOdc12 = false;
                showISOdc13 = false;
                showISOdc14 = true;
            }else{
                showISOdc11 = false;
                showISOdc12 = false;
                showISOdc13 = false;
                showISOdc14 = false;
            }
 
        }
 
        if(ISOppDemandOper2.Name__c == '手术间2'){
            if(ISOppDemandOper2.Operating_Room_Type__c == 'HD整体手术间'){
                showISOdc21 = true;
                showISOdc22 = false;
                showISOdc23 = false;
                showISOdc24 = false;
            }else if(ISOppDemandOper2.Operating_Room_Type__c == '3D整体手术间'){
                showISOdc21 = false;
                showISOdc22 = true;
                showISOdc23 = false;
                showISOdc24 = false;
            }else if(ISOppDemandOper2.Operating_Room_Type__c == '4K整体手术间'){
                showISOdc21 = false;
                showISOdc22 = false;
                showISOdc23 = true;
                showISOdc24 = false;
            }else if(ISOppDemandOper2.Operating_Room_Type__c == '3D/4K整体手术间'){
                showISOdc21 = false;
                showISOdc22 = false;
                showISOdc23 = false;
                showISOdc24 = true;
            }else{
                showISOdc21 = false;
                showISOdc22 = false;
                showISOdc23 = false;
                showISOdc24 = false;
            }
 
        }
        if(ISOppDemandOper3.Name__c == '手术间3'){
            if(ISOppDemandOper3.Operating_Room_Type__c == 'HD整体手术间'){
                showISOdc31 = true;
                showISOdc32 = false;
                showISOdc33 = false;
                showISOdc34 = false;
            }else if(ISOppDemandOper3.Operating_Room_Type__c == '3D整体手术间'){
                showISOdc31 = false;
                showISOdc32 = true;
                showISOdc33 = false;
                showISOdc34 = false;
            }else if(ISOppDemandOper3.Operating_Room_Type__c == '4K整体手术间'){
                showISOdc31 = false;
                showISOdc32 = false;
                showISOdc33 = true;
                showISOdc34 = false;
            }else if(ISOppDemandOper3.Operating_Room_Type__c == '3D/4K整体手术间'){
                showISOdc31 = false;
                showISOdc32 = false;
                showISOdc33 = false;
                showISOdc34 = true;
            }else{
                showISOdc31 = false;
                showISOdc32 = false;
                showISOdc33 = false;
                showISOdc34 = false;
            }
 
        }
        // 需求表初始化的时候为判断是否新建需求表的判断条件赋值
        Operating_Room_Count = ISOppDemandList.Operating_Room_Count__c;
        Operating_Room_Type1 = ISOppDemandOper1.Operating_Room_Type__c;
        Operating_Room_Type2 = ISOppDemandOper2.Operating_Room_Type__c;
        Operating_Room_Type3 = ISOppDemandOper3.Operating_Room_Type__c;
        Demonstration_Number = ISOppDemandList.Demonstration_Number__c;
        Demonstration_Type1 = ISOppDemandDemon1.Demonstration_Type__c;
        Demonstration_Type2 = ISOppDemandDemon2.Demonstration_Type__c;
        Demand_DemonstrationType = ISOppDemandList.Demand_DemonstrationType__c;
        System.debug('oddNeed======='+oddNeed+'odoNeed======'+odoNeed);
    }
 
    // 判断是否是否需要新建SI需求表 
    public Boolean insertSIodOrNot(){
        return Operating_Room_Count == ISOppDemandList.Operating_Room_Count__c && Operating_Room_Type1 == ISOppDemandOper1.Operating_Room_Type__c &&
        Operating_Room_Type2 == ISOppDemandOper2.Operating_Room_Type__c &&
        Operating_Room_Type3 == ISOppDemandOper3.Operating_Room_Type__c &&
        Demonstration_Number == ISOppDemandList.Demonstration_Number__c &&
        Demonstration_Type1 == ISOppDemandDemon1.Demonstration_Type__c &&
        Demonstration_Type2 == ISOppDemandDemon2.Demonstration_Type__c &&
        Demand_DemonstrationType == ISOppDemandList.Demand_DemonstrationType__c;
    }
 
    // 返回
    public PageReference returnOpp(){
        if(ISodcIdStr == '' || ISodcIdStr == null){
            PageReference page = new PageReference('/'+OpporIdStr);
            page.setRedirect(true);
            return page;
        }
        if(ISodcIdStr != '' && ISodcIdStr != null){
            PageReference page = new PageReference('/'+ISodcIdStr);
            page.setRedirect(true);
            return page;
        }
        return null;
    }
 
    // 保存并返回
    public PageReference saveAndReturn(){
        saveAndReturnB = true;
        save();
        if(ISodcIdStr == '' || ISodcIdStr == null){
            PageReference page = new PageReference('/'+OpporIdStr);
            page.setRedirect(true);
            return page;
        }
        if(ISodcIdStr != '' && ISodcIdStr != null){
            PageReference page = new PageReference('/'+ISodcIdStr);
            page.setRedirect(true);
            return page;
        }
        return null;
    }
 
    public PageReference save(){
        PDFfileName = 'save';
        System.debug('需求表信息'+ISOppDemandList);
        System.debug('选择的术间的数量'+ISOppDemandList.Operating_Room_Count__c);
        System.debug('术间1信息'+ISOppDemandOper1);
        System.debug('术间1对应的配置信息'+ISOppDemandConfiguate11);
        System.debug('术间2信息'+ISOppDemandOper2);
        System.debug('术间2对应的配置信息'+ISOppDemandConfiguate22);
        System.debug('术间3信息'+ISOppDemandOper3);
        System.debug('术间>3信息'+ISOppDemandOperMore);
        
        System.debug('选择的示教点的数量'+ISOppDemandList.Demonstration_Number__c);
        System.debug('示教点1信息'+ISOppDemandDemon1);
        System.debug('示教点2信息'+ISOppDemandDemon2);
        System.debug('示教点>2信息'+ISOppDemandDemonMore);
        // 首先先检查完整性
        mustCheck();
        system.debug(ErrorColorChangeStr+'======');
        if(ErrorColorChangeStr != ''){
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, ErrorColorChangeStr));
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, '需求表未填写完整,请修正'));
        }else{
            // ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, '需求表已填写完整'));
        // 保存需求表信息
        if(ISOpptunityDemandList.size() <= 0){
            ISOppDemandList.Data_Check_TF__c = true;
            upsert ISOppDemandList;
        }
        insertOrNot = insertSIodOrNot();
        if(ISOpptunityDemandList.size() > 0){
            if(insertOrNot){
                update ISOppDemandList;
            }else{
                ISOppDemandList.Abort_Date__c = Date.today();
                ISOppDemandList.Data_Check_TF__c = true;
                update ISOppDemandList;
                ISOppDemandList.Id = null;
                ISOppDemandList.Abort_Date__c = null;
                insert ISOppDemandList;
            }
            
        }
        String isoId = ISOppDemandList.Id;
        ISodcIdStr = ISOppDemandList.Id;
        System.debug(isoId+'需求表的id');
        // 根据需求表的信息保存术间的信息
        // 术间数量为1
        
        // List<IS_Opportunity_Demand_Configuration__c> deleteISOdc = new List<IS_Opportunity_Demand_Configuration__c>();
        if(ISOppDemandList.Operating_Room_Count__c == '1' || ISOppDemandList.Operating_Room_Count__c == '2' || ISOppDemandList.Operating_Room_Count__c == '3'){
            // 更新术间1信息
            if(ISOppDemandOper1 != null){
                if(ISOppDemandOper1.IS_Opportunity_Demand__c == null){
                    ISOppDemandOper1.IS_Opportunity_Demand__c = isoId;
                    insert ISOppDemandOper1;
                }
                // if(ISOppDemandOper1.IS_Opportunity_Demand__c != null){
                else{
                    if(!insertOrNot){
                        ISOppDemandOper1.Id = null;
                        ISOppDemandOper1.IS_Opportunity_Demand__c = isoId;
                        insert ISOppDemandOper1;
                    }else{
                        update ISOppDemandOper1;
                    }
                    
                }
                
            }
            // 根据术间1的术间配置类型来更新或创建配置单的信息
            if(ISOppDemandOper1.Operating_Room_Type__c == 'HD整体手术间'){
                updateOrInsertISOdc(ISOppDemandOper1,ISOppDemandConfiguate11);
                // upsert ISOppDemandConfiguate11;
                // deleteISOdc.addAll(ISOppDemandConfiguate12);
                // deleteISOdc.addAll(ISOppDemandConfiguate13);
                // deleteISOdc.addAll(ISOppDemandConfiguate14);
            }
            if(ISOppDemandOper1.Operating_Room_Type__c == '3D整体手术间'){
                updateOrInsertISOdc(ISOppDemandOper1,ISOppDemandConfiguate12);
                // upsert ISOppDemandConfiguate12;
                // deleteISOdc.addAll(ISOppDemandConfiguate11);
                // deleteISOdc.addAll(ISOppDemandConfiguate13);
                // deleteISOdc.addAll(ISOppDemandConfiguate14);
            }
            if(ISOppDemandOper1.Operating_Room_Type__c == '4K整体手术间'){
                updateOrInsertISOdc(ISOppDemandOper1,ISOppDemandConfiguate13);
                // upsert ISOppDemandConfiguate13;
                // deleteISOdc.addAll(ISOppDemandConfiguate11);
                // deleteISOdc.addAll(ISOppDemandConfiguate12);
                // deleteISOdc.addAll(ISOppDemandConfiguate14);
            }
            if(ISOppDemandOper1.Operating_Room_Type__c == '3D/4K整体手术间'){
                updateOrInsertISOdc(ISOppDemandOper1,ISOppDemandConfiguate14);
                // upsert ISOppDemandConfiguate14;
                // deleteISOdc.addAll(ISOppDemandConfiguate11);
                // deleteISOdc.addAll(ISOppDemandConfiguate12);
                // deleteISOdc.addAll(ISOppDemandConfiguate13);
            }
        }
        if(ISOppDemandList.Operating_Room_Count__c == '2' || ISOppDemandList.Operating_Room_Count__c == '3'){
            // 更新术间1信息
            if(ISOppDemandOper2 != null){
                if(ISOppDemandOper2.IS_Opportunity_Demand__c == null){
                    ISOppDemandOper2.IS_Opportunity_Demand__c = isoId;
                    insert ISOppDemandOper2;
                }
                // if(ISOppDemandOper2.IS_Opportunity_Demand__c != null){
                else{
                    if(!insertOrNot){
                        ISOppDemandOper2.Id = null;
                        ISOppDemandOper2.IS_Opportunity_Demand__c = isoId;
                        insert ISOppDemandOper2;
                    }else{
                        update ISOppDemandOper2;
                    }
                    // update ISOppDemandOper2;
                }
                // update ISOppDemandOper2;
            }
 
            // 根据术间1的术间配置类型来更新或创建配置单的信息
            if(ISOppDemandOper2.Operating_Room_Type__c == 'HD整体手术间'){
                updateOrInsertISOdc(ISOppDemandOper2,ISOppDemandConfiguate21);
                // upsert ISOppDemandConfiguate21;
                // deleteISOdc.addAll(ISOppDemandConfiguate22);
                // deleteISOdc.addAll(ISOppDemandConfiguate23);
                // deleteISOdc.addAll(ISOppDemandConfiguate24);
            }
            if(ISOppDemandOper2.Operating_Room_Type__c == '3D整体手术间'){
                updateOrInsertISOdc(ISOppDemandOper2,ISOppDemandConfiguate22);
                // upsert ISOppDemandConfiguate22;
                // deleteISOdc.addAll(ISOppDemandConfiguate21);
                // deleteISOdc.addAll(ISOppDemandConfiguate23);
                // deleteISOdc.addAll(ISOppDemandConfiguate24);
            }
            if(ISOppDemandOper2.Operating_Room_Type__c == '4K整体手术间'){
                updateOrInsertISOdc(ISOppDemandOper2,ISOppDemandConfiguate23);
                // upsert ISOppDemandConfiguate23;
                // deleteISOdc.addAll(ISOppDemandConfiguate21);
                // deleteISOdc.addAll(ISOppDemandConfiguate22);
                // deleteISOdc.addAll(ISOppDemandConfiguate24);
            }
            if(ISOppDemandOper2.Operating_Room_Type__c == '3D/4K整体手术间'){
                updateOrInsertISOdc(ISOppDemandOper2,ISOppDemandConfiguate24);
                // upsert ISOppDemandConfiguate24;
                // deleteISOdc.addAll(ISOppDemandConfiguate21);
                // deleteISOdc.addAll(ISOppDemandConfiguate22);
                // deleteISOdc.addAll(ISOppDemandConfiguate23);
            }
        }
        if(ISOppDemandList.Operating_Room_Count__c == '3'){
            // 更新术间1信息
            if(ISOppDemandOper3 != null){
                if(ISOppDemandOper3.IS_Opportunity_Demand__c == null){
                    ISOppDemandOper3.IS_Opportunity_Demand__c = isoId;
                    insert ISOppDemandOper3;
                }
                // if(ISOppDemandOper3.IS_Opportunity_Demand__c != null){
                else{
                    if(!insertOrNot){
 
                        ISOppDemandOper3.Id = null;
                        ISOppDemandOper3.IS_Opportunity_Demand__c = isoId;
                        insert ISOppDemandOper3;
                    }else{
                        update ISOppDemandOper3;
                    }
                    // update ISOppDemandOper3;
                }
                // upsert ISOppDemandOper3;
            }
            // 根据术间1的术间配置类型来更新或创建配置单的信息
            if(ISOppDemandOper3.Operating_Room_Type__c == 'HD整体手术间'){
                updateOrInsertISOdc(ISOppDemandOper3,ISOppDemandConfiguate31);
                // upsert ISOppDemandConfiguate31;
                // deleteISOdc.addAll(ISOppDemandConfiguate32);
                // deleteISOdc.addAll(ISOppDemandConfiguate33);
                // deleteISOdc.addAll(ISOppDemandConfiguate34);
            }
            if(ISOppDemandOper3.Operating_Room_Type__c == '3D整体手术间'){
                updateOrInsertISOdc(ISOppDemandOper3,ISOppDemandConfiguate32);
                // upsert ISOppDemandConfiguate32;
                // deleteISOdc.addAll(ISOppDemandConfiguate31);
                // deleteISOdc.addAll(ISOppDemandConfiguate33);
                // deleteISOdc.addAll(ISOppDemandConfiguate34);
            }
            if(ISOppDemandOper3.Operating_Room_Type__c == '4K整体手术间'){
                updateOrInsertISOdc(ISOppDemandOper3,ISOppDemandConfiguate33);
                // upsert ISOppDemandConfiguate33;
                // deleteISOdc.addAll(ISOppDemandConfiguate31);
                // deleteISOdc.addAll(ISOppDemandConfiguate32);
                // deleteISOdc.addAll(ISOppDemandConfiguate34);
            }
            if(ISOppDemandOper3.Operating_Room_Type__c == '3D/4K整体手术间'){
                updateOrInsertISOdc(ISOppDemandOper3,ISOppDemandConfiguate34);
                // upsert ISOppDemandConfiguate34;
                // deleteISOdc.addAll(ISOppDemandConfiguate31);
                // deleteISOdc.addAll(ISOppDemandConfiguate32);
                // deleteISOdc.addAll(ISOppDemandConfiguate33);
            }
        }
        if(ISOppDemandList.Operating_Room_Count__c == '>3'){
            // 更新术间1信息
            if(ISOppDemandOperMore != null){
                if(ISOppDemandOperMore.IS_Opportunity_Demand__c == null){
                    ISOppDemandOperMore.IS_Opportunity_Demand__c = isoId;
                    insert ISOppDemandOperMore;
                }
                // if(ISOppDemandOperMore.IS_Opportunity_Demand__c != null){
                else{
                    if(!insertOrNot){
                        ISOppDemandOperMore.Id = null;
                        ISOppDemandOperMore.IS_Opportunity_Demand__c = isoId;
                        insert ISOppDemandOperMore;
                    }else{
                        update ISOppDemandOperMore;
                    }
                    // update ISOppDemandOperMore;
                }
                // upsert ISOppDemandOperMore;
            }
        }
        // 保存示教点信息
        if(ISOppDemandList.Demonstration_Number__c == '1' || ISOppDemandList.Demonstration_Number__c == '2'){
            if(ISOppDemandDemon1 != null){
                if(ISOppDemandDemon1.IS_Opportunity_Demand__c == null){
                    ISOppDemandDemon1.IS_Opportunity_Demand__c = isoId;
                    insert ISOppDemandDemon1;
                }
                // if(ISOppDemandDemon1.IS_Opportunity_Demand__c != null){
                else{
                    if(!insertOrNot){
                        ISOppDemandDemon1.Id = null;
                        ISOppDemandDemon1.IS_Opportunity_Demand__c = isoId;
                        insert ISOppDemandDemon1;
                    }else{
                        update ISOppDemandDemon1;
                    }
                    // update ISOppDemandDemon1;
                }
                // upsert ISOppDemandDemon1;
            }
        }
        if(ISOppDemandList.Demonstration_Number__c == '2'){
            if(ISOppDemandDemon2 != null){
                if(ISOppDemandDemon2.IS_Opportunity_Demand__c == null){
                    ISOppDemandDemon2.IS_Opportunity_Demand__c = isoId;
                    insert ISOppDemandDemon2;
                }
                // if(ISOppDemandDemon2.IS_Opportunity_Demand__c != null){
                else{
                    if(!insertOrNot){
                        ISOppDemandDemon2.Id = null;
                        ISOppDemandDemon2.IS_Opportunity_Demand__c = isoId;
                        insert ISOppDemandDemon2;
                    }else{
                        update ISOppDemandDemon2;
                    }
                    // update ISOppDemandDemon2;
                }
                // upsert ISOppDemandDemon2;
            }
        }
        if(ISOppDemandList.Demonstration_Number__c == '>2'){
            if(ISOppDemandDemonMore != null){
                if(ISOppDemandDemonMore.IS_Opportunity_Demand__c == null){
                    ISOppDemandDemonMore.IS_Opportunity_Demand__c = isoId;
                    insert ISOppDemandDemonMore;
                }
                // if(ISOppDemandDemonMore.IS_Opportunity_Demand__c != null){
                else{
                    if(!insertOrNot){
                        ISOppDemandDemonMore.Id = null;
                        ISOppDemandDemonMore.IS_Opportunity_Demand__c = isoId;
                        insert ISOppDemandDemonMore;
                    }else{
                        update ISOppDemandDemonMore;
                    }
                    // update ISOppDemandDemonMore;
                }
                // upsert ISOppDemandDemonMore;
            }
        }
        // 保存后删除无用的术间和示教点
        List<IS_Opportunity_Demand_Operating__c> deleteOdo = new List<IS_Opportunity_Demand_Operating__c>();
        List<IS_Opportunity_Demand_Demonstration__c> deleteOdd = new List<IS_Opportunity_Demand_Demonstration__c>();
        if(ISOppDemandList.Demonstration_Number__c == '1'){
            if(ISOppDemandDemonMore.Id != null){
                deleteOdd.add(ISOppDemandDemonMore);
            }
            if(ISOppDemandDemon2.Id != null){
                deleteOdd.add(ISOppDemandDemon2);
            }
            
        }
        if(ISOppDemandList.Demonstration_Number__c == '2'){
            if(ISOppDemandDemonMore.Id != null){
                deleteOdd.add(ISOppDemandDemonMore);
            }
            
        }
        if(ISOppDemandList.Demonstration_Number__c == '>2'){
            if(ISOppDemandDemon1.Id != null){
                deleteOdd.add(ISOppDemandDemon1);
            }
            if(ISOppDemandDemon2.Id != null){
                deleteOdd.add(ISOppDemandDemon2);
            }
        }
        if(ISOppDemandList.Operating_Room_Count__c == '1'){
            if(ISOppDemandOper2.Id != null){
                deleteOdo.add(ISOppDemandOper2);
            }
            if(ISOppDemandOper3.Id != null){
                deleteOdo.add(ISOppDemandOper3);
            }
            if(ISOppDemandOperMore.Id != null){
                deleteOdo.add(ISOppDemandOperMore);
            }
        }
        if(ISOppDemandList.Operating_Room_Count__c == '2'){
            if(ISOppDemandOper3.Id != null){
                deleteOdo.add(ISOppDemandOper3);
            }
            if(ISOppDemandOperMore.Id != null){
                deleteOdo.add(ISOppDemandOperMore);
            }
        }
        if(ISOppDemandList.Operating_Room_Count__c == '>3'){
            if(ISOppDemandOper2.Id != null){
                deleteOdo.add(ISOppDemandOper2);
            }
            if(ISOppDemandOper3.Id != null){
                deleteOdo.add(ISOppDemandOper3);
            }
            if(ISOppDemandOper1.Id != null){
                deleteOdo.add(ISOppDemandOper1);
            }
        }
        if(ISOppDemandList.Operating_Room_Count__c == '3'){
            if(ISOppDemandOperMore.Id != null){
                deleteOdo.add(ISOppDemandOperMore);
            }
        }
        if(deleteOdo.size() > 0){
            delete deleteOdo;
        }
        if(deleteOdd.size() > 0){
            delete deleteOdd;
        }
 
        if(returnNew == true && saveAndReturnB == false){
            PageReference page = new PageReference('/apex/ISO_DemandOperAndDemonsNew?OppoerID='+ISOppDemandList.Opportunity_ID__c+'&id='+ISodcIdStr);
            page.setRedirect(true);
            
            return page;
        }
        // 因为新建了需求表,所以需要刷新页面到新的需求表
        if(!insertOrNot){
            PageReference page = new PageReference('/apex/ISO_DemandOperAndDemonsNew?OppoerID='+ISOppDemandList.Opportunity_ID__c+'&id='+ISodcIdStr);
            page.setRedirect(true);
            
            return page;
        }
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, '保存好了'));
        
        }
        // delete deleteISOdc;
        return null;
    }
    // 创建或者更新术间配置单信息
    public void updateOrInsertISOdc(IS_Opportunity_Demand_Operating__c ISOppDemandOper,List<IS_Opportunity_Demand_Configuration__c> ISOppDemandConfiguate){
        // 根据手术间类型更新或创建术间的配置信息
        // if(ISOppDemandOper.Operating_Room_Type__c == operRoomType){
            if(ISOppDemandConfiguate.size() > 0){
                // if(ISOppDemandConfiguate[0].Standard_Configuration__c == true){
                    // 新建术间配置单
                    // List<IS_Opportunity_Demand_Configuration__c> isOdcList11 = new List<IS_Opportunity_Demand_Configuration__c>();
                    for(IS_Opportunity_Demand_Configuration__c isOdc :ISOppDemandConfiguate){
                        // IS_Opportunity_Demand_Configuration__c isOdc11 = new IS_Opportunity_Demand_Configuration__c();
                        // isOdc11.Name = isOdc.Name;
                        // isOdc11.Brand__c = isOdc.Brand__c;
                        // isOdc11.Company__c = isOdc.Company__c;
                        // isOdc11.Configuration_Type__c = isOdc.Configuration_Type__c;
                        // isOdc11.Matching__c = isOdc.Matching__c;
                        // isOdc11.Number__c = isOdc.Number__c;
                        // isOdc11.Selection__c = isOdc.Selection__c;
                        // isOdc11.SerialNumber__c = isOdc.SerialNumber__c;
                        // isOdc11.IS_Opportunity_Demand_Operating__c = ISOppDemandOper.Id;
                        // isOdcList11.add(isOdc11);
                        if(!insertOrNot){
                            isOdc.Id = null;
                        }
                        isOdc.IS_Opportunity_Demand_Operating__c = ISOppDemandOper.Id;
                    }
                    upsert ISOppDemandConfiguate;
                    
                // }else{
                //     // 更新配置单
                //     update ISOppDemandConfiguate;
                // }
            }
        // }
    }
    // 构造si术间配置单
    public IS_Opportunity_Demand_Configuration__c makeISOdc(IS_Opportunity_Demand_Operating__c ISOppDemandOper,IS_Opportunity_Demand_Configuration__c isOdc){
        IS_Opportunity_Demand_Configuration__c isOdc11 = new IS_Opportunity_Demand_Configuration__c();
        isOdc11.Name = isOdc.Name;
        isOdc11.Brand__c = isOdc.Brand__c;
        isOdc11.Company__c = isOdc.Company__c;
        isOdc11.Configuration_Type__c = isOdc.Configuration_Type__c;
        isOdc11.Matching__c = isOdc.Matching__c;
        isOdc11.Number__c = isOdc.Number__c;
        isOdc11.Selection__c = isOdc.Selection__c;
        isOdc11.SerialNumber__c = isOdc.SerialNumber__c;
        isOdc11.IS_Opportunity_Demand_Operating__c = ISOppDemandOper.Id;
        return isodc11;
    }
    // 检查完整性的方法
    public PageReference completenessCheck(){
        mustCheck();
        if(ErrorColorChangeStr != ''){
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, ErrorColorChangeStr));
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, '需求表未填写完整,请修正'));
        }else{
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, '需求表已填写完整'));
        }
        return null;
    }
    // 必填字段的检查
    public void mustCheck(){
        // 术间字段的验证
        ErrorColorChangeStr = '';
        if(ISOppDemandList.Operating_Room_Count__c == null || ISOppDemandList.Operating_Room_Count__c == ''){
            ErrorColorChangeStr += '术间数量不能为空;';
        }
        if(ISOppDemandList.Operating_Room_Count__c == '1'){
            if(ISOppDemandOper1.Operating_Room_Type__c == '' || ISOppDemandOper1.Operating_Room_Type__c == null){
                ErrorColorChangeStr += '术间1的术间类型不能为空;';
            }
        }
        if(ISOppDemandList.Operating_Room_Count__c == '2'){
            if(ISOppDemandOper1.Operating_Room_Type__c == '' || ISOppDemandOper1.Operating_Room_Type__c == null){
                ErrorColorChangeStr += '术间1的术间类型不能为空;';
            }
            if(ISOppDemandOper2.Operating_Room_Type__c == '' || ISOppDemandOper2.Operating_Room_Type__c == null){
                ErrorColorChangeStr += '术间2的术间类型不能为空;';
            }
        }
        if(ISOppDemandList.Operating_Room_Count__c == '3'){
            if(ISOppDemandOper1.Operating_Room_Type__c == '' || ISOppDemandOper1.Operating_Room_Type__c == null){
                ErrorColorChangeStr += '术间1的术间类型不能为空;';
            }
            if(ISOppDemandOper2.Operating_Room_Type__c == '' || ISOppDemandOper2.Operating_Room_Type__c == null){
                ErrorColorChangeStr += '术间2的术间类型不能为空;';
            }
            if(ISOppDemandOper3.Operating_Room_Type__c == '' || ISOppDemandOper3.Operating_Room_Type__c == null){
                ErrorColorChangeStr += '术间3的术间类型不能为空;';
            }
        }
        if(ISOppDemandList.Operating_Room_Count__c == '>3'){
            if(ISOppDemandOperMore.Project_Information__c == ''){
                ErrorColorChangeStr += '术间>3时须填写项目信息;';
            }
        }
 
        // 示教点字段的验证
        // if(ISOppDemandList.Demonstration_Number__c == null || ISOppDemandList.Demonstration_Number__c == ''){
        //     ErrorColorChangeStr += '示教点数量不能为空;';
        // }
        if(ISOppDemandList.Demonstration_Number__c == '1'){
            if(ISOppDemandDemon1.Demonstration_Type__c == '' || ISOppDemandDemon1.Demonstration_Type__c == null){
                ErrorColorChangeStr += '示教点1的示教点类型不能为空;';
            }
        }
        if(ISOppDemandList.Demonstration_Number__c == '2'){
            if(ISOppDemandDemon1.Demonstration_Type__c == '' || ISOppDemandDemon1.Demonstration_Type__c == null){
                ErrorColorChangeStr += '示教点1的示教点类型不能为空;';
            }
            if(ISOppDemandDemon2.Demonstration_Type__c == '' || ISOppDemandDemon2.Demonstration_Type__c == null){
                ErrorColorChangeStr += '示教点2的示教点类型不能为空;';
            }
        }
        if(ISOppDemandList.Demonstration_Number__c == '>2'){
            if(ISOppDemandDemonMore.Teaching_Needs__c == ''){
                ErrorColorChangeStr += '示教点>2时需填写示教需求;';
            }
        }
        if(ISOppDemandList.Operating_Room_Count__c == '2' || ISOppDemandList.Operating_Room_Count__c == '3' || ISOppDemandList.Operating_Room_Count__c == '>3'){
            if(ISOppDemandList.Demand_DemonstrationType__c == '' || ISOppDemandList.Demand_DemonstrationType__c == null){
                ErrorColorChangeStr += '术间数量≥2时示教系统类型必填;';
            }
        }
 
        // 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 );
        // return null;
    }
    // 根据选择来控制术间的显示数量
    // public void updateshowISOdo1(){
    //     showISOdo1 = true;
    //     showISOdo2 = false;
    //     showISOdo3 = false;
    //     showISOdoMore = false;
    // }
    // public void updateshowISOdo2(){
    //     showISOdo1 = true;
    //     showISOdo2 = true;
    //     showISOdo3 = false;
    //     showISOdoMore = false;
    // }
    // public void updateshowISOdo3(){
    //     showISOdo1 = true;
    //     showISOdo2 = true;
    //     showISOdo3 = true;
    //     showISOdoMore = false;
    // }
    // public void updateshowISOdoMore(){
    //     showISOdoMore = true;
    //     showISOdo1 = false;
    //     showISOdo2 = false;
    //     showISOdo3 = false;
    // }
    // // 根据选择来控制配置单的显示
    // public void updateshowISOdcHD(){
    //     System.debug('======'+showISOdc11);
    //     showISOdc11 = true;
    //     showISOdc12 = false;
    //     showISOdc13 = false;
    //     showISOdc14 = false;
    //     System.debug('======'+showISOdc11);
    // }
    // public void updateshowISOdc3D(){
    //     showISOdc11 = false;
    //     showISOdc12 = true;
    //     showISOdc13 = false;
    //     showISOdc14 = false;
    // }
    // public void updateshowISOdc4K(){
    //     showISOdc11 = false;
    //     showISOdc12 = false;
    //     showISOdc13 = true;
    //     showISOdc14 = false;
    // }
    // public void updateshowISOdc3D4K(){
    //     showISOdc11 = false;
    //     showISOdc12 = false;
    //     showISOdc13 = false;
    //     showISOdc14 = true;
    // }
    // public Boolean displayPopup {get;set;}
    // public ISO_DemandOperAndDemonsNewController (ApexPages.StandardController controller)
    // {
  
    // }
    // public void showPopup()
    // {
    //     displayPopup = true;
    // }
    // public void closePopup()
    // {
    //      displayPopup = false;
    // }
    // public List<SelectOption> getItems()
    // {
    // List<SelectOption> options = new List<SelectOption>();
    // options.add(new SelectOption('US','US'));
    // options.add(new SelectOption('CANADA','Canada'));
    // options.add(new SelectOption('MEXICO','Mexico')); return options;
    // }
    // public PageReference redirectPopup()
    // {
    // displayPopup = false;
    // //Please uncomment below 3 statements and replace YourObjectId
    // PageReference p=new Pagereference('/');
    // p.setRedirect(true);
    // return p;
    // }
}