-
Notifications
You must be signed in to change notification settings - Fork 37
/
EVEBlueprints.vb
273 lines (220 loc) · 13.5 KB
/
EVEBlueprints.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
Imports System.Data.SQLite
Public Class EVEBlueprints
Private BlueprintList As List(Of EVEBlueprint)
Private KeyData As SavedTokenData
Public Sub New()
BlueprintList = New List(Of EVEBlueprint)
End Sub
' Loads all blueprints for the character from the DB
Public Sub LoadBlueprints(ByVal ID As Long, ByVal CharacterTokenData As SavedTokenData, ByVal BlueprintType As ScanType, ByVal UpdateBPs As Boolean)
Dim SQL As String
Dim readerBlueprints As SQLiteDataReader
Dim TempBlueprint As EVEBlueprint
Dim Blueprints As New List(Of EVEBlueprint)
' Update Industry Blueprints first
Call UpdateBlueprints(ID, CharacterTokenData, BlueprintType, UpdateBPs)
' See what ID we use for character bps
Dim CharID As Long = 0
If UserApplicationSettings.LoadBPsbyChar Then
' Use the ID sent
CharID = SelectedCharacter.ID
Else
CharID = CommonLoadBPsID
End If
' Load the blueprints
SQL = "SELECT ITEM_ID, LOCATION_ID, BLUEPRINT_ID, BLUEPRINT_NAME, FLAG_ID, QUANTITY, ME, TE, "
SQL &= "RUNS, BP_TYPE, OWNED, SCANNED, FAVORITE, ADDITIONAL_COSTS "
SQL &= "FROM OWNED_BLUEPRINTS WHERE USER_ID = " & CharID
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
readerBlueprints = DBCommand.ExecuteReader
While readerBlueprints.Read
TempBlueprint.ItemID = readerBlueprints.GetInt64(0)
TempBlueprint.LocationID = readerBlueprints.GetInt64(1)
TempBlueprint.TypeID = readerBlueprints.GetInt64(2)
TempBlueprint.TypeName = readerBlueprints.GetString(3)
TempBlueprint.FlagID = readerBlueprints.GetInt32(4)
TempBlueprint.Quantity = readerBlueprints.GetInt32(5)
TempBlueprint.TimeEfficiency = readerBlueprints.GetInt32(6)
TempBlueprint.MaterialEfficiency = readerBlueprints.GetInt32(7)
TempBlueprint.Runs = readerBlueprints.GetInt32(8)
TempBlueprint.BPType = CType(readerBlueprints.GetInt32(9), BPType)
TempBlueprint.Owned = CBool(readerBlueprints.GetInt32(10))
TempBlueprint.Scanned = CBool(readerBlueprints.GetInt32(11))
TempBlueprint.Favorite = CBool(readerBlueprints.GetInt32(12))
TempBlueprint.AdditionalCosts = readerBlueprints.GetDouble(13)
' Insert blueprint
Blueprints.Add(TempBlueprint)
End While
readerBlueprints.Close()
DBCommand = Nothing
readerBlueprints = Nothing
BlueprintList = Blueprints
End Sub
' Updates Blueprints from ESI for the character/corp and inserts them into the Database for later queries
Private Sub UpdateBlueprints(ByVal ID As Long, ByVal CharacterTokenData As SavedTokenData,
ByVal BlueprintType As ScanType, ByVal UpdateBPs As Boolean)
Dim readerBlueprints As SQLiteDataReader
Dim readerCheck As SQLiteDataReader
Dim SQL As String
Dim IndyBlueprints As New List(Of EVEBlueprint)
Dim InsertBP As Boolean
Dim IgnoreBP As Boolean
Dim ScannedFlag As Integer
Dim MEValue As Double
Dim TEValue As Double
Dim ESIData As New ESI
Dim CB As New CacheBox
Dim CacheDate As Date
Dim CDType As CacheDateType
If BlueprintType = ScanType.Personal Then
CDType = CacheDateType.PersonalBlueprints
ScannedFlag = 1
Else
CDType = CacheDateType.CorporateBlueprints
ScannedFlag = 2
End If
' See what ID we save for character bps
Dim TempID As Long = 0
If UserApplicationSettings.LoadBPsbyChar Or BlueprintType = ScanType.Corporation Then
' Use the ID sent
TempID = ID
Else
TempID = CommonLoadBPsID
End If
' Look up the industry Blueprints cache date first
If CB.DataUpdateable(CDType, ID) Then
IndyBlueprints = ESIData.GetBlueprints(ID, CharacterTokenData, BlueprintType, CacheDate)
If Not IsNothing(IndyBlueprints) Then
If IndyBlueprints.Count > 0 Then
Call EVEDB.BeginSQLiteTransaction()
' First delete all bps for this ID in the
Call EVEDB.ExecuteNonQuerySQL("DELETE FROM ALL_OWNED_BLUEPRINTS WHERE OWNER_ID = " & CStr(TempID))
' Insert blueprint data
For i = 0 To IndyBlueprints.Count - 1
With IndyBlueprints(i)
' Load all bps in ALL_OWNED_BLUEPRINTS and only limit OWNED_BLUEPRINTS to single records
SQL = "INSERT INTO ALL_OWNED_BLUEPRINTS (OWNER_ID, ITEM_ID, LOCATION_ID, BLUEPRINT_ID, BLUEPRINT_NAME, FLAG_ID, "
SQL &= "QUANTITY, ME, TE, RUNS, BP_TYPE) "
SQL &= "VALUES (" & CStr(TempID) & "," & CStr(.ItemID) & "," & CStr(.LocationID) & ","
SQL &= CStr(.TypeID) & ",'" & FormatDBString(.TypeName) & "',"
SQL &= CStr(.FlagID) & ",1," & CStr(.MaterialEfficiency) & "," & CStr(.TimeEfficiency) & ","
SQL &= .Runs & "," & CStr(.BPType) & ")"
Call EVEDB.ExecuteNonQuerySQL(SQL)
' Make sure it's not already in there before adding to owned
' For now, only include unique BPs until I get the multiple BP support done - use Max ME for the determination or Max TE if they are the same ME
SQL = "SELECT ME, TE, BP_TYPE, ITEM_ID, OWNED, SCANNED FROM OWNED_BLUEPRINTS "
SQL &= "WHERE BLUEPRINT_ID = " & .TypeID & " And USER_ID = " & CStr(TempID)
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
readerBlueprints = DBCommand.ExecuteReader
readerBlueprints.Read()
If readerBlueprints.HasRows Then
' Do not overwrite anything saved by the user (owned = -1 for user owned, 0 for not owned but favorite/ignore/bptype)
If readerBlueprints.GetInt32(4) = 1 Then
MEValue = readerBlueprints.GetInt32(0)
TEValue = readerBlueprints.GetInt32(1)
' If greater ME, or the ME is equal and TE is greater, update it if it's the same type of bp
If MEValue < IndyBlueprints(i).MaterialEfficiency And readerBlueprints.GetInt32(2) = .BPType Then
InsertBP = False
IgnoreBP = False
ElseIf MEValue = IndyBlueprints(i).MaterialEfficiency And TEValue < IndyBlueprints(i).TimeEfficiency And readerBlueprints.GetInt32(2) = .BPType Then
InsertBP = False
IgnoreBP = False
ElseIf readerBlueprints.GetInt32(2) = BPType.Copy And .BPType = BPType.Original Then ' Only update if the new BP is a BPO
InsertBP = False
IgnoreBP = False
Else
' We don't want to do anything with this bp
IgnoreBP = True
End If
Else
' We don't want to do anything with this bp
IgnoreBP = True
InsertBP = False
End If
Else
IgnoreBP = False
InsertBP = True
End If
If Not IgnoreBP Then
' Set the correct BP_Type for the BPs they have
Dim CurrentBPType As BPType = .BPType
' If T2 and a copy, set to invented copy if the ME/TE match, else use what was sent
If CurrentBPType = BPType.Copy Then
SQL = "SELECT TECH_LEVEL FROM ALL_BLUEPRINTS WHERE BLUEPRINT_ID = " & CStr(.TypeID)
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
readerCheck = DBCommand.ExecuteReader
If readerCheck.Read() Then
Dim TempDecryptorList As New DecryptorList
Dim FoundDecryptor As Decryptor = TempDecryptorList.GetDecryptor(.MaterialEfficiency, .TimeEfficiency, .Runs, readerCheck.GetInt32(0))
' If it finds a decryptor, even no decryptor, then set it to invented, else assume it's a copy from a BPO
If FoundDecryptor.TypeID <> 0 Or (.MaterialEfficiency = BaseT2T3ME And .TimeEfficiency = BaseT2T3TE) Then
CurrentBPType = BPType.InventedBPC
End If
readerCheck.Close()
End If
End If
If InsertBP Then
SQL = "INSERT INTO OWNED_BLUEPRINTS (USER_ID, ITEM_ID, LOCATION_ID, BLUEPRINT_ID, BLUEPRINT_NAME, FLAG_ID, "
SQL &= "QUANTITY, ME, TE, RUNS, BP_TYPE, OWNED, SCANNED, FAVORITE, ADDITIONAL_COSTS) "
SQL &= "VALUES (" & CStr(TempID) & "," & CStr(.ItemID) & "," & CStr(.LocationID) & ","
SQL &= CStr(.TypeID) & ",'" & FormatDBString(.TypeName) & "',"
SQL &= CStr(.FlagID) & ",1," & CStr(.MaterialEfficiency) & "," & CStr(.TimeEfficiency) & ","
SQL &= .Runs & "," & CStr(CurrentBPType) & ",1," & CStr(ScannedFlag) & ", 0, 0)"
Else
' Update the BP
SQL = "UPDATE OWNED_BLUEPRINTS SET "
SQL &= "LOCATION_ID = " & CStr(.LocationID) & ","
SQL &= "FLAG_ID = " & CStr(.FlagID) & ","
SQL &= "ME = " & CStr(.MaterialEfficiency) & ","
SQL &= "TE = " & CStr(.TimeEfficiency) & ","
SQL &= "RUNS = " & CStr(.Runs) & ","
SQL &= "QUANTITY = 1," ' Helps determine copies (-2), bpos (-1), or stacks of BPO's (any number),
' but we will set for 1 now and later the total of BPS with the same ME/TE
' Also reset the unqiue itemid
SQL &= "ITEM_ID = " & CStr(.ItemID) & ","
' Could go from a copy to orginial (with single bp loading, will change with multi)
SQL &= "BP_TYPE = " & CStr(CurrentBPType) & ","
' Mark all from ESI as owned
SQL &= "OWNED = 1,"
SQL &= "BLUEPRINT_NAME = '" & FormatDBString(.TypeName) & "', " ' If it changes
SQL &= "SCANNED = " & ScannedFlag & " "
If readerBlueprints.GetInt64(3) <> 0 Then
' Search with ITEM_ID
SQL &= "WHERE ITEM_ID = " & CStr(readerBlueprints.GetInt64(3)) & " AND USER_ID = " & CStr(TempID)
Else
' Search with the ID of the bp and the user ID - they must have saved this manually
SQL &= "WHERE BLUEPRINT_ID = " & .TypeID & " AND USER_ID = " & CStr(TempID)
End If
End If
readerBlueprints.Close()
Call EVEDB.ExecuteNonQuerySQL(SQL)
End If
End With
Next
DBCommand = Nothing
Call EVEDB.CommitSQLiteTransaction()
End If
' Update cache date now that it's all set
Call CB.UpdateCacheDate(CDType, CacheDate, ID)
End If
End If
End Sub
End Class
' For outputing lists of blueprints
Public Structure EVEBlueprint
Dim ItemID As Long
Dim LocationID As Long
Dim TypeID As Long
Dim TypeName As String
Dim FlagID As Integer
Dim Quantity As Integer
Dim TimeEfficiency As Integer
Dim MaterialEfficiency As Integer
Dim Runs As Integer
Dim BPType As BPType
Dim Owned As Boolean
Dim Scanned As Boolean
Dim Favorite As Boolean
Dim AdditionalCosts As Double
End Structure