protected IList <IndexData> GetLastIndexData(stock stock, IndexDefinitionInfo define) { using (StockManDBEntities entity = new StockManDBEntities()) { string sql = @"select * from " + define.table_name + " where f_code='" + stock.code + "' order by code desc limit 50"; entity.Database.Connection.Open(); using (entity.Database.Connection) { System.Data.IDbCommand commond = entity.Database.Connection.CreateCommand(); commond.CommandText = sql; IDataReader reader = commond.ExecuteReader(); IList <IndexData> list = new List <IndexData>(); while (reader.Read()) { IndexData id = new IndexData(); id.date = DateTime.Parse(reader["date"] + ""); foreach (var filed in define.fields) { id.Add(double.Parse(reader[filed.name] + "")); } list.Add(id); } entity.Database.Connection.Close(); return(list); } } }
/* ========================================================================== Operations */ public void AddDocument(IndexDocument document) { var versionId = document.GetIntegerValue(IndexFieldName.VersionId); var storedFields = document.Where(f => f.Store == IndexStoringMode.Yes).ToList(); if (storedFields.Count > 0) { StoredData.Add(new Tuple <int, List <IndexField> >(versionId, storedFields)); } foreach (var field in document) { var fieldName = field.Name; if (!IndexData.TryGetValue(fieldName, out var existingFieldData)) { existingFieldData = new Dictionary <string, List <int> >(); IndexData.Add(fieldName, existingFieldData); } var fieldValues = GetValues(field); foreach (var fieldValue in fieldValues) { if (!existingFieldData.TryGetValue(fieldValue, out var versionIds)) { versionIds = new List <int>(); existingFieldData.Add(fieldValue, versionIds); } versionIds.Add(versionId); } } }