private async void LoadDataButtonClick(object sender, EventArgs e) { InitializeResults(); bool loadDBLP = checkBoxDBLP.Checked; bool loadIEEEXplore = checkBoxIEEEXplore.Checked; bool loadGoogleScholar = checkBoxGoogleScholar.Checked; int initialYear = (int)numericUpDownInitialYear.Value; int finalYear = (int)numericUpDownFinalYear.Value; if (!loadDBLP && !loadIEEEXplore && !loadGoogleScholar) { richTextBoxErrors.Text = "Any source selected, please select at least one."; return; } LoadRequest loadRequest = new LoadRequest(loadDBLP, loadIEEEXplore, loadGoogleScholar, initialYear, finalYear); LoadAnswer loadAnswer; LoadingForm loadingForm = new LoadingForm(); ShowLoadingForm(); try { loadAnswer = await RequestsManager.GetRequestsManager().LoadDataFromDataSources(loadRequest); } catch (Exception) { richTextBoxErrors.Text = "It was not possible to connect to the warehouse."; CloseLoadingForm(); return; } ShowResults(loadAnswer, loadRequest.LoadFromDBLP, loadRequest.LoadFromIEEEXplore, loadRequest.LoadFromGoogleScholar); CloseLoadingForm(); void ShowLoadingForm() { new Task(() => loadingForm.ShowDialog()).Start(); this.Enabled = false; } void CloseLoadingForm() { loadingForm.Invoke((MethodInvoker) delegate { loadingForm.Close(); }); this.Enabled = true; } }
private async void SearchButtonClick(object sender, EventArgs e) { richTextBoxArticles.Text = ""; bool searchArticle = checkBoxArticle.Checked; bool searchBook = checkBoxBook.Checked; bool searchCongress = checkBoxCongressComunication.Checked; int initialYear = (int)numericUpDownInitialYear.Value; int finalYear = (int)numericUpDownFinalYear.Value; string author = textBoxAuthor.Text; string title = textBoxTitle.Text; if (!searchArticle && !searchBook && !searchCongress) { richTextBoxArticles.ForeColor = Color.Red; richTextBoxArticles.Text = "Any publication type selected, please select at least one."; richTextBoxBooks.ForeColor = Color.Red; richTextBoxBooks.Text = "Any publication type selected, please select at least one."; richTextBoxCongressComunications.ForeColor = Color.Red; richTextBoxCongressComunications.Text = "Any publication type selected, please select at least one."; return; } SearchRequest searchRequest = new SearchRequest(searchArticle, searchBook, searchCongress, initialYear, finalYear, author, title); SearchAnswer searchAnswer; LoadingForm loadingForm = new LoadingForm(); ShowLoadingForm(); try { searchAnswer = await RequestsManager.GetRequestsManager().SearchDataInWarehouse(searchRequest); } catch (Exception) { richTextBoxArticles.ForeColor = Color.Red; richTextBoxArticles.Text = "It was not possible to connect to the warehouse."; richTextBoxBooks.ForeColor = Color.Red; richTextBoxBooks.Text = "It was not possible to connect to the warehouse."; richTextBoxCongressComunications.ForeColor = Color.Red; richTextBoxCongressComunications.Text = "It was not possible to connect to the warehouse."; CloseLoadingForm(); return; } ShowResults(searchAnswer, searchArticle, searchBook, searchCongress); CloseLoadingForm(); void ShowLoadingForm() { new Task(() => loadingForm.ShowDialog()).Start(); this.Enabled = false; } void CloseLoadingForm() { loadingForm.Invoke((MethodInvoker) delegate { loadingForm.Close(); }); this.Enabled = true; } }