tbf/SharedDatabase/Entities/OrderInfo.cs

305 lines
12 KiB
C#

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 string ModuleParam { get; set; } /// 7
public virtual string LaserMarking { get; set; } /// 8
public virtual string Packing { get; set; } /// 9
public virtual int PiecesCount { get; set; } /// 10
public virtual string SNPrefix { get; set; } /// 11
public virtual int SNFirst { get; set; } /// 12
public virtual int SNDigitsCount { get; set; } /// 13
public virtual string SNSuffix { get; set; } /// 14
public virtual string RAPrefix { get; set; } /// 15
public virtual int RAFirst { get; set; } /// 16
public virtual string RASuffix { get; set; } /// 17
public virtual int CurrentPcsCount { get; set; }
public virtual int CurrentSN { get; set; }
public virtual int CurrentRA { get; set; }
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; }
public virtual string Remark { get; set; } /// 18
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;
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.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 ModuleParam;
case 8: return LaserMarking;
case 9: return Packing;
case 10: return PiecesCount.ToString();
case 11: return SNPrefix;
case 12: return SNFirst.ToString();
case 13: return SNDigitsCount.ToString();
case 14: return SNSuffix;
case 15: return RAPrefix;
case 16: return RAFirst.ToString();
case 17: return RASuffix;
case 18: return Remark;
default:
return string.Format("order={0} pcs={1} wflow={2} proc={3} vaco={4} #1={5} #2={6} #3={7} #4={8} #5={9} remark={10}",
POName, PiecesCount, Workflow, TestProcedure, VariantCode,
BaseNr1, BaseNr2, BaseNr3, BaseNr4, BaseNr5, Remark);
}
}
public virtual CfgUpdateFlags UpdateParam(int i, string str)
{
switch (i)
{
case 0: POName = str; 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: ModuleParam = str; break;
case 8: LaserMarking = str; break;
case 9: Packing = str; break;
case 10: PiecesCount = int.Parse(str); break;
case 11: SNPrefix = str; break;
case 12: SNFirst = int.Parse(str); break;
case 13: SNDigitsCount = int.Parse(str); break;
case 14: SNSuffix = str; break;
case 15: RAPrefix = str; break;
case 16: RAFirst = int.Parse(str); break;
case 17: RASuffix = str; break;
case 18: Remark = str; break;
case 1:
POState = (sbyte)((str == OrderState.New.ToString()) ? OrderState.New :
(str == OrderState.Active.ToString()) ? OrderState.Active
: OrderState.Finished);
break;
default:
return CfgUpdateFlags.None;
}
return CfgUpdateFlags.RestartRqrd;
}
public virtual bool ValidateParam(int i, string str, out string message)
{
message = string.Empty;
int idummy;
switch (i)
{
case 0: /// POName
if (str.Length != 7)
{
message = string.Format("Order must have 7 digits");
return false;
}
else if (!int.TryParse(str, out idummy) || idummy <= 0)
{
message = string.Format("Order must be a positive integer number");
return false;
}
return true;
case 2: /// Workflow
case 3: /// TestProcedure
case 8: /// LaserMarking
case 9: /// 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 7: /// ModuleParam
/// string (incl. an empty one)
if (str != null) return true;
message = string.Format("Should not be null", ParamName(i));
return false;
case 1: /// POState
if (ParamValues(i).Contains(str)) return true;
break;
case 10: /// PiecesCount
case 13: /// SNDigits
/// positive integers
if (int.TryParse(str, out idummy) && idummy > 0) return true;
break;
case 11: /// SNPrefix
case 14: /// SNSuffix
case 15: /// RAPrefix
case 17: /// RASuffix
case 18: /// Remark
/// strings
return true;
case 12: /// SNFirst
case 16: /// 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;
}
public virtual void CopyContentTo(OrderInfo dest)
{
dest.POName = POName;
dest.POState = POState;
dest.Workflow = Workflow;
dest.TestProcedure = TestProcedure;
dest.VariantCode = VariantCode;
dest.VacoDescription = VacoDescription;
dest.MadeInText = MadeInText;
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;
dest.CurrentPcsCount = CurrentPcsCount;
dest.CurrentSN = CurrentSN;
dest.CurrentRA = CurrentRA;
dest.BaseNr1 = BaseNr1;
dest.BaseNr2 = BaseNr2;
dest.BaseNr3 = BaseNr3;
dest.BaseNr4 = BaseNr4;
dest.BaseNr5 = BaseNr5;
dest.Remark = Remark;
}
/// <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
}
}