162 lines
4.5 KiB
C#
162 lines
4.5 KiB
C#
using System;
|
|
using CPF.Drawing;
|
|
using CPF.ReoGrid.Core;
|
|
|
|
namespace CPF.ReoGrid.DataFormat
|
|
{
|
|
public class CurrencyDataFormatter : IDataFormatter
|
|
{
|
|
public string FormatCell(Cell cell)
|
|
{
|
|
bool flag = false;
|
|
object innerData = cell.InnerData;
|
|
double num = double.NaN;
|
|
bool flag2 = innerData is double;
|
|
if (flag2)
|
|
{
|
|
flag = true;
|
|
num = (double)innerData;
|
|
}
|
|
else
|
|
{
|
|
bool flag3 = innerData is DateTime;
|
|
if (flag3)
|
|
{
|
|
num = (new DateTime(1900, 1, 1) - (DateTime)innerData).TotalDays;
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
string text = Convert.ToString(innerData).Trim();
|
|
string s = string.Empty;
|
|
bool flag4 = text.StartsWith("$");
|
|
if (flag4)
|
|
{
|
|
s = text.Substring(1);
|
|
bool flag5 = double.TryParse(s, out num);
|
|
if (flag5)
|
|
{
|
|
flag = true;
|
|
cell.InnerData = num;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
flag = double.TryParse(text, out num);
|
|
}
|
|
}
|
|
}
|
|
bool flag6 = flag;
|
|
string result;
|
|
if (flag6)
|
|
{
|
|
bool flag7 = cell.InnerStyle.HAlign == ReoGridHorAlign.General;
|
|
if (flag7)
|
|
{
|
|
cell.RenderHorAlign = ReoGridRenderHorAlign.Right;
|
|
}
|
|
string str = null;
|
|
string str2 = null;
|
|
short count = 2;
|
|
NumberDataFormatter.NumberNegativeStyle numberNegativeStyle = NumberDataFormatter.NumberNegativeStyle.Default;
|
|
string str3 = null;
|
|
string str4 = null;
|
|
bool flag8 = cell.DataFormatArgs != null && cell.DataFormatArgs is CurrencyDataFormatter.CurrencyFormatArgs;
|
|
if (flag8)
|
|
{
|
|
CurrencyDataFormatter.CurrencyFormatArgs currencyFormatArgs = (CurrencyDataFormatter.CurrencyFormatArgs)cell.DataFormatArgs;
|
|
str = currencyFormatArgs.PrefixSymbol;
|
|
str2 = currencyFormatArgs.PostfixSymbol;
|
|
count = currencyFormatArgs.DecimalPlaces;
|
|
numberNegativeStyle = currencyFormatArgs.NegativeStyle;
|
|
str3 = currencyFormatArgs.CustomNegativePrefix;
|
|
str4 = currencyFormatArgs.CustomNegativePostfix;
|
|
}
|
|
bool flag9 = num < 0.0;
|
|
if (flag9)
|
|
{
|
|
bool flag10 = (numberNegativeStyle & NumberDataFormatter.NumberNegativeStyle.Red) == NumberDataFormatter.NumberNegativeStyle.Red;
|
|
if (flag10)
|
|
{
|
|
cell.RenderColor = Color.Red;
|
|
}
|
|
else
|
|
{
|
|
cell.RenderColor = Color.Transparent;
|
|
}
|
|
}
|
|
string str5 = new string('0', (int)count);
|
|
string text2 = str + "#,##0." + str5 + str2;
|
|
bool flag11 = (numberNegativeStyle & NumberDataFormatter.NumberNegativeStyle.Brackets) == NumberDataFormatter.NumberNegativeStyle.Brackets;
|
|
if (flag11)
|
|
{
|
|
text2 = ((num < 0.0) ? ("(" + text2 + ")") : text2);
|
|
}
|
|
else
|
|
{
|
|
bool flag12 = (numberNegativeStyle & NumberDataFormatter.NumberNegativeStyle.Prefix_Sankaku) == NumberDataFormatter.NumberNegativeStyle.Prefix_Sankaku;
|
|
if (flag12)
|
|
{
|
|
text2 = ((num < 0.0) ? ("▲ " + text2) : text2);
|
|
}
|
|
else
|
|
{
|
|
bool flag13 = (numberNegativeStyle & NumberDataFormatter.NumberNegativeStyle.CustomSymbol) == NumberDataFormatter.NumberNegativeStyle.CustomSymbol;
|
|
if (flag13)
|
|
{
|
|
text2 = ((num < 0.0) ? (str3 + text2 + str4) : text2);
|
|
}
|
|
}
|
|
}
|
|
bool flag14 = (numberNegativeStyle & NumberDataFormatter.NumberNegativeStyle.Default) == ~(NumberDataFormatter.NumberNegativeStyle.Default | NumberDataFormatter.NumberNegativeStyle.Red | NumberDataFormatter.NumberNegativeStyle.Brackets | NumberDataFormatter.NumberNegativeStyle.Prefix_Sankaku | NumberDataFormatter.NumberNegativeStyle.CustomSymbol);
|
|
if (flag14)
|
|
{
|
|
num = Math.Abs(num);
|
|
}
|
|
result = num.ToString(text2);
|
|
}
|
|
else
|
|
{
|
|
result = null;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public bool PerformTestFormat()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
[Serializable]
|
|
public class CurrencyFormatArgs : NumberDataFormatter.NumberFormatArgs
|
|
{
|
|
public string PrefixSymbol { get; set; }
|
|
|
|
public string PostfixSymbol { get; set; }
|
|
|
|
public string CultureEnglishName { get; set; }
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
bool flag = !(obj is CurrencyDataFormatter.CurrencyFormatArgs);
|
|
bool result;
|
|
if (flag)
|
|
{
|
|
result = false;
|
|
}
|
|
else
|
|
{
|
|
CurrencyDataFormatter.CurrencyFormatArgs currencyFormatArgs = (CurrencyDataFormatter.CurrencyFormatArgs)obj;
|
|
result = (this.PrefixSymbol == currencyFormatArgs.PrefixSymbol && this.PostfixSymbol == currencyFormatArgs.PostfixSymbol && string.Compare(this.CultureEnglishName, currencyFormatArgs.CultureEnglishName, true) == 0 && base.Equals(obj));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return base.GetHashCode();
|
|
}
|
|
}
|
|
}
|
|
}
|