102 lines
4.1 KiB
C#
102 lines
4.1 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
|
|
namespace BeWo.Scheduler.Converter
|
|
{
|
|
public class TimeScale2TextConverter : IMultiValueConverter
|
|
{
|
|
|
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (values == null || values.Length != 3)
|
|
{
|
|
return null;
|
|
}
|
|
DevExpress.Xpf.Scheduler.Drawing.VisualTimeScaleHeaderContent hc = values[0] as DevExpress.Xpf.Scheduler.Drawing.VisualTimeScaleHeaderContent;
|
|
if (hc != null)
|
|
{
|
|
DateTime start = (DateTime)values[1];
|
|
DateTime end = (DateTime)values[2];
|
|
|
|
|
|
if (hc.Caption == "666") // hour
|
|
return String.Format("{0:HH:mm}", start);
|
|
if (hc.Caption == "555")
|
|
return String.Format("{0:dd}", start);
|
|
if (hc.Caption.Length >= 3 && hc.Caption.Substring(0, 3) == "444") // week
|
|
{
|
|
Calendar objCal = CultureInfo.CurrentCulture.Calendar;
|
|
int weekofyear = objCal.GetWeekOfYear(start, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
|
|
if (weekofyear > 52)
|
|
weekofyear = 1;
|
|
return String.Format("KW {0}", weekofyear);
|
|
}
|
|
if (hc.Caption == "333")
|
|
{
|
|
return String.Format("{0:MMMM yyyy}", start);
|
|
|
|
}
|
|
if (hc.Caption == "222")
|
|
{
|
|
int quarter = (int)Math.Ceiling(start.Month / (double)3);
|
|
return String.Format("{0}. Quartal", quarter);
|
|
|
|
}
|
|
if (hc.Caption == "111")
|
|
{
|
|
return String.Format("{0:yyyy}", start);
|
|
|
|
}
|
|
}
|
|
//return String.Format("{0:dd.MM.yyyy}", value);
|
|
//DevExpress.Xpf.Scheduler.Drawing.VisualTimeScaleHeaderContent hc = value as DevExpress.Xpf.Scheduler.Drawing.VisualTimeScaleHeaderContent;
|
|
//if (hc != null)
|
|
//{
|
|
// if (hc.Caption == "MONTH")
|
|
// return String.Format("{0:MMMM yyyy}", hc.IntervalStart);
|
|
// else if (hc.Caption == "WEEK")
|
|
// return String.Format("{0:dd.MM} - {1:dd.MM}", hc.IntervalStart, hc.IntervalEnd);
|
|
// else if (hc.Caption == "DAY")
|
|
// return String.Format("{0:dd.}", hc.IntervalStart);
|
|
//}
|
|
return "";
|
|
}
|
|
|
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
//public class TimeScale2TextConverter : IValueConverter
|
|
//{
|
|
// public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
// {
|
|
// if (value == null)
|
|
// {
|
|
// return null;
|
|
// }
|
|
|
|
// return String.Format("{0:dd.MM.yyyy}", value);
|
|
// DevExpress.Xpf.Scheduler.Drawing.VisualTimeScaleHeaderContent hc = value as DevExpress.Xpf.Scheduler.Drawing.VisualTimeScaleHeaderContent;
|
|
// if (hc != null)
|
|
// {
|
|
// if (hc.Caption == "MONTH")
|
|
// return String.Format("{0:MMMM yyyy}", hc.IntervalStart);
|
|
// else if (hc.Caption == "WEEK")
|
|
// return String.Format("{0:dd.MM} - {1:dd.MM}", hc.IntervalStart, hc.IntervalEnd);
|
|
// else if (hc.Caption == "DAY")
|
|
// return String.Format("{0:dd.}", hc.IntervalStart);
|
|
// }
|
|
// return "";
|
|
// }
|
|
|
|
// public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
// {
|
|
// throw new NotImplementedException();
|
|
// }
|
|
//}
|
|
|
|
|
|
} |