StockTransactionConverter.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using InABox.Mobile;
  6. using Xamarin.Forms;
  7. namespace PRS.Mobile
  8. {
  9. public class TransactionColorConverter : BindableObject, IMultiValueConverter
  10. {
  11. public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  12. {
  13. var result = Color.Transparent;
  14. if (values?.Length == 2 && values.First() is StockTransaction transaction && values.Last() is Guid guid)
  15. {
  16. result = guid == (transaction?.Source?.LocationID ?? Guid.Empty)
  17. ? Color.Orange
  18. : Color.LightGreen;
  19. }
  20. return result;
  21. }
  22. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  23. {
  24. throw new NotImplementedException();
  25. }
  26. }
  27. public class TransactionDisplayConverter : BindableObject, IMultiValueConverter
  28. {
  29. public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  30. {
  31. if (values?.Length == 2 && values.First() is StockTransaction transaction && values.Last() is Guid guid)
  32. {
  33. StockTransactionView view = guid == (transaction?.Source?.LocationID ?? Guid.Empty)
  34. ? StockTransactionView.Source
  35. : StockTransactionView.Target;
  36. return transaction?.Display(view) ?? string.Empty;
  37. }
  38. return "";
  39. }
  40. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  41. {
  42. throw new NotImplementedException();
  43. }
  44. }
  45. // public class StockTransactionConverter : AbstractConverter<StockTransaction, string>
  46. // {
  47. //
  48. // public StockTransactionView View { get; set; }
  49. //
  50. // public StockTransactionProperty Property { get; set; }
  51. //
  52. // protected override string? Convert(StockTransaction? value, object? parameter = null)
  53. // {
  54. // if (value == null)
  55. // return "";
  56. //
  57. // switch (Property)
  58. // {
  59. // case StockTransactionProperty.Style when value.Source.StyleID != value.Target.StyleID:
  60. // return View == StockTransactionView.Source
  61. // ? value.Source.StyleCode
  62. // : value.Target.StyleCode;
  63. // case StockTransactionProperty.Location when value.Source.LocationID != value.Target.LocationID:
  64. // return View == StockTransactionView.Source
  65. // ? value.Source.LocationCode
  66. // : value.Target.LocationCode;
  67. // case StockTransactionProperty.Job when value.Source.JobID != value.Target.JobID:
  68. // return View == StockTransactionView.Source
  69. // ? $"Job {value.Source.JobNumber}"
  70. // : $"Job {value.Target.JobNumber}";
  71. // default:
  72. // return "";
  73. // }
  74. //
  75. // }
  76. // }
  77. }