//Method for requesting a search via the web service. public DataIntermediate Post([FromBody] SearchData value) { DataIntermediate dataObj = new DataIntermediate(); DataModel.getInstance().SearchByLastName(value.searchString, out dataObj.acct, out dataObj.pin, out dataObj.bal, out dataObj.fname, out dataObj.lname); return(dataObj); }
//Method for getting an entry, via an index, through the webservice. public DataIntermediate Get(int id) { DataIntermediate dataObj = new DataIntermediate(); int bal; uint pin, acct; string lname, fname; DataModel.getInstance().GetValuesForEntry(id, out dataObj.acct, out dataObj.pin, out dataObj.bal, out dataObj.fname, out dataObj.lname); Debug.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); return(dataObj); }
private void Button_Click(object sender, RoutedEventArgs e) { //Perform the index search. int i = 0; string firstName = "", lastName = ""; int bal = 0; uint acct = 0, pin = 0; output.Content = " "; try { //Get Num of entries in the app nEntries = Int32.Parse(requestService("api/values/2").Content); entryField.Content = nEntries; i = Int32.Parse(inputfield_index.Text); //Bounds check if ((i >= 0) && (i < nEntries)) { //Perform Search IRestResponse response = requestService("api/getvalues/" + i.ToString()); Debug.WriteLine("\n" + response.Content + "\n"); DataIntermediate data = JsonConvert.DeserializeObject <DataIntermediate>(response.Content); firstName = data.fname; lastName = data.lname; bal = data.bal; acct = data.acct; pin = data.pin; //If the default DataIntermediate was returned, ie no entry was found that matched throw. if (acct == 0 && pin == 0 && bal == 0 && firstName.Equals("") && lastName.Equals("")) { throw new SearchFailedException(" Unable to find an entry with index: " + i); } } else { output.Content = "Please enter a valid index, make sure it is within range"; } } catch (FormatException ex) { output.Content = "Please enter a valid index, make sure it is an integer"; } catch (ArgumentNullException ex) { output.Content = "Please enter a valid index, make sure you actually input something"; } catch (OverflowException ex) { output.Content = "Overflow Error"; } catch (ServiceNotAvailableException ex) { disable(); output.Content = "There was an error connecting to the business server, Please restart the client!"; } catch (SearchFailedException ex) { output.Content = "Your search returned negative, no entry had the lastname you specified!"; } //Display field_fname.Text = firstName; field_lname.Text = lastName; field_bal.Text = bal.ToString("C"); field_actnum.Text = acct.ToString(); field_pin.Text = pin.ToString("D4"); }
private void Button_Click1(object sender, RoutedEventArgs e) { //Search last name. Haven't re-implemented delegates from Prac 2, touched on this in report. delegateSearchOp searchOperation; AsyncCallback cBack; string firstName = "", lastName = "", searchLastName; int bal = 0; uint acct = 0, pin = 0; output.Content = " "; try { //Get num of values. nEntries = Int32.Parse(requestService("api/values/2").Content); entryField.Content = nEntries; //Create a search obj SearchData search = new SearchData(); search.searchString = inputfield_lastname.Text; //Perform search RestRequest req = new RestRequest("api/search/"); req.AddJsonBody(search); IRestResponse response = client.Post(req); DataIntermediate data = JsonConvert.DeserializeObject <DataIntermediate>(response.Content); //Reassign data since we don't like globals :( firstName = data.fname; lastName = data.lname; pin = data.pin; acct = data.acct; bal = data.bal; //Check if it actually found something if (acct == 0 && pin == 0 && bal == 0 && firstName.Equals("Unknown") && lastName.Equals("Uknown")) { throw new SearchFailedException(" Unable to find an entry with: " + search.searchString); } //If we did find what we were looking for, display it! field_fname.Text = firstName; field_lname.Text = lastName; field_bal.Text = bal.ToString("C"); field_actnum.Text = acct.ToString(); field_pin.Text = pin.ToString("D4"); } catch (FormatException) { output.Content = "Please enter a valid string"; } catch (ArgumentNullException) { output.Content = "Please enter a valid string"; } catch (ServiceNotAvailableException ex) { disable(); output.Content = "There was an error connecting to the business server, Please restart the client!"; } catch (SearchFailedException ex) { output.Content = "Your search returned negative, no entry had the lastname you specified!"; } /*Increase the number of entries generated, error handling*/ }