buli
2022-05-13 2f4492ee18f90274582fcc2bb06f5e9bf64136e8
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
public with sharing class NewRepairPartsController {
 
    public RepairPart__c repairPart{get;set;}
    public String swoId{get;set;}
    public String repairId{get;set;}
    public Boolean pageClose{get;set;}
 
    /*public NewRepairPartsController(ApexPages.StandardController stdController) {
        swoId = System.currentPageReference().getParameters().get('swoId');
    }*/
 
    public NewRepairPartsController() {
        swoId = System.currentPageReference().getParameters().get('swoId');
        repairId = System.currentPageReference().getParameters().get('id');
    }
 
    public void init(){
        if(String.isNotBlank(repairId)){
            Schema.DescribeSobjectResult repairPartType = RepairPart__c.sObjectType.getDescribe();
            Map<String, Schema.SObjectField> repairPart_fields = repairPartType.fields.getMap();
            String soql_repair = 'select ';
            String fields = '';
            for (String field : repairPart_fields.keySet()) {
                if (fields.length() > 0) {
                    fields += ', ';
                }
                fields += field;
            }
            soql_repair += fields;
            soql_repair += ' from RepairPart__c where Id = \'' + repairId + '\'';
            repairPart = Database.query(soql_repair);
        }else{
            repairPart = new RepairPart__c();
 
            if(String.isNotBlank(swoId)){
                repairPart.SWO_ID__c = swoId;
            }
        }
    }
 
    public void save(){
        pageClose = false;
        upsert repairPart;
        pageClose = true;
        System.debug('id:'+repairPart.Id);
        repairId = repairPart.Id;
        return;
    }
 
    public Boolean mastData(){
        Boolean temp = true;
        if(repairPart.Product__c == null){
            repairPart.Product__c.addError('ITEM can not be empty');
            temp = false;
        }
        if(repairPart.QUANTITY__c == null){
            repairPart.QUANTITY__c.addError('QUANTITY can not be empty');
            temp = false;
        }
        if(repairPart.LOCATION__c == null){
            repairPart.LOCATION__c.addError('LOCATION can not be empty');
            temp = false;
        }
        System.debug('temp:'+temp);
        return temp;
    }
 
    public void deleteAction(){
        pageClose = true;
        if(String.isNotBlank(repairPart.Id)){
            delete repairPart;
            return;
        }else{
            return;
        }
    }
}