Exemplo n.º 1
0
        /// <summary>
        /// MainWindow 로딩 후 이벤트 함수
        /// </summary>
        ///
        /// <param name="e" type="object">이벤트 발생 객체</param>
        /// <param name="sender" type="RoutedEventArgs">이벤트 객체</param>
        ///
        /// <returns>[void] Form 초기화</returns>
        private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
        {
            StationList stationList = StationList.GetInstance();

            List <StationBean> list = stationList.List;

            // 리스트가 유효하지 않을 경우
            if (list == null)
            {
                this.ShowModalMessageExternal("Error", "주요역 리스트를 불러올 수 없습니다.\n코레일 홈페이지 서버가 응답하지 않거나 네트워크 문제일 수 있습니다.");

                Close();
            }

            // 리스트가 유효할 경우
            else
            {
                foreach (StationBean bean in list)
                {
                    Start.Items.Add(bean);
                    End.Items.Add(bean);
                }
            }

            StartDate.SelectedDateTime = DateTime.Now;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 백그라운드 종료 함수
        /// </summary>
        ///
        /// <param name="e" type="object">이벤트 발생 객체</param>
        /// <param name="sender" type="RunWorkerCompletedEventArgs">이벤트 객체</param>
        ///
        /// <returns>[void] 백그라운드 종료</returns>
        public override void OnCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // 에러가 없을 경우
            if (e.Error == null)
            {
                string result = e.Result.ToString();

                HtmlDocument html = new HtmlDocument();
                html.LoadHtml(result);

                HtmlNodeCollection stations = html.DocumentNode.SelectNodes("//div[@class='cont']/table[@class='tbl_b_no']/tbody/tr");

                // 기차역 리스트가 없을 경우
                if (stations != null)
                {
                    List <StationBean> list = new List <StationBean>();

                    foreach (HtmlNode station in stations)
                    {
                        HtmlNodeCollection tds = station.SelectNodes("td");

                        foreach (HtmlNode td in tds)
                        {
                            string href = td.SelectSingleNode("a").GetAttributeValue("href", "").Trim();

                            Regex reg = new Regex(@"['](.*?)[']");

                            MatchCollection collection = reg.Matches(href);

                            StationBean bean = new StationBean();
                            bean.Name   = collection[0].Groups[1].Value;
                            bean.Number = collection[1].Groups[1].Value;

                            list.Add(bean);
                        }
                    }

                    StationList stationList = StationList.GetInstance();
                    stationList.List = list;
                }
            }
        }