public PostPage() { InitializeComponent(); winhttp = new WinHttpRequest(); PostListView.ItemsSource = PostListViewModel.GetInstance(); MaxPageText.DataContext = PageViewModel.GetInstance(); PresentPageText.DataContext = PageViewModel.GetInstance(); // 학사 공지사항을 default로 설정 // url = "https://www.koreatech.ac.kr/kor/CMS/NoticeMgr/bachelorList.do"; PostListModel.SetSource(GetPostList(url, 1)); }
private List <PostListEntity> GetPostList(string url, int page) { try { winhttp.Open("GET", url + "?page=" + page); winhttp.Send(); winhttp.WaitForResponse(); string temp = Strings.Split(winhttp.ResponseText, "<th scope=\"col\">조회수</th>")[1];; int total_post = Convert.ToInt32(Strings.Split(Strings.Split(winhttp.ResponseText, "총 <em>")[1], "</em>")[0]); // 총 게시글 수 int total_pages = (int)(total_post / 20.0 + 0.999); // 총 페이지 수 PageViewModel.GetInstance().MaxPage = total_pages; int notice_size = Strings.Split(temp, "alt=\"공지\"").Length - 1; // 공지사항 개수 int post_size = Strings.Split(temp, "<td class=\"subject\">").Length - 1; // 페이지당 개시글 개수 PostListModel.BoardId = Convert.ToInt32(Strings.Split(Strings.Split(winhttp.ResponseText, "board_id\" value=\"")[1], "\" />")[0]); List <PostListEntity> result = new List <PostListEntity>(); for (int i = 0; i < post_size; i++) { int number = Convert.ToInt32(Strings.Split(Strings.Split(temp, "<td class=\"num\">")[(i + 1) * 2], "</td>")[0]); string title = Strings.Split(Strings.Split(temp, "title=\"")[i + 1], "\">")[0]; if (i < notice_size) { title = "[공지]" + title; } string time = Strings.Split(Strings.Split(temp, "<td class=\"date\">")[i + 1], "</td>")[0]; string publisher = Strings.Split(Strings.Split(temp, "<td class=\"writer\">")[i + 1], "</td>")[0]; int views = Convert.ToInt32(Strings.Split(Strings.Split(temp, "<td class=\"cnt\">")[i + 1], "</td>")[0]); result.Add(new PostListEntity() { Number = number, Title = title, Time = time, Publisher = publisher, Views = views }); } return(result); } catch (Exception ex) { return(new List <PostListEntity>()); } }
private void PageInit() { PageViewModel.GetInstance().PresentPage = 1; }