示例#1
0
        /// <summary>
        /// Gets the holdings for the selected account from the database.
        /// </summary>
        /// <param name="accountName">Name of the account.</param>
        /// <returns></returns>
        public static List <StocksGrid> GetHoldings(string accountName)
        {
            PortfolioManagerDB dataContext = new PortfolioManagerDB(connString);

            dataContext.ObjectTrackingEnabled = false;

            var r = from stocks in dataContext.Holdings
                    where stocks.Accounts.AccountName == accountName
                    select new StocksGrid
            {
                Symbol             = stocks.Quotes_Symbol,
                CompanyName        = stocks.Quotes.CompanyName,
                Quantity           = stocks.Quantity,
                Price              = stocks.PricePaid,
                PurchaseDate       = stocks.PurchaseDate,
                IndustryName       = stocks.Quotes.Industries.IndusrtyName,
                SectorName         = stocks.Quotes.Industries.Sectors.SectorName,
                StockExchangeName  = stocks.StockExchanges.StockExchangeName,
                QuoteChange        = stocks.Quotes.Change,
                QuotePercentChange = stocks.Quotes.PercentChange,
                Volume             = stocks.Quotes.Volume
            };

            return(r.ToList <StocksGrid>());
        }
        /// <summary>
        /// Gets the historial quotes for symbol from the database.
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        /// <returns></returns>
        List <HistoricalQuotes> GetHistorialQuotesForSymbol(string symbol)
        {
            PortfolioManagerDB dataContext = new PortfolioManagerDB(DataUtils.connString);

            return(dataContext.HistoricalQuotes
                   .Where(quotes => quotes.Symbol == symbol)
                   .OrderBy(quotes => quotes.Date).ToList());
        }
示例#3
0
        /// <summary>
        /// Gets the accounts from the database.
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <string> GetAccounts()
        {
            PortfolioManagerDB dataContext = new PortfolioManagerDB(connString);

            var accountNames = from accounts in dataContext.Accounts
                               orderby accounts.AccountName ascending
                               select accounts.AccountName;

            return(accountNames as IEnumerable <string>);
        }
        /// <summary>
        /// Gets the stock symbols for the selected account from the database.
        /// </summary>
        /// <param name="accountName">Name of the account.</param>
        /// <returns></returns>
        public static IEnumerable <string> GetStockSymbols(string accountName)
        {
            PortfolioManagerDB dataContext = new PortfolioManagerDB(DataUtils.connString);

            var symbolname = from stocks in dataContext.Holdings
                             where stocks.Accounts.AccountName == accountName
                             select stocks.Quotes_Symbol;

            return(symbolname as IEnumerable <string>);
        }
示例#5
0
        /// <summary>
        /// Gets the sector names of the selected account from the database .
        /// </summary>
        /// <param name="accountName">Name of the account.</param>
        /// <returns></returns>
        List <SectorAndValue> GetSectorNames(string accountName)
        {
            PortfolioManagerDB dataContext = new PortfolioManagerDB(DataUtils.connString);

            var Sectors = from stocks in dataContext.Holdings
                          where stocks.Accounts.AccountName == accountName
                          group(stocks.PricePaid *stocks.Quantity) by stocks.Quotes.Industries.Sectors.SectorName into sectors
                          select new SectorAndValue
            {
                SectorName = sectors.Key,
                Value      = sectors.Sum()
            };

            return(Sectors.ToList <SectorAndValue>());
        }
示例#6
0
        /// <summary>
        /// Gets the StockExchange names and values.
        /// </summary>
        /// <param name="accountName">Name of the account.</param>
        /// <returns></returns>
        List <ExchangeAndValue> GetExchangeNamesAndValues(string accountName)
        {
            PortfolioManagerDB dataContext = new PortfolioManagerDB(DataUtils.connString);

            var Exchanges = from holdings in dataContext.Holdings
                            where holdings.Accounts.AccountName == accountName
                            group(holdings.PricePaid *holdings.Quantity) by holdings.StockExchanges.Country into exchanges
                            select new ExchangeAndValue
            {
                ExchangeName = exchanges.Key,
                Value        = exchanges.Sum()
            };

            return(Exchanges.ToList <ExchangeAndValue>());
        }
示例#7
0
        /// <summary>
        /// Gets the account list from the database.
        /// </summary>
        /// <returns>The list of Accounts</returns>
        public static List <Account> GetAccountList()
        {
            PortfolioManagerDB dataContext = new PortfolioManagerDB(DataUtils.connString);

            var accountNames = from accounts in dataContext.Accounts
                               orderby accounts.AccountName ascending
                               select new Account
            {
                AccountName = accounts.AccountName,
                OpenBalance = accounts.OpenBalance,
                Image       = accounts.ImageKey
            };

            return(accountNames.ToList());
        }
示例#8
0
        /// <summary>
        /// Gets the stock info.
        /// </summary>
        /// <returns></returns>
        public List <Holdings> GetStockInfo()
        {
            List <Holdings> stockInfo = new List <Holdings>();

            if (!LayoutControl.IsInDesignMode)
            {
                string             connectionString = string.Format(@"Data Source = {0}", LayoutControl.FindFile("PortfolioManagerDB.sdf"));
                PortfolioManagerDB dataContext      = new PortfolioManagerDB(connectionString);
                var list = dataContext.Holdings.ToList();
                foreach (var o in list)
                {
                    stockInfo.Add(o);
                }
            }
            return(stockInfo);
        }
示例#9
0
        /// <summary>
        /// Gets the quotes data.
        /// </summary>
        /// <returns></returns>
        public ObservableCollection <Quotes> GetQuotesData()
        {
            ObservableCollection <Quotes> _Quotes = new ObservableCollection <Quotes>();

            if (!LayoutControl.IsInDesignMode)
            {
                string             connectionString = string.Format(@"Data Source = {0}", LayoutControl.FindFile("PortfolioManagerDB.sdf"));
                PortfolioManagerDB dataContext      = new PortfolioManagerDB(connectionString);
                var list = dataContext.Quotes.ToList();
                foreach (var l in list)
                {
                    _Quotes.Add(l);
                }
            }
            return(_Quotes);
        }
示例#10
0
        public static List <DateAssetValue> GetDateAndAssetValue(string AccoutName, DateTime MinDate, DateTime MaxDate)
        {
            string connectionString = string.Format(@"Data Source = {0}", LayoutControl.FindFile("PortfolioManagerDB.sdf"));

            using (PortfolioManagerDB DB = new PortfolioManagerDB(connectionString))
            {
                DB.ObjectTrackingEnabled = false;

                List <DateAssetValue> list = new List <DateAssetValue>();

                var Dates = from hist in DB.HistoricalQuotes
                            where hist.Date > MinDate
                            where hist.Date <= MaxDate
                            group hist by hist.Date into date
                            orderby date.Key descending
                            select new { date.Key };

                foreach (var Date in Dates)
                {
                    DateTime date = DateTime.Parse(Date.Key.ToString());

                    var w = from holdings in DB.Holdings.Where(acct => acct.Accounts.AccountName == AccoutName)
                            join histQuotes in DB.HistoricalQuotes.Where(histQuotes => histQuotes.Date == date)
                            on holdings.Quotes_Symbol equals histQuotes.Symbol
                            group(holdings.Quantity *histQuotes.Close) by AccoutName into AssetValueAtDate
                            select new
                    {
                        Value = AssetValueAtDate.Sum()
                    };

                    Decimal?AssetValue = 0;
                    AssetValue = w.SingleOrDefault().Value;

                    DateAssetValue value = new DateAssetValue()
                    {
                        Date = date, AssetValue = AssetValue
                    };
                    list.Add(value);
                }

                return(list);
            }
        }