/// <summary> /// filter a specfic stock with a key word to find a specifc stock to get tips fpr later on in the program /// username must be entered to filter stocks. can also filter with empty string to get all stocks back /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void FindStocks_Click(object sender, EventArgs e) { MultipartFormDataContent form = new MultipartFormDataContent(); statusLabel.Text = "getting filtered data stocks"; { // have user enter a username(needed to run request) and a filter word or words //to filter for a specifc stock. done with a collection type var postData = new Dictionary <string, string>() { { "username", UsernameTextBox.Text }, { "action", "stocks" }, { "filter", FilterTextBox.Text } }; // Transfer to form to send foreach (var item in postData) { form.Add(new StringContent(item.Value), item.Key); } } //send POSTdata request to webservice, return and display data in DGV_filter using (HttpClient hc = new HttpClient()) { //issuse request var postResponse = await hc.PostAsync(url, form); //if there is content in request, //read it as a string and call a decode method to Deserialized json data if (postResponse.Content != null) { // Get our response from the Content, decode the data var stringResp = await postResponse.Content.ReadAsStringAsync(); //decode method to Deserialized json data and display to DGV_filter Filterdecode(stringResp); DGV_Filter.AutoResizeColumns(); } } }
/// <summary> /// pre-load filter data into DGV_Filter with empty string to see all data that can be filtered /// </summary> private async void loadData() { MultipartFormDataContent form = new MultipartFormDataContent(); //setup default data post data web request to load all avalible stocks with empty string { var postData = new Dictionary <string, string>() { { "username", "name here" }, { "action", "stocks" }, { "filter", "" } }; // Transfer to form to send foreach (var item in postData) { form.Add(new StringContent(item.Value), item.Key); } } //send POSTdata request to webservice, return and display data in DGV_filter using (HttpClient hc = new HttpClient()) { //issuse request var postResponse = await hc.PostAsync(url, form); //if there is content in request, //read it as a string and call a decode method to Deserialized json data if (postResponse.Content != null) { // Get our response from the Content, decode the data var stringResp = await postResponse.Content.ReadAsStringAsync(); //decode method to Deserialized json data and display to DGV_filter Filterdecode(stringResp); DGV_Filter.AutoResizeColumns(); } } statusLabel.Text = "loaded stock data"; }