%PDF- %PDF-
Direktori : /data/bordel/diplomka/ |
Current File : //data/bordel/diplomka/DatapointRefactor_1.patch |
Index: ConfigApp.Logic/ConfigApp.Logic.csproj =================================================================== --- ConfigApp.Logic/ConfigApp.Logic.csproj (revision 3260) +++ ConfigApp.Logic/ConfigApp.Logic.csproj (working copy) @@ -95,6 +95,7 @@ <ItemGroup> <Compile Include="Bus2DatapointHelper.cs" /> <Compile Include="DataLoader.cs" /> + <Compile Include="DatapointNumberHelper.cs" /> <Compile Include="DataTemplateManager.cs" /> <Compile Include="DataTemplateNames.cs" /> <Compile Include="DeviceCatalogue.cs" /> Index: ConfigApp.Logic/DatapointNumberHelper.cs =================================================================== --- ConfigApp.Logic/DatapointNumberHelper.cs (revision 0) +++ ConfigApp.Logic/DatapointNumberHelper.cs (working copy) @@ -0,0 +1,112 @@ +using Honeywell.MBEMEA.ConfigApp.Data; +using System.Linq; + +namespace Honeywell.MBEMEA.ConfigApp.Logic +{ + public static class DatapointNumberHelper + { + public const int PartitionStart = 1000; + public const int PartitionEnd = 1511; + public const int DetectorGroupStart = 1512; + public const int DetectorGroupEnd = 5607; + public const int DoorStart = 5608; + public const int DoorEnd = 6631; + public const int MacroStart = 6632; + public const int MacroEnd = 8631; + + public static int GetPartitionNumber(int number = 0) + { + int retVal = PartitionStart; + if (number != 0 && IsPartitionNumberAvailable(number)) + { + return number; + } + while (!IsPartitionNumberAvailable(retVal) && retVal <= PartitionEnd) + { + retVal++; + } + return retVal; + } + + public static int GetDetectorGroupNumber(int number = 0) + { + int retVal = DetectorGroupStart; + if (number != 0 && IsDetectorGroupNumberAvailable(number)) + { + return number; + } + while (!IsDetectorGroupNumberAvailable(retVal) && retVal <= DetectorGroupEnd) + { + retVal++; + } + return retVal; + } + + public static int GetMacroNumber(int number = 0) + { + int retVal = MacroStart; + if (number != 0 && IsMacroNumberAvailable(number)) + { + return number; + } + while (!IsMacroNumberAvailable(retVal) && retVal <= MacroEnd) + { + retVal++; + } + return retVal; + } + + public static int GetDoorNumber(int number = 0) + { + int retVal = DoorStart; + if (number != 0 && IsDoorNumberAvailable(number)) + { + return number; + } + while (!IsDoorNumberAvailable(retVal) && retVal <= DoorEnd) + { + retVal++; + } + return retVal; + } + + + + private static bool IsPartitionNumberAvailable(int number) + { + bool retVal = + InternalDataStore.DataSet.Partition.Count(p => !p.IsDatapointNumberNull() && p.DatapointNumber == number) == 0 + && number >= PartitionStart && number <= PartitionEnd; + return retVal; + } + + private static bool IsDetectorGroupNumberAvailable(int number) + { + bool retVal = + InternalDataStore.DataSet.DetectorGroup.Count(p => !p.IsDatapointNumberNull() && p.DatapointNumber == number) == 0 + && number >= DetectorGroupStart && number <= DetectorGroupEnd; + return retVal; + } + + private static bool IsMacroNumberAvailable(int number) + { + bool retVal = + InternalDataStore.DataSet.Macro.Count(p => !p.IsDatapointNumberNull() && p.DatapointNumber == number) == 0 + && number >= MacroStart && number <= MacroEnd; + return retVal; + } + + private static bool IsDoorNumberAvailable(int number) + { + bool retVal = + ( + InternalDataStore.DataSet.HWBus2DoorGuard.Count(p => !p.IsDoorDatapointNumberNull() && p.DoorDatapointNumber == number) + + InternalDataStore.DataSet.HWBus2DoorControllerModule.Count(p => !p.IsDoorDatapointNumberNull() && p.DoorDatapointNumber == number) + + InternalDataStore.DataSet.HWBus2Identkey3.Count(p => !p.IsDoorDatapointNumberNull() && p.DoorDatapointNumber == number) + ) == 0 + && number >= DoorStart && number <= DoorEnd; + return retVal; + } + + } +} Index: ConfigApp/Views/Hardware/HardwareTreeDetails/HardwareDevices/Bus2DoorControllerModuleDetail.cs =================================================================== --- ConfigApp/Views/Hardware/HardwareTreeDetails/HardwareDevices/Bus2DoorControllerModuleDetail.cs (revision 3260) +++ ConfigApp/Views/Hardware/HardwareTreeDetails/HardwareDevices/Bus2DoorControllerModuleDetail.cs (working copy) @@ -79,32 +79,11 @@ return; int val = (int) spinEditDatapointNumber.Value; - if (InternalDataStore.DataSet.HWBus2DoorControllerModule.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2Identkey3.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2DoorGuard.Count(p => p.DoorDatapointNumber == val) == 1) + int val2 = DatapointNumberHelper.GetDoorNumber(val); + if (val != val2) { - // If value is unique, do not do anything else - return; + spinEditDatapointNumber.Value = val2; } - - bool modified = true; - val = (int) spinEditDatapointNumber.Properties.MinValue; - while ((InternalDataStore.DataSet.HWBus2DoorControllerModule.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2Identkey3.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2DoorGuard.Count(p => p.DoorDatapointNumber == val) > 0) && - val <= spinEditDatapointNumber.Properties.MaxValue) - { - val++; - } - if (val > spinEditDatapointNumber.Properties.MaxValue) - { - // Do not modify if out of range - modified = false; - } - if (modified) - { - spinEditDatapointNumber.Value = val; - } } private void MainBindingSource_CurrentChanged(object sender, EventArgs e) @@ -114,15 +93,7 @@ var currRow = currView.Row as InternalDataSet.HWBus2DoorControllerModuleRow; if (currRow != null && currRow.IsDoorDatapointNumberNull()) { - int val = (int) spinEditDatapointNumber.Properties.MinValue; - while ((InternalDataStore.DataSet.HWBus2DoorControllerModule.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2Identkey3.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2DoorGuard.Count(p => p.DoorDatapointNumber == val) > 0) && - val <= spinEditDatapointNumber.Properties.MaxValue) - { - val++; - } - currRow.DoorDatapointNumber = val; + currRow.DoorDatapointNumber = DatapointNumberHelper.GetDoorNumber(); currRow.AcceptChanges(); } } Index: ConfigApp/Views/Hardware/HardwareTreeDetails/HardwareDevices/Bus2DoorGuardDetail.cs =================================================================== --- ConfigApp/Views/Hardware/HardwareTreeDetails/HardwareDevices/Bus2DoorGuardDetail.cs (revision 3260) +++ ConfigApp/Views/Hardware/HardwareTreeDetails/HardwareDevices/Bus2DoorGuardDetail.cs (working copy) @@ -98,15 +98,7 @@ var currRow = currView.Row as InternalDataSet.HWBus2DoorGuardRow; if (currRow != null && currRow.IsDoorDatapointNumberNull()) { - int val = (int)spinEditDatapointNumber.Properties.MinValue; - while ((InternalDataStore.DataSet.HWBus2DoorControllerModule.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2Identkey3.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2DoorGuard.Count(p => p.DoorDatapointNumber == val) > 0) && - val <= spinEditDatapointNumber.Properties.MaxValue) - { - val++; - } - currRow.DoorDatapointNumber = val; + currRow.DoorDatapointNumber = DatapointNumberHelper.GetDoorNumber(); currRow.AcceptChanges(); } } @@ -118,32 +110,11 @@ return; int val = (int)spinEditDatapointNumber.Value; - if (InternalDataStore.DataSet.HWBus2DoorControllerModule.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2Identkey3.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2DoorGuard.Count(p => p.DoorDatapointNumber == val) == 1) + int val2 = DatapointNumberHelper.GetDoorNumber(val); + if (val != val2) { - // If value is unique, do not do anything else - return; + spinEditDatapointNumber.Value = val2; } - - bool modified = true; - val = (int)spinEditDatapointNumber.Properties.MinValue; - while ((InternalDataStore.DataSet.HWBus2DoorControllerModule.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2Identkey3.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2DoorGuard.Count(p => p.DoorDatapointNumber == val) > 0) && - val <= spinEditDatapointNumber.Properties.MaxValue) - { - val++; - } - if (val > spinEditDatapointNumber.Properties.MaxValue) - { - // Do not modify if out of range - modified = false; - } - if (modified) - { - spinEditDatapointNumber.Value = val; - } } } Index: ConfigApp/Views/Hardware/HardwareTreeDetails/HardwareDevices/Bus2IdentKey3Detail.cs =================================================================== --- ConfigApp/Views/Hardware/HardwareTreeDetails/HardwareDevices/Bus2IdentKey3Detail.cs (revision 3260) +++ ConfigApp/Views/Hardware/HardwareTreeDetails/HardwareDevices/Bus2IdentKey3Detail.cs (working copy) @@ -83,15 +83,7 @@ var currRow = currView.Row as InternalDataSet.HWBus2Identkey3Row; if (currRow != null && currRow.IsDoorDatapointNumberNull()) { - int val = (int)spinEditDatapointNumber.Properties.MinValue; - while ((InternalDataStore.DataSet.HWBus2DoorControllerModule.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2Identkey3.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2DoorGuard.Count(p => p.DoorDatapointNumber == val) > 0) && - val <= spinEditDatapointNumber.Properties.MaxValue) - { - val++; - } - currRow.DoorDatapointNumber = val; + currRow.DoorDatapointNumber = DatapointNumberHelper.GetDoorNumber(); currRow.AcceptChanges(); } } @@ -103,32 +95,11 @@ return; int val = (int)spinEditDatapointNumber.Value; - if (InternalDataStore.DataSet.HWBus2DoorControllerModule.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2Identkey3.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2DoorGuard.Count(p => p.DoorDatapointNumber == val) == 1) + int val2 = DatapointNumberHelper.GetDoorNumber(val); + if (val != val2) { - // If value is unique, do not do anything else - return; + spinEditDatapointNumber.Value = val2; } - - bool modified = true; - val = (int)spinEditDatapointNumber.Properties.MinValue; - while ((InternalDataStore.DataSet.HWBus2DoorControllerModule.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2Identkey3.Count(p => p.DoorDatapointNumber == val) + - InternalDataStore.DataSet.HWBus2DoorGuard.Count(p => p.DoorDatapointNumber == val) > 0) && - val <= spinEditDatapointNumber.Properties.MaxValue) - { - val++; - } - if (val > spinEditDatapointNumber.Properties.MaxValue) - { - // Do not modify if out of range - modified = false; - } - if (modified) - { - spinEditDatapointNumber.Value = val; - } } } Index: ConfigApp/Views/SystemData/Macros/MacroViewNew.cs =================================================================== --- ConfigApp/Views/SystemData/Macros/MacroViewNew.cs (revision 3260) +++ ConfigApp/Views/SystemData/Macros/MacroViewNew.cs (working copy) @@ -274,13 +274,7 @@ var currRow = currView.Row as InternalDataSet.MacroRow; if (currRow != null && currRow.IsDatapointNumberNull()) { - int val = (int)spinEditDatapointNumber.Properties.MinValue; - while (InternalDataStore.DataSet.Macro.Count(p => !p.IsDatapointNumberNull() && p.DatapointNumber == val) > 0 && - val <= spinEditDatapointNumber.Properties.MaxValue) - { - val++; - } - currRow.DatapointNumber = val; + currRow.DatapointNumber = DatapointNumberHelper.GetMacroNumber(); currRow.AcceptChanges(); } } @@ -292,28 +286,11 @@ return; int val = (int)spinEditDatapointNumber.Value; - if (InternalDataStore.DataSet.Macro.Count(p => p.DatapointNumber == val) == 1) + int val2 = DatapointNumberHelper.GetMacroNumber(val); + if (val != val2) { - // If value is unique, do not do anything else - return; + spinEditDatapointNumber.Value = val2; } - - bool modified = true; - val = (int)spinEditDatapointNumber.Properties.MinValue; - while (InternalDataStore.DataSet.Macro.Count(p => p.DatapointNumber == val) > 0 && - val <= spinEditDatapointNumber.Properties.MaxValue) - { - val++; - } - if (val > spinEditDatapointNumber.Properties.MaxValue) - { - // Do not modify if out of range - modified = false; - } - if (modified) - { - spinEditDatapointNumber.Value = val; - } } } } \ No newline at end of file Index: ConfigApp/Views/SystemData/Partitions/PartitionTreeDetails/DetectorGroupDetail.cs =================================================================== --- ConfigApp/Views/SystemData/Partitions/PartitionTreeDetails/DetectorGroupDetail.cs (revision 3260) +++ ConfigApp/Views/SystemData/Partitions/PartitionTreeDetails/DetectorGroupDetail.cs (working copy) @@ -7,7 +7,6 @@ using System; using System.Data; using System.Drawing; -using System.Linq; namespace Honeywell.MBEMEA.ConfigApp.Views.SystemData.Partitions.PartitionTreeDetails { @@ -748,28 +747,11 @@ return; int val = (int)spinEditDatapointNumber.Value; - if (InternalDataStore.DataSet.DetectorGroup.Count(p => p.DatapointNumber == val) == 1) + int val2 = DatapointNumberHelper.GetDetectorGroupNumber(val); + if (val != val2) { - // If value is unique, do not do anything else - return; + spinEditDatapointNumber.Value = val2; } - - bool modified = true; - val = (int)spinEditDatapointNumber.Properties.MinValue; - while (InternalDataStore.DataSet.DetectorGroup.Count(p => p.DatapointNumber == val) > 0 && - val <= spinEditDatapointNumber.Properties.MaxValue) - { - val++; - } - if (val > spinEditDatapointNumber.Properties.MaxValue) - { - // Do not modify if out of range - modified = false; - } - if (modified) - { - spinEditDatapointNumber.Value = val; - } } private void MainBindingSource_CurrentChanged(object sender, EventArgs e) @@ -780,13 +762,7 @@ var currRow = currView.Row as InternalDataSet.DetectorGroupRow; if (currRow != null && currRow.IsDatapointNumberNull()) { - int val = (int) spinEditDatapointNumber.Properties.MinValue; - while (InternalDataStore.DataSet.DetectorGroup.Count(p => !p.IsDatapointNumberNull() && p.DatapointNumber == val) > 0 && - val <= spinEditDatapointNumber.Properties.MaxValue) - { - val++; - } - currRow.DatapointNumber = val; + currRow.DatapointNumber = DatapointNumberHelper.GetDetectorGroupNumber(); currRow.AcceptChanges(); } } Index: ConfigApp/Views/SystemData/Partitions/PartitionTreeDetails/PartitionDetail.cs =================================================================== --- ConfigApp/Views/SystemData/Partitions/PartitionTreeDetails/PartitionDetail.cs (revision 3260) +++ ConfigApp/Views/SystemData/Partitions/PartitionTreeDetails/PartitionDetail.cs (working copy) @@ -887,12 +887,17 @@ var currRow = currView.Row as InternalDataSet.PartitionRow; if (currRow != null && currRow.IsDatapointNumberNull()) { - currRow.DatapointNumber = (currRow.Number + (int)spinEditDatapointNumber.Properties.MinValue - 1); + currRow.DatapointNumber = DatapointNumberHelper.GetPartitionNumber(currRow.Number + DatapointNumberHelper.PartitionStart - 1); currRow.AcceptChanges(); } } } + /// <summary> + /// Checks if selected datapoint number is unique, if not, sets it to lowest free one + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> private void spinEditDatapointNumber_Leave(object sender, EventArgs e) { if (spinEditDatapointNumber.EditValue == null) @@ -899,30 +904,11 @@ return; int val = (int)spinEditDatapointNumber.Value; - if (InternalDataStore.DataSet.Partition.Count(p => p.DatapointNumber == val) == 1) + int val2 = DatapointNumberHelper.GetPartitionNumber(val); + if (val != val2) { - // If value is unique, do not do anything else - return; + spinEditDatapointNumber.EditValue = val2; } - - bool modified = true; - val = (int)spinEditDatapointNumber.Properties.MinValue; - while (InternalDataStore.DataSet.Partition.Count(p => p.DatapointNumber == val) > 0 && - val <= spinEditDatapointNumber.Properties.MaxValue) - { - val++; - } - if (val > spinEditDatapointNumber.Properties.MaxValue) - { - // Do not modify if out of range - modified = false; - } - if (modified) - { - spinEditDatapointNumber.Value = val; - } } - - } }