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 { private 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 { if ((value == null) || String.Equals(value,"")) return ""; var block = Serialization.Deserialize(value.ToString()); if (String.Equals(parameter, "ID")) return block.ID; if (String.Equals(parameter, "Revision")) return String.IsNullOrWhiteSpace(block.Revision) ? "--" : String.Format("Rev {0}",block.Revision); if (String.Equals(parameter, "Status")) return block.Status.ToString().SplitCamelCase(); if (String.Equals(parameter, "Color")) return ImageUtils.ColorToString(_statuscolors[block.Status]); if (String.Equals(parameter, "Date")) return String.Format("{0:dd MMM yy}", block.Date); if (String.Equals(parameter, "Notes")) return block.Notes; if (String.Equals(parameter, "NotesColor")) return String.IsNullOrWhiteSpace(block.Notes) ? ImageUtils.ColorToString(Color.Transparent) : ImageUtils.ColorToString(Color.Orchid); if (String.Equals(parameter, "Attachments")) return String.Format("{0} files attached", block.Attachments); if (String.Equals(parameter, "AttachmentsColor")) return block.Attachments == 0 ? ImageUtils.ColorToString(Color.Transparent) : ImageUtils.ColorToString(Color.CornflowerBlue); return parameter.ToString(); } catch (Exception e) { return e.Message; } } public object ConvertBack(object value, Type t, object parameter, CultureInfo culture) { return value.Equals(false) ? DependencyProperty.UnsetValue : parameter; } } }