CPF/CPF.ReoGrid/XML/XmlFileFormatHelper.cs
2024-06-24 10:15:59 +08:00

694 lines
14 KiB
C#

using System;
using System.Text;
using CPF.ReoGrid.Core;
using CPF.ReoGrid.DataFormat;
using CPF.ReoGrid.Print;
namespace CPF.ReoGrid.XML
{
internal sealed class XmlFileFormatHelper
{
internal static string EncodeHorizontalAlign(ReoGridHorAlign halign)
{
string result;
switch (halign)
{
default:
result = "general";
break;
case ReoGridHorAlign.Left:
result = "left";
break;
case ReoGridHorAlign.Center:
result = "center";
break;
case ReoGridHorAlign.Right:
result = "right";
break;
case ReoGridHorAlign.DistributedIndent:
result = "distributed-indent";
break;
}
return result;
}
internal static string EncodeVerticalAlign(ReoGridVerAlign valign)
{
switch (valign)
{
case ReoGridVerAlign.Top:
return "top";
case ReoGridVerAlign.Bottom:
return "bottom";
}
return "middle";
}
internal static ReoGridHorAlign DecodeHorizontalAlign(string align)
{
if (!(align == "general"))
{
if (align == "left")
{
return ReoGridHorAlign.Left;
}
if (align == "center")
{
return ReoGridHorAlign.Center;
}
if (align == "right")
{
return ReoGridHorAlign.Right;
}
if (align == "distributed-indent")
{
return ReoGridHorAlign.DistributedIndent;
}
}
return ReoGridHorAlign.General;
}
internal static ReoGridVerAlign DecodeVerticalAlign(string valign)
{
ReoGridVerAlign result;
if (!(valign == "top"))
{
if (!(valign == "middle"))
{
if (valign == "bottom")
{
return ReoGridVerAlign.Bottom;
}
}
result = ReoGridVerAlign.Middle;
}
else
{
result = ReoGridVerAlign.Top;
}
return result;
}
internal static string EncodeCellDataFormat(CellDataFormatFlag format)
{
string result;
switch (format)
{
default:
result = null;
break;
case CellDataFormatFlag.Number:
result = "number";
break;
case CellDataFormatFlag.DateTime:
result = "datetime";
break;
case CellDataFormatFlag.Percent:
result = "percent";
break;
case CellDataFormatFlag.Currency:
result = "currency";
break;
case CellDataFormatFlag.Text:
result = "text";
break;
}
return result;
}
internal static CellDataFormatFlag DecodeCellDataFormat(string format)
{
bool flag = format == null;
CellDataFormatFlag result;
if (flag)
{
result = CellDataFormatFlag.General;
}
else
{
string text = format.ToLower();
string a = text;
if (!(a == "number"))
{
if (!(a == "text"))
{
if (!(a == "datetime"))
{
if (!(a == "percent"))
{
if (!(a == "currency"))
{
result = CellDataFormatFlag.General;
}
else
{
result = CellDataFormatFlag.Currency;
}
}
else
{
result = CellDataFormatFlag.Percent;
}
}
else
{
result = CellDataFormatFlag.DateTime;
}
}
else
{
result = CellDataFormatFlag.Text;
}
}
else
{
result = CellDataFormatFlag.Number;
}
}
return result;
}
internal static string EncodeNegativeNumberStyle(NumberDataFormatter.NumberNegativeStyle numberNegativeStyle)
{
bool flag = numberNegativeStyle == NumberDataFormatter.NumberNegativeStyle.Default;
string result;
if (flag)
{
result = null;
}
else
{
StringBuilder stringBuilder = new StringBuilder(30);
bool flag2 = (numberNegativeStyle & NumberDataFormatter.NumberNegativeStyle.Red) == NumberDataFormatter.NumberNegativeStyle.Red;
if (flag2)
{
stringBuilder.Append("red ");
}
bool flag3 = (numberNegativeStyle & NumberDataFormatter.NumberNegativeStyle.Brackets) == NumberDataFormatter.NumberNegativeStyle.Brackets;
if (flag3)
{
stringBuilder.Append("brackets ");
}
bool flag4 = (numberNegativeStyle & NumberDataFormatter.NumberNegativeStyle.Prefix_Sankaku) == NumberDataFormatter.NumberNegativeStyle.Prefix_Sankaku;
if (flag4)
{
stringBuilder.Append("sankaku ");
}
bool flag5 = (numberNegativeStyle & NumberDataFormatter.NumberNegativeStyle.CustomSymbol) == NumberDataFormatter.NumberNegativeStyle.CustomSymbol;
if (flag5)
{
stringBuilder.Append("custom ");
}
bool flag6 = stringBuilder[stringBuilder.Length - 1] == ' ';
if (flag6)
{
StringBuilder stringBuilder2 = stringBuilder;
int length = stringBuilder2.Length;
stringBuilder2.Length = length - 1;
}
result = stringBuilder.ToString();
}
return result;
}
internal static NumberDataFormatter.NumberNegativeStyle DecodeNegativeNumberStyle(string p)
{
NumberDataFormatter.NumberNegativeStyle numberNegativeStyle = NumberDataFormatter.NumberNegativeStyle.Default;
bool flag = string.IsNullOrEmpty(p);
NumberDataFormatter.NumberNegativeStyle result;
if (flag)
{
result = numberNegativeStyle;
}
else
{
bool flag2 = false;
string[] array = p.Split(new char[]
{
' '
});
foreach (string text in array)
{
string text2 = text;
string a = text2;
if (!(a == "red"))
{
if (!(a == "brackets"))
{
if (!(a == "minus"))
{
if (!(a == "sankaku"))
{
if (a == "custom")
{
numberNegativeStyle |= NumberDataFormatter.NumberNegativeStyle.CustomSymbol;
}
}
else
{
numberNegativeStyle |= NumberDataFormatter.NumberNegativeStyle.Prefix_Sankaku;
}
}
else
{
flag2 = true;
}
}
else
{
numberNegativeStyle |= NumberDataFormatter.NumberNegativeStyle.Brackets;
}
}
else
{
numberNegativeStyle |= NumberDataFormatter.NumberNegativeStyle.Red;
}
}
bool flag3 = !flag2;
if (flag3)
{
numberNegativeStyle &= ~NumberDataFormatter.NumberNegativeStyle.Default;
}
result = numberNegativeStyle;
}
return result;
}
internal static string EncodeBorderPos(BorderPositions pos)
{
return pos.ToString().ToLower();
}
internal static object DecodeBorderPos(string p)
{
bool flag = string.IsNullOrEmpty(p);
object result;
if (flag)
{
result = BorderPositions.None;
}
else
{
result = (BorderPositions)Enum.Parse(typeof(BorderPositions), p);
}
return result;
}
internal static string EncodeHBorderOwnerPos(HBorderOwnerPosition pos)
{
return pos.ToString().ToLower();
}
internal static HBorderOwnerPosition DecodeHBorderOwnerPos(string p)
{
bool flag = string.IsNullOrEmpty(p);
HBorderOwnerPosition result;
if (flag)
{
result = HBorderOwnerPosition.None;
}
else
{
bool flag2 = p.Equals("all", StringComparison.CurrentCultureIgnoreCase);
if (flag2)
{
result = HBorderOwnerPosition.All;
}
else
{
bool flag3 = p.Equals("top", StringComparison.CurrentCultureIgnoreCase);
if (flag3)
{
result = HBorderOwnerPosition.Top;
}
else
{
bool flag4 = p.Equals("bottom", StringComparison.CurrentCultureIgnoreCase);
if (flag4)
{
result = HBorderOwnerPosition.Bottom;
}
else
{
result = HBorderOwnerPosition.None;
}
}
}
}
return result;
}
internal static string EncodeVBorderOwnerPos(VBorderOwnerPosition pos)
{
return pos.ToString().ToLower();
}
internal static VBorderOwnerPosition DecodeVBorderOwnerPos(string p)
{
bool flag = string.IsNullOrEmpty(p);
VBorderOwnerPosition result;
if (flag)
{
result = VBorderOwnerPosition.None;
}
else
{
bool flag2 = p.Equals("all", StringComparison.CurrentCultureIgnoreCase);
if (flag2)
{
result = VBorderOwnerPosition.All;
}
else
{
bool flag3 = p.Equals("left", StringComparison.CurrentCultureIgnoreCase);
if (flag3)
{
result = VBorderOwnerPosition.Left;
}
else
{
bool flag4 = p.Equals("right", StringComparison.CurrentCultureIgnoreCase);
if (flag4)
{
result = VBorderOwnerPosition.Right;
}
else
{
result = VBorderOwnerPosition.None;
}
}
}
}
return result;
}
internal static string EncodeTextWrapMode(TextWrapMode wrapMode)
{
string result;
switch (wrapMode)
{
default:
result = "no-wrap";
break;
case TextWrapMode.WordBreak:
result = "word-break";
break;
case TextWrapMode.BreakAll:
result = "break-all";
break;
}
return result;
}
internal static TextWrapMode DecodeTextWrapMode(string p)
{
bool flag = string.IsNullOrEmpty(p);
TextWrapMode result;
if (flag)
{
result = TextWrapMode.NoWrap;
}
else
{
bool flag2 = p.Equals("word-break", StringComparison.CurrentCultureIgnoreCase);
if (flag2)
{
result = TextWrapMode.WordBreak;
}
else
{
bool flag3 = p.Equals("break-all", StringComparison.CurrentCultureIgnoreCase);
if (flag3)
{
result = TextWrapMode.BreakAll;
}
else
{
result = TextWrapMode.NoWrap;
}
}
}
return result;
}
internal static string EncodeSelectionMode(WorksheetSelectionMode selMode)
{
string result;
switch (selMode)
{
case WorksheetSelectionMode.None:
result = "none";
break;
case WorksheetSelectionMode.Cell:
result = "cell";
break;
default:
result = "range";
break;
case WorksheetSelectionMode.Row:
result = "row";
break;
case WorksheetSelectionMode.Column:
result = "column";
break;
}
return result;
}
internal static WorksheetSelectionMode DecodeSelectionMode(string arg)
{
bool flag = arg.Equals("cell", StringComparison.CurrentCultureIgnoreCase);
WorksheetSelectionMode result;
if (flag)
{
result = WorksheetSelectionMode.Cell;
}
else
{
bool flag2 = arg.Equals("none", StringComparison.CurrentCultureIgnoreCase);
if (flag2)
{
result = WorksheetSelectionMode.None;
}
else
{
bool flag3 = arg.Equals("row", StringComparison.CurrentCultureIgnoreCase);
if (flag3)
{
result = WorksheetSelectionMode.Row;
}
else
{
bool flag4 = arg.Equals("column", StringComparison.CurrentCultureIgnoreCase);
if (flag4)
{
result = WorksheetSelectionMode.Column;
}
else
{
result = WorksheetSelectionMode.Range;
}
}
}
}
return result;
}
internal static string EncodeSelectionStyle(WorksheetSelectionStyle selStyle)
{
string result;
switch (selStyle)
{
case WorksheetSelectionStyle.None:
result = "none";
break;
default:
result = "default";
break;
case WorksheetSelectionStyle.FocusRect:
result = "windows-focus";
break;
}
return result;
}
internal static WorksheetSelectionStyle DecodeSelectionStyle(string arg)
{
bool flag = arg.Equals("windows-focus", StringComparison.CurrentCultureIgnoreCase);
WorksheetSelectionStyle result;
if (flag)
{
result = WorksheetSelectionStyle.FocusRect;
}
else
{
bool flag2 = arg.Equals("default", StringComparison.CurrentCultureIgnoreCase);
if (flag2)
{
result = WorksheetSelectionStyle.None;
}
else
{
result = WorksheetSelectionStyle.Default;
}
}
return result;
}
internal static string EncodeFocusForwardDirection(SelectionForwardDirection forwardDirection)
{
string result;
if (forwardDirection == SelectionForwardDirection.Right || forwardDirection != SelectionForwardDirection.Down)
{
result = "right";
}
else
{
result = "down";
}
return result;
}
internal static SelectionForwardDirection DecodeFocusForwardDirection(string arg)
{
bool flag = arg.Equals("down", StringComparison.CurrentCultureIgnoreCase);
SelectionForwardDirection result;
if (flag)
{
result = SelectionForwardDirection.Down;
}
else
{
result = SelectionForwardDirection.Right;
}
return result;
}
internal static string EncodeFocusPosStyle(FocusPosStyle focusPosStyle)
{
string result;
if (focusPosStyle == FocusPosStyle.Default || focusPosStyle != FocusPosStyle.None)
{
result = "default";
}
else
{
result = "none";
}
return result;
}
internal static FocusPosStyle DecodeFocusPosStyle(string arg)
{
bool flag = arg.Equals("none", StringComparison.CurrentCultureIgnoreCase);
FocusPosStyle result;
if (flag)
{
result = FocusPosStyle.None;
}
else
{
result = FocusPosStyle.Default;
}
return result;
}
internal static string EncodePageOrder(PrintPageOrder pageOrder)
{
string result;
if (pageOrder == PrintPageOrder.DownThenOver || pageOrder != PrintPageOrder.OverThenDown)
{
result = "down-over";
}
else
{
result = "over-down";
}
return result;
}
internal static PrintPageOrder DecodePageOrder(string data)
{
bool flag = data.Equals("over-down", StringComparison.CurrentCultureIgnoreCase);
PrintPageOrder result;
if (flag)
{
result = PrintPageOrder.OverThenDown;
}
else
{
result = PrintPageOrder.DownThenOver;
}
return result;
}
public static string EncodeFreezeArea(FreezeArea area)
{
string result;
switch (area)
{
default:
result = "left-top";
break;
case FreezeArea.LeftBottom:
result = "left-top";
break;
case FreezeArea.RightTop:
result = "left-top";
break;
case FreezeArea.RightBottom:
result = "left-top";
break;
}
return result;
}
public static FreezeArea DecodeFreezeArea(string str)
{
bool flag = string.IsNullOrEmpty(str);
FreezeArea result;
if (flag)
{
result = FreezeArea.LeftTop;
}
else
{
bool flag2 = string.Compare(str, "left-top", true) == 0;
if (flag2)
{
result = FreezeArea.LeftTop;
}
else
{
bool flag3 = string.Compare(str, "left-bottom", true) == 0;
if (flag3)
{
result = FreezeArea.LeftBottom;
}
else
{
bool flag4 = string.Compare(str, "right-top", true) == 0;
if (flag4)
{
result = FreezeArea.RightTop;
}
else
{
bool flag5 = string.Compare(str, "right-bottom", true) == 0;
if (flag5)
{
result = FreezeArea.RightBottom;
}
else
{
result = FreezeArea.LeftTop;
}
}
}
}
}
return result;
}
}
}