190 lines
4.0 KiB
C#
190 lines
4.0 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Threading;
|
|
using CPF.ReoGrid.Core;
|
|
using CPF.ReoGrid.Utility;
|
|
|
|
namespace CPF.ReoGrid.DataFormat
|
|
{
|
|
public class DateTimeDataFormatter : IDataFormatter
|
|
{
|
|
public static DateTime BaseStartDate
|
|
{
|
|
get
|
|
{
|
|
return DateTimeDataFormatter.baseStartDate;
|
|
}
|
|
set
|
|
{
|
|
DateTimeDataFormatter.baseStartDate = value;
|
|
}
|
|
}
|
|
|
|
public string FormatCell(Cell cell)
|
|
{
|
|
object innerData = cell.InnerData;
|
|
bool flag = false;
|
|
DateTime value = DateTimeDataFormatter.baseStartDate;
|
|
string text = null;
|
|
bool flag2 = innerData is DateTime;
|
|
if (flag2)
|
|
{
|
|
value = (DateTime)innerData;
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
double d;
|
|
bool flag3 = CellUtility.TryGetNumberData(innerData, out d);
|
|
if (flag3)
|
|
{
|
|
try
|
|
{
|
|
value = DateTime.FromOADate(d);
|
|
flag = true;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string s = (innerData is string) ? ((string)innerData) : Convert.ToString(innerData);
|
|
double value2 = 0.0;
|
|
bool flag4 = double.TryParse(s, out value2);
|
|
if (flag4)
|
|
{
|
|
try
|
|
{
|
|
value = value.AddDays(value2);
|
|
flag = true;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
else
|
|
{
|
|
flag = DateTime.TryParse(s, out value);
|
|
}
|
|
}
|
|
}
|
|
bool flag5 = flag;
|
|
if (flag5)
|
|
{
|
|
bool flag6 = cell.InnerStyle.HAlign == ReoGridHorAlign.General;
|
|
if (flag6)
|
|
{
|
|
cell.RenderHorAlign = ReoGridRenderHorAlign.Right;
|
|
}
|
|
string text2 = Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern;
|
|
bool flag7 = cell.DataFormatArgs != null && cell.DataFormatArgs is DateTimeDataFormatter.DateTimeFormatArgs;
|
|
CultureInfo cultureInfo;
|
|
if (flag7)
|
|
{
|
|
DateTimeDataFormatter.DateTimeFormatArgs dateTimeFormatArgs = (DateTimeDataFormatter.DateTimeFormatArgs)cell.DataFormatArgs;
|
|
bool flag8 = !string.IsNullOrEmpty(dateTimeFormatArgs.Format);
|
|
if (flag8)
|
|
{
|
|
text2 = dateTimeFormatArgs.Format;
|
|
}
|
|
cultureInfo = ((dateTimeFormatArgs.CultureName == null || string.Equals(dateTimeFormatArgs.CultureName, Thread.CurrentThread.CurrentCulture.Name)) ? Thread.CurrentThread.CurrentCulture : new CultureInfo(dateTimeFormatArgs.CultureName));
|
|
}
|
|
else
|
|
{
|
|
cultureInfo = Thread.CurrentThread.CurrentCulture;
|
|
cell.DataFormatArgs = new DateTimeDataFormatter.DateTimeFormatArgs
|
|
{
|
|
Format = text2,
|
|
CultureName = cultureInfo.Name
|
|
};
|
|
}
|
|
bool flag9 = cultureInfo.Name.StartsWith("ja") && text2.Contains("g");
|
|
if (flag9)
|
|
{
|
|
cultureInfo = new CultureInfo("ja-JP", true);
|
|
cultureInfo.DateTimeFormat.Calendar = new JapaneseCalendar();
|
|
}
|
|
try
|
|
{
|
|
string text3 = text2;
|
|
string a = text3;
|
|
if (!(a == "d"))
|
|
{
|
|
text = value.ToString(text2, cultureInfo);
|
|
}
|
|
else
|
|
{
|
|
text = value.Day.ToString();
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
text = Convert.ToString(value);
|
|
}
|
|
}
|
|
return flag ? text : null;
|
|
}
|
|
|
|
public bool PerformTestFormat()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
private static DateTime baseStartDate = new DateTime(1900, 1, 1);
|
|
|
|
[Serializable]
|
|
public struct DateTimeFormatArgs
|
|
{
|
|
public string Format
|
|
{
|
|
get
|
|
{
|
|
return this.format;
|
|
}
|
|
set
|
|
{
|
|
this.format = value;
|
|
}
|
|
}
|
|
|
|
public string CultureName
|
|
{
|
|
get
|
|
{
|
|
return this.cultureName;
|
|
}
|
|
set
|
|
{
|
|
this.cultureName = value;
|
|
}
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
bool flag = !(obj is DateTimeDataFormatter.DateTimeFormatArgs);
|
|
bool result;
|
|
if (flag)
|
|
{
|
|
result = false;
|
|
}
|
|
else
|
|
{
|
|
DateTimeDataFormatter.DateTimeFormatArgs dateTimeFormatArgs = (DateTimeDataFormatter.DateTimeFormatArgs)obj;
|
|
result = (this.format.Equals(dateTimeFormatArgs.format) && this.cultureName.Equals(dateTimeFormatArgs.cultureName));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return this.format.GetHashCode() ^ this.cultureName.GetHashCode();
|
|
}
|
|
|
|
private string format;
|
|
|
|
private string cultureName;
|
|
}
|
|
}
|
|
}
|