tbf/MonitoringDB/Entities/Workstep.cs
2018-01-26 13:56:06 +01:00

83 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
namespace MonitoringDB.Entities
{
public class Workstep
{
public virtual int Id { get; protected set; }
public virtual int WorkstepNr { get; set; }
public virtual string Name { get; set; }
public virtual string Description { get; set; }
public virtual int CheckPartNr { get; set; }
public virtual bool AllowRepairs { get; set; }
public virtual Process Process { get; set; }
public virtual Part ReferencePart { get; set; }
public virtual IList<Part> Parts { get; set; }
/// <summary>
/// Default (private) constructor inicializing a list
/// </summary>
protected Workstep()
{
Parts = new List<Part>();
}
/// <summary>
/// Constructor used when this workstep is added to a process
/// </summary>
/// <param name="name">Workstep name</param>
/// <param name="process">Process to be referenced</param>
public Workstep(int workstepNr, string name, Process process)
: this()
{
WorkstepNr = workstepNr;
Name = name;
Description = string.Empty;
CheckPartNr = 0;
AllowRepairs = false;
Process = process;
ReferencePart = null;
}
public virtual Workstep Clone(Process owningProcess)
{
Workstep rslt = new Workstep(WorkstepNr, Name, owningProcess);
rslt.Description = Description;
rslt.CheckPartNr = CheckPartNr;
rslt.AllowRepairs = AllowRepairs;
if (ReferencePart != null)
{
foreach (var p in owningProcess.Parts)
{
if (p.Name == ReferencePart.Name) rslt.ReferencePart = p;
}
}
foreach (var srcP in Parts)
{
foreach (var p in owningProcess.Parts)
{
if (p.Name == srcP.Name)
{
rslt.Parts.Add(p);
p.StepNumber = srcP.StepNumber;
p.Workstep = rslt;
}
}
}
return rslt;
}
public override string ToString()
{
//return string.Format("{0} {1} ({2}) Ref: {3}", WorkstepNr, Name, Description, (ReferencePart != null) ? ReferencePart.Name : "none");
return string.Format("{0}: {1}", WorkstepNr, Name);
}
}
}