using iBemsDataService.Model; using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace iBemsDataService.Controllers.Bems.Formula { public class FormulaTableManager { private iBemsEntities db; Dictionary tables; public FormulaTableManager() { db = new iBemsEntities(); tables = new Dictionary(); } public TableComparerValue[] GetTableValues( string functionName ) { TableComparerValue[] values; if( this.tables.ContainsKey( functionName ) ) { values = this.tables[functionName]; } else { var queryTable = from table in db.BemsFormulaTable from value in db.BemsFormulaTableValue where table.FunctionName == functionName && table.TableId == value.TableId select new TableComparerValue { XValue = value.XValue, YValue = value.YValue }; if( queryTable.Any() == false ) { return null; } values = queryTable.ToArray(); } return values; } public class TableComparerValue : IComparable { public double XValue { get; set; } public double YValue { get; set; } public int CompareTo( TableComparerValue other ) { var otherXValue = other.XValue; if( XValue < otherXValue ) { return -1; } else if( XValue > otherXValue ) { return 1; } return 0; } }; } }