FormulaTableManager.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using FMSAdmin.Data;
  8. namespace FMSAdmin.Helpers {
  9. public class FormulaTableManager {
  10. private FMSContext _context;
  11. Dictionary<string, TableComparerValue[]> tables;
  12. public FormulaTableManager(FMSContext context) {
  13. _context = context;
  14. tables = new Dictionary<string, TableComparerValue[]>();
  15. }
  16. public TableComparerValue[] GetTableValues(string functionName) {
  17. TableComparerValue[] values;
  18. if (this.tables.ContainsKey(functionName)) {
  19. values = this.tables[functionName];
  20. } else {
  21. var queryTable = from table in _context.BemsFormulaTable
  22. from value in _context.BemsFormulaTableValue
  23. where table.FunctionName == functionName &&
  24. table.TableId == value.TableId
  25. select new TableComparerValue {
  26. XValue = value.XValue,
  27. YValue = value.YValue
  28. };
  29. if (queryTable.Any() == false) {
  30. return null;
  31. }
  32. values = queryTable.ToArray();
  33. }
  34. return values;
  35. }
  36. public class TableComparerValue : IComparable<TableComparerValue> {
  37. public double XValue { get; set; }
  38. public double YValue { get; set; }
  39. public int CompareTo(TableComparerValue other) {
  40. var otherXValue = other.XValue;
  41. if (XValue < otherXValue) {
  42. return -1;
  43. } else if (XValue > otherXValue) {
  44. return 1;
  45. }
  46. return 0;
  47. }
  48. };
  49. }
  50. }