private void DisplayStation(StationStats station, int m, ref int ycursor, int stationxicon, int stationlabel)
    {
        int stationavail    = station.AvailableCarts;
        int stationassigned = station.AssignedCarts;

        this.manager.AddIcon("stationicon" + m, "Minecart Load", Color.white, stationxicon, ycursor);
        this.manager.AddBigLabel("stationnetwork" + m, (!string.IsNullOrEmpty(station.StationName) ? station.StationName : "UNNAMED") + " - " + station.NetworkID, station.StationFull <= 0 ? Color.white : Color.red, stationlabel, ycursor);
        this.manager.AddBigLabel("stationcarts" + m, "Carts: " + stationavail.ToString() + " / " + stationassigned.ToString(), stationavail > stationassigned ? Color.green : stationavail == stationassigned ? Color.white : Color.red, stationlabel + 350, ycursor);
        ycursor += 60;
    }
    public void Read(NetIncomingMessage message)
    {
        // Track Networks
        this.NetworkCount = message.ReadInt32();
        this.NetworkStats = new List <TrackNetworkStats>(this.NetworkCount);
        for (int n = 0; n < NetworkCount; n++)
        {
            TrackNetworkStats stats = new TrackNetworkStats();
            stats.Read(message);
            this.NetworkStats.Add(stats);
        }

        // Stations
        this.StationCount = message.ReadInt32();
        if (this.StationCount > 0)
        {
            this.Stations = new List <StationStats>(this.StationCount);
            for (int n = 0; n < StationCount; n++)
            {
                StationStats stats = new StationStats();
                stats.Read(message);
                this.Stations.Add(stats);
            }
        }

        ReadRegistries(message, true);
        ReadRegistries(message, false);

        // Carts
        this.CartCount = message.ReadInt32();
        if (this.CartCount > 0)
        {
            this.Carts = new List <CartStats>(this.CartCount);
            for (int n = 0; n < CartCount; n++)
            {
                CartStats stats = new CartStats();
                stats.Read(message);
                this.Carts.Add(stats);
            }
        }

        // Displayed Cart
        int count = message.ReadInt32();

        CartInventory = new List <ItemBase>(count);
        for (int n = 0; n < count; n++)
        {
            ItemBase item;
            item = ItemReader(message);
            if (item != null)
            {
                CartInventory.Add(item);
            }
        }
    }
        private void GetAllStatsByStation(Project currentProject)
        {
            try {
                foreach (Station st in currentProject.StationsList)
                {
                    StationStats stst = new StationStats(st.Guid, st.StationID);

                    foreach (string s in SpeciesInProject(currentProject))                   //SpeciesInStation(st))
                    {
                        stst.SpeciesStats.Add(StatsByStation(s, st));
                    }

                    _allStatsByStation.Add(stst);
                }
            } catch (Exception ex) {
                throw ex;
            }
        }
    private void SpawnTrackNetworks(FreightSystemMonitor monitor)
    {
        this.manager.SetTitle("Track Systems");
        this.manager.AddButton("allnetworks", "Global Inventory", buttonx2, 0);
        this.manager.AddButton("selnetwork", "Select Network", buttonx3, 0);
        this.manager.AddButton("tracknetworks", "Network Status", buttonx4, 0);
        this.manager.AddButton("viewinventory", "View Inventory", buttonx5, 0);

        int ycursor      = 65;
        int trackiconx   = globalxoffset + 175;
        int trackxoffset = trackiconx + 65;
        int tracklabel   = trackxoffset + 250;
        int stationxicon = trackiconx + 50;
        int stationlabel = stationxicon + 65;
        int cartxicon    = stationxicon + 50;
        int cartlabel    = cartxicon + 65;
        int invxicon     = cartxicon + 50;
        int invlabel     = invxicon + 65;

        if (NetworkSync.TrackNetworks == null)
        {
            SystemMonitorWindow.RequestTrackNetworks(this.TrackNetworkDisplay, this.StationDisplay, this.CartDisplay, WorldScript.mLocalPlayer, monitor);
        }

        //int networkcount = FreightCartManager.instance.GlobalTrackNetworks.Count;

        if (NetworkSync.TrackNetworks != null && NetworkSync.TrackNetworks.NetworkCount > 0)
        {
            for (int n = 0; n < NetworkSync.TrackNetworks.NetworkCount; n++)
            {
                TrackNetworkStats network = NetworkSync.TrackNetworks.NetworkStats[n];
                if (network == null)
                {
                    continue;
                }
                this.DisplayTrackNetworks(network, n, ref ycursor, trackiconx, trackxoffset, tracklabel);

                if (this.TrackNetworkDisplay == n)
                {
                    List <StationStats> stations = NetworkSync.TrackNetworks.Stations;
                    for (int m = 0; m < NetworkSync.TrackNetworks.StationCount; m++)
                    {
                        StationStats station = NetworkSync.TrackNetworks.Stations[m];
                        this.DisplayStation(station, m, ref ycursor, stationxicon, stationlabel);

                        if (this.StationDisplay == m)
                        {
                            // How do I network this? ...
                            //this.manager.AddButton("addcart", "Add Cart", stationlabel + 475, ycursor - 60);
                            //this.manager.AddButton("removecart", "Remove Cart", stationlabel + 475, ycursor - 10);
                            //this.CurrentStation = station;

                            //List<FreightRegistry> LocalDeficits = new List<FreightRegistry>();
                            //List<FreightRegistry> LocalSurplus = new List<FreightRegistry>();
                            //if (station.massStorageCrate != null)
                            //{
                            //    LocalDeficits = FreightCartManager.instance.GetLocalDeficit(station.NetworkID, station.massStorageCrate);
                            //    LocalSurplus = FreightCartManager.instance.GetLocalSurplus(station.NetworkID, station.massStorageCrate);
                            //}
                            //else if (station.HopperInterface != null)
                            //{
                            //    LocalDeficits = this.FreightListingConversion(station.HopperInterface.FreightRequests.OrderByDescending(x => x.Quantity).Take(3).ToList());
                            //    LocalSurplus = this.FreightListingConversion(station.HopperInterface.FreightOfferings.OrderByDescending(x => x.Quantity).Take(3).ToList());
                            //}
                            //else if (station.AttachedInterface != null)
                            //{
                            //    LocalDeficits = this.FreightListingConversion(station.AttachedInterface.FreightRequests.OrderByDescending(x => x.Quantity).Take(3).ToList());
                            //    LocalSurplus = this.FreightListingConversion(station.AttachedInterface.FreightOfferings.OrderByDescending(x => x.Quantity).Take(3).ToList());
                            //}
                            this.DisplayDefSur(ref ycursor, stationlabel);

                            for (int p = 0; p < NetworkSync.TrackNetworks.CartCount; p++)
                            {
                                CartStats cart = NetworkSync.TrackNetworks.Carts[p];
                                this.DisplayCart(cart, p, ref ycursor, cartlabel, cartxicon);

                                if (p == CartDisplay)
                                {
                                    this.DisplayCartInventory(cart, ref ycursor, invxicon, invlabel);
                                }
                            }
                        }
                    }
                    //Insert Tour cart staion listing here
                }
            }
        }
        else if (WorldScript.mbIsServer || (NetworkSync.TrackNetworks != null && NetworkSync.TrackNetworks.NetworkCount == 0))
        {
            this.manager.AddBigLabel("notracknetworks", "No track networks found...", Color.red, 225, 150);
        }
        else
        {
            this.manager.AddBigLabel("notracknetworks", "Waiting for server...", Color.red, 225, 150);
        }
    }
        private void WriteGridAbundances(Project currentProject, string shapefileName)
        {
            try {
                List <IPolygon> projectGrids = new List <IPolygon>();
                General_queries projq        = new General_queries(currentProject);

                foreach (Station st in currentProject.StationsList)
                {
                    IPolygon     grid             = st.Grid;
                    StationStats tempStationStats = new StationStats(st.Guid, st.StationID);

                    foreach (StationStats stst in projq.AllStatsByStation)
                    {
                        if (stst.StationGUID == st.Guid)
                        {
                            tempStationStats = stst;
                            grid.UserData    = tempStationStats;
                        }
                    }

                    projectGrids.Add(grid);
                }

                GeometryCollection gc = new GeometryCollection(projectGrids.ToArray());

                //Open Writer
                ShapefileWriter shpWriter = new ShapefileWriter();
                shpWriter.Write(shapefileName, gc);

                //Create Header & Columns for points
                DbaseFileHeader dbfHeader = new DbaseFileHeader();


                dbfHeader.AddColumn("Station_ID", 'C', 20, 0);
                //One column for each species in project
                foreach (SpeciesStats spcst in projq.AllStatsBySpecies)
                {
                    dbfHeader.AddColumn(spcst.SpeciesName, 'N', 20, 0);
                }

                dbfHeader.NumRecords = gc.Count;

                //DBF Writer
                DbaseFileWriter dbfWriter = new DbaseFileWriter(shapefileName + ".dbf");
                dbfWriter.Write(dbfHeader);

                //Loop through Business Object to get Features
                foreach (IPolygon p in gc.Geometries)
                {
                    StationStats data = (StationStats)p.UserData;


                    ArrayList columnValues = new System.Collections.ArrayList();
                    //Add Values

                    columnValues.Add(data.StationID);
                    foreach (SpeciesStats s in data.SpeciesStats)
                    {
                        columnValues.Add(s.SpeciesPictures);
                    }

                    dbfWriter.Write(columnValues);
                }

                //Close File
                dbfWriter.Close();
            } catch (Exception ex) {
                throw ex;
            }
        }