protected void Page_Load(object sender, EventArgs e) { string userid = HttpContext.Current.User.Identity.Name; if (userid == null) logout(); BSLClient businessServicesClient = new BSLClient(); totalHoldings = businessServicesClient.getHoldingsBySymbolSubTotaled(userid); numOfUniqueStocks.Text = totalHoldings.uniqueStockCount.ToString(); PortfolioBySymbolRepeater.DataSource = totalHoldings.holdings; PortfolioBySymbolRepeater.DataBind(); }
protected void Page_PreRenderComplete(object sender, EventArgs e) { totalHoldings = caller1.EndInvoke(result1); customer = caller2.EndInvoke(result2); decimal gain = (decimal)0.00; decimal percentGain = (decimal)0.00; Name.Text = customer.profileID + "!"; AccountID.Text = customer.accountID.ToString(); CreationDate.Text = customer.creationDate.ToString(); LoginCount.Text = customer.loginCount.ToString(); OpenBalance.Text = string.Format("{0:C}", customer.openBalance); Balance.Text = string.Format("{0:C}", customer.balance); NumHoldings.Text = totalHoldings.holdings.Count.ToString(); HoldingsTotal.Text = string.Format("{0:C}", totalHoldings.marketValue); decimal totalcashandholdings = totalHoldings.marketValue + customer.balance; SumOfCashHoldings.Text = string.Format("{0:C}", totalcashandholdings); gain = totalcashandholdings - customer.openBalance; string percentGainString = ""; if (customer.openBalance != 0) percentGain = gain / customer.openBalance * 100; else percentGain = 0; if (gain > 0) { percentGainString = string.Format("{0:N}%" + Settings.UPARROWLINK, percentGain); Gain.ForeColor = System.Drawing.ColorTranslator.FromHtml("#43A12B"); PercentGain.ForeColor = System.Drawing.ColorTranslator.FromHtml("#43A12B"); } else if (gain < 0) { percentGainString = string.Format("{0:N}%" + Settings.DOWNARROWLINK, percentGain); Gain.ForeColor = System.Drawing.ColorTranslator.FromHtml("#A40707"); PercentGain.ForeColor = System.Drawing.ColorTranslator.FromHtml("#A40707"); } else { percentGainString = string.Format("{0:N}%", percentGain); } Gain.Text = string.Format("{0:C}", gain); PercentGain.Text = percentGainString; }
/// <summary> /// This routine allows us to take an unsorted list (or list sorted by HoldingID) of holdings, /// such as that returned by the WebSphere Trade 6.1 service, and return a sorted list of /// holdings by stock symbol. At the same time, we produce subtotal lines for each unique stock. /// This is used in a new page we added for StockTrader that Trade 6.1 does not have: /// (PortfolioBySymbol.aspx). Yet, it will work with the existing WebSphere backend service, /// since we do the sort here on the UI tier. We do it this way becuase WebSphere Trade 6.1 /// will always return an unsorted list of stock holdings since it does not implement a web service /// method to return a list sorted by quoteID. Without this limiting factor, a better and more /// performant way of doing this would be to implement a business services method and corresponding DAL method /// to execute a query that returned pre-sorted values by stock symbol (as opposed to unsorted, /// as the EJB/Trade 6.1 getHoldings operation does; or sorted by HoldingID as our getHoldings operation /// does. This would avoid the need to do a sort on the UI tier at all. The extra load this /// would place on the database would be negligable, given a typically small number of rows returned. /// At any rate, the sort is implemented here by taking advantage of a custom comparer in our /// HoldingsUI class on the quoteID property (stock symbol), and .NET's ability to sort /// generic typed lists. /// Hence, we can display even WebSphere-returned data that is non sorted in our extra /// PortfolioBySymbol page, adding the subtotal lines for each unique stock as well. /// We resisted adding a second method to the BSL and DAL to return a different sort order (quoteID), simply to /// be consistent across the InProcess and Web Service modes of operation and for true benchmark comparison /// purposes between the InProcess and web service modes. Note this logic is never called in /// published benchmark data, given the fact WebSphere Trade 6.1 does not implement this /// functionality, although even with the extra sort it performs very well. /// </summary> /// <param name="userID">User id to retrieve data for.</param> public Trade.StockTraderWebApplicationModelClasses.TotalHoldingsUI getHoldingsBySymbolSubTotaled(string userID) { try { //get the list of holdings from the BSL List<HoldingDataModel> holdings = BSL.getHoldings(userID); List<HoldingDataUI> holdingsUI = new List<HoldingDataUI>(); decimal marketValue = 0; decimal gain = 0; decimal basis = 0; //create our HoldingsUI class to pass back to the ASPX page. for (int i = 0; i < holdings.Count; i++) { //Now Removed: QuoteDataModel quote = BSL.getQuote(holdings[i].quoteID); HoldingDataUI holdingitem = new HoldingDataUI(holdings[i].holdingID, holdings[i].quantity, holdings[i].purchasePrice, holdings[i].purchaseDate.ToString(), holdings[i].quoteID, holdings[i].price); holdingsUI.Add(holdingitem); decimal _marketValue = (decimal)holdings[i].quantity * holdings[i].price; decimal _basis = (decimal)holdings[i].quantity * holdings[i].purchasePrice; gain += _marketValue - _basis; marketValue += _marketValue; basis += _basis; } //Call our implemented comparer class: see Trade.StockTraderWebApplicationModelClasses.HoldingDataUI.cs for the compararer //class source code. HoldingDataUI.HoldingDataUIComparer comparer = new HoldingDataUI.HoldingDataUIComparer(); comparer.ComparisonMethod = HoldingDataUI.HoldingDataUIComparer.ComparisonType.quoteID; //Do the sort! Sort method is built into the C# Generic List functionality; the comparer //calls our delegate method to compare by quoteID, so just one line of code here! holdingsUI.Sort(comparer); //Our list is now sorted, proceed with building in the subtotal lines. htmlRowBuilder rowBuilder = new htmlRowBuilder(); int uniqueStockCount = rowBuilder.buildPortfolioBySymbol(holdingsUI); TotalHoldingsUI totalHoldings = new TotalHoldingsUI(holdingsUI, marketValue, basis, gain, uniqueStockCount, holdingsUI.Count - uniqueStockCount); return totalHoldings; } catch (Exception e) { ConfigUtility.writeErrorConsoleMessage("StockTraderWebApplicationServiceClient.getHoldingsBySymbolSubTotaled Error: " + e.ToString(), EventLogEntryType.Error, true, new Settings()); throw; } }
/// <summary> /// Gets holding data for a user. Transforms data from DataContract to model UI class for HTML display. /// </summary> /// <param name="userID">User id to retrieve data for.</param> public Trade.StockTraderWebApplicationModelClasses.TotalHoldingsUI getHoldings(string userID) { try { List<HoldingDataModel> holdings = BSL.getHoldings(userID); List<HoldingDataUI> holdingsUI = new List<HoldingDataUI>(); decimal marketValue = 0; decimal gain = 0; decimal basis = 0; for (int i = 0; i < holdings.Count; i++) { //Now removed: QuoteDataModel quote = BSL.getQuote(holdings[i].quoteID); HoldingDataUI holdingitem = new HoldingDataUI(holdings[i].holdingID, holdings[i].quantity, holdings[i].purchasePrice, holdings[i].purchaseDate.ToString(), holdings[i].quoteID, holdings[i].price); holdingitem.convertNumericsForDisplay(false); holdingsUI.Add(holdingitem); decimal _marketValue = (decimal)holdings[i].quantity * holdings[i].price; decimal _basis = (decimal)holdings[i].quantity * (decimal)holdings[i].purchasePrice; gain += _marketValue - _basis; marketValue += _marketValue; basis += _basis; } TotalHoldingsUI totalHoldings = new TotalHoldingsUI(holdingsUI, marketValue, basis, gain); return totalHoldings; } catch (Exception e) { ConfigUtility.writeErrorConsoleMessage("StockTraderWebApplicationServiceClient.getHoldings Error: " + e.ToString(), EventLogEntryType.Error, true, new Settings()); throw; } }