FormulaTableManager.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using iBemsDataService.Model;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. namespace iBemsDataService.Controllers.Bems.Formula
  7. {
  8. public class FormulaTableManager
  9. {
  10. private iBemsEntities db;
  11. Dictionary<string, TableComparerValue[]> tables;
  12. public FormulaTableManager()
  13. {
  14. db = new iBemsEntities();
  15. tables = new Dictionary<string , TableComparerValue[]>();
  16. }
  17. public TableComparerValue[] GetTableValues( string functionName )
  18. {
  19. TableComparerValue[] values;
  20. if( this.tables.ContainsKey( functionName ) )
  21. {
  22. values = this.tables[functionName];
  23. }
  24. else
  25. {
  26. var queryTable = from table in db.BemsFormulaTable
  27. from value in db.BemsFormulaTableValue
  28. where table.FunctionName == functionName &&
  29. table.TableId == value.TableId
  30. select new TableComparerValue {
  31. XValue = value.XValue,
  32. YValue = value.YValue
  33. };
  34. if( queryTable.Any() == false )
  35. {
  36. return null;
  37. }
  38. values = queryTable.ToArray();
  39. }
  40. return values;
  41. }
  42. public class TableComparerValue : IComparable<TableComparerValue>
  43. {
  44. public double XValue { get; set; }
  45. public double YValue { get; set; }
  46. public int CompareTo( TableComparerValue other )
  47. {
  48. var otherXValue = other.XValue;
  49. if( XValue < otherXValue )
  50. {
  51. return -1;
  52. }
  53. else if( XValue > otherXValue )
  54. {
  55. return 1;
  56. }
  57. return 0;
  58. }
  59. };
  60. }
  61. }