59 lines
2.2 KiB
C#
59 lines
2.2 KiB
C#
///
|
|
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
|
|
namespace TBF
|
|
{
|
|
public class Data
|
|
{
|
|
public static int WMsCount;
|
|
public static int LineSize;
|
|
public static int CompoundWMsCount;
|
|
public static int HeatMetersCount;
|
|
public static int MaxPartNr;
|
|
|
|
static Data()
|
|
{
|
|
/// Default values applied when there is no BanchInfo component
|
|
WMsCount = 20;
|
|
LineSize = 10;
|
|
CompoundWMsCount = 1;
|
|
HeatMetersCount = 0;
|
|
MaxPartNr = WMsCount / LineSize;
|
|
}
|
|
|
|
public static void SetData(int wmsCount, int compoundWMsCount, int linesCount)
|
|
{
|
|
WMsCount = wmsCount;
|
|
CompoundWMsCount = compoundWMsCount;
|
|
LineSize = wmsCount / Math.Max(1, linesCount);
|
|
HeatMetersCount = 0;
|
|
MaxPartNr = (LineSize != 0) ? (WMsCount / LineSize) : 1;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determines whether tests part number is OK.
|
|
/// Examples of correct part number are:
|
|
/// 1, 2, 12, 21 in case of max. part nr.== 2
|
|
/// 1, 2, 3, 4, 12, 13, 14, 23, 24, 34, 123, 124, 134, 234, 1234 in case of max. part nr.== 4
|
|
/// </summary>
|
|
/// <param name="partNr">Tests par tnumber</param>
|
|
/// <returns>true when Part number is OK</returns>
|
|
public static bool IsGoodPartNr(int partNr)
|
|
{
|
|
bool firstDigitIsOK = ((partNr % 10) > 0) && ((partNr % 10) <= MaxPartNr);
|
|
bool secondDigitIsOK = (((partNr / 10) % 10) > 0) && (((partNr / 10) % 10) <= MaxPartNr);
|
|
bool thirdDigitIsOK = (((partNr / 100) % 10) > 0) && (((partNr / 100) % 10) <= MaxPartNr);
|
|
bool fourthDigitIsOK = (((partNr / 1000) % 10) > 0) && (((partNr / 1000) % 10) <= MaxPartNr);
|
|
|
|
if (firstDigitIsOK && (partNr / 10 == 0)) return true;
|
|
if (firstDigitIsOK && secondDigitIsOK && (partNr / 100 == 0)) return true;
|
|
if (firstDigitIsOK && secondDigitIsOK && thirdDigitIsOK && (partNr / 1000 == 0)) return true;
|
|
if (firstDigitIsOK && secondDigitIsOK && thirdDigitIsOK && fourthDigitIsOK && (partNr / 10000 == 0)) return true;
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|