-
Notifications
You must be signed in to change notification settings - Fork 2
/
Variable.vb
1394 lines (1230 loc) · 49.6 KB
/
Variable.vb
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports PCAxis.Paxiom.ClassAttributes
Imports PCAxis.Paxiom.Localization
Namespace PCAxis.Paxiom
' Klass som beskriver en variabel
<Serializable()> _
Public Class Variable
Implements System.Runtime.Serialization.ISerializable
#Region "Protected Members"
Protected Friend mLanguageIndex As Integer = 0
Private _meta As PXMeta
<LanguageDependent()> _
Protected Friend m_name() As String
Private _time As String
Private _timeVariable As Boolean = False
<LanguageDependent()> _
Private _domain() As String
Private _elimination As Boolean
Private _eliminationValue As Value
Private _map As String
Private _presentationText As Integer = 1 ' Text is default (0=Code, 1=Text, 2=Code+Text, 3=Text+Code)
Private _doubleColumn As Boolean = False
Private _values As Values = New Values
Private _placement As PlacementType
<LanguageDependent()> _
Private _notes() As Notes
Private _isContentVariable As Boolean = False
Private _variableType As String
Private _hierarchy As Hierarchy
Private _partitions As New Partitions
Private _code As String
Private _keys As KeysTypes = KeysTypes.None
Private _extendedProperties As New ExtendedPropertiesList
Private _valueSets As New List(Of ValueSetInfo)
<LanguageDependent()> _
Private _groupings() As List(Of GroupingInfo)
Private _currentGrouping As Grouping
Private _currentValueSet As ValueSetInfo
Private _TimeScale As TimeScaleType = TimeScaleType.NotSet
Private _sortVariable As Boolean = False
Private _valueTextOption As ValueTextOptionType = ValueTextOptionType.NormalText
<LanguageDependent()> _
Private _datanote(0) As String
<LanguageDependent()> _
Private _metaId(0) As String
<LanguageDependent()> _
Private _hasValueMetaId(0) As String
#End Region
Protected Friend Sub SetMeta(ByVal meta As PXMeta)
_meta = meta
End Sub
#Region "Public Properties"
''' <summary>
''' the meta object that the list is attached to
''' </summary>
''' <value>the meta object that the list is attached to </value>
''' <returns>the meta object that the list is attached to </returns>
''' <remarks></remarks>
Public ReadOnly Property Meta() As PXMeta
Get
Return _meta
End Get
End Property
''' <summary>
''' Check to see if the variable have any notes
''' </summary>
''' <returns>True if there are any notes in the Notes list</returns>
''' <remarks></remarks>
Public Function HasNotes() As Boolean
If Me._notes Is Nothing Then
Return False
End If
If Me._notes(mLanguageIndex) Is Nothing Then
Return False
End If
Return True
End Function
''' <summary>
''' Check to see if the variable have any groupings
''' </summary>
''' <returns>True if there are any notes in the Groupings list</returns>
''' <remarks></remarks>
Public Function HasGroupings() As Boolean
If Me._groupings Is Nothing Then
Return False
End If
If Me._groupings(mLanguageIndex) Is Nothing Then
Return False
End If
If Me._groupings(mLanguageIndex).Count > 0 Then
Return True
Else
Return False
End If
End Function
''' <summary>
''' Check to see if the variable have any value sets
''' </summary>
''' <returns>True if there are any notes in the ValueSets list</returns>
''' <remarks></remarks>
Public Function HasValuesets() As Boolean
If Me._valueSets Is Nothing Then
Return False
End If
If Me._valueSets.Count > 0 Then
Return True
Else
Return False
End If
End Function
'''<summary>Returns the variable code</summary>
'''<value>Model unique code for the variable</value>
'''<remarks>
'''This keyword dosn't exisit in the PC-Axis file format.
'''At the moment the code is the variable name of the
'''default language but this may change in the future
'''</remarks>
Public ReadOnly Property Code() As String
Get
Return _code
End Get
End Property
'''<summary>Returns the variables name</summary>
'''<value>Name of the variable</value>
Public Property Name() As String 'Implements IPXItem.Name
Get
'If Me.IsTime Then
' Select Case TimeScale
' Case TimeScaleType.Annual
' Return PxResourceManager.GetResourceManager().GetString("PxcYear", Me.Meta.CurrentLanguage)
' Case TimeScaleType.Halfyear
' Return PxResourceManager.GetResourceManager().GetString("PxcHalfyear", Me.Meta.CurrentLanguage)
' Case TimeScaleType.Quartely
' Return PxResourceManager.GetResourceManager().GetString("PxcQuarter", Me.Meta.CurrentLanguage)
' Case TimeScaleType.Monthly
' Return PxResourceManager.GetResourceManager().GetString("PxcMonth", Me.Meta.CurrentLanguage)
' Case TimeScaleType.Weekly
' Return PxResourceManager.GetResourceManager().GetString("PxcWeek", Me.Meta.CurrentLanguage)
' Case Else
' Return Me.m_name(mLanguageIndex)
' End Select
'Else
Return Me.m_name(mLanguageIndex)
'End If
End Get
Set(ByVal value As String)
Me.m_name(mLanguageIndex) = value
End Set
End Property
''' <summary>
''' Tells if the variable is a time variable or not
''' </summary>
''' <value></value>
''' <returns>True if the variable is a time variable, else false</returns>
''' <remarks></remarks>
Public Property IsTime() As Boolean
Get
Return _timeVariable
End Get
Set(ByVal value As Boolean)
_timeVariable = value
End Set
End Property
'''<summary>Time value of the variable</summary>
'''<value></value>
Public Property TimeValue() As String
Get
Return Me._time
End Get
Set(ByVal value As String)
'TODO: Create values if there is none
Me._time = value
End Set
End Property
''' <summary>
''' Returns what type of keys that should be used when storing the model as
''' a PX file in the KEYS format.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Keys() As KeysTypes
Get
Return _keys
End Get
Set(ByVal value As KeysTypes)
_keys = value
End Set
End Property
'''<summary>Returns the variable domain</summary>
'''<value>The doamin of the variable</value>
Public Property Domain() As String
Get
Return Me._domain(mLanguageIndex)
End Get
Set(ByVal value As String)
Me._domain(mLanguageIndex) = value
End Set
End Property
'''<summary>Returns is the variable can be eliminated</summary>
'''<value>If the variable can be eliminated</value>
Public Property Elimination() As Boolean
Get
Return Me._elimination
End Get
Set(ByVal value As Boolean)
Me._elimination = value
End Set
End Property
'''<summary>Returns the values selected for elimination</summary>
'''<value>The elimination value if one have been specified</value>
Public Property EliminationValue() As Value
Get
Return Me._eliminationValue
End Get
Set(ByVal value As Value)
Me._eliminationValue = value
End Set
End Property
'''<summary>Returns the variable map</summary>
'''<value>The map recommend for the varibale</value>
Public Property Map() As String
Get
Return Me._map
End Get
Set(ByVal value As String)
Me._map = value
End Set
End Property
'TODO check if it should be obsolete
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property PresentationText() As Integer
Get
Return Me._presentationText
End Get
Set(ByVal value As Integer)
Me._presentationText = value
End Set
End Property
'''<summary>Returns if the should be separate columns for the codes and the values</summary>
'''<value>If there should be separet columns for code and values</value>
Public Property DoubleColumn() As Boolean
Get
Return Me._doubleColumn
End Get
Set(ByVal value As Boolean)
Me._doubleColumn = value
End Set
End Property
'''<summary>Returns if the variable is in the stub or in the heading</summary>
'''<value>The placment of the variable</value>
Public Property Placement() As PlacementType
Get
Return Me._placement
End Get
Set(ByVal value As PlacementType)
Me._placement = value
End Set
End Property
'''<summary>Returns the values for the variable</summary>
'''<value>The variable values</value>
Public ReadOnly Property Values() As Values
Get
Return Me._values
End Get
End Property
'''<summary>Checks if the variable is a content variable</summary>
'''<value>Checks if variable is a content variable</value>
Public Property IsContentVariable() As Boolean
Get
Return Me._isContentVariable
End Get
Set(ByVal value As Boolean)
Me._isContentVariable = value
End Set
End Property
'''<summary>Checks if the variable has a timevalue (TIMEVAL)</summary>
'''<value>Checks if variable is a time variable</value>
Public ReadOnly Property HasTimeValue() As Boolean
Get
Return Not String.IsNullOrEmpty(Me._time)
End Get
End Property
'''<summary>Returns the variable type</summary>
'''<value>The variable type</value>
Public Property VariableType() As String
Get
Return _variableType
End Get
Set(ByVal value As String)
_variableType = value
End Set
End Property
'''<summary>Returns the variable hirarchy if the variable is hierarcical</summary>
'''<value>The hierarchy of the variable</value>
Public Property Hierarchy() As Hierarchy
Get
Return _hierarchy
End Get
Set(ByVal value As Hierarchy)
_hierarchy = value
End Set
End Property
'''<summary>Returns the partiotions of the variable if it is partitioned</summary>
'''<value>The partitions of the variable</value>
Public ReadOnly Property Partitions() As Partitions
Get
Return _partitions
End Get
End Property
'''<summary>Returns the notes for the variable</summary>
'''<value>Notes for the variable</value>
Public ReadOnly Property Notes() As Notes
Get
If _notes Is Nothing Then
Return Nothing
End If
Return _notes(mLanguageIndex)
End Get
End Property
''' <summary>
''' Extended properties for the variable
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property ExtendedProperties() As ExtendedPropertiesList
Get
Return _extendedProperties
End Get
End Property
''' <summary>
''' List of available value setsfor the variable
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property ValueSets() As List(Of ValueSetInfo)
Get
Return _valueSets
End Get
End Property
''' <summary>
''' List of groupings for the variable
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property Groupings() As List(Of GroupingInfo)
Get
Return _groupings(mLanguageIndex)
End Get
End Property
''' <summary>
''' The value set that is currently applied
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property CurrentValueSet() As ValueSetInfo
Get
Return _currentValueSet
End Get
Set(ByVal value As ValueSetInfo)
_currentValueSet = value
End Set
End Property
''' <summary>
''' The grouping that is currently applied
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property CurrentGrouping() As Grouping
Get
Return _currentGrouping
End Get
Set(ByVal value As Grouping)
_currentGrouping = value
End Set
End Property
''' <summary>
''' The time scale
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property TimeScale() As TimeScaleType
Get
Return _TimeScale
End Get
End Property
''' <summary>
''' Is this a sortvariable? ($$SORT)
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property SortVariable() As Boolean
Get
Return _sortVariable
End Get
Set(ByVal value As Boolean)
_sortVariable = value
End Set
End Property
''' <summary>
''' Describes how the value texts are created
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property ValueTextOption() As ValueTextOptionType
Get
Return _valueTextOption
End Get
Set(ByVal value As ValueTextOptionType)
_valueTextOption = value
End Set
End Property
''' <summary>
''' Datanote is used to indicate that a note exist for the variable
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Datanote() As String
Get
Return _datanote(mLanguageIndex)
End Get
Set(ByVal value As String)
Me._datanote(mLanguageIndex) = value
End Set
End Property
''' <summary>
''' A Metadata Id for the variable
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property MetaId() As String
Get
Return _metaId(mLanguageIndex)
End Get
Set(ByVal value As String)
Me._metaId(mLanguageIndex) = value
End Set
End Property
''' <summary>
''' Shows if any of the variable values has got a MetaId
''' </summary>
''' <value></value>
''' <returns>True if one or more values has got a MetaId, else false</returns>
''' <remarks></remarks>
Public Property HasValueMetaId() As Boolean
Get
If (String.IsNullOrEmpty(_hasValueMetaId(mLanguageIndex))) Then
Return False
Else
Return _hasValueMetaId(mLanguageIndex).Equals("true")
End If
End Get
Set(ByVal value As Boolean)
_hasValueMetaId(mLanguageIndex) = value.ToString().ToLower()
End Set
End Property
#End Region
#Region "Constructor"
''' <summary>
''' Constructor
''' </summary>
''' <remarks></remarks>
Public Sub New()
Me._values.SetVariable(Me)
Me.m_name = New String(0) {}
Me._domain = New String(0) {}
Me._eliminationValue = Nothing
Me._code = Guid.NewGuid.ToString()
Me._groupings = New List(Of GroupingInfo)(0) {}
Me._hierarchy = New Hierarchy()
End Sub
''' <summary>
''' Constructor
''' </summary>
''' <param name="name">name of the variable</param>
''' <param name="placment">variable placment</param>
''' <remarks></remarks>
Public Sub New(ByVal name As String, ByVal placment As PlacementType)
Me._values.SetVariable(Me)
Me.m_name = New String(0) {}
Me._domain = New String(0) {}
Me._eliminationValue = Nothing
Me.m_name(mLanguageIndex) = name
Me._placement = placment
Me._code = name
Me._groupings = New List(Of GroupingInfo)(0) {}
Me._hierarchy = New Hierarchy()
End Sub
''' <summary>
''' Constructor
''' </summary>
''' <param name="name">name of the variable</param>
''' <param name="placment">variable placment</param>
''' <param name="internalBufferSize">
''' for how many languages that the
''' variable should be dimension for
''' </param>
''' <remarks></remarks>
Public Sub New(ByVal name As String, ByVal placment As PlacementType, ByVal internalBufferSize As Integer)
Me._values.SetVariable(Me)
Me.m_name = New String(internalBufferSize) {}
Me._domain = New String(internalBufferSize) {}
Me._eliminationValue = Nothing
Me.m_name(mLanguageIndex) = name
Me._placement = placment
Me._code = name
Me._groupings = New List(Of GroupingInfo)(internalBufferSize) {}
Me._hierarchy = New Hierarchy(internalBufferSize)
Me._datanote = New String(internalBufferSize) {}
Me._metaId = New String(internalBufferSize) {}
Me._hasValueMetaId = New String(internalBufferSize) {}
End Sub
''' <summary>
''' Constructor
''' </summary>
''' <param name="name">name of the variable</param>
''' ''' <param name="code">the variable code</param>
''' <param name="placment">variable placment</param>
''' <param name="internalBufferSize">
''' for how many languages that the
''' variable should be dimension for
''' </param>
''' <remarks></remarks>
Public Sub New(ByVal name As String, ByVal code As String, ByVal placment As PlacementType, ByVal internalBufferSize As Integer)
Me._values.SetVariable(Me)
Me.m_name = New String(internalBufferSize) {}
Me._domain = New String(internalBufferSize) {}
Me._eliminationValue = Nothing
Me.m_name(mLanguageIndex) = name
Me._placement = placment
Me._code = code
Me._groupings = New List(Of GroupingInfo)(internalBufferSize) {}
Me._hierarchy = New Hierarchy(internalBufferSize)
Me._datanote = New String(internalBufferSize) {}
Me._metaId = New String(internalBufferSize) {}
Me._hasValueMetaId = New String(internalBufferSize) {}
End Sub
#End Region
#Region "SetFunctions"
''' <summary>
''' Sets the code for the variable
''' </summary>
''' <param name="code">the code</param>
''' <remarks></remarks>
Protected Friend Sub SetCode(ByVal code As String)
_code = code
End Sub
'TODO: Petros Prio A fixa else om de olika längderna inte är samma.
''' <summary>
''' Creates new values or just theer names if the values already exist
''' </summary>
''' <param name="values">name of values</param>
''' <remarks></remarks>
Protected Friend Sub SetValues(ByVal values As String())
If _values.Count = values.Length Then
For i As Integer = 0 To _values.Count - 1
_values(i).Value = values(i)
Next
Else
Dim size As Integer = Me.m_name.Length - 1
For Each s As String In values
Me._values.Add(New Value(s, size))
Next
End If
End Sub
''' <summary>
''' If the variable is a timevariable this method creates the timevalues for each of
''' the variables values.
''' </summary>
''' <param name="values">
''' Array containing the timevalues. The first value in the array shall contain the timescale
''' type, for example: TLIST(M1). The rest of the values in the array contains the actual timevalues.
''' </param>
''' <remarks>
''' Timevalues can be described in the ways:
''' 1. Interval
''' Example:
''' TimeValue for the variable: TLIST(M1, 199601-200812)
''' 2. Individual values
''' Example:
''' TimeValue for the variable: TLIST(M1), 200610, 200611, 200612, ...
''' </remarks>
Protected Friend Sub SetTimeValues(ByVal values As String())
If String.IsNullOrEmpty(Me.TimeValue) Then
Exit Sub
End If
If Not values.Count > 1 Then
Exit Sub
End If
SetTimeScale(values(0))
'Find out in which way timevalues are described
If Me.TimeValue.IndexOf("""-""") <> -1 Then
'Timevalues are described as an interval
SetTimeValuesFromInterval(values)
Else
'Timevalues are described with individual values
If (_values.Count = values.Length - 1) And values.Length > 1 Then
For i As Integer = 0 To _values.Count - 1
_values(i).TimeValue = GetTimeValue(values(i + 1))
Next
End If
End If
End Sub
''' <summary>
''' Timevalue shall only contain digits.
''' For example January 1993 shall have the timevalue 199301 and not 1993M01
''' This method removes any characters in the timevalue
''' </summary>
''' <param name="val">The timevalue to strip from characters</param>
''' <returns>A timevalue without chracters</returns>
''' <remarks></remarks>
Private Function GetTimeValue(ByVal val As String) As String
Dim timevalue As New Text.StringBuilder
For i As Integer = 0 To val.Length - 1
If Char.IsDigit(val.Chars(i)) Then
timevalue.Append(val.Chars(i))
End If
Next
Return timevalue.ToString
End Function
''' <summary>
''' Generates the timevalues when described as an interval in the px-file
''' </summary>
''' <param name="values">
''' Array with the length of 2. The first value contains timescale and the second value the interval.
''' </param>
''' <remarks></remarks>
Private Sub SetTimeValuesFromInterval(ByVal values As String())
Dim periods As Integer
Dim arrPeriods As String()
Dim year As Integer
Dim period As Integer = 0
Dim endYear As Integer
Dim endPeriod As Integer = 0
Dim timeValues As New Collections.Specialized.StringCollection
Dim timeValue As String = ""
'In this case there shall be only two values in the array.
'The first one contains the timescale type and the second one the interval
If values.Count = 2 Then
If values(1).IndexOf("-") <> -1 Then
'Set number of periods for this timescale
Select Case Me.TimeScale
Case TimeScaleType.Annual
periods = 0
Case TimeScaleType.Halfyear
periods = 2
Case TimeScaleType.Monthly
periods = 12
Case TimeScaleType.Quartely
periods = 4
Case TimeScaleType.Weekly
periods = 52
Case Else
Exit Sub
End Select
'Find interval...
arrPeriods = values(1).Split("-"c)
arrPeriods(1) = arrPeriods(1).TrimEnd(")"c)
year = CInt(arrPeriods(0).Substring(0, 4))
endYear = CInt(arrPeriods(1).Substring(0, 4))
If Me.TimeScale <> TimeScaleType.Annual Then
period = CInt(arrPeriods(0).Substring(4))
endPeriod = CInt(arrPeriods(1).Substring(4))
End If
While True
'Continue?
If (year > endYear) Or ((year = endYear) And (period > endPeriod)) Then
Exit While
End If
'Format timevalue...
Select Case Me.TimeScale
Case TimeScaleType.Annual
timeValue = year.ToString
Case TimeScaleType.Halfyear
timeValue = year.ToString & period.ToString
Case TimeScaleType.Quartely
timeValue = year.ToString & period.ToString
Case TimeScaleType.Monthly
timeValue = year.ToString & period.ToString.PadLeft(2, "0"c)
Case TimeScaleType.Weekly
timeValue = year.ToString & period.ToString.PadLeft(2, "0"c)
End Select
'Add to collection...
timeValues.Add(timeValue)
'Increment...
If Me.TimeScale = TimeScaleType.Annual Then
year = year + 1
Else
If period = periods Then
year = year + 1
period = 1
Else
period = period + 1
End If
End If
End While
'Apply timevalues...
If _values.Count = timeValues.Count Then
For i As Integer = 0 To _values.Count - 1
_values(i).TimeValue = timeValues(i)
Next
End If
End If
End If
End Sub
''' <summary>
''' If the variable is a timevariable this method sets the timescale of the variable.
''' </summary>
''' <param name="timeScaleDesc">Contains the timescale part of the variables TimeValue</param>
''' <remarks></remarks>
Protected Friend Sub SetTimeScale(ByVal timeScaleDesc As String)
Dim start As Integer
Dim timeScale As String = ""
If timeScaleDesc.ToLower.IndexOf("tlist(") = -1 Then
Exit Sub
End If
start = timeScaleDesc.IndexOf("(") + 1
If timeScaleDesc.Length < start + 2 Then
Exit Sub
End If
timeScale = timeScaleDesc.Substring(start, 2)
Select Case timeScale
Case "A1"
_TimeScale = TimeScaleType.Annual
Case "H1"
_TimeScale = TimeScaleType.Halfyear
Case "Q1"
_TimeScale = TimeScaleType.Quartely
Case "M1"
_TimeScale = TimeScaleType.Monthly
Case "W1"
_TimeScale = TimeScaleType.Weekly
Case Else
Exit Sub
End Select
End Sub
''' <summary>
''' Sets value codes
''' </summary>
''' <param name="codes">the codes</param>
''' <remarks></remarks>
Protected Friend Sub SetValueCodes(ByVal codes As String())
'BUG 316: If _values.count = 0 --> Create new values with text and code = code
If Me._values.Count = 0 Then
Me.SetValues(codes)
Me.ValueTextOption = ValueTextOptionType.ValueTextMissing
End If
If Me._values.Count <> codes.Length Then
Throw New PXException("", "PxcErrToManyCodes", New Object() {Me.Name})
End If
For index As Integer = 0 To Me._values.Count - 1
Me._values(index).SetCode(codes(index))
Next
End Sub
''' <summary>
''' Sets the doamin
''' </summary>
''' <param name="domain">the domain</param>
''' <remarks></remarks>
<Obsolete()> _
Protected Friend Sub SetDomain(ByVal domain As String)
Me._domain(mLanguageIndex) = domain
End Sub
''' <summary>
''' Sets the Elimination and the EliminationValue
''' </summary>
''' <param name="elimination">the type of elimination</param>
''' <remarks>
''' if YES is passed in as a elimination then Elmimination is set to true
''' but no elimination value is set.
''' </remarks>
Public Sub SetElimination(ByVal elimination As String)
If String.Compare(elimination.ToUpper(), "NO") = 0 Then
Me._elimination = False
Exit Sub
End If
Me._elimination = True
If String.Compare(elimination, "YES", True) = 0 Then
Me._eliminationValue = Nothing
Else
Dim v As Value = Values.GetByName(elimination)
Me._eliminationValue = v
End If
End Sub
''' <summary>
''' Set the elemination value
''' </summary>
''' <param name="code">code of the value</param>
''' <remarks></remarks>
Public Sub SetEliminationValue(ByVal code As String)
Me.EliminationValue = Me.Values.GetByCode(code)
End Sub
<Obsolete()> _
Protected Friend Sub SetMap(ByVal map As String)
Me._map = map
End Sub
<Obsolete()> _
Protected Friend Sub SetPresText(ByVal presText As Integer)
Me._presentationText = presText
End Sub
'TODO PETROS check builder how it is used should be done in meta.
''' <summary>
''' Marks the variable as a content variable
''' </summary>
''' <param name="b"></param>
''' <remarks></remarks>
Protected Friend Sub SetAsContentVariable(ByVal b As Boolean)
Me._isContentVariable = b
End Sub
#End Region
#Region "Add functions"
''' <summary>
''' Adds a note to the variable
''' </summary>
''' <param name="note">note to add to the Notes list of the variable</param>
''' <remarks>
''' One should always use this function to add notes since this
''' function reassures that the Notes list is created.
''' </remarks>
Protected Friend Sub AddNote(ByVal note As Note)
If Me._notes Is Nothing Then
'Me.mNotes = New NoteCollection
Me._notes = New Notes(m_name.Length - 1) {}
End If
If _notes(mLanguageIndex) Is Nothing Then
_notes(mLanguageIndex) = New Notes
End If
Me._notes(mLanguageIndex).Add(note)
End Sub
''' <summary>
''' Adds a grouping to the variable
''' </summary>
''' <param name="groupingInfo">grouping to add to the Grouping list</param>
''' <remarks>
''' One should always use this function to add groupings since this
''' function reassures that the Groupings list is created.
''' </remarks>
Public Sub AddGrouping(ByVal groupingInfo As GroupingInfo)
If Me._groupings Is Nothing Then
Me._groupings = New List(Of GroupingInfo)(m_name.Length - 1) {}
End If
If _groupings(mLanguageIndex) Is Nothing Then
_groupings(mLanguageIndex) = New List(Of GroupingInfo)
End If
If Not Me._groupings(mLanguageIndex).Contains(groupingInfo) Then
Me._groupings(mLanguageIndex).Add(groupingInfo)
End If
End Sub
#End Region
#Region "Public functions"
''' <summary>
''' Create a deep copy of Me
''' </summary>
''' <returns></returns>
''' <remarks>Variable.Values is not included</remarks>
Public Function CreateCopy() As Variable
Dim newObject As Variable
newObject = CType(Me.MemberwiseClone(), Variable)
newObject.SetMeta(Nothing)
'Handle reference types
' Handle Name
newObject.m_name = Nothing
If Me.m_name IsNot Nothing Then
newObject.m_name = New String(Me.m_name.Count - 1) {}
For i As Integer = 0 To Me.m_name.Count - 1
newObject.m_name(i) = Me.m_name(i)
Next
End If
' Handle Domain
newObject._domain = Nothing
If Me._domain IsNot Nothing Then
newObject._domain = New String(Me._domain.Count - 1) {}
For i As Integer = 0 To Me._domain.Count - 1
newObject._domain(i) = Me._domain(i)
Next
End If
' Handle Values
If Me._values IsNot Nothing Then
newObject._values = Me._values.CreateCopy()
newObject._values.SetVariable(newObject)
End If
' Handle EliminationValue
newObject._eliminationValue = Nothing