-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathEVEIndustryJobs.vb
203 lines (163 loc) · 8.77 KB
/
EVEIndustryJobs.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
Imports System.Data.SQLite
Public Class EVEIndustryJobs
Private JobList As List(Of IndustryJob)
Public Sub New()
JobList = New List(Of IndustryJob)
End Sub
' Loads all the Industry Assets from the DB for the ID sent - I'm not using this locally so don't load anything
Public Sub LoadIndustryJobs(ByVal ID As Long, ByVal TokenData As SavedTokenData, ByVal JobType As ScanType)
'Dim SQL As String
'Dim readerJobs As SQLiteDataReader
'Dim TempJob As IndustryJob
'Dim Jobs As New List(Of IndustryJob)
' Update Industry jobs first
Call UpdateIndustryJobs(ID, TokenData, JobType)
'DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
'readerJobs = DBCommand.ExecuteReader
'While readerJobs.Read
'End While
'readerJobs.Close()
'DBCommand = Nothing
'readerJobs = Nothing
' JobList = Jobs
End Sub
' Updates the Industry Jobs from ESI for the character/corp and inserts them into the Database for later queries
Public Sub UpdateIndustryJobs(ByVal ID As Long, ByVal CharacterTokenData As SavedTokenData, ByVal JobType As ScanType)
Dim SQL As String
Dim IndyJobs As New List(Of ESIIndustryJob)
Dim ESIData As New ESI
Dim CB As New CacheBox
Dim CacheDate As Date
Dim LocationID As Long = 0
Dim TempDate As Date
Dim CorpCharIDs As New List(Of Long)
Dim CDType As CacheDateType
If JobType = ScanType.Personal Then
CDType = CacheDateType.PersonalIndyJobs
Else
CDType = CacheDateType.CorporateIndyJobs
End If
' Look up the industry Blueprints cache date first
If CB.DataUpdateable(CDType, ID) Then
IndyJobs = ESIData.GetIndustryJobs(ID, CharacterTokenData, JobType, CacheDate)
If Not IsNothing(IndyJobs) Then
If IndyJobs.Count > 0 Then
Call EVEDB.BeginSQLiteTransaction()
' Clear out all the industry jobs for the user if not a corp lookup
If JobType = ScanType.Personal Then
SQL = "DELETE FROM INDUSTRY_JOBS WHERE InstallerID = " & CharacterTokenData.CharacterID & " AND JobType = " & CStr(JobType)
Else
' Delete all jobs and reload for corp
SQL = "DELETE FROM INDUSTRY_JOBS WHERE JobType = " & CStr(JobType)
' Also, get the list of character IDs stored in the DB with this corporation and only load those jobs
Dim rsIDs As SQLiteDataReader
DBCommand = New SQLiteCommand("SELECT CHARACTER_ID FROM ESI_CHARACTER_DATA WHERE CORPORATION_ID = " & CStr(ID), EVEDB.DBREf)
rsIDs = DBCommand.ExecuteReader
While rsIDs.Read
CorpCharIDs.Add(rsIDs.GetInt64(0))
End While
rsIDs.Close()
End If
Call EVEDB.ExecuteNonQuerySQL(SQL)
' Insert industry data
For i = 0 To IndyJobs.Count - 1
' First make sure it's not already in there
With IndyJobs(i)
' Insert it
If .location_id = 0 Then
LocationID = .station_id
Else
LocationID = .location_id
End If
If JobType = ScanType.Personal Or (CorpCharIDs.Contains(.installer_id) And JobType = ScanType.Corporation) Then ' update fields
SQL = "INSERT INTO INDUSTRY_JOBS (jobID, installerID, facilityID, locationID, activityID, "
SQL &= "blueprintID, blueprintTypeID, blueprintLocationID, outputLocationID, "
SQL &= "runs, cost, licensedRuns, probability, productTypeID, status, duration, "
SQL &= "startDate, endDate, pauseDate, completedDate, completedCharacterID, successfulRuns, JobType) VALUES ("
SQL &= .job_id & "," & .installer_id & "," & .facility_id & "," & LocationID & ","
' Bug fix until a decision is made to update SDE or ESI
If .activity_id = 9 Then
.activity_id = 11
End If
SQL &= .activity_id & "," & .blueprint_id & "," & .blueprint_type_id & "," & .blueprint_location_id & "," & .output_location_id & ","
SQL &= .runs & "," & .cost & "," & .licensed_runs & "," & .probability & "," & .product_type_id & ",'" & .status & "'," & .duration & ","
TempDate = ESIData.FormatESIDate(.start_date)
If TempDate <> NoDate Then
SQL &= "'" & Format(TempDate, SQLiteDateFormat) & "',"
Else
SQL &= "NULL,"
End If
TempDate = ESIData.FormatESIDate(.end_date)
If TempDate <> NoDate Then
SQL &= "'" & Format(TempDate, SQLiteDateFormat) & "',"
Else
SQL &= "NULL,"
End If
TempDate = ESIData.FormatESIDate(.pause_date)
If TempDate <> NoDate Then
SQL &= "'" & Format(TempDate, SQLiteDateFormat) & "',"
Else
SQL &= "NULL,"
End If
TempDate = ESIData.FormatESIDate(.completed_date)
If TempDate <> NoDate Then
SQL &= "'" & Format(TempDate, SQLiteDateFormat) & "',"
Else
SQL &= "NULL,"
End If
SQL &= .completed_character_id & "," & .successful_runs & "," & CStr(JobType) & ")"
Call EVEDB.ExecuteNonQuerySQL(SQL)
End If
End With
Next
' Now look up distinct location ids to find any public upwell structures to update
Dim rsStructure As SQLiteDataReader
Dim StructureIDList As New List(Of Long)
' Select facilties only for this character, since others may not have the same rights to this token
SQL = "SELECT DISTINCT facilityID FROM INDUSTRY_JOBS WHERE installerID = " & CStr(ID)
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
rsStructure = DBCommand.ExecuteReader
While rsStructure.Read
StructureIDList.Add(rsStructure.GetInt64(0))
End While
rsStructure.Close()
' Update all the structures we don't have names for
' Add the data
Dim SP As New StructureProcessor
For Each StructureID In StructureIDList
Call SP.UpdateStructureData(StructureID, SelectedCharacter.CharacterTokenData, False, True)
Next
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
Public Structure IndustryJob
Dim JobID As Integer
Dim InstallerID As Integer
Dim FacilityID As Integer
Dim LocationID As Integer
Dim ActivityID As Integer
Dim BlueprintID As Integer
Dim BlueprintTypeID As Integer
Dim BlueprintLocationID As Integer
Dim OutputlocationID As Integer
Dim Runs As Integer
Dim Cost As Double
Dim Licensedruns As Integer
Dim Probability As Double
Dim ProductTypeID As Integer
Dim Status As Integer
Dim Duration As Integer
Dim StartDate As Date
Dim EndDate As Date
Dim PauseDate As Date
Dim CompletedDate As Date
Dim CompletedCharacterID As Integer
Dim SuccessfulRuns As Integer
Dim JobType As Integer
End Structure