示例#1
0
        // 6 Exploration
        // 6.2 MaterialCollected
        private void JournalMaterialCollected(string jstr)
        {
            MaterialCollectedEvent materialcollected = JsonConvert.DeserializeObject <MaterialCollectedEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                MaterialList mater = db.MaterialLists.Where(p => p.EDCodeName == materialcollected.Name).First();
                if (db.Materials.Any(o => o.MaterialName == mater.MaterialName))
                {
                    //Update Materials record
                    Material materialUpdate = db.Materials.Where(o => o.MaterialName == mater.MaterialName).First();
                    materialUpdate.Quantity = materialUpdate.Quantity + materialcollected.Count;
                }
                else
                {
                    //Add Materials record
                    db.Materials.Add(new Material()
                    {
                        MaterialName = mater.MaterialName, Quantity = materialcollected.Count
                    });
                }
                db.SaveChanges();
                db.Dispose();
            }
        }
示例#2
0
        // 6.3 MaterialDiscarded
        private void JournalMaterialDiscarded(string jstr)
        {
            MaterialDiscardedEvent materialdiscarded = JsonConvert.DeserializeObject <MaterialDiscardedEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                MaterialList mater = db.MaterialLists.Where(p => p.EDCodeName == materialdiscarded.Name).First();
                if (db.Materials.Any(o => o.MaterialName == mater.MaterialName))
                {
                    Material materialitem = db.Materials.Where(o => o.MaterialName == mater.MaterialName).First();
                    if (materialitem.Quantity == materialdiscarded.Count)
                    {
                        //Remove item from materials
                        db.Materials.RemoveRange(db.Materials.Where(o => o.MaterialName == mater.MaterialName));
                    }
                    else
                    {
                        //Update Materials record
                        materialitem.Quantity = materialitem.Quantity - materialdiscarded.Count;
                    }
                    db.SaveChanges();
                }
                db.Dispose();
            }
        }
示例#3
0
        private void DisplayMaterial()
        {
            using (var db = new EDTSQLEntities())
            {
                if (db.Materials.Count() > 0)
                {
                    lvRaw.Items.Clear();
                    lvMaterials.Items.Clear();
                    lvEncoded.Items.Clear();

                    foreach (Material matitem in db.Materials)
                    {
                        var matlistitem = new ListViewItem(new[] { matitem.MaterialName, matitem.Quantity.ToString() });

                        if (matitem.MaterialGroup == "Raw")
                        {
                            lvRaw.Items.Add(matlistitem);
                        }
                        if (matitem.MaterialGroup == "Manufactured")
                        {
                            lvMaterials.Items.Add(matlistitem);
                        }
                        if (matitem.MaterialGroup == "Encoded")
                        {
                            lvEncoded.Items.Add(matlistitem);
                        }
                    }
                    lvRaw.Refresh();
                    lvMaterials.Refresh();
                    lvEncoded.Refresh();
                }
            }
        }
示例#4
0
        // 8.18 MissionCompleted
        private void JournalMissionCompleted(string jstr)
        {
            MissionCompletedEvent missioncomplete = JsonConvert.DeserializeObject <MissionCompletedEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                if (db.ActiveMissions.Any(o => o.MissionID == missioncomplete.MissionID))
                {
                    // Remove mission
                    db.ActiveMissions.RemoveRange(db.ActiveMissions.Where(o => o.MissionID == missioncomplete.MissionID));
                    db.SaveChanges();
                }

                if (db.CargoHolds.Any(o => o.CommodityName == missioncomplete.Commodity_Localised && o.MissionCargo == true))
                {
                    CargoHold cargoitem = db.CargoHolds.Where(o => o.CommodityName == missioncomplete.Commodity_Localised && o.MissionCargo == true).First();
                    if (cargoitem.Qty == missioncomplete.Count)
                    {
                        //Remove item of cargo
                        //db.CargoHolds.RemoveRange(db.CargoHolds.Where(o => o.CommodityName == missioncomplete.Commodity_Localised && o.MissionCargo = true));
                        db.CargoHolds.RemoveRange(db.CargoHolds.Where(o => o.TradeID == cargoitem.TradeID));
                    }
                    else
                    {
                        //Update quantity of cargo
                        cargoitem.Qty = cargoitem.Qty - missioncomplete.Count;
                    }
                    db.SaveChanges();
                }
                if ((missioncomplete.CommodityReward != null) && (missioncomplete.CommodityReward.Count > 0))
                {
                    foreach (var item in missioncomplete.CommodityReward)
                    {
                        Commodity commod = db.Commodities.Where(p => p.EDCodeName == item.Name.ToLower()).First();
                        if (db.CargoHolds.Any(o => o.CommodityName == commod.CommodityName && o.MissionCargo == false))
                        {
                            //Update CargoHold record
                            CargoHold cargoUpdate        = db.CargoHolds.Where(o => o.CommodityName == commod.CommodityName && o.MissionCargo == false).First();
                            var       existingCargoValue = cargoUpdate.AvgPurchasePrice * cargoUpdate.Qty;
                            cargoUpdate.Qty = cargoUpdate.Qty + item.Count;
                            cargoUpdate.AvgPurchasePrice = existingCargoValue / cargoUpdate.Qty;
                        }
                        else
                        {
                            //Add CargoHold record
                            db.CargoHolds.Add(new CargoHold()
                            {
                                CommodityName = commod.CommodityName, Qty = item.Count, AvgPurchasePrice = 0, Stolen = false, StockChecked = true, MissionCargo = false
                            });
                        }
                        db.SaveChanges();
                    }
                }
                db.Dispose();
            }
        }
示例#5
0
        // 7.4 MarketBuy
        private void JournalMarketBuy(string jstr)
        {
            MarketBuyEvent marketbuy = JsonConvert.DeserializeObject <MarketBuyEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                //Lookup NiceName of Cargo Item from Commodities table
                try
                {
                    Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketbuy.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketbuy.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate        = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        var       existingCargoValue = cargoUpdate.AvgPurchasePrice * cargoUpdate.Qty;
                        cargoUpdate.Qty = cargoUpdate.Qty + marketbuy.Count;
                        cargoUpdate.AvgPurchasePrice = (existingCargoValue + (marketbuy.BuyPrice * marketbuy.Count)) / cargoUpdate.Qty;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = marketbuy.Count, AvgPurchasePrice = marketbuy.BuyPrice, Stolen = false, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                catch
                {
                    RareCommodity commod = db.RareCommodities.Where(p => p.EDCodeName == marketbuy.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketbuy.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate        = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        var       existingCargoValue = cargoUpdate.AvgPurchasePrice * cargoUpdate.Qty;
                        cargoUpdate.Qty = cargoUpdate.Qty + marketbuy.Count;
                        cargoUpdate.AvgPurchasePrice = (existingCargoValue + (marketbuy.BuyPrice * marketbuy.Count)) / cargoUpdate.Qty;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = marketbuy.Count, AvgPurchasePrice = marketbuy.BuyPrice, Stolen = false, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                db.Dispose();
            }
        }
示例#6
0
        // 7.6 Miningrefined
        private void JournalMiningRefined(string jstr)
        {
            MiningRefinedEvent miningrefined = JsonConvert.DeserializeObject <MiningRefinedEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                //Lookup NiceName of Mined Item from Commodities table
                try
                {
                    Commodity commod = db.Commodities.Where(p => p.EDCodeName == miningrefined.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == miningrefined.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        cargoUpdate.Qty = cargoUpdate.Qty + 1;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new EDTraderSQL.CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = 1, AvgPurchasePrice = 0, Stolen = false, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                catch
                {
                    RareCommodity commod = db.RareCommodities.Where(p => p.EDCodeName == miningrefined.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == miningrefined.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        cargoUpdate.Qty = cargoUpdate.Qty + 1;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new EDTraderSQL.CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = 1, AvgPurchasePrice = 0, Stolen = false, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                db.Dispose();
            }
        }
示例#7
0
        // 7.5 MarketSell
        private void JournalMarketSell(string jstr)
        {
            MarketSellEvent marketsell = JsonConvert.DeserializeObject <MarketSellEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                //Lookup NiceName of Cargo Item from Commodities table
                try
                {
                    Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketsell.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketsell.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        CargoHold cargoitem = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        if (cargoitem.Qty == marketsell.Count)
                        {
                            //Remove item of cargo
                            db.CargoHolds.RemoveRange(db.CargoHolds.Where(o => o.TradeID == cargoitem.TradeID));
                            db.SaveChanges();
                        }
                        else
                        {
                            //Update quantity of cargo
                            cargoitem.Qty = cargoitem.Qty - marketsell.Count;
                            db.SaveChanges();
                        }
                    }
                }
                catch
                {
                    RareCommodity commod = db.RareCommodities.Where(p => p.EDCodeName == marketsell.Type).First();
                    //Commodity commod = db.Commodities.Where(p => p.EDCodeName == marketsell.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false))
                    {
                        CargoHold cargoitem = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.MissionCargo == false).First();
                        if (cargoitem.Qty == marketsell.Count)
                        {
                            //Remove item of cargo
                            db.CargoHolds.RemoveRange(db.CargoHolds.Where(o => o.TradeID == cargoitem.TradeID));
                            db.SaveChanges();
                        }
                        else
                        {
                            //Update quantity of cargo
                            cargoitem.Qty = cargoitem.Qty - marketsell.Count;
                            db.SaveChanges();
                        }
                    }
                }
                db.Dispose();
            }
        }
示例#8
0
        // 7 Trade
        // 7.2 CollectCargo
        private void JournalCollectCargo(string jstr)
        {
            CollectCargoEvent collectcargo = JsonConvert.DeserializeObject <CollectCargoEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                //Lookup NiceName of Cargo Item from Commodities table
                try
                {
                    Commodity commod = db.Commodities.Where(p => p.EDCodeName == collectcargo.Type).First();
                    // Commodity commod = db.Commodities.Where(p => p.EDCodeName == collectcargo.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.Stolen == collectcargo.Stolen))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.Stolen == collectcargo.Stolen).First();
                        cargoUpdate.Qty = cargoUpdate.Qty + 1;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record because record of matching stolen status not found
                        db.CargoHolds.Add(new EDTraderSQL.CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = 1, AvgPurchasePrice = 0, Stolen = collectcargo.Stolen, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                catch
                {
                    RareCommodity commod = db.RareCommodities.Where(p => p.EDCodeName == collectcargo.Type).First();
                    // Commodity commod = db.Commodities.Where(p => p.EDCodeName == collectcargo.Type).First();
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.Stolen == collectcargo.Stolen))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper() && o.Stolen == collectcargo.Stolen).First();
                        cargoUpdate.Qty = cargoUpdate.Qty + 1;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record because record of matching stolen status not found
                        db.CargoHolds.Add(new EDTraderSQL.CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = 1, AvgPurchasePrice = 0, Stolen = collectcargo.Stolen, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                db.Dispose();
            }
        }
示例#9
0
        // 8.19 MissionFailed
        private void JournalMissionFailed(string jstr)
        {
            MissionFailedEvent missionfailed = JsonConvert.DeserializeObject <MissionFailedEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                if (db.ActiveMissions.Any(o => o.MissionID == missionfailed.MissionID))
                {
                    // Remove Mission
                    db.ActiveMissions.RemoveRange(db.ActiveMissions.Where(o => o.MissionID == missionfailed.MissionID));
                    db.SaveChanges();
                }
                db.Dispose();
            }
        }
示例#10
0
        // 5 Combat
        // 5.3 Died
        private void JournalDied()
        {
            using (var db = new EDTSQLEntities())
            {
                var allrecords = db.CargoHolds;
                foreach (CargoHold item in allrecords)
                {
                    item.StockChecked = false; //false
                }
                db.SaveChanges();

                // Delete Cargo entries not found on load of Journal
                db.CargoHolds.RemoveRange(db.CargoHolds.Where(o => o.StockChecked == false));
                db.SaveChanges();
                db.Dispose();
            }
        }
示例#11
0
        // 8.20 MissionRedirected
        private void JournalMissionRedirected(string jstr)
        {
            MissionRedirectedEvent missionredirect = JsonConvert.DeserializeObject <MissionRedirectedEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                if (db.ActiveMissions.Any(o => o.MissionID == missionredirect.MissionID))
                {
                    // Update Mission record
                    ActiveMission missionupdate = db.ActiveMissions.Where(o => o.MissionID == missionredirect.MissionID).First();
                    missionupdate.DestinationStation = missionredirect.NewDestinationStation;
                    missionupdate.DestinationSystem  = missionredirect.NewDestinationSystem;
                    db.SaveChanges();
                }
                db.Dispose();
            }
        }
示例#12
0
        // 3 Startup
        // 3.1 Cargo
        private void JournalCargo(string jstr)
        {
            CargoEvent cargo = JsonConvert.DeserializeObject <CargoEvent>(jstr);

            // Reset stored list of Cargo
            using (var db = new EDTSQLEntities())
            {
                var allrecords = db.CargoHolds;
                foreach (CargoHold item in allrecords)
                {
                    item.StockChecked = false; //false
                }
                db.SaveChanges();
                DisplayCargo();

                foreach (var inventitem in cargo.Inventory)
                {
                    //Lookup NiceName of Cargo Item from Commodities table
                    Commodity commod = db.Commodities.Where(p => p.EDCodeName == inventitem.Name).First();
                    //Locate Cargo Item in CargoHold table
                    if (db.CargoHolds.Any(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper()))
                    {
                        //Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName.ToUpper() == commod.CommodityName.ToUpper()).First();
                        cargoUpdate.StockChecked = true;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new CargoHold()
                        {
                            CommodityName = commod.CommodityName, Qty = inventitem.Count, AvgPurchasePrice = 0, Stolen = false, StockChecked = true, MissionCargo = false
                        });
                        db.SaveChanges();
                    }
                }
                // Delete Cargo entries not found on load of Journal
                db.CargoHolds.RemoveRange(db.CargoHolds.Where(o => o.StockChecked == false));
                db.SaveChanges();
                db.Dispose();
            }
        }
示例#13
0
        // 3.4 Materials
        private void JournalMaterials(string jstr)
        {
            MaterialsEvent materials = JsonConvert.DeserializeObject <MaterialsEvent>(jstr);

            // Reset stored list of Materials
            using (var db = new EDTSQLEntities())
            {
                if (materials.Raw.Count() > 0 || materials.Manufactured.Count() > 0 || materials.Encoded.Count() > 0)
                {
                    // Delete all existing records
                    db.Materials.RemoveRange(db.Materials);
                    db.SaveChanges();
                    // Add reported materials to table
                    foreach (var item in materials.Raw)
                    {
                        MaterialList matlookup = db.MaterialLists.Where(p => p.EDCodeName == item.Name).First();
                        db.Materials.Add(new Material()
                        {
                            MaterialName = matlookup.MaterialName, Quantity = item.Count, MaterialGroup = "Raw"
                        });
                    }
                    foreach (var item in materials.Manufactured)
                    {
                        MaterialList matlookup = db.MaterialLists.Where(p => p.EDCodeName == item.Name).First();
                        db.Materials.Add(new Material()
                        {
                            MaterialName = matlookup.MaterialName, Quantity = item.Count, MaterialGroup = "Manufactured"
                        });
                    }
                    foreach (var item in materials.Encoded)
                    {
                        MaterialList matlookup = db.MaterialLists.Where(p => p.EDCodeName == item.Name).First();
                        db.Materials.Add(new Material()
                        {
                            MaterialName = matlookup.MaterialName, Quantity = item.Count, MaterialGroup = "Encoded"
                        });
                    }
                    db.SaveChanges();
                }
                db.Dispose();
            }
        }
示例#14
0
        private void ObtainTopProductsDemanded()
        {
            using (var db = new EDTSQLEntities())
            {
                UpdateMonitor("Calculating items in highest demand");

                StarSystem starsystem = db.StarSystems.SingleOrDefault(p => p.SystemName == CurrSystem);                                         // Get System
                Station    station    = db.Stations.SingleOrDefault(o => o.SystemID == starsystem.SystemID && o.StationName == lblStation.Text); // Get Station
                // List of items demanded by this station
                List <MarketDetail> topmarketdemands = db.MarketDetails.Where(n => n.SystemID == starsystem.SystemID && n.StationID == station.StationID && n.DemandStatus > 0).ToList();
                // Sort list by demand level
                topmarketdemands = topmarketdemands.OrderByDescending(s => s.DemandStatus).ToList();

                lvDemand.Items.Clear();                  // Clear the items in the grid

                FillProductDemandList(topmarketdemands); // Fill the list with details of best place to buy the items

                lvDemand.Refresh();                      // Display the items in the grid

                db.Dispose();
            }
        }
示例#15
0
        private void ObtainTopProductsToBuy()
        {
            using (var db = new EDTSQLEntities())
            {
                UpdateMonitor("Calculating best items to buy");

                StarSystem starsystem = db.StarSystems.SingleOrDefault(p => p.SystemName == CurrSystem);                                         // Get System
                Station    station    = db.Stations.SingleOrDefault(o => o.SystemID == starsystem.SystemID && o.StationName == lblStation.Text); // Get Station
                // List of items supplied at this station
                List <MarketDetail> topmarketsupplies = db.MarketDetails.Where(n => n.SystemID == starsystem.SystemID && n.StationID == station.StationID && n.SupplyStatus > 0).ToList();
                // Sort list by supply availability
                topmarketsupplies = topmarketsupplies.OrderByDescending(s => s.SupplyStatus).ToList();

                lvSupply.Items.Clear();                   // Clear the items in the grid

                FillProductSupplyList(topmarketsupplies); // Fill the list with details of best place to sell the items

                lvSupply.Refresh();                       // Display the items in the grid

                db.Dispose();
            }
        }
示例#16
0
        // 4 Travel
        // 4.1 Docked
        private void JournalDocked(string jstr)
        {
            DockedEvent docked = JsonConvert.DeserializeObject <DockedEvent>(jstr);

            //Display System & Station from event
            lblStarSystem.Text = docked.StarSystem;
            CurrSystem         = docked.StarSystem;
            lblStation.Text    = docked.StationName;
            lblEconomy.Text    = docked.StationEconomy_Localised;
            // Check for Station in Database
            using (var db = new EDTSQLEntities())
            {
                StarSystem starsystem = db.StarSystems.SingleOrDefault(p => p.SystemName == docked.StarSystem);
                if (db.Stations.Any(o => o.SystemID == starsystem.SystemID && o.StationName == docked.StationName))
                {
                    //Update Station record
                    Station stationUpdate = db.Stations.Where(p => p.SystemID == starsystem.SystemID && p.StationName == docked.StationName).First();
                    stationUpdate.Economy = docked.StationEconomy_Localised;
                    db.SaveChanges();
                }
                else
                {
                    //Add Station record
                    Station stationAdd = new Station();
                    stationAdd.StationID            = 0;
                    stationAdd.SystemID             = starsystem.SystemID;
                    stationAdd.StationName          = docked.StationName;
                    stationAdd.StationType          = docked.StationType;
                    stationAdd.Economy              = docked.StationEconomy_Localised;
                    stationAdd.BlackMarketAvailable = false;
                    db.Stations.Add(stationAdd);
                    db.SaveChanges();
                    lblDBStations.Text = db.Stations.Count().ToString();
                }
                db.Dispose();
            }
        }
示例#17
0
        // 8 Station Services
        // 8.17 MissionAccepted
        private void JournalMissionAccepted(string jstr)
        {
            MissionAcceptedEvent missionaccept = JsonConvert.DeserializeObject <MissionAcceptedEvent>(jstr);

            using (var db = new EDTSQLEntities())
            {
                if (db.ActiveMissions.Any(o => o.MissionID == missionaccept.MissionID))
                {
                    return;
                }

                DateTimeOffset dto = new DateTimeOffset(missionaccept.getExpiryAsDate());

                if (missionaccept.Commodity_Localised != null)
                {
                    missionaccept.Commodity_Localised = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(missionaccept.Commodity_Localised);
                }

                string MissType = "";
                if (missionaccept.Name.Contains("Collect"))
                {
                    MissType = "Collect";
                    db.ActiveMissions.Add(new ActiveMission()
                    {
                        MissionID = missionaccept.MissionID, MissionCargo = $"{missionaccept.Commodity_Localised} ({missionaccept.Count.ToString()}) - Required", MissionType = MissType, DestinationSystem = missionaccept.DestinationSystem, DestinationStation = missionaccept.DestinationStation, Expiry = Convert.ToInt32(dto.ToUnixTimeSeconds())
                    });
                }
                if (missionaccept.Name.Contains("Delivery"))
                {
                    MissType = "Delivery";
                    db.ActiveMissions.Add(new ActiveMission()
                    {
                        MissionID = missionaccept.MissionID, MissionCargo = $"{missionaccept.Commodity_Localised} ({missionaccept.Count.ToString()})", MissionType = MissType, DestinationSystem = missionaccept.DestinationSystem, DestinationStation = missionaccept.DestinationStation, Expiry = Convert.ToInt32(dto.ToUnixTimeSeconds())
                    });
                }
                if (missionaccept.Name.Contains("Courier"))
                {
                    MissType = "Courier";
                    db.ActiveMissions.Add(new ActiveMission()
                    {
                        MissionID = missionaccept.MissionID, MissionCargo = "Data Only", MissionType = MissType, DestinationSystem = missionaccept.DestinationSystem, DestinationStation = missionaccept.DestinationStation, Expiry = Convert.ToInt32(dto.ToUnixTimeSeconds())
                    });
                }
                if (missionaccept.Name.Contains("Salvage"))
                {
                    MissType = "Salvage";
                    db.ActiveMissions.Add(new ActiveMission()
                    {
                        MissionID = missionaccept.MissionID, MissionCargo = $"{missionaccept.Commodity_Localised} ({missionaccept.Count.ToString()})", MissionType = MissType, DestinationSystem = missionaccept.DestinationSystem, DestinationStation = missionaccept.DestinationStation, Expiry = Convert.ToInt32(dto.ToUnixTimeSeconds())
                    });
                }
                db.SaveChanges();

                if (missionaccept.Name.Contains("Delivery") == true)
                {
                    if (db.CargoHolds.Any(o => o.CommodityName == missionaccept.Commodity_Localised))
                    {
                        // Update CargoHold record
                        CargoHold cargoUpdate = db.CargoHolds.Where(o => o.CommodityName == missionaccept.Commodity_Localised && o.MissionCargo == true).First();
                        cargoUpdate.Qty = cargoUpdate.Qty + missionaccept.Count;
                        db.SaveChanges();
                    }
                    else
                    {
                        //Add CargoHold record
                        db.CargoHolds.Add(new CargoHold()
                        {
                            CommodityName = missionaccept.Commodity_Localised, Qty = missionaccept.Count, AvgPurchasePrice = 0, Stolen = false, StockChecked = true, MissionCargo = true
                        });
                        db.SaveChanges();
                    }
                }
                db.Dispose();
            }
        }
示例#18
0
        private void FillProductSupplyList(List <MarketDetail> sourcelist)
        {
            Dictionary <string, string> StockLevels = new Dictionary <string, string>();

            StockLevels.Add("4", "High");
            StockLevels.Add("2", "Med");
            StockLevels.Add("1", "Low");
            StockLevels.Add("0", "");

            using (var db = new EDTSQLEntities())
            {
                StarSystem currsystem  = db.StarSystems.Single(n => n.SystemName == CurrSystem);    // Get Current System
                Station    currstation = db.Stations.Single(n => n.StationName == lblStation.Text); // Get Current Station

                List <TopDemands> SuppliesWithDemand = new List <TopDemands>();

                int itemsfound = 0;

                foreach (var item in sourcelist)
                {
                    //Find Systems-Stations that need (have Demand for) the product on sale
                    List <MarketDetail> ItemLocationsWithDemand = db.MarketDetails.Where(n => n.CommodityName == item.CommodityName && n.DemandStatus > 0).ToList();

                    List <DemandList> DemandItemList = new List <DemandList>(); // List of Demand Locations for Supply Item with calculated profit
                    foreach (MarketDetail DemandItem in ItemLocationsWithDemand)
                    {
                        StarSystem starsystem = db.StarSystems.Single(n => n.SystemID == DemandItem.SystemID);
                        Station    station    = db.Stations.Single(n => n.StationID == DemandItem.StationID);
                        // Calculate the distance between current location and possible selling system
                        double distance = Program.SystemDistance(currsystem.SpaceX, currsystem.SpaceY, currsystem.SpaceZ, starsystem.SpaceX, starsystem.SpaceY, starsystem.SpaceZ);
                        // Calculate estimated amount of profit per unit
                        int profit = Convert.ToInt16((DemandItem.SellPrice ?? 0) - (item.BuyPrice ?? 0));

                        int sellingprice = Convert.ToInt16(DemandItem.SellPrice ?? 0);
                        DemandItemList.Add(new DemandList {
                            ProductName = DemandItem.CommodityName, SellSystem = starsystem.SystemName, SellStation = station.StationName, Distance = distance, SellPrice = sellingprice, Profit = profit
                        });
                    }
                    // Sort list by amount of profit , distance
                    DemandItemList = DemandItemList.OrderByDescending(s => s.Profit).ThenBy(s => s.Distance).ToList();

                    // Return the best profit item if one exists
                    if (DemandItemList.Count() > 0)
                    {
                        var TopDemandItem = DemandItemList.First();
                        if (TopDemandItem.Profit > 0)
                        {
                            TopDemands TopItem = new TopDemands()
                            {
                                CommodityName = item.CommodityName,
                                SupplyStatus  = item.SupplyStatus.ToString(),
                                BuyPrice      = item.BuyPrice.ToString(),
                                SellSystem    = TopDemandItem.SellSystem,
                                SellSysDist   = TopDemandItem.Distance,
                                SellStation   = TopDemandItem.SellStation,
                                SellPrice     = TopDemandItem.SellPrice.ToString(),
                                Profit        = TopDemandItem.Profit
                            };
                            itemsfound++;
                            lblMonitoredEvent.Text = "Found " + itemsfound + " items";
                            lblMonitoredEvent.Refresh();

                            SuppliesWithDemand.Add(TopItem);
                        }
                    }
                }
                // Sort the List by Supply Status then Profit per unit
                SuppliesWithDemand = SuppliesWithDemand.OrderByDescending(s => s.Profit).ToList();
                // Add the Top 10 to the Supply List
                int i = 1;
                foreach (var prod in SuppliesWithDemand)
                {
                    if (i <= 10)
                    {
                        var listitem = new ListViewItem(new[] { prod.CommodityName, StockLevels[prod.SupplyStatus], prod.BuyPrice, prod.SellSystem, prod.SellSysDist.ToString(), prod.SellStation, prod.SellPrice, prod.Profit.ToString() });
                        lvSupply.Items.Add(listitem);
                        i++;
                    }
                }
                db.Dispose();
            }
        }
示例#19
0
        //4.7 FSDJump
        private void JournalFSDJump(string jstr)
        {
            FSDJumpEvent fsdjump = JsonConvert.DeserializeObject <FSDJumpEvent>(jstr);

            lblStarSystem.Text = fsdjump.StarSystem;
            CurrSystem         = fsdjump.StarSystem;
            lblStation.Text    = "IN SPACE";
            lblFaction.Text    = fsdjump.SystemFaction;
            lblEconomy.Text    = "";
            // Check for System in Database
            using (var db = new EDTSQLEntities())
            {
                if (db.StarSystems.Any(o => o.SystemName == fsdjump.StarSystem))
                {
                    StarSystem starsystem = db.StarSystems.SingleOrDefault(p => p.SystemName == fsdjump.StarSystem);
                    //Delete all existing Factions in System
                    if (fsdjump.Factions != null)
                    {
                        db.Factions.RemoveRange(db.Factions.Where(x => x.StarSystemID == starsystem.SystemID));
                        db.SaveChanges();

                        //Store array of Factions present in System
                        foreach (var item in fsdjump.Factions)
                        {
                            Faction addFact = new Faction();
                            addFact.SSIDFaction  = starsystem.SystemID.ToString() + "-" + item.Name;
                            addFact.StarSystemID = starsystem.SystemID;
                            addFact.FactionName  = item.Name;
                            db.Factions.Add(addFact);
                        }
                        db.SaveChanges();
                    }

                    //Update System record
                    StarSystem systemUpdate = db.StarSystems.Where(p => p.SystemName == fsdjump.StarSystem).First();
                    systemUpdate.Allegiance    = fsdjump.SystemAllegiance;
                    systemUpdate.Economy       = fsdjump.SystemEconomy_Localised;
                    systemUpdate.Government    = fsdjump.SystemGovernment_Localised;
                    systemUpdate.SystemFaction = fsdjump.SystemFaction;
                    systemUpdate.TimesVisited  = systemUpdate.TimesVisited + 1;
                    db.SaveChanges();
                    lblStarSystem.Text = lblStarSystem.Text + " = Visits (" + systemUpdate.TimesVisited.ToString() + ")";
                }
                else
                {
                    //Add System record
                    StarSystem systemAdd = new StarSystem();
                    systemAdd.SystemID      = 0;
                    systemAdd.SystemName    = fsdjump.StarSystem;
                    systemAdd.SpaceX        = fsdjump.StarPos[0];
                    systemAdd.SpaceY        = fsdjump.StarPos[1];
                    systemAdd.SpaceZ        = fsdjump.StarPos[2];
                    systemAdd.Allegiance    = fsdjump.SystemAllegiance;
                    systemAdd.Economy       = fsdjump.SystemEconomy_Localised;
                    systemAdd.Government    = fsdjump.SystemGovernment_Localised;
                    systemAdd.SystemFaction = fsdjump.SystemFaction;
                    systemAdd.TimesVisited  = 1;
                    db.StarSystems.Add(systemAdd);
                    db.SaveChanges();
                    lblDBSystems.Text  = db.StarSystems.Count().ToString();
                    lblStarSystem.Text = lblStarSystem.Text + " = Visits (1)";

                    StarSystem starsystem = db.StarSystems.SingleOrDefault(p => p.SystemName == fsdjump.StarSystem);
                    if (fsdjump.Factions != null)
                    {
                        //Store array of Factions present in System
                        foreach (var item in fsdjump.Factions)
                        {
                            Faction addFact = new Faction();
                            addFact.SSIDFaction  = starsystem.SystemID.ToString() + "-" + item.Name;
                            addFact.StarSystemID = starsystem.SystemID;
                            addFact.FactionName  = item.Name;
                            db.Factions.Add(addFact);
                        }
                        db.SaveChanges();
                    }
                }
                db.Dispose();
            }
        }
示例#20
0
        private void DisplayMission()
        {
            // Current date & time as seconds
            DateTimeOffset dto         = new DateTimeOffset(DateTime.Now);
            var            currseconds = dto.ToUnixTimeSeconds();

            using (var db = new EDTSQLEntities())
            {
                if (db.StarSystems.Count() == 0)
                {
                    return;
                }
                if (CurrSystem != null)
                {
                    if (CurrSystem.Contains("=") == true)
                    {
                        int index = CurrSystem.IndexOf("=");
                        CurrSystem = (index > 1 ? CurrSystem.Substring(0, index - 1) : null);
                    }
                }
                if (CurrSystem != null)
                {
                    StarSystem currsystem = new StarSystem();
                    if (CurrSystem == "" | db.StarSystems.Count(n => n.SystemName == CurrSystem) == 0)
                    {
                        currsystem = new StarSystem()
                        {
                            SpaceX = 0, SpaceY = 0, SpaceZ = 0
                        };
                    }
                    else
                    {
                        currsystem = db.StarSystems.Single(n => n.SystemName == CurrSystem); // Get Current System
                    }

                    lvMissions.Items.Clear();

                    if (db.ActiveMissions.Count() > 0)
                    {
                        foreach (ActiveMission amitem in db.ActiveMissions)
                        {
                            var    remainingtime = amitem.Expiry.Value - currseconds;
                            var    timeSpan      = TimeSpan.FromSeconds(remainingtime);
                            int    dy            = timeSpan.Days;
                            int    hr            = timeSpan.Hours;
                            int    mn            = timeSpan.Minutes;
                            int    sec           = timeSpan.Seconds;
                            string expiresIn     = "D:" + dy + " H:" + hr + " M:" + mn + " S:" + sec;

                            if (db.StarSystems.Any(o => o.SystemName == amitem.DestinationSystem))
                            {
                                StarSystem starsystem = db.StarSystems.Single(n => n.SystemName == amitem.DestinationSystem);
                                // Calculate the distance between current location and possible selling system
                                double distance = Program.SystemDistance(currsystem.SpaceX, currsystem.SpaceY, currsystem.SpaceZ, starsystem.SpaceX, starsystem.SpaceY, starsystem.SpaceZ);

                                var amlistitem = new ListViewItem(new[] { amitem.MissionID.ToString(), amitem.MissionType, amitem.MissionCargo, amitem.DestinationSystem, distance.ToString(), amitem.DestinationStation, expiresIn });
                                lvMissions.Items.Add(amlistitem);
                            }
                            else
                            {
                                var amlistitem = new ListViewItem(new[] { amitem.MissionID.ToString(), amitem.MissionType, amitem.MissionCargo, amitem.DestinationSystem, "", amitem.DestinationStation, expiresIn });
                                lvMissions.Items.Add(amlistitem);
                            }
                        }
                    }
                    lvMissions.Sort();
                    lvMissions.Refresh();
                }
            }
        }
示例#21
0
        private void DisplayCargo()
        {
            using (var db = new EDTSQLEntities())
            {
                if (db.StarSystems.Count() == 0)
                {
                    return;
                }
                if (CurrSystem != null)
                {
                    if (CurrSystem.Contains("=") == true)
                    {
                        int index = CurrSystem.IndexOf("=");
                        CurrSystem = (index > 1 ? CurrSystem.Substring(0, index - 1) : null);
                    }
                }
                if (CurrSystem != null)
                {
                    StarSystem currsystem = new StarSystem();
                    if (CurrSystem == "" | db.StarSystems.Count(n => n.SystemName == CurrSystem) == 0)
                    {
                        currsystem = new StarSystem()
                        {
                            SpaceX = 0, SpaceY = 0, SpaceZ = 0
                        };
                    }
                    else
                    {
                        currsystem = db.StarSystems.Single(n => n.SystemName == CurrSystem); // Get Current System
                    }

                    lvCargo.Items.Clear();

                    if (db.CargoHolds.Count() > 0)
                    {
                        foreach (CargoHold chitem in db.CargoHolds)
                        {
                            //Find Systems-Stations that need (have Demand for) the product on sale
                            List <MarketDetail> possdemand = db.MarketDetails.Where(n => n.CommodityName == chitem.CommodityName && n.DemandStatus > 0).ToList();

                            List <DemandList> demandlist = new List <DemandList>();
                            foreach (MarketDetail possitem in possdemand)
                            {
                                StarSystem starsystem = db.StarSystems.Single(n => n.SystemID == possitem.SystemID);
                                Station    station    = db.Stations.Single(n => n.StationID == possitem.StationID);
                                // Calculate the distance between current location and possible selling system
                                double distance = Program.SystemDistance(currsystem.SpaceX, currsystem.SpaceY, currsystem.SpaceZ, starsystem.SpaceX, starsystem.SpaceY, starsystem.SpaceZ);
                                // Calculate estimated amount of profit per unit
                                int profit = Convert.ToInt16((possitem.SellPrice ?? 0) - (chitem.AvgPurchasePrice ?? 0));

                                int sellingprice = Convert.ToInt16(possitem.SellPrice ?? 0);
                                demandlist.Add(new DemandList {
                                    ProductName = possitem.CommodityName, SellSystem = starsystem.SystemName, SellStation = station.StationName, Distance = distance, SellPrice = sellingprice, Profit = profit
                                });
                            }
                            // Sort list by amount of profit , distance
                            demandlist = demandlist.OrderByDescending(s => s.Profit).ThenBy(s => s.Distance).ToList();

                            // Return the best profit item
                            var cargostatus = "Tradable";
                            if (chitem.Stolen == true)
                            {
                                cargostatus = "Stolen";
                            }
                            else
                            {
                                if (chitem.MissionCargo == true)
                                {
                                    cargostatus = "Mission";
                                }
                            }
                            if (demandlist.Count() > 0)
                            {
                                var topdemand = demandlist.First();
                                // var chlistitem = new ListViewItem(new[] { chitem.CommodityName, chitem.Qty.ToString(), chitem.AvgPurchasePrice.ToString(), chitem.Stolen.ToString(), topdemand.SellSystem, topdemand.Distance.ToString(), topdemand.SellStation, topdemand.Profit.ToString() });
                                var chlistitem = new ListViewItem(new[] { chitem.CommodityName, chitem.Qty.ToString(), chitem.AvgPurchasePrice.ToString(), cargostatus, topdemand.SellSystem, topdemand.Distance.ToString(), topdemand.SellStation, topdemand.Profit.ToString() });
                                lvCargo.Items.Add(chlistitem);
                            }
                            else
                            {
                                // var chlistitem = new ListViewItem(new[] { chitem.CommodityName, chitem.Qty.ToString(), chitem.AvgPurchasePrice.ToString(), chitem.Stolen.ToString(), "", "0.0", "", "0" });
                                var chlistitem = new ListViewItem(new[] { chitem.CommodityName, chitem.Qty.ToString(), chitem.AvgPurchasePrice.ToString(), cargostatus, "", "0.0", "", "0" });
                                lvCargo.Items.Add(chlistitem);
                            }
                        }
                    }
                    lvCargo.Refresh();
                }
            }
        }
示例#22
0
        // 4.9 Location
        private void JournalLocation(string jstr)
        {
            LocationEvent location = JsonConvert.DeserializeObject <LocationEvent>(jstr);

            //Test for in Training
            if (location.StarSystem == "Training")
            {
                return;
            }

            //Display System & Station from event
            lblStarSystem.Text = location.StarSystem;
            CurrSystem         = location.StarSystem;
            lblStation.Text    = location.StationName;

            //Update System Faction and display
            using (var db = new EDTSQLEntities())
            {
                lblFaction.Text = location.SystemFaction;
                try
                {
                    try
                    {
                        StarSystem ssystem = db.StarSystems.Single(p => p.SystemName == location.StarSystem);
                    }
                    catch
                    {
                        //Add System record
                        StarSystem systemAdd = new StarSystem();
                        systemAdd.SystemID      = 0;
                        systemAdd.SystemName    = location.StarSystem;
                        systemAdd.SpaceX        = location.StarPos[0];
                        systemAdd.SpaceY        = location.StarPos[1];
                        systemAdd.SpaceZ        = location.StarPos[2];
                        systemAdd.Allegiance    = location.SystemAllegiance;
                        systemAdd.Economy       = location.SystemEconomy_Localised;
                        systemAdd.Government    = location.SystemGovernment_Localised;
                        systemAdd.SystemFaction = location.SystemFaction;
                        db.StarSystems.Add(systemAdd);
                        db.SaveChanges();
                        lblDBSystems.Text = db.StarSystems.Count().ToString();
                    }
                    StarSystem starsystem = db.StarSystems.SingleOrDefault(p => p.SystemName == location.StarSystem);
                    if (starsystem.SystemFaction != location.SystemFaction)
                    {
                        starsystem.SystemFaction = location.SystemFaction;
                        db.SaveChanges();
                    }

                    //Delete all existing Factions in System
                    if (location.Factions != null)
                    {
                        db.Factions.RemoveRange(db.Factions.Where(x => x.StarSystemID == starsystem.SystemID));
                        db.SaveChanges();
                        //Store array of Factions present in System
                        foreach (var item in location.Factions)
                        {
                            Faction addFact = new Faction();
                            addFact.SSIDFaction  = starsystem.SystemID.ToString() + "-" + item.Name;
                            addFact.StarSystemID = starsystem.SystemID;
                            addFact.FactionName  = item.Name;
                            db.Factions.Add(addFact);
                        }
                        db.SaveChanges();
                    }
                    //Display current System Faction
                    lblFaction.Text = starsystem.SystemFaction;
                }
                catch
                {
                    lblStarSystem.Text = lblStarSystem.Text + " = not in DataBase";
                    lblStation.Text    = "";
                    lblFaction.Text    = "";
                }
                db.Dispose();
            }
        }
示例#23
0
        // Default Data functions
        private static void PopulateDefaultData()
        {
            // Clear default tables and adds starting data from textfiles
            using (var db = new EDTSQLEntities())
            {
                //Delete Commodities
                db.Commodities.RemoveRange(db.Commodities);
                db.SaveChanges();
                //Delete Rares
                db.RareCommodities.RemoveRange(db.RareCommodities);
                db.SaveChanges();
                //Delete CommodityGroups
                db.CommodityGroups.RemoveRange(db.CommodityGroups);
                db.SaveChanges();
                //Delete Materials
                db.MaterialLists.RemoveRange(db.MaterialLists);
                db.SaveChanges();

                var assembly     = Assembly.GetExecutingAssembly();
                var resourceName = "";
                //Read and process the standard Commodities file
                resourceName = "EDTraderSQL.DefaultCommodities.txt";

                using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string line = null;

                        while ((line = reader.ReadLine()) != null)
                        {
                            CommodityData cd = JsonConvert.DeserializeObject <CommodityData>(line);
                            db.CommodityGroups.Add(new CommodityGroup()
                            {
                                CommodGroupName = cd.Name
                            });
                            db.SaveChanges();

                            foreach (var item in cd.Commodities)
                            {
                                db.Commodities.Add(new Commodity()
                                {
                                    CommodGroupName = cd.Name, CommodityName = item.Name, EDCodeName = item.EDCode
                                });
                            }
                        }
                        db.SaveChanges();
                        reader.Dispose();
                        stream.Dispose();
                    }

                //Read and process the Rare Commodities file
                resourceName = "EDTraderSQL.DefaultRares.txt";

                using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string line = null;

                        //Added to cover the Rares that we do not know the group of
                        db.CommodityGroups.Add(new CommodityGroup()
                        {
                            CommodGroupName = "NotKnown"
                        });
                        db.SaveChanges();

                        while ((line = reader.ReadLine()) != null)
                        {
                            RaresData rd = JsonConvert.DeserializeObject <RaresData>(line);

                            foreach (var item in rd.Rares)
                            {
                                db.RareCommodities.Add(new RareCommodity()
                                {
                                    CommodGroupName = rd.Name, CommodityName = item.Name, EDCodeName = item.EDCode
                                });
                            }
                        }
                        db.SaveChanges();
                        reader.Dispose();
                        stream.Dispose();
                    }

                //Read and process the Materials file
                resourceName = "EDTraderSQL.DefaultMaterials.txt";

                using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string line = null;

                        while ((line = reader.ReadLine()) != null)
                        {
                            MaterialData md = JsonConvert.DeserializeObject <MaterialData>(line);

                            foreach (var item in md.Items)
                            {
                                db.MaterialLists.Add(new MaterialList()
                                {
                                    MaterialGroup = md.Name, MaterialName = item.Name, EDCodeName = item.EDCode
                                });
                            }
                        }
                        db.SaveChanges();
                        reader.Dispose();
                        stream.Dispose();
                    }
                db.Dispose();
            }
        }
示例#24
0
        } // ReadJournalLines() End

        private void ReadMarketLines()
        {
            Dictionary <string, string> CommodityInGroup = new Dictionary <string, string>();
            Dictionary <string, string> RareInGroup      = new Dictionary <string, string>();

            using (var db = new EDTSQLEntities())
            {
                foreach (var commod in db.Commodities)
                {
                    CommodityInGroup.Add(commod.CommodityName.ToUpper(), commod.CommodGroupName);
                }
                foreach (var rare in db.RareCommodities)
                {
                    RareInGroup.Add(rare.CommodityName.ToUpper(), rare.CommodGroupName);
                }
                db.Dispose();
            }
            Dictionary <string, int> StockLevels = new Dictionary <string, int>();

            StockLevels.Add("High", 4);
            StockLevels.Add("Med", 2);
            StockLevels.Add("Low", 1);
            StockLevels.Add("", 0);

            using (var sr = new StreamReader(MarketDump))
            {
                var reader = new CsvReader(sr);
                reader.Configuration.HasHeaderRecord = true;
                reader.Configuration.Delimiter       = ";";
                List <MarketInfo> records = new List <MarketInfo>();
                bool     setdate          = false;
                DateTime rectime          = DateTime.UtcNow;
                // string strrectime = rectime.ToString();
                int xxx = 0;
                while (reader.Read())
                {
                    if (setdate == false)
                    {
                        string strdate     = reader.GetField <string>(9).Substring(0, 10);
                        string strtime     = reader.GetField <string>(9).Substring(11, 8);
                        string strdatetime = strdate + " " + strtime;
                        rectime = DateTime.ParseExact(strdatetime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                        // strrectime = rectime.ToString();
                        setdate = true;
                    }

                    MarketInfo addrec = new MarketInfo();
                    addrec.StarSystem = reader.GetField <string>(0);
                    addrec.Station    = reader.GetField <string>(1);
                    addrec.Commodity  = reader.GetField <string>(2);
                    if (int.TryParse(reader.GetField <string>(3), out xxx))
                    {
                        addrec.SellPrice = int.Parse(reader.GetField <string>(3));
                    }
                    else
                    {
                        addrec.SellPrice = xxx;
                    }
                    if (int.TryParse(reader.GetField <string>(4), out xxx))
                    {
                        addrec.BuyPrice = int.Parse(reader.GetField <string>(4));
                    }
                    else
                    {
                        addrec.BuyPrice = xxx;
                    }
                    addrec.DemandLevel = reader.GetField <string>(6);
                    addrec.SupplyLevel = reader.GetField <string>(8);
                    // addrec.LogDate = strrectime;
                    addrec.LogDate = rectime;
                    records.Add(addrec);
                }

                //Read System & Station so previous market entries can be removed
                if (records.Count > 0)
                {
                    MarketInfo getLocation = records.First();
                    using (var db = new EDTSQLEntities())
                    {
                        StarSystem starsystem = db.StarSystems.SingleOrDefault(p => p.SystemName == getLocation.StarSystem);
                        Station    station    = db.Stations.SingleOrDefault(o => o.StationName == getLocation.Station);
                        UpdateMonitor("Market Data - Update found");

                        if (station == null)
                        {
                            UpdateMonitor("Market Data - Station not yet known");
                            db.Dispose();
                        }
                        else
                        {
                            db.MarketDetails.RemoveRange(db.MarketDetails.Where(x => x.SystemID == starsystem.SystemID && x.StationID == station.StationID));
                            db.SaveChanges();

                            foreach (MarketInfo marketcommodity in records)
                            {
                                if (CommodityInGroup.ContainsKey(marketcommodity.Commodity.ToUpper()))
                                {
                                    //Add new Market detail lines
                                    db.MarketDetails.Add(new MarketDetail()
                                    {
                                        SystemID        = starsystem.SystemID,
                                        StationID       = station.StationID,
                                        CommodGroupName = CommodityInGroup[marketcommodity.Commodity.ToUpper()],
                                        CommodityName   = marketcommodity.Commodity,
                                        SellPrice       = marketcommodity.SellPrice,
                                        BuyPrice        = marketcommodity.BuyPrice,
                                        DemandStatus    = StockLevels[marketcommodity.DemandLevel],
                                        SupplyStatus    = StockLevels[marketcommodity.SupplyLevel],
                                        EntryDate       = marketcommodity.LogDate
                                    });
                                }
                                else
                                {
                                    //Add new Market detail lines
                                    db.MarketDetails.Add(new MarketDetail()
                                    {
                                        SystemID        = starsystem.SystemID,
                                        StationID       = station.StationID,
                                        CommodGroupName = RareInGroup[marketcommodity.Commodity.ToUpper()],
                                        CommodityName   = marketcommodity.Commodity,
                                        SellPrice       = marketcommodity.SellPrice,
                                        BuyPrice        = marketcommodity.BuyPrice,
                                        DemandStatus    = StockLevels[marketcommodity.DemandLevel],
                                        SupplyStatus    = StockLevels[marketcommodity.SupplyLevel],
                                        EntryDate       = marketcommodity.LogDate
                                    });
                                }
                            }
                            UpdateMonitor("Market Data - Updated");
                            db.SaveChanges();
                            db.Dispose();
                            MarketDirty         = false;
                            btnMDirty.BackColor = Color.Red;
                            btnMDirty.Refresh();
                            //File.Delete(MarketDump);
                        }
                    }
                    sr.Dispose();

                    ObtainTopProductsToBuy();
                    ObtainTopProductsDemanded();
                }
                DisplayCargo();
            }
        } // ReadMarketLines() End