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
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
package com.vci.client.oq.ui;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.Border;
 
import org.jdesktop.swingx.JXDatePicker;
 
import com.vci.client.omd.provider.ApProvider;
import com.vci.common.qt.object.Operator;
import com.vci.corba.omd.qtm.QTInfo;
 
 
public class ConditionDialog extends JDialog{
 
    /**
     * 
     */
    private static final long serialVersionUID = 190296528238845070L;
    private JPanel centerPanel;
    private JPanel southPanel;
    private JComboBox combCons;
    private JTextArea tfValue;
    private JButton btnOK;
    private JButton btnCancel;
    private JButton btnModify;
    private String attName;
    private String condition;
    /**
     * 记录关闭事件0:cancel,X, 1: OK
     */
    private int disposeEvent = 0;
    private JXDatePicker datePicker;
    private Chooser chooser;
    private String attType;
    public static final int disposeByCancel = 0;
    public static final int disposeByOK = 1;
    
    /**
     * 记录关闭事件0:cancel,X, 1: OK
     */
    public int getDisposeEvent() {
        return disposeEvent;
    }
    
    /**
     * 记录关闭事件0:cancel,X, 1: OK
     */
    public void setDisposeEvent(int disposeEvent) {
        this.disposeEvent = disposeEvent;
    }
    public ConditionDialog(String condition){
        this.condition = condition;
        
        int index = this.condition.indexOf(' ');
        if (index > 0)
            this.attName = condition.substring(0, index);
        else
            this.attName = condition;
        initUI();
        addListener();
    }
    private void initUI(){
        this.setTitle("查询条件设置框");
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        this.setSize(500, 300);
        this.setModal(true);
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        this.setLayout(new BorderLayout(5, 5));
        centerPanel = new JPanel();
        southPanel = new JPanel();
        this.add(centerPanel, BorderLayout.CENTER);
        this.add(southPanel, BorderLayout.SOUTH);
        
        centerPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
        JLabel lable = new JLabel(this.attName);
        combCons = new JComboBox();
        combCons.setPreferredSize(new Dimension(80, 20));
        attType = ApProvider.getAbItemDataType(attName);
        
        if(attType.equalsIgnoreCase("VTInteger") || attType.equalsIgnoreCase("VTDouble")
                || attType.equalsIgnoreCase("VTLong")){
            combCons.addItem(Operator.EQUAL);
            combCons.addItem(Operator.UNEQUAL);
            combCons.addItem(Operator.CONTAINS);
            combCons.addItem(Operator.IN);
            combCons.addItem(Operator.NOTIN);
            combCons.addItem(Operator.GTE);
            combCons.addItem(Operator.GT);
            combCons.addItem(Operator.LTE);
            combCons.addItem(Operator.LT);
        }else if(attType.equalsIgnoreCase("VTDateTime") || attType.equalsIgnoreCase("VTDate")
                || attType.equalsIgnoreCase("VTTime")){
            combCons.addItem(Operator.EQUAL);
            combCons.addItem(Operator.UNEQUAL);
            combCons.addItem(Operator.IN);
            combCons.addItem(Operator.NOTIN);
            combCons.addItem(Operator.GTE);
            combCons.addItem(Operator.LTE);
        }else{
            combCons.addItem(Operator.EQUAL);
            combCons.addItem(Operator.UNEQUAL);
            combCons.addItem(Operator.CONTAINS);
            combCons.addItem(Operator.IN);
            combCons.addItem(Operator.NOTIN);
        }
        //add by caill start 通过分割字符串获得数据库中的数据并在修改时回显到条件框中
        int size=combCons.getModel().getSize();
        String singleValue=null;
        //add by caill start 2015.12.25
        List<Integer> list = new ArrayList<Integer>();
        Map<Integer,String> map = new HashMap<Integer, String>();
        String str = null;
        int index = -1;
        for(int i = 0;i < size;i++){
            String sign = combCons.getItemAt(i).toString();
            str = " " + sign + " ";
            index = this.condition.indexOf(str);
            if(index != -1){
                list.add(index);
                map.put(index, str);
            }
            
        }
        if(list.size()>0){
            Collections.sort(list);
            index = list.get(0);
            str = map.get(index);
            
            int length = str.length();
            if(index!=-1){
                combCons.setSelectedItem(str.substring(1, length-1));    //将选择的下拉列表符号做回显
                singleValue=this.condition.substring(index+length-1, this.condition.length());
            }
        }
        //add by caill end 
        
        /*for(int i=0;i<size;i++){
            String sign=combCons.getItemAt(i).toString();
            String str = " " + sign + " ";
            int length=str.length();
            int index = attName.indexOf(str);
            
            int length=sign.length();
            int index = attName.indexOf(sign);
            if(index!=-1){
                //add by caill start 2015.12.24 在分割字符串的时候特别要对not in 和 in做判断
                if(str.equals(" in ")){
                    String speStr = " not in ";
                    if(attName.indexOf(speStr) != -1){
                        length=speStr.length();
                        index = attName.indexOf(speStr);
                        combCons.setSelectedItem("not in");
                        singleValue=attName.substring(index+length-1, attName.length());
                    } else{
                        combCons.setSelectedItem(sign);    //将选择的下拉列表符号做回显
                         singleValue=attName.substring(index+length-1, attName.length());
                    }
                    //add by caill end
                }else{
                     combCons.setSelectedItem(sign);    //将选择的下拉列表符号做回显
                     singleValue=attName.substring(index+length-1, attName.length());
                }
            
            // break;
            }
        }*/
        tfValue = new JTextArea();
        Border border = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
        tfValue.setBorder(BorderFactory.createCompoundBorder(border, BorderFactory.createEmptyBorder(5, 5, 5, 5)));
        tfValue.setLineWrap(true);    //设置多行文本框自动换行
        tfValue.setPreferredSize(new Dimension(480, 200));
        tfValue.setText(singleValue);
        //add by caill end
        chooser = Chooser.getInstance();
        chooser.setLayout(centerPanel.getLayout());
//        datePicker = new JXDatePicker();
        btnModify = new JButton("选择查询模板");
//        datePicker.setPreferredSize(tfValue.getPreferredSize());
//        chooser.setPreferredSize(tfValue.getPreferredSize());
        
        centerPanel.add(lable);
        centerPanel.add(combCons);
        if(attType.equalsIgnoreCase("VTDateTime") || attType.equalsIgnoreCase("VTDate")
                || attType.equalsIgnoreCase("VTTime")){
            JTextField text = new JTextField(50);
            chooser.register(text);
            centerPanel.add(chooser);
//            centerPanel.add(datePicker);
        }else{
            centerPanel.add(tfValue);
        }
        btnOK = new JButton("确定");
        btnCancel = new JButton("取消");
        
        southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
        southPanel.add(btnModify);
        southPanel.add(btnOK);
        southPanel.add(btnCancel);
        
    }
    
    private void addListener(){
        btnOK.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
//                if(attType.equalsIgnoreCase("VTDateTime") || attType.equalsIgnoreCase("VTDate")
//                        || attType.equalsIgnoreCase("VTTime")){
//                    if(datePicker.getDate() == null){
//                        JOptionPane.showMessageDialog(southPanel, "请选择日期", "请选择日期", JOptionPane.ERROR_MESSAGE);
//                        return;
//                    }
//                }else{
//                    if(tfValue.getText().equals("")){
//                        JOptionPane.showMessageDialog(southPanel, "请输入条件值", "输入条件值", JOptionPane.ERROR_MESSAGE);
//                        return;
//                    }
                    //add by caill start 对高级查询条件下的输入框中的数据进行校验
//                    int size=combCons.getModel().getSize();
//                    for(int i=0;i<size;i++){
//                        String sign=combCons.getItemAt(i).toString();
//                        if( tfValue.getText().contains("'")){    //add by caill 2015.12.24 值中可以含有in 或not in的关键字,所以将值不能含有关键字的判断限制删掉
//                            JOptionPane.showMessageDialog(southPanel, "条件值中包含了非法字符", "非法字符", JOptionPane.ERROR_MESSAGE);
//                            return;
//                        }
//                    }
                    //add by caill end
                setDisposeEvent(disposeByOK);
                dispose();
            }
        });
        
        btnCancel.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                setDisposeEvent(disposeByCancel);
                dispose();
            }
        });
        btnModify.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                SelectorQTDialog eid = new SelectorQTDialog(centerPanel);
                QTInfo item = eid.getItem();
                //修改取消查询模板空指针bug
                if(item!=null){
                    String attr = eid.getAttr();
                    //选中的查询模板
                    tfValue.setText(item.qtName + ";" + attr); 
                }else{
//                    tfValue.setText(""); 
                }
            }
        });
    }
    /**
     * 获取逻辑关系运算符
     * @return
     */
    public String getCons(){
        return (String) combCons.getSelectedItem();
    }
    
    /**
     * 获取条件值
     * @return
     */
    public String getValue(){
        if(attType.equalsIgnoreCase("VTDateTime") || attType.equalsIgnoreCase("VTDate")
                || attType.equalsIgnoreCase("VTTime")){
//            if (datePicker.getDate() == null) {
//                return "";
//            } else {
//                return Tool.df.format(datePicker.getDate());
//            }
//        }else{
//            return tfValue.getText().trim();
            Component[] texts = chooser.getComponents();
            String text = ((JTextField)texts[0]).getText();
            if(text==null && "".equals(text)){
                return "";
            }else{
                return text;
            }
        }else{
            return tfValue.getText().trim();
        }
    }
    //**********
    public JComboBox getCombCons(){
        return  combCons;
    }
    //**********
}