コード例 #1
0
        protected void Create_Click(object sender, EventArgs e)
        {
            using (var context = new FatDataContext())
            {
                var code = CodeTextBox.Text;
                var existingStock = context.Stocks.Find(code);

                if (existingStock != null)
                {
                    SetMessage("Stock {0} already exists.", code);
                    return;
                }

                var newStock = context.Stocks.Create();

                newStock.Code = code;
                newStock.CreatedUtcDate = DateTime.UtcNow;
                newStock.Industry = IndustryDropDownList.SelectedValue;
                newStock.IsActive = true;
                newStock.Name = NameTextBox.Text;

                context.Stocks.Add(newStock);
                context.SaveChanges();

                SetMessage("Stock {0} created.", code);

                CodeTextBox.Text = "";
                IndustryDropDownList.SelectedIndex = -1;
                NameTextBox.Text = "";
            }
        }
コード例 #2
0
        protected void Download_Click(object sender, EventArgs e)
        {
            using (var context = new FatDataContext())
            {
                var code = Request.QueryString["code"];

                var earnings = context.StockEarnings.Where(
                    s => s.StockCode == code)
                    .Select(earning => new
                    {
                        earning.StockCode,
                        earning.Year,
                        earning.Period,
                        earning.FormattedReportedDate,
                        earning.NPAT,
                        earning.Margin,
                        earning.CashFlow,
                        earning.EPS,
                        earning.DPS,
                        earning.ROE
                    }).AsQueryable();

                DownloadHelper.DownloadAsCsv(Context, earnings, code + "_earnings.csv");
            }
        }
コード例 #3
0
ファイル: List.ascx.cs プロジェクト: benmcevoy/FatDividends
        protected void Download_Click(object sender, EventArgs e)
        {
            using (var context = new FatDataContext())
            {
                IEnumerable<Services.Models.Stock> stocks;
                var filter = FilterTextBox.Text;

                if (string.IsNullOrWhiteSpace(filter))
                {
                    stocks = context.Stocks;
                }
                else
                {
                    stocks = context.Stocks.Where(
                           s => s.Code.StartsWith(FilterTextBox.Text)
                                || s.Name.StartsWith(FilterTextBox.Text));
                }

                // TODO: move to repository?
                var csv = stocks.Select(s => new
                    {
                        s.Code,
                        s.Name,
                        s.Industry,
                        Active = s.IsActive ? "active" : "inactive"
                    }).AsQueryable();

                DownloadHelper.DownloadAsCsv(Context, csv, "stock.csv");
            }
        }
コード例 #4
0
        private void AddIndexQuoteUncommited(FatDataContext context, IndexQuote quote)
        {
            // exists
            var indexQuote = context.IndexQuotes.Find(quote.ClosingDate);

            if (indexQuote == null)
            {
                context.IndexQuotes.Add(quote);
            }
        }
コード例 #5
0
        private void AddUncomitted(FatDataContext context, StockDividend stockDividend)
        {
            // exists
            var dividend = context.StockDividends.Find(stockDividend.StockCode, stockDividend.ExDate);

            if (dividend == null)
            {
                context.StockDividends.Add(stockDividend);
            }
        }
コード例 #6
0
        private void AddUncomitted(FatDataContext context, StockEarning stockEarning)
        {
            // exists
            var earning = context.StockEarnings.Find(stockEarning.StockCode, stockEarning.ReportedDate);

            if (earning == null)
            {
                context.StockEarnings.Add(stockEarning);
            }
        }
コード例 #7
0
        public void AddQuotes(IEnumerable<StockQuote> quotes)
        {
            using (var context = new FatDataContext())
            {
                foreach (var quote in quotes)
                {
                    AddQuoteUncommited(context, quote);
                }

                context.SaveChanges();
            }
        }
コード例 #8
0
        public void AddIndexQuotes(IEnumerable<IndexQuote> quotes)
        {
            // use own context for bulk insert
            using (var context = new FatDataContext())
            {
                foreach (var quote in quotes)
                {
                    AddIndexQuoteUncommited(context, quote);
                }

                context.SaveChanges();
            }
        }
コード例 #9
0
        public void Add(IEnumerable<StockDividend> stockDividends)
        {
            // use own context for bulk insert
            using (var context = new FatDataContext())
            {
                foreach (var dividend in stockDividends)
                {
                    AddUncomitted(context, dividend);
                }

                context.SaveChanges();
            }
        }
コード例 #10
0
        public void Add(IEnumerable<StockEarning> stockEarnings)
        {
            // use own context for bulk insert
            using (var context = new FatDataContext())
            {
                foreach (var earning in stockEarnings)
                {
                    AddUncomitted(context, earning);
                }

                context.SaveChanges();
            }
        }
コード例 #11
0
        protected void Create_Click(object sender, EventArgs e)
        {
            using (var context = new FatDataContext())
            {
                var code = Request.QueryString["code"];
                var reportedDate = ReportedDateTextBox.Text.ToDate();
                var existingEarning = context.StockEarnings.Find(code, reportedDate);

                if (existingEarning != null)
                {
                    SetMessage("Earning already exists for this stock and reported date.");
                    return;
                }

                var newEarning = context.StockEarnings.Create();

                newEarning.StockCode = code;
                newEarning.CreatedUtcDate = DateTime.UtcNow;
                newEarning.ReportedDate = ReportedDateTextBox.Text.ToDate().Value;
                newEarning.Year = YearTextBox.Text;
                newEarning.Period = PeriodTextBox.Text;
                newEarning.NPAT = NPATTextBox.Text.ToDecimal();
                newEarning.Margin = MarginTextBox.Text;
                newEarning.CashFlow = CashFlowTextBox.Text;
                newEarning.EPS = EPSTextBox.Text.ToDecimal();
                newEarning.DPS = DPSTextBox.Text.ToDecimal();
                newEarning.ROE = ROETextBox.Text.ToDecimal();

                Fat.Import.EarningsCalendarImporter.Import(newEarning);

                SetMessage("Earning created.");

                ReportedDateTextBox.Text = "";
                YearTextBox.Text = "";
                PeriodTextBox.Text = "";
                NPATTextBox.Text = "";
                MarginTextBox.Text = "";
                CashFlowTextBox.Text = "";
                EPSTextBox.Text = "";
                DPSTextBox.Text = "";
                ROETextBox.Text = "";
            }
        }
コード例 #12
0
        protected void Download_Click(object sender, EventArgs e)
        {
            using (var context = new FatDataContext())
            {
                var code = Request.QueryString["code"];
                var dividends = context.StockDividends.Where(
                    s => s.StockCode == code)
                    .Select(d => new
                        {
                            d.StockCode,
                            d.FormattedExDate,
                            d.Amount,
                            d.Franked,
                            d.FormattedRecordDate,
                            d.FormattedPayableDate,
                            d.FrankingCredit,
                            d.ClosingPrice
                        }).AsQueryable();

                DownloadHelper.DownloadAsCsv(Context, dividends,  code + "_dividends.csv");
            }
        }
コード例 #13
0
        protected void Create_Click(object sender, EventArgs e)
        {
            using (var context = new FatDataContext())
            {
                var code = Request.QueryString["code"];
                var exDate = ExDateTextBox.Text.ToDate();
                var existingDividend = context.StockDividends.Find(code, exDate);

                if (existingDividend != null)
                {
                    SetMessage("Dividend already exists for this stock and ex date.");
                    return;
                }

                var newDividend = context.StockDividends.Create();

                newDividend.StockCode = code;
                newDividend.CreatedUtcDate = DateTime.UtcNow;
                newDividend.Amount = AmountTextBox.Text.ToDecimal();
                newDividend.ExDate = exDate.Value;
                newDividend.Franked = FrankedTextBox.Text.ToDecimal();
                newDividend.FrankingCredit = FrankingCreditTextBox.Text.ToDecimal();
                newDividend.PayableDate = PayableDateTextBox.Text.ToDate().Value;
                newDividend.RecordDate = RecordDateTextBox.Text.ToDate();

                Fat.Import.DividendCalendarImporter.Import(newDividend);

                SetMessage("Dividend created.");

                ExDateTextBox.Text = "";
                AmountTextBox.Text = "";
                FrankedTextBox.Text = "";
                FrankingCreditTextBox.Text = "";
                RecordDateTextBox.Text = "";
                PayableDateTextBox.Text = "";
            }
        }
コード例 #14
0
        private void AddQuoteUncommited(FatDataContext context, StockQuote quote)
        {
            // exists
            var stockQuote = context.StockQuotes.Find(quote.StockCode, quote.ClosingDate);
            var stock = context.Stocks.Find(quote.StockCode);

            if (stockQuote == null)
            {
                context.StockQuotes.Add(quote);
            }

            stock.LastRefreshDateTime = DateTime.UtcNow;
        }
コード例 #15
0
ファイル: Service.cs プロジェクト: benmcevoy/FatDividends
 protected Service()
 {
     _context = new FatDataContext();
 }
コード例 #16
0
 protected void StocksEntityDataSource_OnContextCreating(object sender, EntityDataSourceContextCreatingEventArgs e)
 {
     var db = new FatDataContext();
     e.Context = (db as IObjectContextAdapter).ObjectContext;
 }