JobDocumentSetMileStoneConverter.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. private 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. if ((value == null) || String.Equals(value,""))
  31. return "";
  32. var block = Serialization.Deserialize<JobDocumentSetMileStoneBlock>(value.ToString());
  33. if (String.Equals(parameter, "ID"))
  34. return block.ID;
  35. if (String.Equals(parameter, "Revision"))
  36. return String.IsNullOrWhiteSpace(block.Revision)
  37. ? "--"
  38. : String.Format("Rev {0}",block.Revision);
  39. if (String.Equals(parameter, "Status"))
  40. return block.Status.ToString().SplitCamelCase();
  41. if (String.Equals(parameter, "Color"))
  42. return ImageUtils.ColorToString(_statuscolors[block.Status]);
  43. if (String.Equals(parameter, "Date"))
  44. return String.Format("{0:dd MMM yy}", block.Date);
  45. if (String.Equals(parameter, "Notes"))
  46. return block.Notes;
  47. if (String.Equals(parameter, "NotesColor"))
  48. return String.IsNullOrWhiteSpace(block.Notes)
  49. ? ImageUtils.ColorToString(Color.Transparent)
  50. : ImageUtils.ColorToString(Color.Orchid);
  51. if (String.Equals(parameter, "Attachments"))
  52. return String.Format("{0} files attached", block.Attachments);
  53. if (String.Equals(parameter, "AttachmentsColor"))
  54. return block.Attachments == 0
  55. ? ImageUtils.ColorToString(Color.Transparent)
  56. : ImageUtils.ColorToString(Color.CornflowerBlue);
  57. return parameter.ToString();
  58. }
  59. catch (Exception e)
  60. {
  61. return e.Message;
  62. }
  63. }
  64. public object ConvertBack(object value, Type t, object parameter, CultureInfo culture)
  65. {
  66. return value.Equals(false) ? DependencyProperty.UnsetValue : parameter;
  67. }
  68. }
  69. }