WarningSignConverter.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using Muchinfo.MTPClient.Data.Enums;
  2. using Muchinfo.MTPClient.Resources;
  3. using System;
  4. using System.Windows.Data;
  5. namespace Muchinfo.MTPClient.Infrastructure.Converters
  6. {
  7. public class WarningSignConverter : IMultiValueConverter
  8. {
  9. public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  10. {
  11. string result = string.Empty;
  12. string direction = string.Empty;
  13. string warningSign = string.Empty;
  14. string warningValue = string.Empty;
  15. if (values != null && values.Length == 4)
  16. {
  17. if (values[0] is WarningType)
  18. {
  19. WarningType warningType = (WarningType)values[0];
  20. if (warningType == WarningType.Quote)
  21. {
  22. Direction value1 = (Direction)values[1];
  23. switch (value1)
  24. {
  25. case Direction.Ask:
  26. direction = Client_Resource.Infrastructure_sell;
  27. break;
  28. case Direction.Bid:
  29. direction = Client_Resource.Infrastructure_buy;
  30. break;
  31. }
  32. }
  33. var value = (WarningSign)values[2];
  34. switch (value)
  35. {
  36. case WarningSign.Equal:
  37. warningSign = "=";
  38. break;
  39. case WarningSign.GreaterThan:
  40. warningSign = ">";
  41. break;
  42. case WarningSign.LessThan:
  43. warningSign = "<";
  44. break;
  45. }
  46. warningValue = values[3].ToString();
  47. }
  48. }
  49. return string.Format("{0}{1}{2}", direction, warningSign, warningValue);
  50. }
  51. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
  52. {
  53. throw new NotImplementedException();
  54. }
  55. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  56. {
  57. string result = string.Empty;
  58. if (value != null)
  59. {
  60. var warningSign = (WarningSign)value;
  61. switch (warningSign)
  62. {
  63. case WarningSign.Equal:
  64. result = "=";
  65. break;
  66. case WarningSign.GreaterThan:
  67. result = ">";
  68. break;
  69. case WarningSign.LessThan:
  70. result = "<";
  71. break;
  72. }
  73. }
  74. return result;
  75. }
  76. }
  77. }