Example #1
0
        /// <summary>
        /// 출발역 선택 이벤트 함수
        /// </summary>
        ///
        /// <param name="sender" type="object">이벤트 발생 객체</param>
        /// <param name="e" type="SelectionChangedEventArgs">이벤트 객체</param>
        ///
        /// <returns>[void] 출발역 코드에 코드 입력</returns>
        private void Start_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            StationBean bean = (StationBean)Start.SelectedItem;

            // 임의의 값을 입력할 경우
            if (bean == null)
            {
                StartCode.Text = "";
            }

            // 정해진 값을 선택할 경우
            else
            {
                StartCode.Text = bean.Number;
            }
        }
Example #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;
                }
            }
        }