| trigger SyncMBRepair on Repair__c (after insert, before delete) { | 
| /*    // MB_修理插入用 | 
|     List<MB_Repair__c> ins_mb_repairs = new List<MB_Repair__c>(); | 
|     // MB_修理删除用 | 
|     List<Repair__c> del_repairs = new List<Repair__c>(); | 
|     List<Id> RepairIds = new List<Id>(); | 
|     if (Trigger.isInsert) { | 
|         for (Repair__c r : Trigger.new) { | 
|             MB_Repair__c mbr = new MB_Repair__c( | 
|                   Repair__c = r.Id | 
|                 , CurrencyIsoCode = r.CurrencyIsoCode | 
| // CIC 125725 start | 
| //                , OwnerId = r.Acc_OwnerId__c | 
|                 , Opp_OCM_text__c = r.HP_OCM__c | 
|                 , State_Text__c = r.State_Hospital__c | 
|                 , Opportunity_Category_text__c = r.Acc_Department_Class_Name__c | 
| // CIC 125725 end | 
|             ); | 
|             ins_mb_repairs.add(mbr); | 
|         } | 
|     } else if (Trigger.isDelete) { | 
|         for (Repair__c r : Trigger.old) { | 
|             RepairIds.add(r.Id); | 
|             //del_repairs.add(r); | 
|         } | 
|         //有备品借出申请的修改 | 
|         List<Rental_Apply__c> raList = [select id, Status__c, Repair__c, RA_Status__c from Rental_Apply__c where Repair__c in :RepairIds and Status__c != '取消']; | 
|         //有备品借出申请的修理 | 
|         Map<Id,List<Rental_Apply__c>> RaMapList = new Map<Id,List<Rental_Apply__c>>(); | 
|          | 
|         if(raList.size() >0){ | 
|             for(Rental_Apply__c ra :raList){ | 
|                 List<Rental_Apply__c> RenList = new List<Rental_Apply__c>(); | 
|                 if(RaMapList.containsKey(Ra.Repair__c)){ | 
|                     RenList.add(ra); | 
|                 } | 
|                 RaMapList.put(Ra.Repair__c, RenList); | 
|             } | 
|         } | 
|   | 
|         for (Repair__c r : Trigger.old) { | 
|             if(RaMapList.containsKey(r.Id)){ | 
|                 r.addError('不能删除有备品借出申请的修理。'); | 
|             }else{ | 
|                 del_repairs.add(r); | 
|             } | 
|         } | 
|   | 
|   | 
|     } | 
|     if (del_repairs.size() > 0) { | 
|         ControllerUtil.delMBRepairList(del_repairs); | 
|     } | 
|     if (ins_mb_repairs.size() > 0) { | 
|         ControllerUtil.insMBRepairList(ins_mb_repairs); | 
|     }*/ | 
| } |