tbf/TBF/Rig/DataEntry/DEUtils.cs

117 lines
5.0 KiB
C#

///
/// Copyright (c) 2018-2023 Sensus Slovensko a.s.
///
using System.Windows.Forms;
using Results.Entities;
using TBF.Resources;
namespace TBF.Rig.DataEntry
{
public class DEUtils
{
public static string GetContent(Ct content, WaterMeter wm)
{
if (wm == null) return string.Empty;
switch (content)
{
default:
case Ct.None: return string.Empty;
case Ct.SerialNr: return (!wm.Disabled && wm.SerialNr != null) ? wm.SerialNr : string.Empty;
case Ct.SerialNrAux: return (!wm.Disabled && wm.SerialNrAux != null) ? wm.SerialNrAux : string.Empty;
case Ct.RadioAddress: return (!wm.Disabled && wm.RadioAddress != null) ? wm.RadioAddress : string.Empty;
case Ct.YearOfCalibration: return (!wm.Disabled) ? wm.YearOfProduction.ToString() : string.Empty;
case Ct.StartState: return (!wm.Disabled && wm.GetStartState() != null) ? wm.GetStartState() : string.Empty;
case Ct.StartStateAux: return string.Empty;
case Ct.EndState: return (!wm.Disabled && wm.EndState != null) ? wm.EndState : string.Empty;
case Ct.EndStateAux: return (!wm.Disabled && wm.GetEndStateAux() != null) ? wm.GetEndStateAux() : string.Empty;
case Ct.ArchivePath: return (!wm.Disabled && wm.ArchivePath != null) ? wm.ArchivePath : string.Empty;
case Ct.WmOrder: return (!wm.Disabled && wm.PurchaseOrder != null) ? wm.PurchaseOrder : string.Empty;
case Ct.BatchOrder: return (wm.Batch != null && wm.Batch.PurchaseOrder != null) ? wm.Batch.PurchaseOrder : string.Empty;
case Ct.BatchAndWmOrder: return (wm.Batch != null && wm.Batch.PurchaseOrder != null) ? wm.Batch.PurchaseOrder : string.Empty;
case Ct.WmRemark: return (!wm.Disabled && wm.Remark != null) ? wm.Remark : string.Empty;
case Ct.BatchRemark: return (wm.Batch != null && wm.Batch.Remark != null) ? wm.Batch.Remark : string.Empty;
case Ct.BatchAndWmRemark: return (wm.Batch != null && wm.Batch.Remark != null) ? wm.Batch.Remark : string.Empty;
case Ct.PrintLabel: return wm.PrintLabel ? Strings.yes : Strings.no;
#if ORACLE_DB
case Ct.Prefix: return (!wm.Disabled && wm.Prefix != null) ? wm.Prefix : string.Empty;
case Ct.Suffix: return (!wm.Disabled && wm.Suffix != null) ? wm.Suffix : string.Empty;
#endif
}
}
public static void PutContent(Ct content, WaterMeter wm, string value)
{
if (wm == null || wm.Disabled) return;
int year;
switch (content)
{
default:
case Ct.None: return;
case Ct.SerialNr: wm.SerialNr = value; return;
case Ct.SerialNrAux: wm.SerialNrAux = value; return;
case Ct.RadioAddress: wm.RadioAddress = value; return;
case Ct.YearOfCalibration: if (int.TryParse(value, out year)) wm.YearOfProduction = year; return;
case Ct.StartState: wm.SetStartState(value); return;
case Ct.StartStateAux: return;
case Ct.EndState: wm.EndState = value; return;
case Ct.EndStateAux: wm.SetEndStateAux(value); return;
case Ct.ArchivePath: wm.ArchivePath = value; return;
case Ct.WmOrder:
wm.PurchaseOrder = value;
return;
case Ct.BatchOrder:
case Ct.BatchAndWmOrder:
if (wm.Batch != null) wm.Batch.PurchaseOrder = value;
return;
case Ct.WmRemark:
wm.Remark = value;
return;
case Ct.BatchRemark:
case Ct.BatchAndWmRemark:
if (wm.Batch != null) wm.Batch.Remark = value;
return;
case Ct.PrintLabel:
wm.PrintLabel = (value == Strings.yes);
return;
#if ORACLE_DB
case Ct.Prefix: wm.Prefix = value; return;
case Ct.Suffix: wm.Suffix = value; return;
#endif
}
}
/// <summary>
/// Load Purchase order combo box items from the LocalSettings PurchaseOrderHistory array
/// </summary>
/// <param name="comboBox">Puchase order ComboBox</param>
public static void PrepareCombo(ComboBox comboBox, string[] history, bool emptyOnStart = false)
{
int historyLen = (history != null) ? history.Length : 0;
if (!emptyOnStart && (historyLen > 0))
{
comboBox.Text = history[0];
}
else
{
comboBox.Text = string.Empty;
}
for (int i = 0; i < historyLen; i++)
{
comboBox.Items.Add(history[i]);
}
}
}
}