buli
2022-05-14 ead4df22dca33a867279471821ca675f91dec760
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
public with sharing class SWOSearchProductContaroller {
    public Integer quoteEntryMaxSet {get; private set;}
 
    public List<ProductInfo> productInfoList { get; set; }
 
    public Integer ProductInfoListSize {get; set;}
   
    public String searchMode;                         // 検索モード
    public String lineNo {get;set;}                   // 親画面の選択した行
    public String val {get;set;}
    public String type {get;set;}                     //主数据类型
    public String SearchName {get;set;}               // 検索文字列
    
    public SWOSearchProductContaroller(ApexPages.StandardController controller){
        this();
    }
 
    public SWOSearchProductContaroller() {
        this.quoteEntryMaxSet = Integer.valueOf(System.Label.QuoteEntryMaxSet);
        
        this.lineNo = Apexpages.currentPage().getParameters().get('lineno');
        this.val = Apexpages.currentPage().getParameters().get('val');
        this.type = Apexpages.currentPage().getParameters().get('type');
        if (String.isNotBlank(val)) {
            SearchName = val;
            val = null;
        }
        productInfoList = new  List<ProductInfo>();
        ProductInfoListSize = 1;
    }
 
    public void init () {
        system.debug('init==========> start');
        system.debug('SearchName==========>' + SearchName);
        if (SearchName != null && SearchName != '') {
            serProduct();
        }
 
        system.debug('init==========> end');
 
    }
 
    public PageReference serProduct(){
        productInfoList = new  List<ProductInfo>();
        ProductInfoListSize = 1;
        if (String.isNotBlank(SearchName)) {
 
             String sql = 'Select Id,Name,ProductCode,Description,PART_NUMBER__c,ProductInventory__c,ProductReferencePrice__c,Product_ECCode__c from Product2 Where Id != null ';
            String likename = String.escapeSingleQuotes(SearchName);
            String prdcd = String.escapeSingleQuotes(SearchName);
            String prdec = String.escapeSingleQuotes(SearchName);
            if (likename.indexOf('*') >= 0) {
                likename = likename.replace('*', '%');
            } else {
                likename = '%' + likename + '%';
            }
            if (prdcd.indexOf('*') >= 0) {
                prdcd = prdcd.replace('*', '%');
            } else {
                prdcd = '%' + prdcd + '%';
            }
            if (prdec.indexOf('*') >= 0) {
                prdec = prdcd.replace('*', '%');
            } else {
                prdec = '%' + prdec + '%';
            }
           
            sql += ' and (Name Like ' + '\'' + likename + '\' or ProductCode Like ' + '\'' + prdcd + '\' or Product_ECCode__c like ' + '\'' + prdec + '\')';
            sql += ' order by ProductCode,Name desc limit 200';
            List<Product2> product2List = Database.query(sql);
            if (product2List.size() > 0) {
                for (Product2 product :product2List) {
                    productInfoList.add(new ProductInfo(ProductInfoListSize,product));
                    ProductInfoListSize++;
                }
            }
            
        }
        return null;
    }
    public class ProductInfo {
 
        public Product2 productPage {get; set;}//产品
        public String productId {get; set;} //产品Id
        public Integer lineNumber {get; set;}//行号
        
        public ProductInfo (Integer productNo){
            lineNumber = productNo;
        }
        public ProductInfo ( Integer productNo,Product2 product) {
            productPage = product;
            lineNumber = productNo;
            productId = product.Id;
        }
    }
}