using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Windows.Input;
using System.Threading.Tasks;
using MarketData.MarketDataModel;
using MarketData.DataAccess;
using MarketData;
using TradeBlotter.Command;
using TradeBlotter.Model;
using System.Windows;
using System.Text;

namespace TradeBlotter.ViewModels
{
  public class ETFHoldingViewModel : WorkspaceViewModel
  {
    private ETFHoldingModel selectedItem = null;
    private List<String> etfSymbols;
    private String selectedSymbol;
    private String selectedCompanyName;
    private bool isSearchSymbolChecked = true;
    private bool isSearchTextChecked = false;
    private String searchValue;
    private RelayCommand searchCommand;
    private RelayCommand displayAnalystRatingsUnderlying;
    private RelayCommand displayBollingerBandETF;
    private RelayCommand displayBollingerBandUnderlying;
    private RelayCommand displayStochasticsETF;
    private RelayCommand displayStochasticsUnderlying;
    private RelayCommand displayMACDETF;
    private RelayCommand displayMACDUnderlying;
    private RelayCommand displayPriceHistoryETF;
    private RelayCommand displayPriceHistoryUnderlying;
    private RelayCommand displayDCFValuationUnderlying;
    private RelayCommand displayStickerValuationUnderlying;
    private RelayCommand displayHistoricalCommand=null;
    private RelayCommand displaySECFilingsCommand;
    private RelayCommand addToWatchListCommand;
    private RelayCommand removeFromWatchListCommand;
    private String title;
    private bool busyIndicator = false;

    public ETFHoldingViewModel()
    {
      base.DisplayName = "ETFHoldingView";
      etfSymbols = PricingDA.GetSymbolsETF();
      PropertyChanged += OnETFHoldingViewModelPropertyChanged;
    }
    public override SaveParameters GetSaveParameters()
    {
      return null;
    }
    public override void SetSaveParameters(SaveParameters saveParameters)
    {
    }
    public override bool CanPersist()
    {
      return false;
    }
    public ObservableCollection<ETFHoldingModel> AllETFHoldings
    {
      get;
      private set;
    }
    public bool BusyIndicator
    {
      get { return busyIndicator; }
      set { busyIndicator = value; }
    }
    private void CreateAllETFHoldings()
    {
      try
      {
        if (null == selectedSymbol) return;
        BusyIndicator = true;
        Task workerTask = Task.Factory.StartNew(() =>
        {
          ETFHoldings etfHoldings = ETFHoldingsDA.GetETFHoldings(selectedSymbol);
          List<ETFHoldingModel> etfHoldingModelList = new List<ETFHoldingModel>();
          foreach (ETFHolding etfHolding in etfHoldings) etfHoldingModelList.Add(new ETFHoldingModel(etfHolding));
          this.AllETFHoldings = new ObservableCollection<ETFHoldingModel>(etfHoldingModelList);
        });
        workerTask.ContinueWith((continuation) =>
        {
          BusyIndicator = false;
          base.OnPropertyChanged("AllETFHoldings");
        });
      }
      catch (Exception exception)
      {
        MDTrace.WriteLine(LogLevel.DEBUG,exception);
      }
    }
    private void OnETFHoldingViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
    {
      if (eventArgs.PropertyName.Equals("SelectedSymbol"))
      {
        BusyIndicator = true;
        Task workerTask = Task.Factory.StartNew(() =>
        {
          title = null;
          CreateAllETFHoldings();
          selectedCompanyName = PricingDA.GetNameForSymbol(selectedSymbol);
        });
        workerTask.ContinueWith((continuation) =>
        {
          BusyIndicator = false;
          base.OnPropertyChanged("AllETFHoldings");
          base.OnPropertyChanged("Title");
        });
      }
    }
    public ObservableCollection<MenuItem> MenuItems
    {
      get
      {
        ObservableCollection<MenuItem> collection = new ObservableCollection<MenuItem>();
        collection.Add(new MenuItem() { Text = "Underlying - Display Bollinger Band",MenuItemClickedCommand=DisplayBollingerBandUnderlying,StaysOpenOnClick=false });
        collection.Add(new MenuItem() { Text = "Underlying - Display Analyst Ratings", MenuItemClickedCommand = DisplayAnalystRatings, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Underlying - Display Sticker Valuation", MenuItemClickedCommand = DisplayStickerValuationUnderlying, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Underlying - Display Historical", MenuItemClickedCommand = DisplayHistoricalUnderlying, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Underlying - Display Stochastics", MenuItemClickedCommand = DisplayStochasticsUnderlying, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Underlying - Display MACD", MenuItemClickedCommand = DisplayMACDUnderlying, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Underlying - Display Price History", MenuItemClickedCommand = DisplayPriceHistoryUnderlying, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Underlying - Display DCF Valuation", MenuItemClickedCommand = DisplayDCFValuationUnderlying, StaysOpenOnClick = false });
  			collection.Add(new MenuItem() { Text = "Underlying - Display SEC Filings", MenuItemClickedCommand = DisplaySECFilings, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Underlying - Remove from Watchlist", MenuItemClickedCommand = RemoveFromWatchList, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Underlying - Add To Watchlist", MenuItemClickedCommand = AddToWatchList, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "ETF - Display Bollinger Band", MenuItemClickedCommand = DisplayBollingerBandETF, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "ETF - Display Stochastics", MenuItemClickedCommand = DisplayStochasticsETF, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "ETF - Display MACD", MenuItemClickedCommand = DisplayMACDETF, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "ETF - Display Price History", MenuItemClickedCommand = DisplayPriceHistoryETF, StaysOpenOnClick = false });
        return collection;
      }
    }
    public ICommand AddToWatchList
    {
      get
      {
        if (addToWatchListCommand == null)
        {
          addToWatchListCommand = new RelayCommand(param => this.AddToWatchListCommand(),
            param =>
            {
              if (null == selectedItem || null == selectedItem.HoldingSymbol) return false;
              if (WatchListDA.IsInWatchList(selectedItem.HoldingSymbol)) return false;
              return true;
            });
        }
        return addToWatchListCommand;
      }
    }
    public ICommand RemoveFromWatchList
    {
      get
      {
        if (removeFromWatchListCommand == null)
        {
          removeFromWatchListCommand = new RelayCommand(param => this.RemoveFromWatchListCommand(),
            param =>
            {
              if (null == selectedItem || null == selectedItem.HoldingSymbol) return false;
              if (!WatchListDA.IsInWatchList(selectedItem.HoldingSymbol)) return false;
              return true;
            });
        }
        return removeFromWatchListCommand;
      }
    }
    public ICommand DisplaySECFilings
    {
      get
      {
        if (null == displaySECFilingsCommand)
        {
          displaySECFilingsCommand = new RelayCommand(param =>
          {
            SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.SECFilingViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,Valuations");
            saveParams.Referer=this;
            WorkspaceInstantiator.Invoke(saveParams);
          }, param => { return null != selectedItem && null!=selectedItem.HoldingSymbol; });
        }
        return displaySECFilingsCommand;
      }
    }
    public ICommand DisplayAnalystRatings
    {
      get
      {
        if (null == displayAnalystRatingsUnderlying)
        {
          displayAnalystRatingsUnderlying = new RelayCommand(param =>
          {
            String companyName = PricingDA.GetNameForSymbol(selectedSymbol);
            SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.AnalystRatingsViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All},SelectedDate,{All},SelectedCompany,"+companyName);
            saveParams.Referer=this;
            WorkspaceInstantiator.Invoke(saveParams);
          }, param => 
          { 
            if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
            return true;
//            return !(null != selectedItem && selectedItem.HoldingSymbol.Equals("N/A")); 
          });
        }
        return displayAnalystRatingsUnderlying;
      }
    }
    public ICommand DisplayStickerValuationUnderlying
    {
      get
      {
        if (null == displayStickerValuationUnderlying)
        {
          displayStickerValuationUnderlying = new RelayCommand(param =>
          {
            SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StickerPriceViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All}");
            saveParams.Referer=this;
            WorkspaceInstantiator.Invoke(saveParams);
          }, param => 
          {
            if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
            return true;
//            return !(null != selectedItem && selectedItem.HoldingSymbol.Equals("N/A")); 
          });
        }
        return displayStickerValuationUnderlying;
      }
    }
      public ICommand DisplayHistoricalUnderlying
      {
        get
        {
          if (displayHistoricalCommand == null)
          {
            displayHistoricalCommand = new RelayCommand(param => 
            {
              SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.HistoricalViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All}");
              saveParams.Referer=this;
              WorkspaceInstantiator.Invoke(saveParams);
            }, param => 
            { 
              if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
              return true;
            });
          }
          return displayHistoricalCommand;
        }
      }
    public ICommand DisplayDCFValuationUnderlying
    {
      get
      {
        if (null == displayDCFValuationUnderlying)
        {
          displayDCFValuationUnderlying = new RelayCommand(param =>
          {
            SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.DCFValuationViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All}");
            saveParams.Referer=this;
            WorkspaceInstantiator.Invoke(saveParams);
          }, param => 
          { 
            if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
            return true;
//            return !(null != selectedItem && selectedItem.HoldingSymbol.Equals("N/A")); 
          });
        }
        return displayDCFValuationUnderlying;
      }
    }
    public ICommand DisplayBollingerBandETF
    {
      get
      {
        if (null == displayBollingerBandETF)
        {
          displayBollingerBandETF = new RelayCommand(param =>
          {
            SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol," + selectedItem.ETFHoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
            saveParams.Referer=this;
            WorkspaceInstantiator.Invoke(saveParams);
          }, param => 
          {
            if(null==selectedItem || null==selectedItem.ETFHoldingSymbol || selectedItem.ETFHoldingSymbol.Equals("N/A"))return false;
            return true;
//            return !(null==selectedItem); 
          });
        }
        return displayBollingerBandETF;
      }
    }
    public ICommand DisplayBollingerBandUnderlying
    {
      get
      {
        if (null == displayBollingerBandUnderlying)
        {
          displayBollingerBandUnderlying = new RelayCommand(param => 
          {
            SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
            saveParams.Referer=this;
            WorkspaceInstantiator.Invoke(saveParams);
          }, param => 
          { 
            if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
            return true;
//             return !(null != selectedItem && selectedItem.HoldingSymbol.Equals("N/A")); 
          });
        }
        return displayBollingerBandUnderlying;
      }
    }
    public ICommand DisplayStochasticsETF
    {
      get
      {
        if (null == displayStochasticsETF)
        {
          displayStochasticsETF = new RelayCommand(param => 
            {
              SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StochasticsViewModel,SelectedSymbol," + selectedItem.ETFHoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
              saveParams.Referer=this;
              WorkspaceInstantiator.Invoke(saveParams);
            }, param => 
            {
            if(null==selectedItem || null==selectedItem.ETFHoldingSymbol || selectedItem.ETFHoldingSymbol.Equals("N/A"))return false;
            return true; 
//              return !(null==selectedItem); 
            });
        }
        return displayStochasticsETF;
      }
    }
    public ICommand DisplayStochasticsUnderlying
    {
      get
      {
        if (null == displayStochasticsUnderlying)
        {
          displayStochasticsUnderlying = new RelayCommand(param => 
            {
              SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StochasticsViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
              saveParams.Referer=this;
              WorkspaceInstantiator.Invoke(saveParams);
            }, param => 
            { 
            if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
            return true;
//              return !(null != selectedItem && selectedItem.HoldingSymbol.Equals("N/A")); 
            });
        }
        return displayStochasticsUnderlying;
      }
    }
    public ICommand DisplayMACDETF
    {
      get
      {
        if (null == displayMACDETF)
        {
          displayMACDETF = new RelayCommand(param => 
            {
              SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.MACDViewModel,SelectedSymbol," + selectedItem.ETFHoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
              saveParams.Referer=this;
              WorkspaceInstantiator.Invoke(saveParams);
            }, param => 
            { 
            if(null==selectedItem || null==selectedItem.ETFHoldingSymbol || selectedItem.ETFHoldingSymbol.Equals("N/A"))return false;
            return true; 
//              return !(null==selectedItem); 
            });
        }
        return displayMACDETF;
      }
    }
    public ICommand DisplayMACDUnderlying
    {
      get
      {
        if (null == displayMACDUnderlying)
        {
          displayMACDUnderlying = new RelayCommand(param => 
            {
              SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.MACDViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
              saveParams.Referer=this;
              WorkspaceInstantiator.Invoke(saveParams);
            }, param => 
            { 
            if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
            return true;
//              return !(null != selectedItem && selectedItem.HoldingSymbol.Equals("N/A")); 
            });
        }
        return displayMACDUnderlying;
      }
    }
    public ICommand DisplayPriceHistoryETF
    {
      get
      {
        if (null == displayPriceHistoryETF)
        {
          displayPriceHistoryETF = new RelayCommand(param => 
            {
              SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.PricingViewModel,SelectedSymbol," + selectedItem.ETFHoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
              saveParams.Referer=this;
              WorkspaceInstantiator.Invoke(saveParams);
            }, param => 
            { 
            if(null==selectedItem || null==selectedItem.ETFHoldingSymbol || selectedItem.ETFHoldingSymbol.Equals("N/A"))return false;
            return true; 
//              return !(null==selectedItem); 
            });
        }
        return displayPriceHistoryETF;
      }
    }
    public ICommand DisplayPriceHistoryUnderlying
    {
      get
      {
        if (null == displayPriceHistoryUnderlying)
        {
          displayPriceHistoryUnderlying = new RelayCommand(param => 
            {
              SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.PricingViewModel,SelectedSymbol," + selectedItem.HoldingSymbol + ",SelectedWatchList,{All},SelectedDayCount,180");
              saveParams.Referer=this;
              WorkspaceInstantiator.Invoke(saveParams);
            }, param => 
            { 
            if(null==selectedItem || null==selectedItem.HoldingSymbol || selectedItem.HoldingSymbol.Equals("N/A") )return false;
            return true;
//              return !(null != selectedItem && selectedItem.HoldingSymbol.Equals("N/A")); 
            });
        }
        return displayPriceHistoryUnderlying;
      }
    }
// ***************************************************************************************************************************
    public List<String> ETFSymbols
    {
      get { return etfSymbols; }
    }
    public String SelectedSymbol
    {
      get { return selectedSymbol; }
      set { selectedSymbol = value; base.OnPropertyChanged("SelectedSymbol"); }
    }
    public override string DisplayName
    {
      get { return base.DisplayName; }
    }
    public override String Title
    {
      get 
      {
        if (null != title) return title;
        return null==selectedCompanyName?null:selectedCompanyName+"("+selectedSymbol+") (Top 10 Holdings)"; 
      }
    }
    public Boolean IsSearchSymbolChecked
    {
      get { return isSearchSymbolChecked; }
      set { isSearchSymbolChecked = value; base.OnPropertyChanged("IsSearchSymbolChecked"); }
    }
    public Boolean IsSearchTextChecked
    {
      get { return isSearchTextChecked; }
      set { isSearchTextChecked = value; base.OnPropertyChanged("IsSearchTextChecked"); }
    }
    public String SearchValue
    {
      get { return searchValue; }
      set
      { 
        searchValue = value; 
      }
    }
    public ICommand SearchCommand
    {
      get
      {
        if (searchCommand == null)
        {
          searchCommand = new RelayCommand(param => this.Search(), param => this.CanSearch);
        }
        return searchCommand;
      }
    }
    public void Search()
    {
      if(isSearchSymbolChecked) 
      {
        BusyIndicator = true;
        Task workerTask = Task.Factory.StartNew(() =>
        {
          ETFHoldings etfHoldings = ETFHoldingsDA.GetETFHoldingsWithExposureToSymbolLike(searchValue);
          List<ETFHoldingModel> etfHoldingModelList = new List<ETFHoldingModel>();
          foreach (ETFHolding etfHolding in etfHoldings) etfHoldingModelList.Add(new ETFHoldingModel(etfHolding));
          this.AllETFHoldings = new ObservableCollection<ETFHoldingModel>(etfHoldingModelList);
          title = "ETF's with exposure to symbol like '" + searchValue + "'";
        });
        workerTask.ContinueWith((continuation) =>
        {
          BusyIndicator = false;
          base.OnPropertyChanged("AllETFHoldings");
          base.OnPropertyChanged("Title");
        });
      }
      else
      {
        BusyIndicator = true;
        Task workerTask = Task.Factory.StartNew(() =>
        {
          ETFHoldings etfHoldings = ETFHoldingsDA.GetETFHoldingsWithExposureToCompanyLike(searchValue);
          List<ETFHoldingModel> etfHoldingModelList = new List<ETFHoldingModel>();
          foreach (ETFHolding etfHolding in etfHoldings) etfHoldingModelList.Add(new ETFHoldingModel(etfHolding));
          this.AllETFHoldings = new ObservableCollection<ETFHoldingModel>(etfHoldingModelList);
          title = "ETF's with exposure to company like '" + searchValue + "'";
        });
        workerTask.ContinueWith((continuation) =>
        {
          BusyIndicator = false;
          base.OnPropertyChanged("AllETFHoldings");
          base.OnPropertyChanged("Title");
        });
      }
    }
    private bool CanSearch
    {
      get
      {
        return true;
      }
    }
    public ETFHoldingModel SelectedItem
    {
      get
      {
        return selectedItem;
      }
      set
      {
        selectedItem = value;
      }
    }
    public void AddToWatchListCommand()
    {
      if (WatchListDA.IsInWatchList(selectedItem.HoldingSymbol))
      {
        System.Windows.MessageBox.Show("'" + selectedItem.HoldingSymbol + "' is already in watchlist", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
        return;
      }
      if (!WatchListDA.AddToWatchList(selectedItem.HoldingSymbol))
      {
        System.Windows.MessageBox.Show("Error adding '" + selectedItem.HoldingSymbol + "' to watchlist", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
      }
      else
      {
        System.Windows.MessageBox.Show("Added '" + selectedItem.HoldingSymbol + "'", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
      }
    }
    public void RemoveFromWatchListCommand()
    {
      if (!WatchListDA.IsInWatchList(selectedItem.HoldingSymbol))
      {
        System.Windows.MessageBox.Show("'" + selectedItem.HoldingSymbol + "' is not in watchlist", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
        return;
      }
      if (!WatchListDA.RemoveFromWatchList(selectedItem.HoldingSymbol))
      {
        System.Windows.MessageBox.Show("Error removing '" + selectedItem.HoldingSymbol + "' from watchlist", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
      }
      else
      {
        System.Windows.MessageBox.Show("Removed '" + selectedItem.HoldingSymbol + "'", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
      }
    }
// ********************************************************************** T O O L T I P   C A L L O U T S **************************************************************
    public String ETFSymbolDescription
    {
      get
      {
        if(null==selectedItem||null==selectedItem.ETFHoldingSymbol) return "No row selected.";
        StringBuilder sb=new StringBuilder();
        CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(selectedItem.ETFHoldingSymbol);
        if(null!=companyProfile&&null!=companyProfile.Symbol&&null!=companyProfile.CompanyName) sb.Append(companyProfile.Symbol).Append(" - ").Append(companyProfile.CompanyName).Append("\n");
        String sector=PricingDA.GetSectorForSymbol(selectedItem.ETFHoldingSymbol);
        String industry=PricingDA.GetIndustryForSymbol(selectedItem.ETFHoldingSymbol);
        if(!String.IsNullOrEmpty(sector))sb.Append(sector);
        if(!String.IsNullOrEmpty(industry))sb.Append("/").Append(industry);
        if(null!=companyProfile && null!=companyProfile.Description)sb.Append("\n").Append(companyProfile.Description);
        return sb.ToString();
      }
    }
    public String HoldingSymbolDescription
    {
      get
      {
        if(null==selectedItem||null==selectedItem.HoldingSymbol) return "No row selected.";
        StringBuilder sb=new StringBuilder();
        CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(selectedItem.HoldingSymbol);
        if(null!=companyProfile&&null!=companyProfile.Symbol&&null!=companyProfile.CompanyName)sb.Append(companyProfile.Symbol).Append(" - ").Append(companyProfile.CompanyName).Append("\n");
        String sector=PricingDA.GetSectorForSymbol(selectedItem.HoldingSymbol);
        String industry=PricingDA.GetIndustryForSymbol(selectedItem.HoldingSymbol);
        if(!String.IsNullOrEmpty(sector)) sb.Append(sector);
        if(!String.IsNullOrEmpty(industry)) sb.Append("/").Append(industry);
        if(null!=companyProfile&&null!=companyProfile.Description) sb.Append("\n").Append(companyProfile.Description);
        return sb.ToString();
      }
    }   
  }
}
