-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathShoppingList.vb
1893 lines (1512 loc) · 86 KB
/
ShoppingList.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 System.Data.SQLite
Public Class ShoppingList
Implements ICloneable
' Master Lists of materials to display. These are single lists that are updated when deleting quantity or full items
Private TotalItemList As List(Of ShoppingListItem) ' This is the total list of items, with orginal values - not updated
Private TotalBuyList As Materials ' Buy mats
Private TotalBuildList As BuiltItemList ' Build mats (components)
Private TotalInventionMats As Materials ' All Invention/RE materials used
Private TotalCopyMats As Materials ' All the copy materials needed to make copies to invent
' Use onhandlist of materials so we can keep track of user entries (of calculations they make based on mats on hand)
Public OnHandMatList As New Materials
Public OnHandComponentList As New Materials
' Price data
Private AdditionalCosts As Double ' For any additional costs added on the shopping list form
Private MaterialsBrokerFee As Double ' For the total broker fee for buying the materials in the list
Private TotalListUsage As Double ' Total of all usage values for the items in the list
Private TotalListMarketPrice As Double ' Total market price of everything in the list
Private TotalListCost As Double ' Total cost of everything in the list mats (with invention/copy costs) + usage + taxes + fees
Private TotalListBuildTime As Double ' Total time to build the items in the list in seconds
Private TotalListInventionCost As Double ' Total of all the invention materials in the list
Private TotalListCopyCost As Double ' Total of all the copy materials in the list
Protected ItemToFind As ShoppingListItem
Protected ProfitItemtoFind As String
Public Sub New()
Call Clear()
End Sub
Public Sub Clear()
TotalItemList = New List(Of ShoppingListItem)
TotalBuildList = New BuiltItemList
TotalBuyList = New Materials
TotalInventionMats = New Materials
TotalCopyMats = New Materials
AdditionalCosts = 0
MaterialsBrokerFee = 0
TotalListUsage = 0
TotalListMarketPrice = 0
TotalListCost = 0
ItemToFind = Nothing
' Reset onhand mats lists
OnHandMatList = New Materials
OnHandComponentList = New Materials
End Sub
#Region "Update Shopping List Functions"
' Removes or updates the item quantity and all mats associated with that item from the full list - i.e. Anshar
Public Sub UpdateShoppingItemQuantity(ByVal SentItem As ShoppingListItem, ByVal UpdateItemQuantity As Long)
Dim FoundItem As ShoppingListItem
Dim FoundBuildItem As BuiltItem
Dim TempBuiltItem As New BuiltItem
Dim UpdatedRunQuantity As Long
Dim BuiltComponents As New BuiltItemList
' First, see if there are any other items in the list, if this is the only one and the quantity is 0 then just clear all lists and leave
If UpdateItemQuantity <= 0 And TotalItemList.Count = 1 And TotalItemList(0).Name = SentItem.Name Then
Call Clear()
Exit Sub
End If
' Look for the item
ItemToFind = SentItem
FoundItem = TotalItemList.Find(AddressOf FindItem)
' Remove or update quantity for materials, built items, RE and invention mats
' Check the component list of the BP first, if we are building it, then update the number for built items, else we are buying it and update that
If FoundItem IsNot Nothing Then
' Look at built items first, then check materials only
If Not IsNothing(FoundItem.BPBuiltItems) Then
With FoundItem.BPBuiltItems
For i = 0 To .GetBuiltItemList.Count - 1
' Make sure the item exists (might have been deleted already in the main list) before updating
' Find the built item in the build list for this item
Call TotalBuildList.SetItemToFind(.GetBuiltItemList(i))
FoundBuildItem = TotalBuildList.GetBuiltItemList.Find(AddressOf TotalBuildList.FindBuiltItem)
If FoundBuildItem IsNot Nothing Then
' Copy current built item info
TempBuiltItem = New BuiltItem
TempBuiltItem = CType(FoundBuildItem.Clone, BuiltItem)
' Use group name as facility location
Dim UpdateMaterial As New Material(TempBuiltItem.ItemTypeID, TempBuiltItem.ItemName, TempBuiltItem.ManufacturingFacility.FacilityName, TempBuiltItem.ItemQuantity,
TempBuiltItem.ItemVolume, 0, CStr(TempBuiltItem.BuildME), CStr(TempBuiltItem.BuildTE), True)
' Figure out how many runs we need to do of this component item for the updated quantity of the main item
UpdatedRunQuantity = GetUpdatedQuantity("Build", FoundItem, UpdateItemQuantity, UpdateMaterial, True, TempBuiltItem.PortionSize)
' Update built item name with runs we did to get this quantity
TempBuiltItem.ItemName = UpdateItemNamewithRuns(TempBuiltItem.ItemName, CLng(Math.Ceiling(UpdatedRunQuantity / TempBuiltItem.PortionSize)))
' Need to update to the quantity sent in the built item list
Call UpdateShoppingBuiltItemQuantity(TempBuiltItem, UpdatedRunQuantity)
End If
Next
End With
End If
' Now look at the materials
If Not IsNothing(FoundItem.BPMaterialList) Then
With FoundItem.BPMaterialList
For i = 0 To .GetMaterialList.Count - 1
' Look at buy items
If .GetMaterialList(i).GetBuildItem = False Then
' Make sure the item exists (might have been deleted already in the main list) before updating
If Not IsNothing(TotalBuyList.SearchListbyName(.GetMaterialList(i).GetMaterialName)) Then
UpdatedRunQuantity = GetUpdatedQuantity("Buy", FoundItem, UpdateItemQuantity, .GetMaterialList(i), True)
' Need to update to the quantity sent in the Buy list
Call UpdateShoppingBuyQuantity(.GetMaterialList(i).GetMaterialName, UpdatedRunQuantity)
End If
End If
' Update the quantity of the material in the total list too, but needs to be for each individual material
Dim x As Long = GetNewMatQuantity(FoundItem, IndustryActivities.Manufacturing, .GetMaterialList(i), UpdateItemQuantity)
Call .GetMaterialList(i).SetQuantity(x)
Next
End With
End If
' Update Buy List with invention mats
If Not IsNothing(FoundItem.InventionMaterials) Then
If Not IsNothing(FoundItem.InventionMaterials.GetMaterialList) Then
With FoundItem.InventionMaterials ' Update all base materials for this item first
Dim TempInventionMaterials As New Materials
For i = 0 To .GetMaterialList.Count - 1
' Make sure the material exists (might have been deleted already in the main list) before updating
If Not IsNothing(TotalBuyList.SearchListbyName(.GetMaterialList(i).GetMaterialName)) Then
' Need to update to the quantity sent in the Buy List
UpdatedRunQuantity = GetUpdatedQuantity("Invention", FoundItem, UpdateItemQuantity, .GetMaterialList(i), True)
Call UpdateShoppingBuyQuantity(.GetMaterialList(i).GetMaterialName, UpdatedRunQuantity)
' Update this material in the item's invention list for copy/paste function
If UpdatedRunQuantity > 0 Then
' Need to copy, remove, update, then add to update the volumes and prices of the material lists
Dim TempMat As Material
TempMat = CType(TotalInventionMats.SearchListbyName(.GetMaterialList(i).GetMaterialName).Clone, Material)
Call TempInventionMaterials.InsertMaterial(TempMat)
End If
End If
Next
' Reset the Invention Materials for this item
FoundItem.InventionMaterials = TempInventionMaterials
End With
End If
End If
' Update buy list with copy materials
If Not IsNothing(FoundItem.CopyMaterials) Then
If Not IsNothing(FoundItem.CopyMaterials.GetMaterialList) Then
With FoundItem.CopyMaterials ' Update all base materials for this item first
Dim TempCopyMaterials As New Materials
For i = 0 To .GetMaterialList.Count - 1
' Make sure the material exists (might have been deleted already in the main list) before updating
If Not IsNothing(TotalBuyList.SearchListbyName(.GetMaterialList(i).GetMaterialName)) Then
' Need to update to the quantity sent in the Buy List
UpdatedRunQuantity = GetUpdatedQuantity("Copying", FoundItem, UpdateItemQuantity, .GetMaterialList(i), True)
Call UpdateShoppingBuyQuantity(.GetMaterialList(i).GetMaterialName, UpdatedRunQuantity)
' Update this material in the item's invention list for copy/paste function
If UpdatedRunQuantity <= 0 Then
Call TotalCopyMats.RemoveMaterial(.GetMaterialList(i))
Else
' Need to copy, remove, update, then add to update the volumes and prices of the material lists
Dim TempMat As Material
TempMat = CType(TotalCopyMats.SearchListbyName(.GetMaterialList(i).GetMaterialName).Clone, Material)
Call TempCopyMaterials.InsertMaterial(TempMat)
End If
End If
Next
' Reset the Invention Materials for this item
FoundItem.CopyMaterials = TempCopyMaterials
End With
End If
End If
' Need to increment or decrement the new item quantity and volume, the rest of the mats and components will be updated above
If UpdateItemQuantity = 0 Then
Call TotalItemList.Remove(FoundItem)
Else
' This is simplistic but the easiest way to get an approximate value for a change in the shopping list - won't be exact!
FoundItem.BuildVolume = FoundItem.BuildVolume / FoundItem.Runs * UpdateItemQuantity
'FoundItem.TotalMaterialCost = FoundItem.TotalMaterialCost / FoundItem.Quantity * UpdateItemQuantity
FoundItem.TotalUsage = FoundItem.TotalUsage / FoundItem.Runs * UpdateItemQuantity
FoundItem.TotalItemMarketCost = FoundItem.TotalItemMarketCost / FoundItem.Runs * UpdateItemQuantity
FoundItem.TotalBuildTime = FoundItem.TotalBuildTime / FoundItem.Runs * UpdateItemQuantity
' Update the invention jobs if they update this later
If FoundItem.InventionJobs <> 0 Then
FoundItem.InventionJobs = CInt(Math.Ceiling(FoundItem.AvgInvRunsforSuccess * Math.Ceiling(UpdateItemQuantity / FoundItem.InventedRunsPerBP)))
' How many bps do we need to make?
FoundItem.NumBPs = CInt(Math.Ceiling(UpdateItemQuantity / FoundItem.InventedRunsPerBP))
End If
' Finally update the quantity
FoundItem.Runs = UpdateItemQuantity
End If
End If
End Sub
' Removes or updates a built item quantity from the build list and its materials from the material list - i.e. remove particle accelerator and raw mats from item - Hammerhead II
Public Sub UpdateShoppingBuiltItemQuantity(ByRef SentItem As BuiltItem, ByVal UpdateItemQuantity As Long)
Dim FoundItem As BuiltItem
Dim UpdatedQuantity As Long ' This is the final mat quantity for updating the shopping buy/build list ammount
Dim RefMatQuantity As Long ' This is the reference for materials we send in the update quantity - will be the mat quantity for that built item
Dim UpdateItem As New BuiltItem
Dim UpdateItemMatList As New Materials
Dim UpdateBuiltItemMatList As New Materials
Dim UpdateBuildList As New List(Of BuiltItem)
Dim RefBuildList As New List(Of BuiltItem)
Dim InsertMat As Material
Dim InsertBuiltItem As New BuiltItem
Dim BuiltComponentList As New List(Of BuiltItem)
Dim ShoppingItem As New ShoppingListItem
Dim UpdateMaterial As Material
Dim SQL As String = ""
Dim rsMatCheck As SQLiteDataReader
Application.DoEvents()
' Task here: Update build list with correct quantity, and then the buy list with the correct material quantities
' First look up the item and the mats used to build it in the saved list
Call TotalBuildList.SetItemToFind(SentItem)
FoundItem = TotalBuildList.GetBuiltItemList.Find(AddressOf TotalBuildList.FindBuiltItem)
' Update the materials in the built list, take total number, divide mats by it and then multiply by quantity sent
If Not IsNothing(FoundItem) Then
With FoundItem.BuildMaterials
For i = 0 To .GetMaterialList.Count - 1
' Make sure the item exists (might have been deleted already in the main list) before updating
If Not IsNothing(TotalBuyList.SearchListbyName(.GetMaterialList(i).GetMaterialName)) Then
' Make sure the material is part of the build materials for the built item
' Look up mat quantities for this BP
SQL = "SELECT 'X' FROM ALL_BLUEPRINT_MATERIALS "
SQL &= "WHERE PRODUCT_ID = " & FoundItem.ItemTypeID & " AND MATERIAL_ID = " & .GetMaterialList(i).GetMaterialTypeID & " AND ACTIVITY IN (1,11)"
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
rsMatCheck = DBCommand.ExecuteReader
If rsMatCheck.HasRows Then
' Set the values we need to get updated quantity
ShoppingItem.Name = FoundItem.ItemName
ShoppingItem.TypeID = FoundItem.ItemTypeID
ShoppingItem.ManufacturingFacility = FoundItem.ManufacturingFacility
ShoppingItem.IncludeActivityCost = FoundItem.IncludeActivityCost
ShoppingItem.IncludeActivityTime = FoundItem.IncludeActivityTime
ShoppingItem.IncludeActivityUsage = FoundItem.IncludeActivityUsage
ShoppingItem.ItemME = FoundItem.BuildME
ShoppingItem.ItemTE = FoundItem.BuildTE
ShoppingItem.Runs = FoundItem.ItemQuantity
ShoppingItem.PortionSize = FoundItem.PortionSize
' Blank these out for now if we use them later
ShoppingItem.InventionJobs = 0
ShoppingItem.InventedRunsPerBP = 0
ShoppingItem.AvgInvRunsforSuccess = 0
ShoppingItem.NumBPs = 1 ' Built items (components) are always one bp for now
UpdateMaterial = CType(.GetMaterialList(i).Clone, Material)
' Get the new quantity for each material to build this item - which will be in the buy list
UpdatedQuantity = GetUpdatedQuantity("Buy", ShoppingItem, UpdateItemQuantity, UpdateMaterial, False, 1, RefMatQuantity)
' Need to update to the quantity sent in the Buy List
Call UpdateShoppingBuyQuantity(.GetMaterialList(i).GetMaterialName, UpdatedQuantity)
' Save the updated materials for the build list with the difference
If UpdatedQuantity > 0 Then
With .GetMaterialList(i)
' Need to save the new value we want for this item, not the new quantity, to update the other lists with
InsertMat = New Material(.GetMaterialTypeID, .GetMaterialName, .GroupName, RefMatQuantity, .GetTotalVolume, 0, "", "")
End With
UpdateItemMatList.InsertMaterial(InsertMat)
End If
End If
rsMatCheck.Close()
End If
Next
End With
' Now update the materials from any component items that this item may have built for the found item
For i = 0 To FoundItem.ComponentBuildList.Count - 1
Dim RefBuiltItem As New BuiltItem
' Look up how many runs of the component we need
If UpdateItemQuantity = 0 Then
' Need to update the quantity in the build list to delete the total we needed here - so what's in build list now minus this quantity
Dim FoundBuildItem As New BuiltItem
' Look up current built items
Call TotalBuildList.SetItemToFind(FoundItem.ComponentBuildList(i))
FoundBuildItem = TotalBuildList.GetBuiltItemList.Find(AddressOf TotalBuildList.FindBuiltItem)
If FoundBuildItem IsNot Nothing Then
UpdatedQuantity = FoundBuildItem.ItemQuantity - FoundItem.ComponentBuildList(i).ItemQuantity
Else
UpdatedQuantity = 0
End If
If UpdatedQuantity < 0 Then
UpdatedQuantity = 0
End If
Else
' Need to calculate the new amount
SQL = "SELECT QUANTITY FROM ALL_BLUEPRINT_MATERIALS "
SQL &= "WHERE BLUEPRINT_ID = " & FoundItem.BPTypeID
SQL &= " AND ACTIVITY IN (1,11)"
SQL &= " AND MATERIAL_ID = " & FoundItem.ComponentBuildList(i).ItemTypeID
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
rsMatCheck = DBCommand.ExecuteReader
If rsMatCheck.Read Then
' Now adjust the quantity based on the ME bonus and runs for the original bp
Dim Runs As Long = CInt(Math.Ceiling(UpdateItemQuantity / FoundItem.PortionSize))
Dim MEBonus As Double = GetMEBonus(FoundItem.BuildME, FoundItem.ManufacturingFacility.MaterialMultiplier)
Dim TempBuildQuantity As Long = 0
RefBuiltItem = CType(FoundItem.ComponentBuildList(i).Clone, BuiltItem)
Dim FoundbuiltItem As BuiltItem
Dim ListmatQuantity As Long
Call TotalBuildList.SetItemToFind(RefBuiltItem)
FoundbuiltItem = TotalBuildList.GetBuiltItemList.Find(AddressOf TotalBuildList.FindBuiltItem)
If FoundbuiltItem IsNot Nothing Then
ListmatQuantity = FoundbuiltItem.ItemQuantity
Else
ListmatQuantity = 0
End If
TempBuildQuantity = CLng(Math.Max(Runs, Math.Ceiling(Math.Round(Runs * rsMatCheck.GetInt64(0) * MEBonus, 2))))
' Figure out what we needed prior to update
Dim OldMatQuantity As Long = CLng(Math.Max(SentItem.BPRuns, Math.Ceiling(Math.Round(SentItem.BPRuns * rsMatCheck.GetInt64(0) * MEBonus, 2))))
' Remove what was in the list prior (old mat quantity)
UpdatedQuantity = ListMatQuantity - OldMatQuantity
If UpdatedQuantity < 0 Then
UpdatedQuantity = 0
End If
' Add what we need now
UpdatedQuantity += TempBuildQuantity
' UpdatedQuantity = GetUpdatedQuantity("Buy", FoundItem, UpdateItemQuantity, UpdateMaterial, False, 1, RefMatQuantity)
' Save what we need in the sent item reference
RefBuiltItem.ItemQuantity = TempBuildQuantity
RefBuiltItem.BPRuns = CLng(Math.Ceiling(TempBuildQuantity / RefBuiltItem.PortionSize))
RefBuiltItem.ItemName = UpdateItemNamewithRuns(RefBuiltItem.ItemName, RefBuiltItem.BPRuns)
rsMatCheck.Close()
End If
End If
' Update this component in the main built item list with the new quantity
Call UpdateShoppingBuiltItemQuantity(FoundItem.ComponentBuildList(i), UpdatedQuantity)
' Add the item with the new quantity to the reference build list
UpdateBuildList.Add(RefBuiltItem)
Next
' Save the base data
UpdateItem = New BuiltItem
UpdateItem = CType(FoundItem.Clone, BuiltItem)
Dim BPRuns As Long = CLng(Math.Ceiling(UpdateItemQuantity / FoundItem.PortionSize))
' Update built item name with runs we did to get this quantity
UpdateItem.ItemName = UpdateItemNamewithRuns(UpdateItem.ItemName, BPRuns)
' Update the new built list quantity and runs
UpdateItem.ItemQuantity = UpdateItemQuantity
UpdateItem.BPRuns = BPRuns
' Update the new built list material list, with updated quantities
UpdateItem.BuildMaterials = UpdateItemMatList
' Update the component build list as well with updated quantities
UpdateItem.ComponentBuildList = UpdateBuildList
' Update the data of the build list item
Call TotalBuildList.RemoveBuiltItem(FoundItem) ' Remove the old one
If UpdateItemQuantity <> 0 Then
Call TotalBuildList.AddBuiltItem(UpdateItem) ' Add the updated one
End If
' Update the sent item reference list
SentItem.ComponentBuildList = RefBuildList
End If
End Sub
' Removes or updates the quantity of material in all lists of materials. i.e. Tritanium
Public Sub UpdateShoppingBuyQuantity(ByVal SentItemName As String, ByVal Quantity As Long)
If Not IsNothing(TotalBuyList) Then
If Not IsNothing(TotalBuyList.GetMaterialList) Then
If Quantity <= 0 Then
' We just delete the item (all quantity) from the total materials list
Call TotalBuyList.RemoveMaterial(TotalBuyList.SearchListbyName(SentItemName))
' Also remove from the total copy and invention lists
Call TotalInventionMats.RemoveMaterial(TotalInventionMats.SearchListbyName(SentItemName))
Call TotalCopyMats.RemoveMaterial(TotalCopyMats.SearchListbyName(SentItemName))
Else
Dim TempMaterial As Material
Dim FindMaterial As Material = TotalBuyList.SearchListbyName(SentItemName)
' Catch if item isn't in the list to what was sent
If Not IsNothing(FindMaterial) Then
TempMaterial = CType(FindMaterial.Clone, Material)
TotalBuyList.RemoveMaterial(TempMaterial)
' Set the new quantity
Call TempMaterial.SetQuantity(Quantity)
' Re-add so the prices are updated
TotalBuyList.InsertMaterial(TempMaterial)
End If
' Update Invention mats (if there)
FindMaterial = TotalInventionMats.SearchListbyName(SentItemName)
' Catch if item isn't in the list to what was sent
If Not IsNothing(FindMaterial) Then
TempMaterial = CType(FindMaterial.Clone, Material)
TotalInventionMats.RemoveMaterial(TempMaterial)
' Set the new quantity
Call TempMaterial.SetQuantity(Quantity)
' Re-add so the prices are updated
TotalInventionMats.InsertMaterial(TempMaterial)
End If
' Update Copy mats (if there)
FindMaterial = TotalCopyMats.SearchListbyName(SentItemName)
' Catch if item isn't in the list to what was sent
If Not IsNothing(FindMaterial) Then
TempMaterial = CType(FindMaterial.Clone, Material)
TotalCopyMats.RemoveMaterial(TempMaterial)
' Set the new quantity
Call TempMaterial.SetQuantity(Quantity)
' Re-add so the prices are updated
TotalCopyMats.InsertMaterial(TempMaterial)
End If
End If
End If
End If
End Sub
' Calculates the MEBonus based on inputs
Private Function GetMEBonus(ItemME As Double, FacilityMEModifier As Double) As Double
Return (1 - (ItemME / 100)) * FacilityMEModifier
End Function
' Calculates the updated item quantity for updating lists
' ProcessingType = Invention/RE/Build/Buy
' CurrentItem = the current item in the shopping list for reference of old values
' NewMaterialQuantity = new quantity of the current item (not runs) we want to update
' UpdateMaterial = material of the item we are updating the quantity of based on the new item quantity
' UpdateMaterialPortionSize = portion size of the bp for the update material
' BuiltComponents = ref of any built components for the update material to save
' ShoppingItem = flag if it's a built item (uses quantity) or a main shopping item from the list (uses runs for quantity)
Private Function GetUpdatedQuantity(ByVal ProcessingType As String, ByVal CurrentItem As ShoppingListItem,
ByVal NewMaterialQuantity As Long, ByVal UpdateMaterial As Material,
ByVal ShoppingItem As Boolean, Optional ByVal UpdateMaterialPortionSize As Long = 1,
Optional ByRef RefMatQuantity As Long = 0) As Long
Dim UpdatedQuantity As Long = 0
Dim OnHandMats As Long
Dim ListMatQuantity As Long
Dim NumInventionJobs As Integer
Dim NewMatQuantity As Long = 0
Dim OldMatQuantity As Long = 0
' Set up the ME bonus and then calculate the new material quantity
Dim MEBonus As Double = 0
Dim SingleRunQuantity As Long = 0
Dim ItemBPRuns As Long = 0
Dim rsMatQuantity As SQLiteDataReader
Dim SQL As String
Dim ActivitySQL As String
Dim ProductIDSQL As String
' Set how many runs of the main item bp are we going to do
If ShoppingItem Then
ItemBPRuns = NewMaterialQuantity
Else
ItemBPRuns = CLng(Math.Ceiling(NewMaterialQuantity / CurrentItem.PortionSize))
End If
Select Case ProcessingType
Case "Invention"
ProductIDSQL = CStr(CurrentItem.BlueprintTypeID)
ActivitySQL = " AND ACTIVITY = 8"
Case "Copying"
ProductIDSQL = CStr(CurrentItem.BlueprintTypeID)
ActivitySQL = " AND ACTIVITY = 5"
Case Else
ProductIDSQL = CStr(CurrentItem.TypeID)
ActivitySQL = " AND ACTIVITY IN (1,11)"
End Select
' Look up the single run quantity for the material
SQL = "SELECT QUANTITY FROM ALL_BLUEPRINT_MATERIALS LEFT OUTER JOIN ALL_BLUEPRINTS ON ALL_BLUEPRINTS.ITEM_ID = ALL_BLUEPRINT_MATERIALS.MATERIAL_ID "
SQL &= "WHERE PRODUCT_ID = " & ProductIDSQL & " AND MATERIAL_ID = " & UpdateMaterial.GetMaterialTypeID
SQL &= ActivitySQL
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
rsMatQuantity = DBCommand.ExecuteReader
If rsMatQuantity.Read Then
SingleRunQuantity = rsMatQuantity.GetInt64(0)
rsMatQuantity.Close()
Else
' This item isn't required to build this bp, so exit
rsMatQuantity.Close()
RefMatQuantity = 0
Return UpdateMaterial.GetQuantity
End If
' Calc out final mat quantity
If ProcessingType = "Invention" Or ProcessingType = "Copying" Then
ListMatQuantity = TotalBuyList.SearchListbyName(UpdateMaterial.GetMaterialName).GetQuantity
' For invention materials, find out how many mats we need by calcuating the new value from the item runs and invention jobs per item
If NewMaterialQuantity <= 0 Then
' Easy case, just remove the update material quantity (add the negative)
NewMatQuantity = 0
Else
' Here, we need to figure out how many items per run to remove (3 inv mats per job, and remove 2 items, then remove 6 invention mats)
NumInventionJobs = CInt(Math.Ceiling(CurrentItem.AvgInvRunsforSuccess * Math.Ceiling(ItemBPRuns / CurrentItem.InventedRunsPerBP)))
' Update quantity based on invention calculations
NewMatQuantity = NumInventionJobs * SingleRunQuantity
RefMatQuantity = NewMatQuantity
End If
ElseIf ProcessingType = "Buy" Or ProcessingType = "Build" Then
Dim UpdatedItemNumBPs As Integer = 0
' Figure out how many bps for the component we need
If CurrentItem.InventionJobs <> 0 Then
If NewMaterialQuantity <> 0 Then
' Calc how many bps we will need based off of invention
UpdatedItemNumBPs = CInt(Math.Ceiling(ItemBPRuns / CurrentItem.InventedRunsPerBP))
Else
' Deleting, so need the original amount and bps
UpdatedItemNumBPs = CurrentItem.NumBPs
End If
Else
' This isn't invented so just use the number of blueprints
UpdatedItemNumBPs = CurrentItem.NumBPs
' Make sure we aren't building more bps than the quantity
If UpdatedItemNumBPs > NewMaterialQuantity And NewMaterialQuantity <> 0 Then
UpdatedItemNumBPs = CInt(NewMaterialQuantity)
End If
End If
Dim TempItemRuns As Long = 0
If NewMaterialQuantity = 0 Then
' Deleting so use the original numbers to figure out what to remove later
TempItemRuns = CurrentItem.Runs
Else
TempItemRuns = ItemBPRuns
End If
' Set the minimum per bp, shouldn't go over the runs per bp since the user sends in the total numbps they need
Dim RunsPerLine As Integer = CInt(Math.Floor(TempItemRuns / UpdatedItemNumBPs))
' Add these extra runs evenly (until gone) for each bp on runs per line
Dim ExtraRuns As Integer = CInt(TempItemRuns - (RunsPerLine * UpdatedItemNumBPs))
' To track how many runs we have used in the batch setup
Dim RunTracker As Long = 0
Dim AdjRunsperBP As Integer
' List to use later to calc values
Dim BlueprintsRunList As New List(Of Integer)
' Fill a list of runs per bp
For i = 0 To UpdatedItemNumBPs - 1
' As we add the runs, adjust with extra runs proportionally until they are gone
If ExtraRuns <> 0 Then
' Since it's a fraction of a total batch run, this will always just be one until gone ** not right?
AdjRunsperBP = RunsPerLine + 1
ExtraRuns = ExtraRuns - 1 ' Adjust extra
Else
' No extra runs, so just add the original runs now
AdjRunsperBP = RunsPerLine
End If
' Add the bp runs to the list to run
BlueprintsRunList.Add(AdjRunsperBP)
Next
' Set the ME of the main item to calculate how many runs we need of the component
MEBonus = GetMEBonus(CurrentItem.ItemME, CurrentItem.ManufacturingFacility.MaterialMultiplier)
' Get the quantity from the correct list so we have the right total materials of all items using this material
If ProcessingType = "Buy" Then
ListMatQuantity = TotalBuyList.SearchListbyName(UpdateMaterial.GetMaterialName).GetQuantity
' Figure out what we needed prior to update
Dim OldRuns As Long
If ShoppingItem Then
OldRuns = CurrentItem.Runs
Else
OldRuns = CLng(Math.Ceiling(CurrentItem.Runs / CurrentItem.PortionSize))
End If
OldMatQuantity = CLng(Math.Max(OldRuns, Math.Ceiling(Math.Round(OldRuns * SingleRunQuantity * MEBonus, 2))))
ElseIf ProcessingType = "Build" Then
Dim TempBuildItem As New BuiltItem
TempBuildItem.ItemTypeID = UpdateMaterial.GetMaterialTypeID
TempBuildItem.BuildME = CInt(UpdateMaterial.GetItemME)
TempBuildItem.ManufacturingFacility.FacilityName = UpdateMaterial.GroupName
Call TotalBuildList.SetItemToFind(TempBuildItem)
Dim FoundBuiltItem As BuiltItem
FoundBuiltItem = TotalBuildList.GetBuiltItemList.Find(AddressOf TotalBuildList.FindBuiltItem)
If FoundBuiltItem IsNot Nothing Then
ListMatQuantity = FoundBuiltItem.ItemQuantity
Else
ListMatQuantity = 0
End If
' Figure out what we needed prior to update - adjust ME bonus for each blueprint need, not the total
'If Not ShoppingItem Then
OldMatQuantity = CLng(Math.Max(CurrentItem.Runs, Math.Ceiling(Math.Round(CurrentItem.Runs * SingleRunQuantity * MEBonus, 2))))
'Else
' For i = 0 To BlueprintsRunList.Count - 1
' OldMatQuantity += CLng(Math.Max(BlueprintsRunList(i), Math.Ceiling(Math.Round(BlueprintsRunList(i) * SingleRunQuantity * MEBonus, 2))))
' Next
'End If
End If
If NewMaterialQuantity <> 0 Then
' Now for each bp, calc the runs with the ME value - only do this for buy
If ProcessingType = "Buy" Then
For i = 0 To BlueprintsRunList.Count - 1
' Set the quantity required = max(runs,ceil(round(runs * baseQuantity * materialModifier,2)) and sum for each bp
NewMatQuantity += CLng(Math.Max(BlueprintsRunList(i), Math.Ceiling(Math.Round(BlueprintsRunList(i) * SingleRunQuantity * MEBonus, 2))))
Next
Else
' Default to 1 run for build items to match the main blueprint function - this is the quantity of the new material for the item runs
NewMatQuantity = CLng(Math.Max(TempItemRuns, Math.Ceiling(Math.Round(TempItemRuns * SingleRunQuantity * MEBonus, 2))))
End If
Else
' Deleting, so no need to calculate, just reduce from what was in list for this item already
NewMatQuantity = 0
End If
' Set the mat quantity for reference
RefMatQuantity = NewMatQuantity
End If
' Update with onhand mats functionality
If UpdateMaterial.GetBuildItem Then ' Building
' If entered, use this as the quantity to update to reflect that the user already entered a updated value
OnHandMats = GetOnHandComponentQuantity(UpdateMaterial.GetMaterialName)
Else ' Buying
' If entered, use this as the quantity to update to reflect that the user already entered a updated value
OnHandMats = GetOnHandMaterialQuantity(UpdateMaterial.GetMaterialName)
End If
If OnHandMats <> 0 Then
UpdatedQuantity = NewMatQuantity - OnHandMats
Else
UpdatedQuantity = NewMatQuantity ' Quantity we need now
End If
' Decrease the mats in the shopping list from what we needed before then add what we need now
UpdatedQuantity = (ListMatQuantity - OldMatQuantity) + UpdatedQuantity
' If the update caused it go below zero, reset
If UpdatedQuantity < 0 Then
UpdatedQuantity = 0
End If
Return UpdatedQuantity
End Function
Private Function GetNewMatQuantity(ByVal ItemData As ShoppingListItem, ByVal Activity As IndustryActivities,
ByVal UpdateMaterial As Material, ByVal NewQuantity As Long) As Long
' Set up the ME bonus and then calculate the new material quantity
Dim MEBonus As Double = 0
Dim SingleRunQuantity As Long = 0
Dim rsMatQuantity As SQLiteDataReader
Dim SQL As String
If NewQuantity = 0 Then
Return 0
End If
' Look up the cost for the material
If Activity = IndustryActivities.Invention Or Activity = IndustryActivities.Copying Then
SQL = "SELECT QUANTITY FROM ALL_BLUEPRINT_MATERIALS WHERE PRODUCT_ID = " & ItemData.BlueprintTypeID & " AND MATERIAL_ID = " & UpdateMaterial.GetMaterialTypeID
SQL &= " AND ACTIVITY = 8"
Else
SQL = "SELECT QUANTITY FROM ALL_BLUEPRINT_MATERIALS WHERE PRODUCT_ID = " & ItemData.TypeID & " AND MATERIAL_ID = " & UpdateMaterial.GetMaterialTypeID
SQL &= " AND ACTIVITY IN (1,11)"
End If
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
rsMatQuantity = DBCommand.ExecuteReader
rsMatQuantity.Read()
SingleRunQuantity = rsMatQuantity.GetInt64(0)
rsMatQuantity.Close()
MEBonus = (1 - (ItemData.ItemME / 100)) * ItemData.ManufacturingFacility.MaterialMultiplier
' Figure out how many bps we need now and apply the ME bonus for each bp and sum up
Dim NewNumBPs As Integer
Dim NewRunsperBP As Integer
If ItemData.InventionJobs <> 0 Then
If ItemData.NumBPs = 1 Then
NewNumBPs = CInt(Math.Ceiling(NewQuantity / ItemData.InventedRunsPerBP))
Else
NewNumBPs = CInt(Math.Ceiling(NewQuantity / (ItemData.Runs / ItemData.NumBPs)))
End If
NewRunsperBP = CInt(Math.Ceiling(NewQuantity / NewNumBPs))
Else
' This isn't invented so just use the number of blueprints
NewNumBPs = ItemData.NumBPs
NewRunsperBP = CInt(Math.Ceiling(NewQuantity / NewNumBPs))
' Make sure we aren't building more bps than the quantity
If NewNumBPs > NewQuantity Then
NewNumBPs = CInt(NewQuantity)
End If
End If
Dim NewMatQuantity As Long = 0
' For each bp, apply the me bonus and add up
For i = 1 To NewNumBPs
' Set the quantity: required = max(runs,ceil(round(runs * baseQuantity * materialModifier,2))
NewMatQuantity += CLng(Math.Max(NewRunsperBP, Math.Ceiling(Math.Round(NewRunsperBP * SingleRunQuantity * MEBonus, 2))))
Next
Return NewMatQuantity
End Function
#End Region
' Inserts a full shopping list item into the list
Public Sub InsertShoppingItem(ByVal SentItem As ShoppingListItem, ByVal SentBuildList As BuiltItemList, ByVal SentBuyList As Materials)
Dim FoundItem As New ShoppingListItem
Dim TempMats As New Materials
Dim TempItems As New BuiltItemList
Dim SearchBuiltItems As New BuiltItemList
' Look for the item
ItemToFind = SentItem
FoundItem = TotalItemList.Find(AddressOf FindItem)
If FoundItem IsNot Nothing Then
' If it's already in the list, then remove it, and add the sent items to it, then re-add
TotalItemList.Remove(FoundItem)
' Add the new data to this item
With FoundItem
' Increment items
.Runs = .Runs + SentItem.Runs
.BuildVolume = .BuildVolume + SentItem.BuildVolume
.TotalUsage = .TotalUsage + SentItem.TotalUsage
.TotalItemMarketCost = .TotalItemMarketCost + SentItem.TotalItemMarketCost
.TotalBuildTime = .TotalBuildTime + SentItem.TotalBuildTime
.NumBPs = .NumBPs + SentItem.NumBPs ' Need to add the set of numbps used to the current
.InventionJobs = .InventionJobs + SentItem.InventionJobs
' Increment BP Mat List
If Not IsNothing(SentItem.BPMaterialList) Then
TempMats = New Materials
TempMats = CType(.BPMaterialList.Clone, Materials)
If Not IsNothing(SentItem.BPMaterialList) Then
TempMats.InsertMaterialList(SentItem.BPMaterialList.GetMaterialList)
End If
.BPMaterialList = CType(TempMats.Clone, Materials)
Else
.BPMaterialList = New Materials
.BPMaterialList = CType(FoundItem.BPMaterialList.Clone, Materials)
End If
' Increment BP Build List
If Not IsNothing(SentItem.BPBuiltItems) Then
TempItems = New BuiltItemList
TempItems = CType(.BPBuiltItems.Clone, BuiltItemList)
If Not IsNothing(SentItem.BPBuiltItems) Then
For i = 0 To SentItem.BPBuiltItems.GetBuiltItemList.Count - 1
TempItems.AddBuiltItem(SentItem.BPBuiltItems.GetBuiltItemList(i))
Next
End If
.BPBuiltItems = CType(TempItems.Clone, BuiltItemList)
Else
.BPBuiltItems = New BuiltItemList
.BPBuiltItems = CType(FoundItem.BPBuiltItems.Clone, BuiltItemList)
End If
' Update invention mats
If Not IsNothing(SentItem.InventionMaterials) Then
.InventionMaterials.InsertMaterialList(SentItem.InventionMaterials.GetMaterialList)
End If
' Update copy mats
If Not IsNothing(SentItem.CopyMaterials) Then
.CopyMaterials.InsertMaterialList(SentItem.CopyMaterials.GetMaterialList)
End If
End With
' Now re-add, not a new item so number of items the same
TotalItemList.Add(FoundItem)
Else ' Just add it
TotalItemList.Add(SentItem)
End If
' Total Buy
If Not IsNothing(SentBuyList) Then
If Not IsNothing(SentBuyList.GetMaterialList) Then
TotalBuyList.InsertMaterialList(SentBuyList.GetMaterialList)
End If
End If
' Total Build - Need to rebuild every component as if we are only using one bp to get the numbers exact
If Not IsNothing(SentBuildList) Then
If Not IsNothing(SentBuildList.GetBuiltItemList) Then
' Loop through everything and find all the items to update
For i = 0 To SentBuildList.GetBuiltItemList.Count - 1
Dim FoundBuildItem As New BuiltItem
' Look up current built items
Call TotalBuildList.SetItemToFind(CType(SentBuildList.GetBuiltItemList(i).Clone, BuiltItem))
FoundBuildItem = TotalBuildList.GetBuiltItemList.Find(AddressOf TotalBuildList.FindBuiltItem)
' Rebuild with new quantity
If FoundBuildItem IsNot Nothing Then
' With this item, update the quantity and rebuild for new materials list
With SentBuildList.GetBuiltItemList(i)
' Re-run with new quantity
Dim NewRuns As Integer = CInt(Math.Ceiling((FoundBuildItem.ItemQuantity + .ItemQuantity) / FoundBuildItem.PortionSize))
Dim TempBP As New Blueprint(.BPTypeID, NewRuns, .BuildME, .BuildTE, 1,
UserBPTabSettings.ProductionLines, SelectedCharacter, UserApplicationSettings, False, 0,
.ManufacturingFacility, .ManufacturingFacility, .ManufacturingFacility, .ManufacturingFacility, True, UserBPTabSettings.BuildT2T3Materials, True)
Dim BFI As BrokerFeeInfo
BFI.IncludeFee = CType(UserBPTabSettings.IncludeFees, BrokerFeeType)
BFI.FixedRate = UserBPTabSettings.BrokerFeeRate
Call TempBP.BuildItems(UserBPTabSettings.IncludeTaxes, bfi, True,
UserBPTabSettings.IgnoreMinerals, UserBPTabSettings.IgnoreT1Item)
Dim InsertBuildItem As New BuiltItem
InsertBuildItem.BuildMaterials = TempBP.GetRawMaterials
InsertBuildItem.BPTypeID = TempBP.GetTypeID
InsertBuildItem.ItemTypeID = TempBP.GetItemID
InsertBuildItem.ItemName = UpdateItemNamewithRuns(TempBP.GetItemName, NewRuns)
InsertBuildItem.ItemQuantity = FoundBuildItem.ItemQuantity + .ItemQuantity
InsertBuildItem.BuildME = TempBP.GetME
InsertBuildItem.BuildTE = TempBP.GetTE
InsertBuildItem.ItemVolume = TempBP.GetTotalItemVolume
InsertBuildItem.BuildMaterials = TempBP.GetRawMaterials
InsertBuildItem.ManufacturingFacility = TempBP.GetManufacturingFacility
InsertBuildItem.IncludeActivityCost = TempBP.GetManufacturingFacility.IncludeActivityCost
InsertBuildItem.IncludeActivityTime = TempBP.GetManufacturingFacility.IncludeActivityTime
InsertBuildItem.IncludeActivityUsage = TempBP.GetManufacturingFacility.IncludeActivityUsage
InsertBuildItem.PortionSize = TempBP.GetPortionSize
' Remove the old record
TotalBuildList.RemoveBuiltItem(FoundBuildItem)
' Now add the updated item
TotalBuildList.AddBuiltItem(InsertBuildItem)
End With
Else
' Just add the new item
TotalBuildList.AddBuiltItem(SentBuildList.GetBuiltItemList(i))
End If
Next
End If
End If
' Invention Materials
If Not IsNothing(SentItem.InventionMaterials) Then
TotalInventionMats.InsertMaterialList(SentItem.InventionMaterials.GetMaterialList)
End If
' Copy Materials
If Not IsNothing(SentItem.CopyMaterials) Then
TotalCopyMats.InsertMaterialList(SentItem.CopyMaterials.GetMaterialList)
End If
ItemToFind = Nothing
End Sub
' Will update all the prices in the shopping list
Public Sub UpdateListPrices()
Dim TempBuyList As New Materials ' Buy mats
Dim TempBuildList As New BuiltItemList ' Build mats (components)
Dim TempInventionMats As New Materials ' All Invention materials used
Dim TempCopyMats As New Materials ' All the copy materials used
Dim TempBPMatList As New Materials ' For the Total Item List
Dim TransferMaterial As Material
Dim TransferBuiltItem As BuiltItem
' Basically take the materials from the current lists and put them into new lists with 0 prices to get them updated
' Item List
For i = 0 To TotalItemList.Count - 1
For j = 0 To TotalItemList(i).BPMaterialList.GetMaterialList.Count - 1
With TotalItemList(i).BPMaterialList.GetMaterialList(j)
TransferMaterial = New Material(.GetMaterialTypeID, .GetMaterialName, .GroupName, .GetQuantity, .GetVolume, 0, .GetItemME, .GetItemTE, .GetBuildItem, .GetItemType)
End With
' Add to the temp list
Call TempBPMatList.InsertMaterial(TransferMaterial)
Next
' Reset each BPMaterial list on each item
TotalItemList(i).BPMaterialList = TempBPMatList
Next
' Buy List
If Not IsNothing(TotalBuyList.GetMaterialList) Then
For i = 0 To TotalBuyList.GetMaterialList.Count - 1
With TotalBuyList.GetMaterialList(i)
TransferMaterial = New Material(.GetMaterialTypeID, .GetMaterialName, .GroupName, .GetQuantity, .GetVolume, 0, .GetItemME, .GetItemTE, .GetBuildItem, .GetItemType)
End With
' Add the material with new price to list
Call TempBuyList.InsertMaterial(TransferMaterial)
Next
End If
' Reset List
TotalBuyList = TempBuyList
' Invention List
If Not IsNothing(TotalInventionMats.GetMaterialList) Then
For i = 0 To TotalInventionMats.GetMaterialList.Count - 1