99 lines
2.2 KiB
C#
99 lines
2.2 KiB
C#
using System;
|
|
using System.Threading;
|
|
|
|
namespace CPF.ReoGrid.DataFormat
|
|
{
|
|
public class PercentDataFormatter : IDataFormatter
|
|
{
|
|
public string FormatCell(Cell cell)
|
|
{
|
|
object innerData = cell.InnerData;
|
|
double num = 0.0;
|
|
string text = null;
|
|
bool flag = innerData is double;
|
|
bool flag2;
|
|
if (flag)
|
|
{
|
|
num = (double)innerData;
|
|
flag2 = true;
|
|
}
|
|
else
|
|
{
|
|
bool flag3 = innerData is DateTime;
|
|
if (flag3)
|
|
{
|
|
num = ((DateTime)innerData - new DateTime(1900, 1, 1)).TotalDays;
|
|
flag2 = true;
|
|
}
|
|
else
|
|
{
|
|
string text2 = Convert.ToString(innerData);
|
|
bool flag4 = text2.Length > 1 && text2.EndsWith("%");
|
|
if (flag4)
|
|
{
|
|
text2 = text2.Substring(0, text2.Length - 1);
|
|
flag2 = double.TryParse(text2, out num);
|
|
bool flag5 = flag2;
|
|
if (flag5)
|
|
{
|
|
num /= 100.0;
|
|
int num2 = (int)((short)text2.LastIndexOf(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator));
|
|
bool flag6 = num2 >= 0;
|
|
if (flag6)
|
|
{
|
|
short num3 = (short)(text2.Length - 1 - num2);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
flag2 = double.TryParse(text2, out num);
|
|
bool flag7 = flag2;
|
|
if (flag7)
|
|
{
|
|
int num4 = (int)((short)text2.LastIndexOf(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator));
|
|
bool flag8 = num4 >= 0;
|
|
if (flag8)
|
|
{
|
|
short num3 = (short)(text2.Length - 1 - num4);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
DateTime d = new DateTime(1900, 1, 1);
|
|
bool flag9 = DateTime.TryParse(text2, out d);
|
|
if (flag9)
|
|
{
|
|
num = (d - new DateTime(1900, 1, 1)).TotalDays;
|
|
flag2 = true;
|
|
}
|
|
}
|
|
}
|
|
bool flag10 = flag2;
|
|
if (flag10)
|
|
{
|
|
cell.InnerData = num;
|
|
}
|
|
}
|
|
}
|
|
bool flag11 = flag2;
|
|
string result;
|
|
if (flag11)
|
|
{
|
|
string str = NumberDataFormatter.FormatNumberCellAndGetPattern(cell, ref num, cell.DataFormatArgs as NumberDataFormatter.INumberFormatArgs);
|
|
result = num.ToString(str + "%");
|
|
}
|
|
else
|
|
{
|
|
result = (flag2 ? text : null);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public bool PerformTestFormat()
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|