JobDocumentSetMileStoneConverter.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Globalization;
  5. using System.Windows;
  6. using System.Windows.Data;
  7. using Comal.Classes;
  8. using InABox.Core;
  9. using InABox.WPF;
  10. namespace PRSDesktop
  11. {
  12. public class JobDocumentSetMileStoneConverter : IValueConverter
  13. {
  14. public static Dictionary<JobDocumentSetMileStoneStatus, System.Drawing.Color> StatusColors = new Dictionary<JobDocumentSetMileStoneStatus, Color>()
  15. {
  16. { JobDocumentSetMileStoneStatus.Unknown, System.Drawing.Color.Red },
  17. { JobDocumentSetMileStoneStatus.NotStarted, System.Drawing.Color.LightSalmon },
  18. { JobDocumentSetMileStoneStatus.InProgress, System.Drawing.Color.LightYellow },
  19. { JobDocumentSetMileStoneStatus.OnHold, System.Drawing.Color.Silver },
  20. { JobDocumentSetMileStoneStatus.InfoRequired, System.Drawing.Color.Silver },
  21. { JobDocumentSetMileStoneStatus.Submitted, System.Drawing.Color.Plum },
  22. { JobDocumentSetMileStoneStatus.Approved, System.Drawing.Color.LightGreen },
  23. { JobDocumentSetMileStoneStatus.Rejected, System.Drawing.Color.Gray },
  24. { JobDocumentSetMileStoneStatus.Cancelled, System.Drawing.Color.Gray },
  25. };
  26. public object Convert(object value, Type t, object parameter, CultureInfo culture)
  27. {
  28. try
  29. {
  30. switch (parameter)
  31. {
  32. case "ID":
  33. if (ValidJson(value))
  34. return GetBlock(value).ID;
  35. else
  36. return Guid.Empty;
  37. case "Revision":
  38. if (ValidJson(value))
  39. return String.IsNullOrWhiteSpace(GetBlock(value).Revision)
  40. ? "--"
  41. : String.Format("Rev {0}", GetBlock(value).Revision);
  42. else
  43. return "";
  44. case "Status":
  45. if (ValidJson(value))
  46. return GetBlock(value).Status.ToString().SplitCamelCase();
  47. else
  48. return "";
  49. case "Color":
  50. if (ValidJson(value))
  51. return ImageUtils.ColorToString(StatusColors[GetBlock(value).Status]);
  52. else
  53. return ImageUtils.ColorToString(Color.White);
  54. case "Date":
  55. if (ValidJson(value))
  56. return String.Format("{0:dd MMM yy}", GetBlock(value).Date);
  57. else
  58. return "";
  59. case "Notes":
  60. if (ValidJson(value))
  61. return GetBlock(value).Notes;
  62. else
  63. return "";
  64. case "NotesColor":
  65. if (ValidJson(value))
  66. return String.IsNullOrWhiteSpace(GetBlock(value).Notes)
  67. ? ImageUtils.ColorToString(Color.Transparent)
  68. : ImageUtils.ColorToString(Color.Orchid);
  69. else
  70. return ImageUtils.ColorToString(Color.Transparent);
  71. case "Kanbans":
  72. if (ValidJson(value))
  73. return GetBlock(value).Kanbans > 0 ? "Visible" : "Collapsed";
  74. else
  75. return "Collapsed";
  76. }
  77. return parameter.ToString();
  78. }
  79. catch (Exception e)
  80. {
  81. return e.Message;
  82. }
  83. }
  84. private static JobDocumentSetMileStoneBlock? GetBlock(object value)
  85. {
  86. return Serialization.Deserialize<JobDocumentSetMileStoneBlock>(value.ToString());
  87. }
  88. private bool ValidJson(object value)
  89. {
  90. if (value == null)
  91. return false;
  92. if ("".Equals(value))
  93. return false;
  94. else
  95. return true;
  96. }
  97. public object ConvertBack(object value, Type t, object parameter, CultureInfo culture)
  98. {
  99. return value.Equals(false) ? DependencyProperty.UnsetValue : parameter;
  100. }
  101. }
  102. }