-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathMaterial.vb
237 lines (193 loc) · 6.79 KB
/
Material.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
Public Class Material
Implements ICloneable
Private TypeID As Long
Private TypeName As String
Private _GroupName As String
Private Quantity As Long
Private DQuantity As Double
Private Volume As Double
' Look up cost per item when not set
Private CostPerItem As Double
' If this material is a buildable item, store the ME for the grid
Private ItemME As String
Private ItemTE As String
Private BuildItem As Boolean ' Whether we should build the item or not
' Calculate
Private TotalMatVolume As Double
Private TotalCost As Double
Private ItemType As Integer ' My item type value
Public Sub New(ByVal SentTypeID As Long, ByVal SentTypeName As String, ByVal SentGroupName As String, ByVal SentQuantity As Long,
ByVal SentVolume As Double, ByVal SentPrice As Double, ByVal SentItemME As String, ByVal SentItemTE As String,
Optional ByVal isBuiltItem As Boolean = False, Optional ByVal SentItemType As Integer = 0)
TypeID = SentTypeID
TypeName = SentTypeName
Quantity = SentQuantity
DQuantity = -1
Volume = SentVolume
_GroupName = SentGroupName
BuildItem = isBuiltItem
ItemType = SentItemType
If Trim(SentItemME) <> "" Then
ItemME = SentItemME
Else
ItemME = "-"
End If
If Trim(SentItemTE) <> "" Then
ItemTE = SentItemTE
Else
ItemTE = "-"
End If
If SentPrice = 0 Then
CostPerItem = GetItemPrice(TypeID)
Else
CostPerItem = SentPrice
End If
Call SetTotalCostVolume()
End Sub
Public Sub New(ByVal SentTypeID As Long, ByVal SentTypeName As String, ByVal SentGroupName As String, ByVal SentQuantity As Double,
ByVal SentVolume As Double, ByVal SentPrice As Double, ByVal SentItemME As String, ByVal SentItemTE As String,
Optional ByVal isBuiltItem As Boolean = False, Optional ByVal SentItemType As Integer = 0)
TypeID = SentTypeID
TypeName = SentTypeName
Quantity = -1
DQuantity = SentQuantity
Volume = SentVolume
_GroupName = SentGroupName
BuildItem = isBuiltItem
ItemType = SentItemType
If Trim(SentItemME) <> "" Then
ItemME = SentItemME
Else
ItemME = "-"
End If
If Trim(SentItemTE) <> "" Then
ItemTE = SentItemTE
Else
ItemTE = "-"
End If
If SentPrice = 0 Then
CostPerItem = GetItemPrice(TypeID)
Else
CostPerItem = SentPrice
End If
Call SetTotalCostVolume()
End Sub
' For doing a deep copy of Materials
Public Function Clone() As Object Implements ICloneable.Clone
Dim CopyofMe As Material
If Me.DQuantity = -1 Then
CopyofMe = New Material(Me.TypeID, Me.TypeName, Me.GroupName, Me.Quantity, Me.Volume, Me.CostPerItem, Me.ItemME, Me.ItemTE, Me.BuildItem, Me.ItemType)
Else
CopyofMe = New Material(Me.TypeID, Me.TypeName, Me.GroupName, Me.DQuantity, Me.Volume, Me.CostPerItem, Me.ItemME, Me.ItemTE, Me.BuildItem, Me.ItemType)
End If
Return CopyOfMe
End Function
Private Sub SetTotalCostVolume()
If DQuantity = -1 Then
TotalCost = CostPerItem * Quantity
TotalMatVolume = Volume * Quantity
Else
TotalCost = CostPerItem * DQuantity
TotalMatVolume = Volume * DQuantity
End If
End Sub
' Adds quantity to the material and upates the total cost and volume
Public Sub AddQuantity(ByVal SentQuantity As Long)
Quantity = Quantity + SentQuantity
' New quantity means new total price and volume
Call SetTotalCostVolume()
End Sub
' Sets the quantity of the material and sets the total cost and volume
Public Sub SetQuantity(ByVal SentQuantity As Long)
Quantity = SentQuantity
' New quantity means new total price and volume
Call SetTotalCostVolume()
End Sub
' Adds quantity to the material and upates the total cost and volume
Public Sub AddDQuantity(ByVal SentQuantity As Double)
DQuantity = DQuantity + SentQuantity
' New quantity means new total price and volume
Call SetTotalCostVolume()
End Sub
' Sets the quantity of the material and sets the total cost and volume
Public Sub SetDQuantity(ByVal SentQuantity As Double)
DQuantity = SentQuantity
' New quantity means new total price and volume
Call SetTotalCostVolume()
End Sub
' Sets the Total Cost of the material to the sent cost only if it's built
Public Sub SetBuildCostPerItem(ByVal BuildCost As Double)
If BuildItem Then
CostPerItem = BuildCost
Call SetTotalCostVolume()
End If
End Sub
' Sets the name with the sent name
Public Sub SetName(ByVal SentName As String)
TypeName = SentName
End Sub
' Sets the items ME
Public Sub SetItemME(ByVal SentME As String)
ItemME = SentME
End Sub
' Sets the items TE
Public Sub SetItemTE(ByVal SentTE As String)
ItemTE = SentTE
End Sub
' Sets the item as built
Public Sub SetBuildItem(ByVal BuildValue As Boolean)
BuildItem = BuildValue
End Sub
' Allow setting total cost
Public Sub SetTotalCost(ByVal SentTotalCost As Double)
TotalCost = SentTotalCost
End Sub
Public Function GetItemType() As Integer
Return ItemType
End Function
Public Function GetMaterialTypeID() As Long
Return TypeID
End Function
Public Function GetMaterialName() As String
Return TypeName
End Function
Public Function GetQuantity() As Long
Return Quantity
End Function
Public Function GetDQuantity() As Double
Return DQuantity
End Function
'Public Function GetMaterialGroup() As String
' Return GroupName
'End Function
Public Property GroupName() As String
Get
Return _GroupName
End Get
Set(value As String)
_GroupName = value
End Set
End Property
Public Function GetVolume() As Double
Return Volume
End Function
Public Function GetCostPerItem() As Double
Return CostPerItem
End Function
Public Function GetTotalVolume() As Double
Return TotalMatVolume
End Function
Public Function GetTotalCost() As Double
Return TotalCost
End Function
Public Function GetItemME() As String
Return ItemME
End Function
Public Function GetItemTE() As String
Return ItemTE
End Function
Public Function GetBuildItem() As Boolean
Return BuildItem
End Function
End Class