// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to You under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // .Net StockTrader Sample WCF Application for Benchmarking, Performance Analysis and Design Considerations for Service-Oriented Applications using System; using System.Collections.Generic; using System.Text; using Trade.StockTraderWebApplicationModelClasses; namespace Trade.BusinessServiceClient { /// /// Special class to construct a sorted list of holdings by stock symbol, pre-subtotaled and pre-formatted for ASPX repeater display. /// public class htmlRowBuilder { /// /// Logic to construct a sorted list of holdings by stock symbol, pre-subtotaled and pre-formatted for ASPX repeater display. /// /// Holding data to format public int buildPortfolioBySymbol(List holdingsUI) { if (holdingsUI == null || holdingsUI.Count < 1) return 0; string quoteSymbol = holdingsUI[0].quoteID; decimal quotePrice = holdingsUI[0].quotePriceDecimal; double subtotalquantity = 0; decimal subtotalmktvalue = 0; decimal subtotalbasis = 0; decimal subtotalgain = 0; int uniqueStockCount = 0; int count = holdingsUI.Count; int subtotaledlistcount = 0; for (int i = 0; i <= count; i++) { if (i == count) { subtotaledlistcount--; } if (!quoteSymbol.Equals(holdingsUI[subtotaledlistcount].quoteID)) { uniqueStockCount += 1; HoldingDataUI subtotalline = new HoldingDataUI(subtotalquantity, subtotalgain, subtotalmktvalue, subtotalbasis, quoteSymbol, quotePrice); quoteSymbol = holdingsUI[subtotaledlistcount].quoteID; quotePrice = holdingsUI[subtotaledlistcount].quotePriceDecimal; subtotalgain = holdingsUI[subtotaledlistcount].gainDecimal; subtotalquantity = holdingsUI[subtotaledlistcount].quantityDouble; subtotalmktvalue = holdingsUI[subtotaledlistcount].marketValueDecimal; subtotalbasis = holdingsUI[subtotaledlistcount].basisDecimal; if (i != count) holdingsUI[subtotaledlistcount].convertNumericsForDisplay(true); else subtotaledlistcount++; holdingsUI.Insert(subtotaledlistcount++, subtotalline); subtotaledlistcount++; } else { subtotalgain += holdingsUI[subtotaledlistcount].gainDecimal; subtotalquantity += Convert.ToDouble(holdingsUI[subtotaledlistcount].quantityDouble); subtotalmktvalue += Convert.ToDecimal(holdingsUI[subtotaledlistcount].marketValueDecimal); subtotalbasis += Convert.ToDecimal(holdingsUI[subtotaledlistcount].basisDecimal); holdingsUI[subtotaledlistcount].convertNumericsForDisplay(true); subtotaledlistcount++; } } return uniqueStockCount; } } }