Example #1
0
 /// <summary>
 /// 通过具体API获取图书信息
 /// </summary>
 /// <param name="sender">事件发起者</param>
 /// <param name="e">接收者</param>
 private void btnGetInfo_Click(object sender, EventArgs e)
 {
     try
     {
         this.ChangeShowMessageBox();
         GetDataSource getsource = new GetDataSource();
         string apiUrl = this.textBoxDoubanAPI.Text.ToString().Trim();
         string dateSource = getsource.GetJsonFile(apiUrl);
         JObject readAPI = JObject.Parse(dateSource);
         this.BookName.Text = readAPI["title"].ToString().Trim();
         this.BookAuthor.Text = readAPI["author"][0].ToString().Trim();
         this.BookID.Text = readAPI["id"].ToString().Trim();
         this.BookPublisher.Text = readAPI["publisher"].ToString().Trim();
         this.BookPublishDate.Text = readAPI["pubdate"].ToString().Trim();
         this.BookPrice.Text = readAPI["price"].ToString().Trim();
         this.BookBinding.Text = readAPI["binding"].ToString().Trim();
         this.BookPages.Text = readAPI["pages"].ToString().Trim();
         this.richTextBoxSummery.Text = readAPI["summary"].ToString().Trim();
         this.pictureBoxBookImag.ImageLocation = readAPI["images"]["large"].ToString().Trim();
     }
     catch (Exception)
     {
         this.HideShowMessageBox();
         MessageBox.Show("出现异常,未找到该书或者请检查输入是否正确!");
     }
 }
Example #2
0
 private void buttonCheck_Click(object sender, EventArgs e)
 {
     try
     {
         List<Book> list = new List<Book>();
         GetDataSource getdata = new GetDataSource();
         JObject file = JObject.Parse(getdata.GetBookTag(this.textBoxTags.Text));
         var temp = from tags in file["books"].Children()
                    select tags;
         foreach (var tempFile in temp)
         {
             Book book = new Book();
             book.Index = list.Count + 1;
             book.Title = tempFile["title"].ToString().Trim();
             book.API = tempFile["url"].ToString().Trim();
             list.Add(book);
         }
         this.dataGridView1.DataSource = list;
     }
     catch (Exception)
     {
         MessageBox.Show("请正确填写信息!");
     }
 }