106 lines
2.8 KiB
C#
106 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using CPF.Drawing;
|
|
using CPF.ReoGrid.Core;
|
|
|
|
namespace CPF.ReoGrid.DataFormat
|
|
{
|
|
public sealed class DataFormatterManager
|
|
{
|
|
public static DataFormatterManager Instance
|
|
{
|
|
get
|
|
{
|
|
bool flag = DataFormatterManager.instance == null;
|
|
if (flag)
|
|
{
|
|
DataFormatterManager.instance = new DataFormatterManager();
|
|
}
|
|
return DataFormatterManager.instance;
|
|
}
|
|
}
|
|
|
|
public Dictionary<CellDataFormatFlag, IDataFormatter> DataFormatters
|
|
{
|
|
get
|
|
{
|
|
return this.dataFormatters;
|
|
}
|
|
set
|
|
{
|
|
this.dataFormatters = value;
|
|
}
|
|
}
|
|
|
|
private DataFormatterManager()
|
|
{
|
|
this.dataFormatters.Add(CellDataFormatFlag.General, new GeneralDataFormatter());
|
|
this.dataFormatters.Add(CellDataFormatFlag.Number, new NumberDataFormatter());
|
|
this.dataFormatters.Add(CellDataFormatFlag.DateTime, new DateTimeDataFormatter());
|
|
this.dataFormatters.Add(CellDataFormatFlag.Percent, new PercentDataFormatter());
|
|
this.dataFormatters.Add(CellDataFormatFlag.Currency, new CurrencyDataFormatter());
|
|
this.dataFormatters.Add(CellDataFormatFlag.Text, new TextDataFormatter());
|
|
}
|
|
|
|
internal void FormatCell(Cell cell)
|
|
{
|
|
cell.RenderColor = Color.Transparent;
|
|
bool flag = cell.DataFormat == CellDataFormatFlag.General;
|
|
if (flag)
|
|
{
|
|
bool flag2 = false;
|
|
string innerDisplay = null;
|
|
foreach (CellDataFormatFlag cellDataFormatFlag in this.dataFormatters.Keys)
|
|
{
|
|
IDataFormatter dataFormatter = this.dataFormatters[cellDataFormatFlag];
|
|
bool flag3 = dataFormatter.PerformTestFormat() && (innerDisplay = this.dataFormatters[cellDataFormatFlag].FormatCell(cell)) != null;
|
|
if (flag3)
|
|
{
|
|
cell.DataFormat = cellDataFormatFlag;
|
|
cell.InnerDisplay = innerDisplay;
|
|
flag2 = true;
|
|
break;
|
|
}
|
|
}
|
|
bool flag4 = !flag2;
|
|
if (flag4)
|
|
{
|
|
bool flag5 = cell.InnerData is string;
|
|
if (flag5)
|
|
{
|
|
cell.InnerDisplay = (string)cell.InnerData;
|
|
}
|
|
else
|
|
{
|
|
cell.InnerDisplay = Convert.ToString(cell.InnerData);
|
|
}
|
|
bool flag6 = cell.InnerStyle.HAlign == ReoGridHorAlign.General;
|
|
if (flag6)
|
|
{
|
|
cell.RenderHorAlign = ReoGridRenderHorAlign.Left;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
IDataFormatter dataFormatter2;
|
|
bool flag7 = this.DataFormatters.TryGetValue(cell.DataFormat, out dataFormatter2);
|
|
if (flag7)
|
|
{
|
|
string text = this.DataFormatters[cell.DataFormat].FormatCell(cell);
|
|
bool flag8 = text == null;
|
|
if (flag8)
|
|
{
|
|
text = this.DataFormatters[CellDataFormatFlag.Text].FormatCell(cell);
|
|
}
|
|
cell.InnerDisplay = text;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static DataFormatterManager instance;
|
|
|
|
private Dictionary<CellDataFormatFlag, IDataFormatter> dataFormatters = new Dictionary<CellDataFormatFlag, IDataFormatter>();
|
|
}
|
|
}
|