public void RemoveComponentfromIndex(string index, StockSymbol symbol) { using (StockDataEntities context = new StockDataEntities()) { StockIndex stockIndex = context.StockIndexes .Where(i => string.Compare(i.IndexName, index, true) == 0).FirstOrDefault(); if (stockIndex != null) { var existingSymbol = context.StockSymbols .Where(s => string.Compare(s.Symbol, symbol.Symbol, true) == 0).SingleOrDefault(); if (existingSymbol != null) { stockIndex.StockSymbols.Remove(existingSymbol); } else { throw new ApplicationException(string.Format("Cannot find symbol: {0}", symbol.Symbol)); } context.SaveChanges(); } } }
private void QuerySymbolInfo(string symbol) { if (!string.IsNullOrEmpty(symbol)) { this._stockSymbol = this._symbolRepository.GetSymbol(symbol); if (this._stockSymbol != null) { this._chartDate = DateTime.Today; this.txtSymbol.Text = symbol; this.txtFullInfo.Text = string.Format("{0} - {1} ({2:yyyy-MM-dd} - {3:yyyy-MM-dd})", this._stockSymbol.StockName, this._stockSymbol.Sector, this._stockSymbol.StartDate, this._stockSymbol.EndDate); this.rbDay.IsChecked = true; this._stockChartUI = new StockChartUI(this.cvChart, this._stockSymbol.Symbol, 1, this.ActualWidth); DrawChart(1); } else { MessageBox.Show(string.Format("Cannot find infromation for {0}", this.txtSymbol.Text)); } } EnableControls(); }
/// <summary> /// Upload Symols into database /// The format is /// Index, Symbol, Stock Name, Sector, Country, ETF, HasFuture /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpload_Click(object sender, RoutedEventArgs e) { string[] lines = this.txtSymbols.Text.Replace("\r", "") .Split(new[] {'\n'},StringSplitOptions.RemoveEmptyEntries); List<IndexComponents> indexComponentList = new List<IndexComponents>(); StockCountryRepository countryRepository = new StockCountryRepository(); List<StockCountry> allCountries = countryRepository.GetCountryList(); #region Parse all lines foreach (string line in lines) { string[] items = line.Split(','); if (items.Length != 7) { MessageBox.Show(string.Format("Invalid Symbol : {0}", line), "Invalid Symbol", MessageBoxButton.OK, MessageBoxImage.Error); return; } else { int etf = 0; int hasFuture= 0; string index = string.IsNullOrEmpty(items[0]) ? "NULL" : items[0]; StockSymbol symbol = new StockSymbol(); symbol.Symbol = items[1]; symbol.StockName = items[2]; symbol.Sector = items[3]; symbol.Country = items[4]; if ((allCountries.Where(c => string.Compare(c.Code, symbol.Country, true) <= 0). Count()) <= 0) { MessageBox.Show(string.Format("Invalid Country Code : {0}", line), "Invalid Country Code", MessageBoxButton.OK, MessageBoxImage.Error); return; } int.TryParse(items[5],out etf); symbol.ETF = etf; int.TryParse(items[6], out hasFuture); symbol.HasFuture = hasFuture>0; IndexComponents indexCom = indexComponentList .Where(i => string.Compare(i.Index, index, true) == 0).SingleOrDefault(); if (indexCom == null) { indexCom = new IndexComponents() { Index = index }; indexComponentList.Add(indexCom); } indexCom.Symbols.Add(symbol); } } #endregion foreach (IndexComponents indexCom in indexComponentList) { if (string.Compare(indexCom.Index, "NULL", true) != 0) { StockIndex index = this._stockIndexReposotory.GetAllIndexes() .Where(i => string.Compare(i.IndexName, indexCom.Index, true) == 0).SingleOrDefault(); if (index == null) { MessageBox.Show(string.Format("Invalid index name: {0}", indexCom.Index), "Invalid Index", MessageBoxButton.OK, MessageBoxImage.Error); return; } this._stockSymbolRepository.UpdateSymbols(indexCom.Symbols); this._stockIndexReposotory.AddComponentsToIndex(indexCom.Index, indexCom.Symbols); } } MessageBox.Show("Uploading complete successfully", "Upload Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); }