DeviceManager/TsSFCDevice.Control/CustomFormatProvider/StatusFormatter.cs
2024-07-08 10:44:57 +08:00

81 lines
2.0 KiB
C#

using System;
namespace TsSFCDevice.Control.CustomFormatProvider
{
public class StatusFormatter : IFormatProvider, ICustomFormatter
{
public object GetFormat(Type formatType)
{
if (formatType == typeof(ICustomFormatter))
{
return this;
}
return null;
}
public string Format(string format, object arg, IFormatProvider formatProvider)
{
string value = string.Empty;
switch (format.ToLower())
{
case "tag":
value = tagFormat(arg);
break;
case "status":
value = StatusFormat(arg);
break;
case "Enable":
value = EnableFormat(arg);
break;
default:
break;
}
return value;
}
string tagFormat(object arg)
{
string value = string.Empty;
switch (arg?.ToString() ?? "")
{
case "N":
value = "已提交";
break;
case "C":
value = "已完成";
break;
default:
break;
}
return value;
}
string EnableFormat(object arg)
{
bool Enable = false;
bool.TryParse(arg + "", out Enable);
return Enable ? "启用" : "禁用";
}
string StatusFormat(object arg)
{
string value = string.Empty;
switch (arg?.ToString() ?? "")
{
case "A":
value = "启用";
break;
case "D":
value = "停用";
break;
default:
break;
}
return value;
}
}
}