zhao
2021-07-09 0821715ebc11d3934d0594a1cc2c39686d808906
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
/* ====================================================================
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for Additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at
 
       http://www.apache.org/licenses/LICENSE-2.0
 
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
==================================================================== */
 
namespace HH.WMS.Utils.NPOI.HSSF.UserModel
{
    using System;
 
    using HH.WMS.Utils.NPOI.HSSF.Record;
    using HH.WMS.Utils.NPOI.HSSF.UserModel;
    using HH.WMS.Utils.NPOI.SS.UserModel;
    using HH.WMS.Utils.NPOI.SS.Util;
 
    /**
     *Utility class for creating data validation cells
     * 
     * @author Dragos Buleandra (dragos.buleandra@trade2b.ro)
     */
    public class HSSFDataValidation : IDataValidation
    {
        private String _prompt_title;
        private String _prompt_text;
        private String _error_title;
        private String _error_text;
 
        private int _errorStyle = ERRORSTYLE.STOP;
        private bool _emptyCellAllowed = true;
        private bool _suppress_dropdown_arrow = false;
        private bool _ShowPromptBox = true;
        private bool _ShowErrorBox = true;
        private CellRangeAddressList _regions;
        private DVConstraint _constraint;
 
        /**
         * Constructor which Initializes the cell range on which this object will be
         * applied
         * @param constraint 
         */
        public HSSFDataValidation(CellRangeAddressList regions, IDataValidationConstraint constraint)
        {
            _regions = regions;
 
            //FIXME: This cast can be avoided.
            _constraint = (DVConstraint)constraint;
        }
 
 
        /* (non-Javadoc)
         * @see HH.WMS.Utils.NPOI.HSSF.UserModel.DataValidation#getConstraint()
         */
        public IDataValidationConstraint ValidationConstraint
        {
            get
            {
                return _constraint;
            }
        }
 
        public DVConstraint Constraint
        {
            get
            {
                return _constraint;
            }
        }
 
        public CellRangeAddressList Regions
        {
            get
            {
                return _regions;
            }
        }
        public int ErrorStyle
        {
            get
            {
                return _errorStyle;
            }
            set 
            { 
                _errorStyle = value; 
            }
        }
 
        public bool EmptyCellAllowed
        {
            get
            {
                return _emptyCellAllowed;
            }
            set
            {
                _emptyCellAllowed = value;
            }
        }
 
        public bool SuppressDropDownArrow
        {
            get
            {
                if (_constraint.GetValidationType() == ValidationType.LIST)
                {
                    return _suppress_dropdown_arrow;
                }
                return false;
            }
            set
            {
                _suppress_dropdown_arrow = value;
            }
        }
        public bool ShowPromptBox
        {
            get
            {
                return _ShowPromptBox;
            }
            set
            {
                _ShowPromptBox = value;
            }
        }
        public bool ShowErrorBox
        {
            get
            {
                return _ShowErrorBox;
            }
            set
            {
                _ShowErrorBox = value;
            }
        }
 
 
 
        /* (non-Javadoc)
         * @see HH.WMS.Utils.NPOI.HSSF.UserModel.DataValidation#CreatePromptBox(java.lang.String, java.lang.String)
         */
        public void CreatePromptBox(String title, String text)
        {
            _prompt_title = title;
            _prompt_text = text;
            this.ShowPromptBox = (/*setter*/true);
        }
 
        /* (non-Javadoc)
         * @see HH.WMS.Utils.NPOI.HSSF.UserModel.DataValidation#getPromptBoxTitle()
         */
        public String PromptBoxTitle
        {
            get
            {
                return _prompt_title;
            }
        }
 
        /* (non-Javadoc)
         * @see HH.WMS.Utils.NPOI.HSSF.UserModel.DataValidation#getPromptBoxText()
         */
        public String PromptBoxText
        {
            get
            {
                return _prompt_text;
            }
        }
 
        /* (non-Javadoc)
         * @see HH.WMS.Utils.NPOI.HSSF.UserModel.DataValidation#CreateErrorBox(java.lang.String, java.lang.String)
         */
        public void CreateErrorBox(String title, String text)
        {
            _error_title = title;
            _error_text = text;
            this.ShowErrorBox = (/*setter*/true);
        }
 
        /* (non-Javadoc)
         * @see HH.WMS.Utils.NPOI.HSSF.UserModel.DataValidation#getErrorBoxTitle()
         */
        public String ErrorBoxTitle
        {
            get
            {
                return _error_title;
            }
        }
 
        /* (non-Javadoc)
         * @see HH.WMS.Utils.NPOI.HSSF.UserModel.DataValidation#getErrorBoxText()
         */
        public String ErrorBoxText
        {
            get
            {
                return _error_text;
            }
        }
 
        public DVRecord CreateDVRecord(HSSFSheet sheet)
        {
 
            HH.WMS.Utils.NPOI.HSSF.UserModel.DVConstraint.FormulaPair fp = _constraint.CreateFormulas(sheet);
 
            return new DVRecord(_constraint.GetValidationType(),
                    _constraint.Operator,
                    _errorStyle, _emptyCellAllowed, SuppressDropDownArrow,
                    _constraint.GetValidationType() == ValidationType.LIST && _constraint.ExplicitListValues != null,
                    _ShowPromptBox, _prompt_title, _prompt_text,
                    _ShowErrorBox, _error_title, _error_text,
                    fp.Formula1, fp.Formula2,
                    _regions);
        }
    }
 
}