using System; using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.Windows; using System.Windows.Data; using Comal.Classes; using InABox.Core; using InABox.WPF; namespace PRSDesktop { public class JobDocumentSetMileStoneConverter : IValueConverter { public static Dictionary StatusColors = new Dictionary() { { JobDocumentSetMileStoneStatus.Unknown, System.Drawing.Color.Red }, { JobDocumentSetMileStoneStatus.NotStarted, System.Drawing.Color.LightSalmon }, { JobDocumentSetMileStoneStatus.InProgress, System.Drawing.Color.LightYellow }, { JobDocumentSetMileStoneStatus.OnHold, System.Drawing.Color.Silver }, { JobDocumentSetMileStoneStatus.InfoRequired, System.Drawing.Color.Silver }, { JobDocumentSetMileStoneStatus.Submitted, System.Drawing.Color.Plum }, { JobDocumentSetMileStoneStatus.Approved, System.Drawing.Color.LightGreen }, { JobDocumentSetMileStoneStatus.Rejected, System.Drawing.Color.Gray }, { JobDocumentSetMileStoneStatus.Cancelled, System.Drawing.Color.Gray }, }; public object Convert(object value, Type t, object parameter, CultureInfo culture) { try { switch (parameter) { case "ID": if (ValidJson(value)) return GetBlock(value).ID; else return Guid.Empty; case "Revision": if (ValidJson(value)) return String.IsNullOrWhiteSpace(GetBlock(value).Revision) ? "--" : String.Format("Rev {0}", GetBlock(value).Revision); else return ""; case "Status": if (ValidJson(value)) return GetBlock(value).Status.ToString().SplitCamelCase(); else return ""; case "Color": if (ValidJson(value)) return ImageUtils.ColorToString(StatusColors[GetBlock(value).Status]); else return ImageUtils.ColorToString(Color.White); case "Date": if (ValidJson(value)) return String.Format("{0:dd MMM yy}", GetBlock(value).Date); else return ""; case "Notes": if (ValidJson(value)) return GetBlock(value).Notes; else return ""; case "NotesColor": if (ValidJson(value)) return String.IsNullOrWhiteSpace(GetBlock(value).Notes) ? ImageUtils.ColorToString(Color.Transparent) : ImageUtils.ColorToString(Color.Orchid); else return ImageUtils.ColorToString(Color.Transparent); case "Attachments": if (ValidJson(value)) return String.Format("{0} files attached", GetBlock(value).Attachments); else return ""; case "AttachmeentsColor": if (ValidJson(value)) return GetBlock(value).Attachments == 0 ? ImageUtils.ColorToString(Color.Transparent) : ImageUtils.ColorToString(Color.CornflowerBlue); else return ImageUtils.ColorToString(Color.Transparent); } return parameter.ToString(); } catch (Exception e) { return e.Message; } } private static JobDocumentSetMileStoneBlock? GetBlock(object value) { return Serialization.Deserialize(value.ToString()); } private bool ValidJson(object value) { if (value == null) return false; if ("".Equals(value)) return false; else return true; } public object ConvertBack(object value, Type t, object parameter, CultureInfo culture) { return value.Equals(false) ? DependencyProperty.UnsetValue : parameter; } } }