ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
package com.vci.client.portal.UI.v3.comptdesign.compt.popupcompt;
 
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.util.List;
 
import com.vci.client.oq.QTClient;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJButton;
import com.vci.client.ui.swing.components.VCIJPanel;
import com.vci.client.ui.swing.components.table.AbstractVCIJTableDataProvider;
import com.vci.client.ui.swing.components.table.VCIJTableDataProvider;
import com.vci.client.ui.swing.components.table.VCIJTableNode;
import com.vci.client.ui.swing.components.table.VCIJTablePanel;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.btm.BtmItem;
 
public class BtmTypePopupTablePanel extends VCIJPanel{
 
    /**
     * 
     */
    private static final long serialVersionUID = 8891383036571391327L;
    private final String COLUMN_NAME = "名称"; 
    private final String COLUMN_LABEL = "标签"; 
    private VCIJButton btnSearch = VCISwingUtil.createVCIJButton("search", "查询", "查询", "search.gif", new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            btnSearch_actionPerformed(e);
        }
    });
    private VCIJButton btnClear = VCISwingUtil.createVCIJButton("clear", "清空", "清空查询条件", "clear.gif", new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            btnClear_actionPerformed(e);
        }
    });
    
    private VCIJPanel searchInfoPanel = null;
    private VCIJTableDataProvider<BtmItem> dataProvider = null; 
    private VCIJTablePanel<BtmItem> tablePanel = null;
    
    
    private BtmTypePopupDialog popupDialog = null;
    
    public BtmTypePopupTablePanel(BtmTypePopupDialog popupDialog){
        this.popupDialog = popupDialog;
    }
    
    public void buildTablePanel(){
        setLayout(new BorderLayout());
        
        dataProvider = new AbstractVCIJTableDataProvider<BtmItem>() {
            @Override
            public String[] getSpecialColumns() {
                return new String[]{COLUMN_NAME, COLUMN_LABEL};
            }
            @Override
            public int getTotal() {
                return super.total;
            }
            @Override
            public VCIJTableNode<BtmItem> getNewRowNode(BtmItem obj) {
                VCIJTableNode<BtmItem> res = new VCIJTableNode<BtmItem>(obj);
                res.setPropertyValue(COLUMN_NAME, obj.name);
                res.setPropertyValue(COLUMN_LABEL, obj.label);
                return res;
            }
            @Override
            public BtmItem[] getDatas(int pageIndex, int pageSize) {
                BtmItem[] datas = new BtmItem[0];
                try {
                    ResData<BtmItem> res = getBtmNames(pageIndex, pageSize);
                    datas = res.getDatas();
                    super.total = res.getTotal();
                } catch (VCIError e) {
                    e.printStackTrace();
                }
                return datas;
            }
        };
        tablePanel = new VCIJTablePanel<BtmItem>(dataProvider);
        tablePanel.setShowExport(false);
        tablePanel.setColumnDefaultWidth(250);
        tablePanel.setPageSizeList(new int[]{10,20,30,40,50,100, 10});
        tablePanel.buildTablePanel();
        
        searchInfoPanel = getNorthSearchPanel();
        add(searchInfoPanel, BorderLayout.NORTH);
        add(tablePanel, BorderLayout.CENTER);
    }
 
    private VCIJPanel getNorthSearchPanel(){
        VCIJPanel pal = new VCIJPanel(new GridBagLayout());
        pal.add(btnSearch, getGBC(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, 1));
        pal.add(btnClear, getGBC(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, 1));
        searchInfoPanel = pal;
        return pal;
    }
    private GridBagConstraints getGBC(int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill, int padxy) {
        return new GridBagConstraints(gridx, gridy, gridwidth, gridheight, weightx, weighty, anchor, fill, new Insets(padxy, padxy, padxy, padxy), padxy, padxy);
    }
    
    private ResData<BtmItem> getBtmNames(int pageIndex, int pageSize) throws VCIError{
        BtmItem[] btmNames = null;
        int start = pageIndex <= 1 ? 1 : (pageIndex - 1) * pageSize + 1;
        int end = pageIndex <= 1 ? pageSize : (pageIndex * pageSize);
        
        String where = " 1=1 ";
        String text = "";
 
        if(getPopupDialog() != null){
            if(!getPopupDialog().isIgnoreTxtInputValue()){
                text = getPopupDialog().getSearchInputTxt().getText().trim();
                where += String.format(" and (bt.name like '%%%s%%' or bt.label like '%%%s%%')", text, text);
            }
        }
        String fromWhere = String.format(" from plbtmtype bt where %s ", where);
        String fromWhereOrderBy = String.format(" %s order by bt.name", fromWhere);
        String sql = String.format("select * from(" +
                "  select row_.*,rownum rownum_ from( " +
                "         select bt.name, bt.label %s" +
                "  ) row_ " +
                ") where rownum_ >= %d and rownum_ <= %d ", fromWhereOrderBy, start, end);
        List<BtmItem> list = new LinkedList<BtmItem>();
        String[][] kvss = QTClient.getService().queryBySqlWithoutKey(sql);
        for(String[] kvs : kvss){
            BtmItem bi = new BtmItem();
            bi.name = kvs[0];
            bi.label = kvs[1];
            list.add(bi);
        }
        btmNames = list.toArray(new BtmItem[]{});
        
        sql = String.format("select count(1) count_ %s", fromWhere);
        kvss = QTClient.getService().queryBySqlWithoutKey(sql);
        int total = Integer.valueOf(kvss[0][0]);
        
        ResData<BtmItem> res = new ResData<BtmItem>();
        res.setDatas(btmNames);
        res.setTotal(total);
        return res;
    }
 
    private void btnSearch_actionPerformed(ActionEvent e){
        tablePanel.setPageIndex(1);
        tablePanel.refreshTableData();
    }
    
    private void btnClear_actionPerformed(ActionEvent e){
        tablePanel.setPageIndex(1);
        if(getPopupDialog() != null && getPopupDialog().getSearchInputTxt() != null){
            getPopupDialog().getSearchInputTxt().setText("");
        }
        tablePanel.refreshTableData();
    }
    
    public VCIJTablePanel<BtmItem> getTablePanel() {
        return tablePanel;
    }
 
    public BtmTypePopupDialog getPopupDialog() {
        return popupDialog;
    }
 
    public void setPopupDialog(BtmTypePopupDialog popupDialog) {
        this.popupDialog = popupDialog;
    }
    
    
}