/// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="direction">The direction which applies to this section.</param>
 /// <param name="map">The locations within this section.</param>
 public TimetableSectionModel(Direction direction, LocationCollection map)
 {
     Direction     = direction;
     LocationMap   = map;
     Locations     = new LocationDisplayModelCollection();
     TrainSegments = new TrainSegmentModelCollection();
 }
Example #2
0
        public void DataGridViewExtensionsClass_AddAndPopulateToWorkRowMethod_ThrowsArgumentNullException_IfSecondParameterIsNull()
        {
            TrainSegmentModelCollection testParam1 = null;
            int testParam2 = _rnd.Next();
            int testParam3 = _rnd.Next();

            using (Font testParam4 = new Font("Arial", 10))
                using (DataGridView testObject = new DataGridView())
                {
                    testObject.AddAndPopulateToWorkRow(testParam1, testParam2, testParam3, testParam4);

                    Assert.Fail();
                }
        }
Example #3
0
        public void DataGridViewExtensionsClass_AddAndPopulateLocationRowsMethod_ThrowsArgumentNullException_IfThirdParameterIsNull()
        {
            IEnumerable <LocationDisplayModel> testParam1 = Array.Empty <LocationDisplayModel>();
            TrainSegmentModelCollection        testParam2 = null;
            int testParam3 = _rnd.Next();
            int testParam4 = _rnd.Next();
            int testParam5 = _rnd.Next();

            using (Font testParam6 = new Font("Arial", 8))
                using (Font testParam7 = new Font("Arial", 10))
                    using (DataGridView testObject = new DataGridView())
                    {
                        testObject.AddAndPopulateLocationRows(testParam1, testParam2, testParam3, testParam4, testParam5, testParam6, testParam7);

                        Assert.Fail();
                    }
        }
Example #4
0
        public void DataGridViewExtensionsClass_AddAndPopulateToWorkRowMethod_ThrowsArgumentNullExceptionWithCorrectParamNameProperty_IfSecondParameterIsNull()
        {
            TrainSegmentModelCollection testParam1 = null;
            int testParam2 = _rnd.Next();
            int testParam3 = _rnd.Next();

            using (Font testParam4 = new Font("Arial", 10))
                using (DataGridView testObject = new DataGridView())
                {
                    try
                    {
                        testObject.AddAndPopulateToWorkRow(testParam1, testParam2, testParam3, testParam4);
                        Assert.Fail();
                    }
                    catch (ArgumentNullException ex)
                    {
                        Assert.AreEqual("segments", ex.ParamName);
                    }
                }
        }
Example #5
0
        public void DataGridViewExtensionsClass_AddAndPopulateLocationRowsMethod_ThrowsArgumentNullExceptionWithCorrectParamNameProperty_IfSecondParameterIsNull()
        {
            IEnumerable <LocationDisplayModel> testParam1 = null;
            TrainSegmentModelCollection        testParam2 = new TrainSegmentModelCollection();
            int testParam3 = _rnd.Next();
            int testParam4 = _rnd.Next();
            int testParam5 = _rnd.Next();

            using (Font testParam6 = new Font("Arial", 8))
                using (Font testParam7 = new Font("Arial", 10))
                    using (DataGridView testObject = new DataGridView())
                    {
                        try
                        {
                            testObject.AddAndPopulateLocationRows(testParam1, testParam2, testParam3, testParam4, testParam5, testParam6, testParam7);
                            Assert.Fail();
                        }
                        catch (ArgumentNullException ex)
                        {
                            Assert.AreEqual("locations", ex.ParamName);
                        }
                    }
        }
Example #6
0
        /// <summary>
        /// Populate a grid with location rows and train details.  The grid must have at least as many columns as there are trains.
        /// </summary>
        /// <param name="grid">The grid to populate.</param>
        /// <param name="locations">The list of location display rows.</param>
        /// <param name="segments">The list of train column segments</param>
        /// <param name="locationIdColIdx">The index of the location ID code column.</param>
        /// <param name="locationNameColIdx">The index of the location name column.</param>
        /// <param name="locationADSymColIdx">The index of the row arrival/departure symbol column.</param>
        /// <param name="stoppingFont">The font to display stopping times in.</param>
        /// <param name="passingFont">The font to display passing times in.</param>
        /// <exception cref="InvalidOperationException">Thrown if the grid does not contain enough columns to display the number of train segments passed in.</exception>
        public static void AddAndPopulateLocationRows(this DataGridView grid, IEnumerable <LocationDisplayModel> locations, TrainSegmentModelCollection segments, int locationIdColIdx,
                                                      int locationNameColIdx, int locationADSymColIdx, Font stoppingFont, Font passingFont)
        {
            if (grid is null)
            {
                throw new ArgumentNullException(nameof(grid));
            }
            if (segments is null)
            {
                throw new ArgumentNullException(nameof(segments));
            }
            if (locations is null)
            {
                throw new ArgumentNullException(nameof(locations));
            }

            ColumnCountCheck(grid, locationADSymColIdx, segments.Count);
            foreach (var loc in locations)
            {
                int idx = grid.Rows.Add();
                grid[locationIdColIdx, idx].Value    = loc.LocationKey;
                grid[locationNameColIdx, idx].Value  = loc.EditorDisplayName;
                grid[locationADSymColIdx, idx].Value = loc.ArrivalDepartureLabel;
                for (int i = 0; i < segments.Count; ++i)
                {
                    if (segments[i].TimingsIndex.ContainsKey(loc.LocationKey))
                    {
                        grid[locationADSymColIdx + i + 1, idx].Value = segments[i].TimingsIndex[loc.LocationKey].DisplayedText;
                        if (segments[i].TimingsIndex[loc.LocationKey] is TrainLocationTimeModel tltm && !tltm.IsPassingTime)
                        {
                            grid[locationADSymColIdx + i + 1, idx].Style.Font = stoppingFont;
                        }
                        else
                        {
                            grid[locationADSymColIdx + i + 1, idx].Style.Font = passingFont;
                        }
                    }
                }
            }