private void BindgridUser(ListFbUserSearch model) { try { var items = (from p in model.FbUserSearch select new { p.id, p.name, avata = p.cover == null ? null : ConvertType.GetImageFromUrl(p.cover.source), p.link, hocvan = p.education == null ? null : string.Format("Trường: {0} \nTừng học tại {1}", p.education.FirstOrDefault().school == null ? "" : p.education.FirstOrDefault().school.name, p.education.FirstOrDefault().concentration == null ? "-" : p.education.FirstOrDefault().concentration.FirstOrDefault().name), location = p.location == null ? null : p.location.name, work = p.work == null ? null : p.work.FirstOrDefault().employer.name }).ToList(); var source = new BindingSource(); source.DataSource = items; gridUser.Invoke((Action) delegate { gridUser.DataSource = source; }); } catch (Exception ex) { MessageBox.Show(ex.Message, "BindgridPage"); } }
private void button1_Click(object sender, EventArgs e) { string requestUriString = ""; string strToken = ""; try { if (txtSearch.Text == "") { MessageBox.Show("Vui Lòng nhập thông tin tìm kiếm", "Thông báo"); return; } strToken = Facebook.Token(_arrController); if (strToken == "") { MessageBox.Show("Bạn đã hết Quata token để thực thi việc gọi API của Facebook \n Vui lòng nạp Acc mới hay chờ đến ngày hôm sau.", "Thông báo"); return; } ; string strNoidungtimkiem = Uri.EscapeDataString(txtSearch.Text); switch (tabControl1.SelectedIndex) { case 1: /*Page*/ requestUriString = string.Format(@"https://graph.facebook.com/search?q={0}&type={1}&limit={2}&fields={3}&access_token={4}", strNoidungtimkiem, "page", LimitTopSearch.Value, Facebook.SelectPage(), strToken); new Waiting((MethodInvoker) delegate { ListFbPageSearch model = TheardFacebookWriter.FbSearchByPage(requestUriString, _arrController, strToken, _gioihantimkiemfb); if (model.FbPageSearch.Count() != 0) { BindgridPage(model); return; } }, "Vui Lòng Chờ...").ShowDialog(); break; case 0: requestUriString = string.Format(@"https://graph.facebook.com/search?q={0}&type={1}&limit={2}&fields={3}&access_token={4}", strNoidungtimkiem, "user", LimitTopSearch.Value, Facebook.SelectUser(), strToken); new Waiting((MethodInvoker) delegate { ListFbUserSearch model = TheardFacebookWriter.FbSearchByUser(requestUriString, _arrController, strToken, _gioihantimkiemfb); if (model.FbUserSearch.Count() != 0) { BindgridUser(model); //return; } }, "Vui Lòng Chờ...").ShowDialog(); break; case 2: /*group*/ requestUriString = string.Format(@"https://graph.facebook.com/search?q={0}&limit={1}&fields={2}&type={3}&access_token={4}", strNoidungtimkiem, LimitTopSearch.Value, Facebook.SelectGroup(), "group", strToken); new Waiting((MethodInvoker) delegate { ListFbGroupSearch model = TheardFacebookWriter.FbSearchByGroup(requestUriString, _arrController, strToken, _gioihantimkiemfb); if (model.FbGroupSearch.Count() != 0) { BindgridGroup(model); //return; } }, "Vui Lòng Chờ...").ShowDialog(); break; } MessageBox.Show(string.Format("Đã xử lý"), "Thông Báo"); } catch (Exception ex) { MessageBox.Show(ex.Message, "button1_Click"); } }