Files
hcs/Hcs.Client/ClientApi/DeviceMeteringApi/HcsDeviceMeteringUtil.cs
HOME-LAPTOP\kshkulev 33ab055b43 Add project
Basic formatting applied. Unnecessary comments have been removed. Suspicious code is covered by TODO.
2025-08-12 11:21:10 +09:00

23 lines
1.0 KiB
C#

using System.Text.RegularExpressions;
namespace Hcs.ClientApi.DeviceMeteringApi
{
public class HcsDeviceMeteringUtil
{
public static string ConvertMeterReading(string reading, bool isRequired)
{
if (string.IsNullOrEmpty(reading)) return (isRequired ? "0" : null);
// TODO: Проверить комментарий
// Исправляем типичный отказ ГИС в приеме показаний: заменяем запятую на точку
string betterReading = reading.Contains(",") ? reading.Replace(",", ".") : reading;
// Шаблон из: http://open-gkh.ru/MeteringDeviceBase/MeteringValueType.html
var match = Regex.Match(betterReading, "^\\d{1,15}(\\.\\d{1,7})?$");
if (match.Success) return betterReading;
throw new HcsException($"Значение показания \"{reading}\" не соответствует требованиям ГИС: N.N");
}
}
}