Пример #1
0
 private void SetPageing(BookSearchRslt aBsr)
 {
     if (aBsr.total < 1)
     {
         this.ucPaging.Visible = false;
     }
     else
     {
         this.ucPaging.Visible = true;
         this.ucPaging.Setting(aBsr.total);
     }
 }
Пример #2
0
        private void CreateSearchRsltCtrl(BookSearchRslt aBsr)
        {
            if (aBsr != null)
            {
                this.SetSearchRsltInfo(aBsr.start, aBsr.display, aBsr.total);

                foreach (BookItem itm in aBsr.items)
                {
                    BookControl bc = new BookControl();

                    bc.Width = this.flpSearchRslt.Width - 25;
                    bc.SetValue(itm);

                    this.flpSearchRslt.Controls.Add(bc);
                }
            }
        }
Пример #3
0
        public void Search(bool aNewSearchState)
        {
            if (!this.CheckBeforeSearch())
            {
                return;
            }

            try
            {
                this.Cursor = Cursors.WaitCursor;

                this.ClearSearchBefore(aNewSearchState);

                string subUrl = string.Format("query={0}&display=10&start={1}&d_titl={2}", string.Empty, (this.ucPaging.CurPage.Equals(1) ? 1 : ((this.ucPaging.CurPage - 1) * 10) + 1), this.tbxBookTitle.Text);
                string url    = "https://openapi.naver.com/v1/search/book_adv.json?" + subUrl;
                string text   = string.Empty;

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Headers.Add("X-Naver-Client-Id", Definition.ConstValue.ConstValue.NaverClintInfo.ID);
                request.Headers.Add("X-Naver-Client-Secret", Definition.ConstValue.ConstValue.NaverClintInfo.PASS);

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    string status = response.StatusCode.ToString();

                    if (status == "OK")
                    {
                        using (Stream stream = response.GetResponseStream())
                        {
                            using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
                            {
                                text = reader.ReadToEnd();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(string.Format("에러 발생! {0}", status), "알림", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                BookSearchRslt bsr = Newtonsoft.Json.JsonConvert.DeserializeObject <BookSearchRslt>(text);

                if (bsr.total < 1)
                {
                    MessageBox.Show("검색결과가 존재하지 않습니다.", "알림", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                this.CreateSearchRsltCtrl(bsr);
                this.SetPageing(bsr);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "알림", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }