When saving a new or modified procedure there is a test of the Name uniqueness
This commit is contained in:
parent
5d0b929593
commit
0d6a8b272a
@ -75,6 +75,7 @@
|
||||
<Compile Include="Entities\Group.cs" />
|
||||
<Compile Include="Entities\HeatMetersPath.cs" />
|
||||
<Compile Include="Entities\IHasItemNr.cs" />
|
||||
<Compile Include="Entities\IHasName.cs" />
|
||||
<Compile Include="Entities\IHasValves.cs" />
|
||||
<Compile Include="Entities\MeasurementCorrection.cs" />
|
||||
<Compile Include="Entities\MetersPath.cs" />
|
||||
|
||||
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Config.Entities
|
||||
{
|
||||
public class BenchPath : IHasItemNr, IHasValves
|
||||
public class BenchPath : IHasName, IHasItemNr, IHasValves
|
||||
{
|
||||
public virtual int Id { get; protected set; }
|
||||
public virtual int ItemNr { get; set; }
|
||||
|
||||
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Config.Entities
|
||||
{
|
||||
public class Component : IHasItemNr
|
||||
public class Component : IHasName, IHasItemNr
|
||||
{
|
||||
public virtual int Id { get; protected set; }
|
||||
public virtual int ItemNr { get; set; }
|
||||
|
||||
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Config.Entities
|
||||
{
|
||||
public class FeedingPath : IHasItemNr, IHasValves
|
||||
public class FeedingPath : IHasName, IHasItemNr, IHasValves
|
||||
{
|
||||
public virtual int Id { get; protected set; }
|
||||
public virtual int ItemNr { get; set; }
|
||||
|
||||
@ -5,7 +5,7 @@ using System;
|
||||
|
||||
namespace Config.Entities
|
||||
{
|
||||
public class HeatMetersPath : IHasItemNr
|
||||
public class HeatMetersPath : IHasName, IHasItemNr
|
||||
{
|
||||
public virtual int Id { get; protected set; }
|
||||
public virtual int ItemNr { get; set; }
|
||||
|
||||
11
Config/Entities/IHasName.cs
Normal file
11
Config/Entities/IHasName.cs
Normal file
@ -0,0 +1,11 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
namespace Config.Entities
|
||||
{
|
||||
public interface IHasName
|
||||
{
|
||||
int Id { get; }
|
||||
string Name { get; set; }
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Config.Entities
|
||||
{
|
||||
public class MetersPath : IHasItemNr
|
||||
public class MetersPath : IHasName, IHasItemNr
|
||||
{
|
||||
public virtual int Id { get; protected set; }
|
||||
public virtual int ItemNr { get; set; }
|
||||
|
||||
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Config.Entities
|
||||
{
|
||||
public class OutputPath : IHasItemNr, IHasValves
|
||||
public class OutputPath : IHasName, IHasItemNr, IHasValves
|
||||
{
|
||||
public virtual int Id { get; protected set; }
|
||||
public virtual int ItemNr { get; set; }
|
||||
|
||||
@ -11,7 +11,7 @@ namespace Config.Entities
|
||||
/// <summary>
|
||||
/// Stores one test procedure, supports revisions and history log
|
||||
/// </summary>
|
||||
public class Procedure : IHasItemNr
|
||||
public class Procedure : IHasName, IHasItemNr
|
||||
{
|
||||
public virtual int Id { get; protected set; }
|
||||
public virtual int ItemNr { get; set; }
|
||||
|
||||
@ -11,7 +11,7 @@ namespace Config.Entities
|
||||
/// <summary>
|
||||
/// Test, consisting of one or more repetitions of the test 'SingleTest'.
|
||||
/// </summary>
|
||||
public class Test : IHasItemNr
|
||||
public class Test : IHasName, IHasItemNr
|
||||
{
|
||||
public virtual int Id { get; protected set; }
|
||||
public virtual int ItemNr { get; set; }
|
||||
|
||||
@ -8,7 +8,7 @@ namespace Config.Entities
|
||||
/// <summary>
|
||||
/// Stores one transition sequence containing a list of transition steps
|
||||
/// </summary>
|
||||
public class TransitionSequence : IHasItemNr
|
||||
public class TransitionSequence : IHasName, IHasItemNr
|
||||
{
|
||||
public virtual int Id { get; protected set; }
|
||||
public virtual int ItemNr { get; set; }
|
||||
|
||||
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Config.Entities
|
||||
{
|
||||
public class VirtualBenchSequence : IHasItemNr
|
||||
public class VirtualBenchSequence : IHasName, IHasItemNr
|
||||
{
|
||||
public virtual int Id { get; protected set; }
|
||||
public virtual int ItemNr { get; set; }
|
||||
|
||||
@ -30,6 +30,8 @@ namespace TBF
|
||||
/// </summary>
|
||||
public Procedure LoadedProcedure;
|
||||
|
||||
IList<string> usedNames; /// Already used names
|
||||
|
||||
/// Auxiliary public lists used also by user controls in tab pages
|
||||
public IList<BenchControl.Generic.IComponent> TbfComponents;
|
||||
public IList<IValve> Valves;
|
||||
@ -88,13 +90,15 @@ namespace TBF
|
||||
parametersListViewEx.SubItemEndEditing += new Results.Forms.SubItemEndEditingEventHandler(parametersListViewEx_SubItemEndEditing);
|
||||
}
|
||||
|
||||
public ProcedureDlg(Config.Entities.Procedure procedure)
|
||||
public ProcedureDlg(Config.Entities.Procedure procedure, IList<string> usedNames)
|
||||
: this()
|
||||
{
|
||||
if (procedure == null) throw new ArgumentNullException("procedure");
|
||||
|
||||
LoadedProcedure = procedure;
|
||||
|
||||
this.usedNames = usedNames;
|
||||
|
||||
sharedButtons.RequiredGroupMembership = procedure.Protected ? Users.Grp.GID.Metrologists : Users.Grp.GID.TestingSpecialists;
|
||||
|
||||
/// Prepare a list of components and a list of all valves in the test bench
|
||||
@ -1606,6 +1610,15 @@ namespace TBF
|
||||
foreach (var ctrl in testParamsCtrls) ctrl.UpdateAll();
|
||||
foreach (var ctrl in procedureParamsCtrls) ctrl.UpdateAll();
|
||||
|
||||
if (usedNames != null && usedNames.Contains(LoadedProcedure.Name))
|
||||
{
|
||||
MessageBox.Show(string.Format("There is already a procedure named '{0}'.{1}Choose another name please.", LoadedProcedure.Name, Environment.NewLine),
|
||||
Strings.Warning,
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Exclamation);
|
||||
return;
|
||||
}
|
||||
|
||||
Program.LocalSettings.OneProcedureDlgLeft = Location.X;
|
||||
Program.LocalSettings.OneProcedureDlgTop = Location.Y;
|
||||
Program.LocalSettings.OneProcedureDlgWidth = Size.Width;
|
||||
|
||||
@ -199,5 +199,18 @@ namespace TBF.UiControls
|
||||
Items[ix + 1].Selected = true;
|
||||
Items[ix + 1].EnsureVisible();
|
||||
}
|
||||
|
||||
|
||||
public IList<string> GetUsedNames()
|
||||
{
|
||||
IList<string> usedNames = new List<string>();
|
||||
|
||||
if (MyItems != null)
|
||||
{
|
||||
foreach (var item in MyItems) if (item is IHasName) usedNames.Add((item as IHasName).Name);
|
||||
}
|
||||
|
||||
return usedNames;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ namespace TBF.UiControls
|
||||
newProcedure.CreationUser = Users.GlobalData.CurrentUser.UserName;
|
||||
newProcedure.CreationTime = DateTime.Now;
|
||||
|
||||
if (new ProcedureDlg(newProcedure).ShowDialog() == DialogResult.OK)
|
||||
if (new ProcedureDlg(newProcedure, GetUsedNames()).ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
/// TODO: Make name uniqueness test
|
||||
parent.Unlock();
|
||||
@ -231,9 +231,11 @@ namespace TBF.UiControls
|
||||
modifiedProcedure.Revision = originalProcedure.Revision + 1;
|
||||
modifiedProcedure.ObtainedByCopy = false;
|
||||
|
||||
if (new ProcedureDlg(modifiedProcedure).ShowDialog() == DialogResult.OK)
|
||||
IList<string> usedNames = GetUsedNames();
|
||||
usedNames.Remove(originalProcedure.Name); /// Allow original procedure name
|
||||
///
|
||||
if (new ProcedureDlg(modifiedProcedure, usedNames).ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
/// TODO: Make name uniqueness test
|
||||
parent.Unlock();
|
||||
|
||||
using (var transaction = session.BeginTransaction())
|
||||
@ -285,7 +287,7 @@ namespace TBF.UiControls
|
||||
newProcedure.CreationTime = DateTime.Now;
|
||||
newProcedure.Protected = false;
|
||||
|
||||
if ((new ProcedureDlg(newProcedure)).ShowDialog() == DialogResult.OK)
|
||||
if ((new ProcedureDlg(newProcedure, GetUsedNames())).ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
/// TODO: Make name uniqueness test
|
||||
parent.Unlock();
|
||||
@ -338,7 +340,7 @@ namespace TBF.UiControls
|
||||
newProcedure.CreationUser = Users.GlobalData.CurrentUser.UserName;
|
||||
newProcedure.CreationTime = DateTime.Now;
|
||||
|
||||
if ((new ProcedureDlg(newProcedure)).ShowDialog() == DialogResult.OK)
|
||||
if ((new ProcedureDlg(newProcedure, GetUsedNames())).ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
/// TODO: Make name uniqueness test
|
||||
parent.Unlock();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user