tbf/SharedDatabase/Entities/OrderInfo.cs

381 lines
16 KiB
C#
Raw Permalink Normal View History

using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using Common;
using SharedDatabase.Resources;
namespace SharedDatabase.Entities
{
public class OrderInfo : IParamsProvider, Common.IOrderInfo
{
public virtual int Id { get; protected set; }
public virtual string POName { get; set; } /// 0
public virtual sbyte POState { get; set; } /// 1 0=New, 1=Active, 2=Finished
public virtual string Workflow { get; set; } /// 2
public virtual string TestProcedure { get; set; } /// 3
public virtual string VariantCode { get; set; } /// 4
public virtual string VacoDescription { get; set; } /// 5
public virtual string MadeInText { get; set; } /// 6
public virtual int Year { get; set; } /// 7
public virtual string ModuleParam { get; set; } /// 8
public virtual string LaserMarking { get; set; } /// 9
public virtual string Packing { get; set; } /// 10
public virtual int PiecesCount { get; set; } /// 11
public virtual string SNPrefix { get; set; } /// 12
public virtual int SNFirst { get; set; } /// 13
public virtual int SNDigitsCount { get; set; } /// 14
public virtual string SNSuffix { get; set; } /// 15
public virtual string RAPrefix { get; set; } /// 16
public virtual int RAFirst { get; set; } /// 17
public virtual string RASuffix { get; set; } /// 18
public virtual string Remark { get; set; } /// 19
public virtual int BaseNr1 { get; set; }
public virtual int BaseNr2 { get; set; }
public virtual int BaseNr3 { get; set; }
public virtual int BaseNr4 { get; set; }
public virtual int BaseNr5 { get; set; }
2021-12-15 06:04:17 +00:00
public virtual int CurrentPcsCount { get; set; }
public virtual int CurrentSN { get; set; }
public virtual int CurrentRA { get; set; }
public virtual int CurrentNr1 { get; set; }
public virtual int CurrentNr2 { get; set; }
public virtual int CurrentNr3 { get; set; }
public virtual int CurrentNr4 { get; set; }
public virtual int CurrentNr5 { get; set; }
public OrderInfo()
{
POName = string.Empty;
InitializeAll();
}
public OrderInfo(string orderName)
{
POName = orderName;
InitializeAll();
}
public virtual void InitializeAll()
{
POState = (sbyte)OrderState.New;
Workflow = string.Empty;
TestProcedure = string.Empty;
VariantCode = string.Empty;
VacoDescription = string.Empty;
MadeInText = string.Empty;
Year = DateTime.Now.Year;
ModuleParam = string.Empty;
LaserMarking = string.Empty;
Packing = string.Empty;
SNPrefix = string.Empty;
SNSuffix = string.Empty;
RAPrefix = string.Empty;
RASuffix = string.Empty;
Remark = string.Empty;
}
public virtual XmlSerializer GetSerializer() { return null; }
public virtual string ComponentName { get { return POName; } }
string[] paramNames = new string[]
{
Strings.Order,
Strings.State,
Strings.Workflow,
Strings.Test_procedure,
Strings.Variant_code,
Strings.Variant_description,
Strings.Made_in_text,
Strings.Year_of_calibration,
Strings.Module_parameter,
Strings.Laser_marking,
Strings.Packing,
Strings.Pieces_count,
Strings.Serial_nr + " " + Strings.prefix,
Strings.Serial_nr + " " + Strings.first,
Strings.Serial_nr + " " + Strings.digits_count,
Strings.Serial_nr + " " + Strings.suffix,
Strings.Radio_address + " " + Strings.prefix,
Strings.Radio_address + " " + Strings.first,
Strings.Radio_address + " " + Strings.suffix,
Strings.Remark,
};
public virtual string ParamName(int i) { return paramNames[i]; }
public virtual int ParamsCount() { return paramNames.Length; }
public virtual ICollection<string> ParamValues(int i)
{
var list = new List<string>();
switch (i)
{
case 1:
for (OrderState os = 0; os < OrderState.Count; os++) list.Add(os.ToString());
return list;
default:
return null;
}
}
public virtual string ToString(int i)
{
switch (i)
{
case 0: return POName;
case 1: return ((OrderState)POState).ToString();
case 2: return Workflow;
case 3: return TestProcedure;
case 4: return VariantCode;
case 5: return VacoDescription;
case 6: return MadeInText;
case 7: return Year.ToString();
case 8: return ModuleParam;
case 9: return LaserMarking;
case 10: return Packing;
case 11: return PiecesCount.ToString();
case 12: return SNPrefix;
case 13: return SNFirst.ToString();
case 14: return SNDigitsCount.ToString();
case 15: return SNSuffix;
case 16: return RAPrefix;
case 17: return RAFirst.ToString();
case 18: return RASuffix;
case 19: return Remark;
default:
2021-12-15 06:04:17 +00:00
return string.Format("order={0} pcs={1} wflow={2} proc={3} vaco={4} remark={5}",
POName, PiecesCount, Workflow, TestProcedure, VariantCode, Remark);
}
}
public virtual CfgUpdateFlags UpdateParam(int i, string str)
{
switch (i)
{
case 0: POName = str; break;
case 1: POState = (sbyte)((str == OrderState.New.ToString()) ? OrderState.New :
(str == OrderState.Active.ToString()) ? OrderState.Active
: OrderState.Finished);
break;
case 2: Workflow = str; break;
case 3: TestProcedure = str; break;
case 4: VariantCode = str; break;
case 5: VacoDescription = str; break;
case 6: MadeInText = str; break;
case 7: Year = int.Parse(str); break;
case 8: ModuleParam = str; break;
case 9: LaserMarking = str; break;
case 10: Packing = str; break;
case 11: PiecesCount = int.Parse(str); break;
case 12: SNPrefix = str; break;
case 13: SNFirst = int.Parse(str); break;
case 14: SNDigitsCount = int.Parse(str); break;
case 15: SNSuffix = str; break;
case 16: RAPrefix = str; break;
case 17: RAFirst = int.Parse(str); break;
case 18: RASuffix = str; break;
case 19: Remark = str; break;
default:
return CfgUpdateFlags.None;
}
return CfgUpdateFlags.RestartRqrd;
}
public virtual bool ValidateParam(int i, string str, out string message)
{
message = string.Empty;
int idummy;
long ldummy;
switch (i)
{
case 0: /// POName
if (str.Length < 1 || str.Length > 10)
{
message = string.Format("Order must have up to 10 digits");
return false;
}
else if (!long.TryParse(str, out ldummy) || ldummy <= 0)
{
message = string.Format("Order must be a positive integer number up to 9999999999");
return false;
}
return true;
2022-01-12 09:38:33 +00:00
case 1: /// POState
if (ParamValues(i).Contains(str)) return true;
break;
case 2: /// Workflow
case 3: /// TestProcedure
case 9: /// LaserMarking
case 10: /// Packing
/// nonempty string
if (!string.IsNullOrEmpty(str)) return true;
message = string.Format(Strings._0_should_not_be_empty, ParamName(i));
return false;
case 4: /// VariantCode
case 5: /// VacoDescription
case 6: /// MadeInText
case 8: /// ModuleParam
/// string (incl. an empty one)
if (str != null) return true;
message = string.Format("Should not be null", ParamName(i));
return false;
2022-01-12 09:38:33 +00:00
case 7: /// Year
if (int.TryParse(str, out idummy) && idummy > 2020 && idummy < 2099) return true;
break;
case 11: /// PiecesCount
case 14: /// SNDigits
/// positive integers
if (int.TryParse(str, out idummy) && idummy > 0) return true;
break;
case 12: /// SNPrefix
case 15: /// SNSuffix
case 16: /// RAPrefix
case 18: /// RASuffix
case 19: /// Remark
/// strings
return true;
case 13: /// SNFirst
case 17: /// RAFirst
/// non-negative integer
if (int.TryParse(str, out idummy) && idummy >= 0) return true;
break;
default:
message = "Invalid index";
return false;
}
message = string.Format(Strings.Invalid_0, ParamName(i));
return false;
}
/// <summary>
/// Copy content of one entity to another entity (except of Id)
/// </summary>
/// <param name="dest">Entity to copy to</param>
/// <param name="visibleOnly">true = do not copy invisible members</param>
public virtual void CopyContentTo(OrderInfo dest, bool visibleOnly = false)
{
dest.POName = POName;
dest.POState = POState;
dest.Workflow = Workflow;
dest.TestProcedure = TestProcedure;
dest.VariantCode = VariantCode;
dest.VacoDescription = VacoDescription;
dest.MadeInText = MadeInText;
dest.Year = Year;
dest.ModuleParam = ModuleParam;
dest.LaserMarking = LaserMarking;
dest.Packing = Packing;
dest.PiecesCount = PiecesCount;
dest.SNPrefix = SNPrefix;
dest.SNFirst = SNFirst;
dest.SNDigitsCount = SNDigitsCount;
dest.SNSuffix = SNSuffix;
dest.RAPrefix = RAPrefix;
dest.RAFirst = RAFirst;
dest.RASuffix = RASuffix;
2021-12-15 06:04:17 +00:00
dest.Remark = Remark;
if (!visibleOnly)
{
dest.BaseNr1 = BaseNr1;
dest.BaseNr2 = BaseNr2;
dest.BaseNr3 = BaseNr3;
dest.BaseNr4 = BaseNr4;
dest.BaseNr5 = BaseNr5;
dest.CurrentPcsCount = CurrentPcsCount;
dest.CurrentSN = CurrentSN;
dest.CurrentRA = CurrentRA;
dest.CurrentNr1 = CurrentNr1;
dest.CurrentNr2 = CurrentNr2;
dest.CurrentNr3 = CurrentNr3;
dest.CurrentNr4 = CurrentNr4;
dest.CurrentNr5 = CurrentNr5;
}
}
/// <summary>
/// Compare content of two entities (except of Id)
/// </summary>
/// <param name="dest">Entity to compare with</param>
/// <param name="visibleOnly">true = do not compare invisible members</param>
/// <returns>true = two entities are equal (except of Id)</returns>
public virtual bool Equals(OrderInfo dest, bool visibleOnly = false)
{
if (dest.POName != POName) return false;
if (dest.POState != POState) return false;
if (dest.Workflow != Workflow) return false;
if (dest.TestProcedure != TestProcedure) return false;
if (dest.VariantCode != VariantCode) return false;
if (dest.VacoDescription != VacoDescription) return false;
if (dest.MadeInText != MadeInText) return false;
if (dest.Year != Year) return false;
if (dest.ModuleParam != ModuleParam) return false;
if (dest.LaserMarking != LaserMarking) return false;
if (dest.Packing != Packing) return false;
if (dest.PiecesCount != PiecesCount) return false;
if (dest.SNPrefix != SNPrefix) return false;
if (dest.SNFirst != SNFirst) return false;
if (dest.SNDigitsCount != SNDigitsCount) return false;
if (dest.SNSuffix != SNSuffix) return false;
if (dest.RAPrefix != RAPrefix) return false;
if (dest.RAFirst != RAFirst) return false;
if (dest.RASuffix != RASuffix) return false;
if (dest.Remark != Remark) return false;
if (!visibleOnly)
{
if (dest.BaseNr1 != BaseNr1) return false;
if (dest.BaseNr2 != BaseNr2) return false;
if (dest.BaseNr3 != BaseNr3) return false;
if (dest.BaseNr4 != BaseNr4) return false;
if (dest.BaseNr5 != BaseNr5) return false;
if (dest.CurrentPcsCount != CurrentPcsCount) return false;
if (dest.CurrentSN != CurrentSN) return false;
if (dest.CurrentRA != CurrentRA) return false;
if (dest.CurrentNr1 != CurrentNr1) return false;
if (dest.CurrentNr2 != CurrentNr2) return false;
if (dest.CurrentNr3 != CurrentNr3) return false;
if (dest.CurrentNr4 != CurrentNr4) return false;
if (dest.CurrentNr5 != CurrentNr5) return false;
}
return true;
}
/// <summary>
/// All members are copied except of ID (so that NHibernate works properly).
/// List of groups is empty.
/// </summary>
/// <param name="newOrderNr">New order ID string</param>
/// <param name="targetPiecesCount">-1 = the same number of pieces as the original order</param>
/// <returns></returns>
public virtual IParamsProvider Clone()
{
OrderInfo clone = new OrderInfo();
CopyContentTo(clone);
return clone;
}
public virtual bool UpdateEmbeddedDbEntity()
{
return true; /// =OK, do nothing
}
public override string ToString()
{
return POName;
}
}
public enum OrderState : sbyte
{
New = 0,
Active = 1,
Finished = 2,
Count
}
}