public MainPage() { this.InitializeComponent(); //client = new StockMarketWebService.PurchaseSharesClient(); //lstBxShares.Items.Clear(); //foreach (StockMarketWebService.companyShare company in client.getSharesAsync(null, null).Result.@return) //{ // lstBxShares.Items.Add(company.companyName); //} try { loadShares(null, "GBP", getSortValue()); client = new StockMarketWebService.PurchaseSharesClient(); String[] currencyTypes = client.getCurrencyNamesAsync().Result.@return; foreach (String currency in currencyTypes) { cbxCurrency.Items.Add(currency); } cbxCurrency.SelectedIndex = 0; } catch (Exception ex) { displayMessageBox("Not connected to the Stock Exchange Web Service"); //Wait(); //App.Current.Exit(); } }
private void lstVwShares_SelectionChanged(object sender, SelectionChangedEventArgs e) { client = new StockMarketWebService.PurchaseSharesClient(); //StockMarketWebService.companyShare[] companyShares = companyShares; if (lstVwShares.SelectedIndex >= 0) { int i = lstVwShares.SelectedIndex; txtCompanyName.Text = companyShares[i].companyName.ToString(); } }
private void btnCreateUser_Click(object sender, RoutedEventArgs e) { client = new StockMarketWebService.PurchaseSharesClient(); Boolean success = client.addUserAsync(txtUsername.Text, txtPassword.Password, txtFirstName.Text).Result.@return; if (success == false) { displayMessageBox("Username already exists"); } else { displayMessageBox("User Creation successful"); txtUsername.Text = ""; txtPassword.Password = ""; txtFirstName.Text = ""; } }
private void btnLogin_Click(object sender, RoutedEventArgs e) { client = new StockMarketWebService.PurchaseSharesClient(); Boolean success = client.userLoginAsync(txtUsername.Text, txtPassword.Password).Result.@return; if (success == false) { displayMessageBox("Username and / or password mismatch"); } else { //CreateShares createShares = new CreateShares(); this.Frame.Navigate(new CreateShares().GetType(), null); } }
private void btnBuy_Click(object sender, RoutedEventArgs e) { client = new StockMarketWebService.PurchaseSharesClient(); String output = ""; if ((txtCompanyName.Text.ToString() != null) && (txtSharesWanted.Text.ToString() != null)) { output = client.buySharesAsync(txtCompanyName.Text.ToString(), Int32.Parse(txtSharesWanted.Text.ToString()))[email protected](); loadShares(txtFilter.Text, cbxCurrency.SelectedItem.ToString(), getSortValue()); clearfields(); } else { output = "Please select a company and input the shares required"; } displayMessageBox(output); }
private void loadShares(String filtervalue, String currencyType, int sortType) { client = new StockMarketWebService.PurchaseSharesClient(); lstVwShares.ItemsSource = null; clearfields(); Char[] currency = currencyType.ToCharArray(); currencyType = currency[0].ToString() + currency[1] + currency[2]; if (filtervalue == "") { filtervalue = null; } companyShares = client.getSharesAsync(filtervalue, currencyType).Result.@return; StockMarketWebService.companyShare tempShare = new StockMarketWebService.companyShare(); for (int i = 0; i < companyShares.Length; i++) { for (int x = 1; x < (companyShares.Length - i); x++) { if (sortType == 0) { if (companyShares[x - 1].sharePrice.value > companyShares[x].sharePrice.value) { tempShare = companyShares[x - 1]; companyShares[x - 1] = companyShares[x]; companyShares[x] = tempShare; } } else if (sortType == 1) { if (companyShares[x - 1].sharePrice.value < companyShares[x].sharePrice.value) { tempShare = companyShares[x - 1]; companyShares[x - 1] = companyShares[x]; companyShares[x] = tempShare; } } } } List <CompanyStock> allCompanyStock = new List <CompanyStock>(); foreach (StockMarketWebService.companyShare share in companyShares) { allCompanyStock.Add(new CompanyStock { companyName = share.companyName, symbol = share.companySymbol, volume = share.numOfAvailShares, currency = share.sharePrice.currency, value = share.sharePrice.value, date = share.sharePrice.dateOfLastUpdate }); } lstVwShares.ItemsSource = allCompanyStock; //var loopIndex = 10; //await ThreadPool.RunAsync( // o => // { // // This is a background operation! // while (true) // { // client = new StockMarketWebService.PurchaseSharesClient(); // lstBxShares.Items.Clear(); // //StockMarketWebService.getCurrencyNamesResponse x = await client.getSharesAsync(null, null).Result; // foreach (StockMarketWebService.companyShare company in client.getSharesAsync(null, null).Result.@return) // { // lstBxShares.Items.Add(company.companyName); // } // System.Threading.Tasks.Task.Delay(2000); // } // }); }