コード例 #1
0
        public StationGroup AddStation(Station station)
        {
            StationGroup new_group = FindGroupForStation(station);
            StationGroup old_group = station.Parent as StationGroup;

            if (new_group == old_group && old_group != null)
            {
                return(new_group);
            }

            if (old_group != null)
            {
                old_group.RemoveChild(station);

                if (old_group.ChildCount == 0)
                {
                    RemoveNode(old_group);
                }
            }

            if (new_group == null || old_group == null)
            {
                new_group = CreateGroup(station.Group);
                AddNode(new_group);
            }

            new_group.AddChild(station);
            return(new_group);
        }
コード例 #2
0
        public StationStore(Stations stations) : base(typeof(Station))
        {
            this.stations = stations;

            foreach (Station station in stations.List)
            {
                StationGroup group = FindGroupForStation(station);
                if (group == null)
                {
                    group = CreateGroup(station.Group);
                    AddNode(group);
                }

                group.AddChild(station);
            }
        }
コード例 #3
0
        public void RemoveStation(Station station)
        {
            StationGroup group = station.Parent as StationGroup;

            if (group == null)
            {
                return;
            }

            group.RemoveChild(station);
            if (group.ChildCount == 0)
            {
                RemoveNode(group);
            }

            stations.Remove(station);
            stations.Save();
        }
コード例 #4
0
        private StationGroup FindGroupForStation(Station station)
        {
            if (station == null)
            {
                return(null);
            }

            foreach (TreeNode node in this)
            {
                if (!(node is StationGroup))
                {
                    continue;
                }

                StationGroup group = node as StationGroup;
                if (group.Title != null && station.Group != null &&
                    group.Title.ToLower() == station.Group.ToLower())
                {
                    return(group);
                }
            }

            return(null);
        }