Exemple #1
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();
                }
            }
        }
Exemple #2
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();
                }
            }
        }