init
This commit is contained in:
@@ -0,0 +1,683 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class Region //: BasePropertyChanged
|
||||
{
|
||||
private TestObjectTemplate _template;
|
||||
public TestObjectTemplate Template
|
||||
{
|
||||
get => _template;
|
||||
set
|
||||
{
|
||||
//if (null != _template && _template != value) { _template.PropertyChanged -= Template_PropertyChanged; }
|
||||
_template = value;
|
||||
//Template.PropertyChanged += Template_PropertyChanged;
|
||||
DetermineAvailableISOSettings();
|
||||
}
|
||||
}
|
||||
|
||||
private void Template_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (Enum.TryParse(e.PropertyName, out TestObjectTemplate.Tags tag))
|
||||
{
|
||||
switch (tag)
|
||||
{
|
||||
case TestObjectTemplate.Tags.TemplateAllChannels:
|
||||
RegionChannels = Template.TemplateAllChannels;
|
||||
RegionUIChannels = Template.TemplateAllUIChannels;
|
||||
DetermineAvailableISOSettings();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case "TestObjectType":
|
||||
RegionChannels = Template.TemplateAllChannels;
|
||||
RegionUIChannels = Template.TemplateAllUIChannels;
|
||||
DetermineAvailableISOSettings();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InvalidateVisual()
|
||||
{
|
||||
_adorner?.InvalidateVisual();
|
||||
}
|
||||
private string _name;
|
||||
public string RegionName
|
||||
{
|
||||
get => _name;
|
||||
set { _name = value; InvalidateVisual(); }
|
||||
}
|
||||
|
||||
private string _regionDescription;
|
||||
public string RegionDescription
|
||||
{
|
||||
get => _regionDescription;
|
||||
set { _regionDescription = value; InvalidateVisual(); }
|
||||
}
|
||||
|
||||
private Point _upperLeft;
|
||||
public Point RegionUpperLeft
|
||||
{
|
||||
get => _upperLeft;
|
||||
set => _upperLeft = value;
|
||||
}
|
||||
|
||||
private Point _bottomRight;
|
||||
public Point RegionBottomRight
|
||||
{
|
||||
get => _bottomRight;
|
||||
set => _bottomRight = value;
|
||||
}
|
||||
|
||||
private MMEDirections _direction;
|
||||
public MMEDirections RegionDirection
|
||||
{
|
||||
get => _direction;
|
||||
set
|
||||
{
|
||||
_direction = value;
|
||||
if (null != value)
|
||||
{
|
||||
_directionIndex = _allDirections.IndexOf(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_directionIndex = -1;
|
||||
}
|
||||
SetISOCode();
|
||||
}
|
||||
}
|
||||
|
||||
private MMEFilterClasses _filterClass;
|
||||
public MMEFilterClasses RegionFilterClass
|
||||
{
|
||||
get => _filterClass;
|
||||
set
|
||||
{
|
||||
_filterClass = value;
|
||||
if (null != value)
|
||||
{
|
||||
_filterClassIndex = _filterClasses.IndexOf(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_filterClassIndex = -1;
|
||||
}
|
||||
SetISOCode();
|
||||
}
|
||||
}
|
||||
private MMEFineLocations1 _fineLocation1;
|
||||
public MMEFineLocations1 RegionFineLocation1
|
||||
{
|
||||
get => _fineLocation1;
|
||||
set
|
||||
{
|
||||
_fineLocation1 = value;
|
||||
if (null != value)
|
||||
{
|
||||
_fineLocation1Index = _fineLocations1.IndexOf(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_fineLocation1Index = -1;
|
||||
}
|
||||
SetISOCode();
|
||||
}
|
||||
}
|
||||
|
||||
private MMEFineLocations2 _fineLocation2;
|
||||
public MMEFineLocations2 RegionFineLocation2
|
||||
{
|
||||
get => _fineLocation2;
|
||||
set
|
||||
{
|
||||
_fineLocation2 = value;
|
||||
if (null != value)
|
||||
{
|
||||
_fineLocation2Index = _fineLocations2.IndexOf(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_fineLocation2Index = -1;
|
||||
}
|
||||
SetISOCode();
|
||||
}
|
||||
}
|
||||
|
||||
private MMEFineLocations3 _fineLocation3;
|
||||
public MMEFineLocations3 RegionFineLocation3
|
||||
{
|
||||
get => _fineLocation3;
|
||||
set
|
||||
{
|
||||
_fineLocation3 = value;
|
||||
if (null != value)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
SetISOCode();
|
||||
}
|
||||
}
|
||||
|
||||
private MMETransducerMainLocation _mainLocation;
|
||||
public MMETransducerMainLocation RegionMainLocation
|
||||
{
|
||||
get => _mainLocation;
|
||||
set
|
||||
{
|
||||
if (_mainLocation != value)
|
||||
{
|
||||
_mainLocation = value;
|
||||
if (null != value)
|
||||
{
|
||||
_mainLocationIndex = _mainLocations.IndexOf(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mainLocationIndex = _mainLocations.Count - 1;
|
||||
}
|
||||
SetISOCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void FilterRegionChannels()
|
||||
{
|
||||
_regionChannels = new List<TestObjectTemplateChannel>(Template.TemplateAllChannels);
|
||||
_regionUIChannels = new List<TemplateChannelUI>(Template.TemplateAllUIChannels);
|
||||
for (var i = _regionChannels.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var channel = _regionChannels[i];
|
||||
var mmeChannel = channel.Channel;
|
||||
|
||||
if (RegionMainLocation != null && RegionMainLocation.Trans_Main_Loc != mmeChannel.Trans_Main_Loc)
|
||||
{
|
||||
_regionChannels.RemoveAt(i);
|
||||
_regionUIChannels.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (RegionDirection != null && RegionDirection.Direction != mmeChannel.Direction && RegionDirection.Direction != "?")
|
||||
{
|
||||
_regionChannels.RemoveAt(i);
|
||||
_regionUIChannels.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (RegionFilterClass != null && RegionFilterClass.Filter_Class != mmeChannel.Default_Filter_Class && RegionFilterClass.Filter_Class != "?")
|
||||
{
|
||||
_regionChannels.RemoveAt(i);
|
||||
_regionUIChannels.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (RegionFineLocation1 != null && RegionFineLocation1.Fine_Loc_1 != mmeChannel.Fine_Loc_1 && RegionFineLocation1.Fine_Loc_1 != "??")
|
||||
{
|
||||
_regionChannels.RemoveAt(i);
|
||||
_regionUIChannels.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (RegionFineLocation2 != null && RegionFineLocation2.FINE_LOC_2 != mmeChannel.Fine_Loc_2 && RegionFineLocation2.FINE_LOC_2 != "??")
|
||||
{
|
||||
_regionChannels.RemoveAt(i);
|
||||
_regionUIChannels.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (RegionFineLocation3 != null && RegionFineLocation3.FINE_LOC_3 != mmeChannel.Fine_Loc_3 && RegionFineLocation3.FINE_LOC_3 != "??")
|
||||
{
|
||||
_regionChannels.RemoveAt(i);
|
||||
_regionUIChannels.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (RegionPhysicalDimension != null && RegionPhysicalDimension.Physical_Dimension != mmeChannel.Physical_Dimension && RegionPhysicalDimension.Physical_Dimension != "??")
|
||||
{
|
||||
_regionChannels.RemoveAt(i);
|
||||
_regionUIChannels.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (RegionPosition != null && RegionPosition.Position != mmeChannel.Position && RegionPosition.Position != "?")
|
||||
{
|
||||
_regionChannels.RemoveAt(i);
|
||||
_regionUIChannels.RemoveAt(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
RegionChannels = _regionChannels.ToArray();
|
||||
RegionUIChannels = _regionUIChannels.ToArray();
|
||||
SetISOCode();
|
||||
}
|
||||
private MMEPhysicalDimensions _physicalDimension;
|
||||
public MMEPhysicalDimensions RegionPhysicalDimension
|
||||
{
|
||||
get => _physicalDimension;
|
||||
set
|
||||
{
|
||||
_physicalDimension = value;
|
||||
if (null != value)
|
||||
{
|
||||
_physicalDimensionIndex = _physicalDimensions.IndexOf(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_physicalDimensionIndex = -1;
|
||||
}
|
||||
SetISOCode();
|
||||
}
|
||||
}
|
||||
|
||||
private MMEPositions _position;
|
||||
public MMEPositions RegionPosition
|
||||
{
|
||||
get => _position;
|
||||
set
|
||||
{
|
||||
_position = value;
|
||||
if (null != value)
|
||||
{
|
||||
_positionIndex = _positions.IndexOf(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_positionIndex = -1;
|
||||
}
|
||||
SetISOCode();
|
||||
}
|
||||
}
|
||||
|
||||
private MMETestObjects _testObject;
|
||||
public MMETestObjects RegionTestObject
|
||||
{
|
||||
get => _testObject;
|
||||
set => _testObject = value;
|
||||
}
|
||||
|
||||
|
||||
private RegionAdorner _adorner;
|
||||
|
||||
public Region(RegionAdorner adorner, TestObjectTemplate template)
|
||||
{
|
||||
_adorner = adorner;
|
||||
RegionName = "New region";
|
||||
RegionDescription = "Describe region";
|
||||
Template = template;
|
||||
RegionTestObject = template.TestObject;
|
||||
RegionChannels = template.TemplateAllChannels;
|
||||
RegionUIChannels = template.TemplateAllUIChannels;
|
||||
DetermineAvailableISOSettings();
|
||||
}
|
||||
|
||||
public Region(TestObjectTemplate template, TemplateRegion r)
|
||||
{
|
||||
RegionName = r.RegionName;
|
||||
RegionDescription = r.RegionDescription;
|
||||
Template = template;
|
||||
RegionChannels = template.TemplateAllChannels;
|
||||
RegionUIChannels = template.TemplateAllUIChannels;
|
||||
RegionTestObject = ((App)Application.Current).IsoDb.GetTestObjectByIso(r.TestObject);
|
||||
RegionBottomRight = new Point(r.LowerRight.X, r.LowerRight.Y);
|
||||
RegionUpperLeft = new Point(r.UpperLeft.X, r.UpperLeft.Y);
|
||||
RegionDirection = ((App)Application.Current).IsoDb.GetDirectionByIso(r.Direction);
|
||||
RegionFilterClass = ((App)Application.Current).IsoDb.GetFilterClassByIso(r.FilterClass);
|
||||
RegionFineLocation1 = ((App)Application.Current).IsoDb.GetFineLocation1ByIso(r.FineLocation1);
|
||||
RegionFineLocation2 = ((App)Application.Current).IsoDb.GetFineLocation2ByIso(r.FineLocation2);
|
||||
RegionFineLocation3 = ((App)Application.Current).IsoDb.GetFineLocation3ByIso(r.FineLocation3);
|
||||
RegionMainLocation = ((App)Application.Current).IsoDb.GetMainLocationByIso(r.MainLocation);
|
||||
RegionPhysicalDimension = ((App)Application.Current).IsoDb.GetPhysicalDimensionByIso(r.PhysicalDimension);
|
||||
RegionPosition = ((App)Application.Current).IsoDb.GetPosition(r.Position);
|
||||
FilterRegionChannels();
|
||||
SetISOCode();
|
||||
}
|
||||
|
||||
private Visibility _regionAddVisibility = Visibility.Visible;
|
||||
public Visibility RegionAddVisibility
|
||||
{
|
||||
get => _regionAddVisibility;
|
||||
set => _regionAddVisibility = value;
|
||||
}
|
||||
private Visibility _regionDeleteVisibility = Visibility.Hidden;
|
||||
public Visibility RegionDeleteVisibility
|
||||
{
|
||||
get => _regionDeleteVisibility;
|
||||
set => _regionDeleteVisibility = value;
|
||||
}
|
||||
|
||||
private List<MMEDirections> _allDirections = new List<MMEDirections>();
|
||||
public MMEDirections[] AllDirections
|
||||
{
|
||||
get => _allDirections.ToArray();
|
||||
set
|
||||
{
|
||||
_allDirections = new List<MMEDirections>(value);
|
||||
AllDirectionsStrings = _allDirections.Select(dir => null == dir ? "?" : dir.Text_L1).ToArray();
|
||||
}
|
||||
}
|
||||
private List<string> _allDirectionsStrings = new List<string>();
|
||||
public string[] AllDirectionsStrings
|
||||
{
|
||||
get => _allDirectionsStrings.ToArray();
|
||||
set => _allDirectionsStrings = new List<string>(value);
|
||||
}
|
||||
private int _directionIndex = -1;
|
||||
|
||||
private List<MMEFilterClasses> _filterClasses = new List<MMEFilterClasses>();
|
||||
public MMEFilterClasses[] AllFilterClasses
|
||||
{
|
||||
get => _filterClasses.ToArray();
|
||||
set
|
||||
{
|
||||
_filterClasses = new List<MMEFilterClasses>(value);
|
||||
var filterclasses = new List<string>();
|
||||
foreach (var fc in _filterClasses) { filterclasses.Add(fc.Text_L1); }
|
||||
AllFilterClassStrings = filterclasses.ToArray();
|
||||
}
|
||||
}
|
||||
private List<string> _allFilterClassStrings = new List<string>();
|
||||
public string[] AllFilterClassStrings
|
||||
{
|
||||
get => _allFilterClassStrings.ToArray();
|
||||
set => _allFilterClassStrings = new List<string>(value);
|
||||
}
|
||||
public int _filterClassIndex = -1;
|
||||
|
||||
private List<MMEFineLocations1> _fineLocations1 = new List<MMEFineLocations1>();
|
||||
public MMEFineLocations1[] AllFineLocations1
|
||||
{
|
||||
get => _fineLocations1.ToArray();
|
||||
set
|
||||
{
|
||||
_fineLocations1 = new List<MMEFineLocations1>(value);
|
||||
var fineLocations1 = new List<string>();
|
||||
foreach (var loc in _fineLocations1)
|
||||
{
|
||||
if (null == loc) { fineLocations1.Add("??"); }
|
||||
else { fineLocations1.Add(loc.Text_L1); }
|
||||
}
|
||||
AllFineLocations1Strings = fineLocations1.ToArray();
|
||||
}
|
||||
}
|
||||
private List<string> _allFineLocations1Strings = new List<string>();
|
||||
public string[] AllFineLocations1Strings
|
||||
{
|
||||
get => _allFineLocations1Strings.ToArray();
|
||||
set => _allFineLocations1Strings = new List<string>(value);
|
||||
}
|
||||
private int _fineLocation1Index = -1;
|
||||
|
||||
private List<MMEFineLocations2> _fineLocations2 = new List<MMEFineLocations2>();
|
||||
public MMEFineLocations2[] AllFineLocations2
|
||||
{
|
||||
get => _fineLocations2.ToArray();
|
||||
set
|
||||
{
|
||||
_fineLocations2 = new List<MMEFineLocations2>(value);
|
||||
var locations = new List<string>();
|
||||
foreach (var loc in _fineLocations2) { locations.Add(loc.Text_L1); }
|
||||
AllFineLocations2Strings = locations.ToArray();
|
||||
}
|
||||
}
|
||||
private List<string> _allFineLocations2Strings = new List<string>();
|
||||
public string[] AllFineLocations2Strings
|
||||
{
|
||||
get => _allFineLocations2Strings.ToArray();
|
||||
set => _allFineLocations2Strings = new List<string>(value);
|
||||
}
|
||||
private int _fineLocation2Index = -1;
|
||||
public int FineLocation2Index
|
||||
{
|
||||
get => _fineLocation2Index;
|
||||
set
|
||||
{
|
||||
if (value == _fineLocation2Index) { return; }
|
||||
if (value < 0) { RegionFineLocation2 = null; }
|
||||
else { RegionFineLocation2 = _fineLocations2[value]; }
|
||||
FilterRegionChannels();
|
||||
}
|
||||
}
|
||||
|
||||
private List<MMEFineLocations3> _fineLocations3 = new List<MMEFineLocations3>();
|
||||
public MMEFineLocations3[] AllFineLocations3
|
||||
{
|
||||
get => _fineLocations3.ToArray();
|
||||
set
|
||||
{
|
||||
_fineLocations3 = new List<MMEFineLocations3>(value);
|
||||
var locations = new List<string>();
|
||||
foreach (var l in _fineLocations3) { locations.Add(l.Text_L1); }
|
||||
AllFineLocations3Strings = locations.ToArray();
|
||||
}
|
||||
}
|
||||
private List<string> _allFineLocations3Strings = new List<string>();
|
||||
public string[] AllFineLocations3Strings
|
||||
{
|
||||
get => _allFineLocations3Strings.ToArray();
|
||||
set => _allFineLocations3Strings = new List<string>(value);
|
||||
}
|
||||
|
||||
private List<MMETransducerMainLocation> _mainLocations = new List<MMETransducerMainLocation>();
|
||||
public MMETransducerMainLocation[] AllMainLocations
|
||||
{
|
||||
get => _mainLocations.ToArray();
|
||||
set
|
||||
{
|
||||
_mainLocations = new List<MMETransducerMainLocation>(value);
|
||||
AllMainLocationsStrings = _mainLocations.Select(loc => null == loc ? "????" : loc.Text_L1).ToArray();
|
||||
}
|
||||
}
|
||||
private List<string> _allMainLocationsStrings = new List<string>();
|
||||
public string[] AllMainLocationsStrings
|
||||
{
|
||||
get => _allMainLocationsStrings.ToArray();
|
||||
set => _allMainLocationsStrings = new List<string>(value);
|
||||
}
|
||||
private int _mainLocationIndex = -1;
|
||||
private List<MMEPhysicalDimensions> _physicalDimensions = new List<MMEPhysicalDimensions>();
|
||||
public MMEPhysicalDimensions[] AllPhysicalDimensions
|
||||
{
|
||||
get => _physicalDimensions.ToArray();
|
||||
set
|
||||
{
|
||||
_physicalDimensions = new List<MMEPhysicalDimensions>(value);
|
||||
var dimensions = new List<string>();
|
||||
foreach (var dim in _physicalDimensions)
|
||||
{
|
||||
dimensions.Add(null == dim ? "??" : dim.Text_L1);
|
||||
}
|
||||
AllPhysicalDimensionStrings = dimensions.ToArray();
|
||||
}
|
||||
}
|
||||
private List<string> _allPhysicalDimensionStrings = new List<string>();
|
||||
public string[] AllPhysicalDimensionStrings
|
||||
{
|
||||
get => _allPhysicalDimensionStrings.ToArray();
|
||||
set => _allPhysicalDimensionStrings = new List<string>(value);
|
||||
}
|
||||
private int _physicalDimensionIndex = -1;
|
||||
|
||||
private List<MMEPositions> _positions = new List<MMEPositions>();
|
||||
public MMEPositions[] AllPositions
|
||||
{
|
||||
get => _positions.ToArray();
|
||||
set
|
||||
{
|
||||
_positions = new List<MMEPositions>(value);
|
||||
AllPositionStrings = _positions.Select(pos => pos.Text_L1).ToArray();
|
||||
}
|
||||
}
|
||||
private List<string> _allPositionsStrings = new List<string>();
|
||||
public string[] AllPositionStrings
|
||||
{
|
||||
get => _allPositionsStrings.ToArray();
|
||||
set => _allPositionsStrings = new List<string>(value);
|
||||
}
|
||||
private int _positionIndex = -1;
|
||||
private string _isoCode = "????????????????";
|
||||
public string ISOCode
|
||||
{
|
||||
get => _isoCode;
|
||||
set => _isoCode = value;
|
||||
}
|
||||
private void SetISOCode()
|
||||
{
|
||||
var testObject = "?";
|
||||
if (null != RegionTestObject) { testObject = RegionTestObject.Test_Object; }
|
||||
var position = "?";
|
||||
if (null != RegionPosition) { position = RegionPosition.Position; }
|
||||
var main = "????";
|
||||
if (null != RegionMainLocation) { main = RegionMainLocation.Trans_Main_Loc; }
|
||||
var floc1 = "??";
|
||||
if (null != RegionFineLocation1) { floc1 = RegionFineLocation1.Fine_Loc_1; }
|
||||
var floc2 = "??";
|
||||
if (null != RegionFineLocation2) { floc2 = RegionFineLocation2.FINE_LOC_2; }
|
||||
var floc3 = "??";
|
||||
if (null != RegionFineLocation3) { floc3 = RegionFineLocation3.FINE_LOC_3; }
|
||||
var physdim = "??";
|
||||
if (null != RegionPhysicalDimension) { physdim = RegionPhysicalDimension.Physical_Dimension; }
|
||||
var dir = "?";
|
||||
if (null != RegionDirection) { dir = RegionDirection.Direction; }
|
||||
var fc = "?";
|
||||
if (null != RegionFilterClass) { fc = RegionFilterClass.Filter_Class; }
|
||||
ISOCode = ISO.IsoCode.GetString(testObject, position, main, floc1, floc2, floc3, physdim, dir, fc);
|
||||
}
|
||||
private List<TestObjectTemplateChannel> _regionChannels = new List<TestObjectTemplateChannel>();
|
||||
public TestObjectTemplateChannel[] RegionChannels
|
||||
{
|
||||
get => _regionChannels.ToArray();
|
||||
set
|
||||
{
|
||||
_regionChannels = new List<TestObjectTemplateChannel>(value);
|
||||
DetermineAvailableISOSettings();
|
||||
}
|
||||
}
|
||||
private void DetermineAvailableISOSettings()
|
||||
{
|
||||
var regionChannels = RegionChannels;
|
||||
var templateChannels = Template.TemplateAllChannels;
|
||||
|
||||
var testObjects = (from pc in regionChannels.AsParallel() select pc.Channel.Test_Object).Distinct().ToArray();
|
||||
if (testObjects.Length < 1) { return; }
|
||||
RegionTestObject = ((App)Application.Current).IsoDb.GetTestObjectByIso(testObjects[0]);
|
||||
|
||||
|
||||
var dirs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Direction).Distinct().ToArray());
|
||||
dirs.Sort();
|
||||
var directions = dirs.Select(dir => ((App)Application.Current).IsoDb.GetDirectionByIso(dir)).ToList();
|
||||
var d = ((App)Application.Current).IsoDb.GetDirectionByIso("?");
|
||||
if (!directions.Contains(d)) { directions.Add(d); }
|
||||
AllDirections = directions.ToArray();
|
||||
dirs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Direction).Distinct().ToArray());
|
||||
if (dirs.Count == 1) { RegionDirection = ((App)Application.Current).IsoDb.GetDirectionByIso(dirs[0]); }
|
||||
else if (dirs.Count == 0) { RegionDirection = null; }
|
||||
|
||||
var fcs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Default_Filter_Class).Distinct().ToArray());
|
||||
fcs.Sort();
|
||||
var filterclasses = fcs.Select(fc => ((App)Application.Current).IsoDb.GetFilterClassByIso(fc)).ToList();
|
||||
var fc2 = ((App)Application.Current).IsoDb.GetFilterClassByIso("?");
|
||||
if (!filterclasses.Contains(fc2)) { filterclasses.Add(fc2); }
|
||||
AllFilterClasses = filterclasses.ToArray();
|
||||
fcs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Default_Filter_Class).Distinct().ToArray());
|
||||
if (1 == fcs.Count) { RegionFilterClass = ((App)Application.Current).IsoDb.GetFilterClassByIso(fcs[0]); }
|
||||
else if (0 == fcs.Count) { RegionFilterClass = null; }
|
||||
|
||||
var locs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Fine_Loc_1).Distinct().ToArray());
|
||||
locs.Sort();
|
||||
var finelocations1 = new List<MMEFineLocations1>();
|
||||
foreach (var loc in locs) { finelocations1.Add(((App)Application.Current).IsoDb.GetFineLocation1ByIso(loc)); }
|
||||
var f = ((App)Application.Current).IsoDb.GetFineLocation1ByIso("??");
|
||||
if (!finelocations1.Contains(f)) { finelocations1.Add(f); }
|
||||
AllFineLocations1 = finelocations1.ToArray();
|
||||
locs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Fine_Loc_1).Distinct().ToArray());
|
||||
if (1 == locs.Count) { RegionFineLocation1 = ((App)Application.Current).IsoDb.GetFineLocation1ByIso(locs[0]); }
|
||||
else if (0 == locs.Count) { RegionFineLocation1 = null; }
|
||||
|
||||
locs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Fine_Loc_2).Distinct().ToArray());
|
||||
locs.Sort();
|
||||
var finelocations2 = locs.Select(loc => ((App)Application.Current).IsoDb.GetFineLocation2ByIso(loc)).ToList();
|
||||
AllFineLocations2 = finelocations2.ToArray();
|
||||
var f2 = ((App)Application.Current).IsoDb.GetFineLocation2ByIso("??");
|
||||
if (!finelocations2.Contains(f2)) { finelocations2.Add(f2); }
|
||||
locs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Fine_Loc_2).Distinct().ToArray());
|
||||
if (1 == locs.Count) { RegionFineLocation2 = ((App)Application.Current).IsoDb.GetFineLocation2ByIso(locs[0]); }
|
||||
else if (0 == locs.Count) { RegionFineLocation2 = null; }
|
||||
|
||||
|
||||
locs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Fine_Loc_3).Distinct().ToArray());
|
||||
locs.Sort();
|
||||
var finelocations3 = locs.Select(loc => ((App)Application.Current).IsoDb.GetFineLocation3ByIso(loc)).ToList();
|
||||
var f3 = ((App)Application.Current).IsoDb.GetFineLocation3ByIso("??");
|
||||
if (!finelocations3.Contains(f3)) { finelocations3.Add(f3); }
|
||||
AllFineLocations3 = finelocations3.ToArray();
|
||||
locs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Fine_Loc_3).Distinct().ToArray());
|
||||
if (1 == locs.Count) { RegionFineLocation3 = ((App)Application.Current).IsoDb.GetFineLocation3ByIso(locs[0]); }
|
||||
else if (0 == locs.Count) { RegionFineLocation3 = null; }
|
||||
|
||||
locs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Trans_Main_Loc).Distinct().ToArray());
|
||||
locs.Sort();
|
||||
var mains = locs.Select(loc => ((App)Application.Current).IsoDb.GetMainLocationByIso(loc)).ToList();
|
||||
var m = ((App)Application.Current).IsoDb.GetMainLocationByIso("????");
|
||||
if (!mains.Contains(m)) { mains.Add(m); }
|
||||
AllMainLocations = mains.ToArray();
|
||||
locs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Trans_Main_Loc).Distinct().ToArray());
|
||||
if (1 == locs.Count) { RegionMainLocation = ((App)Application.Current).IsoDb.GetMainLocationByIso(locs[0]); }
|
||||
else if (0 == locs.Count) { RegionMainLocation = null; }
|
||||
|
||||
var dims = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Physical_Dimension).Distinct().ToArray());
|
||||
dims.Sort();
|
||||
var dimensions = dims.Select(dim => ((App)Application.Current).IsoDb.GetPhysicalDimensionByIso(dim)).ToList();
|
||||
var pd = ((App)Application.Current).IsoDb.GetPhysicalDimensionByIso("??");
|
||||
if (!dimensions.Contains(pd)) { dimensions.Add(pd); }
|
||||
AllPhysicalDimensions = dimensions.ToArray();
|
||||
dims = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Physical_Dimension).Distinct().ToArray());
|
||||
if (1 == dims.Count) { RegionPhysicalDimension = ((App)Application.Current).IsoDb.GetPhysicalDimensionByIso(dims[0]); }
|
||||
else if (0 == dims.Count) { RegionPhysicalDimension = null; }
|
||||
|
||||
var poss = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Position).Distinct().ToArray());
|
||||
poss.Sort();
|
||||
var positions = poss.Select(pos => (Application.Current as App).IsoDb.GetPositionByISO(pos)).ToList();
|
||||
AllPositions = positions.ToArray();
|
||||
poss = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Position).Distinct().ToArray());
|
||||
if (1 == poss.Count) { RegionPosition = positions[0]; }
|
||||
else if (0 == poss.Count) { RegionPosition = null; }
|
||||
}
|
||||
|
||||
public TemplateRegion ToISORegion(TestObjectTemplate template, Zone zone, int number)
|
||||
{
|
||||
var region = new TemplateRegion(template.TemplateName, zone.Name, template.IsLocalOnly);
|
||||
region.Direction = null == RegionDirection ? "?" : RegionDirection.Direction;
|
||||
region.FilterClass = null == RegionFilterClass ? "?" : RegionFilterClass.Filter_Class;
|
||||
region.FineLocation1 = null == RegionFineLocation1 ? "??" : RegionFineLocation1.Fine_Loc_1;
|
||||
region.FineLocation2 = null == RegionFineLocation2 ? "??" : RegionFineLocation2.FINE_LOC_2;
|
||||
region.FineLocation3 = null == RegionFineLocation3 ? "??" : RegionFineLocation3.FINE_LOC_3;
|
||||
region.LowerRight = new System.Drawing.Point(Convert.ToInt32(RegionBottomRight.X), Convert.ToInt32(RegionBottomRight.Y));
|
||||
region.MainLocation = null == RegionMainLocation ? "????" : RegionMainLocation.Trans_Main_Loc;
|
||||
region.PhysicalDimension = null == RegionPhysicalDimension ? "??" : RegionPhysicalDimension.Physical_Dimension;
|
||||
region.Position = null == RegionPosition ? "?" : RegionPosition.Position;
|
||||
region.RegionDescription = RegionDescription;
|
||||
region.RegionName = RegionName;
|
||||
region.RegionNumber = number;
|
||||
region.TestObject = null == RegionTestObject ? "?" : RegionTestObject.Test_Object;
|
||||
region.UpperLeft = new System.Drawing.Point(Convert.ToInt32(RegionUpperLeft.X), Convert.ToInt32(RegionUpperLeft.Y));
|
||||
return region;
|
||||
}
|
||||
|
||||
private List<TemplateChannelUI> _regionUIChannels = new List<TemplateChannelUI>();
|
||||
public TemplateChannelUI[] RegionUIChannels
|
||||
{
|
||||
get => _regionUIChannels.ToArray();
|
||||
set => _regionUIChannels = new List<TemplateChannelUI>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
/// <summary>
|
||||
/// generic base class for settings
|
||||
/// </summary>
|
||||
public abstract class Setting
|
||||
{
|
||||
protected string _propertyId;
|
||||
/// <summary>
|
||||
/// string id of property
|
||||
/// </summary>
|
||||
public string PropertyId => _propertyId;
|
||||
protected int _propertyType;
|
||||
protected string _propertyValue;
|
||||
/// <summary>
|
||||
/// value of property
|
||||
/// does not currently do length checking and there is a max length
|
||||
/// </summary>
|
||||
public string PropertyValue => _propertyValue;
|
||||
protected string _userId;
|
||||
/// <summary>
|
||||
/// User for user specific settings
|
||||
/// </summary>
|
||||
public string UserId => _userId;
|
||||
|
||||
public enum PropertyTypes
|
||||
{
|
||||
User = 1 << 0,
|
||||
Global = 1 << 1
|
||||
}
|
||||
|
||||
protected Setting(string id, PropertyTypes type, string defaultPropertyValue, string userId)
|
||||
{
|
||||
_userId = userId;
|
||||
_propertyId = id;
|
||||
_propertyType = (int)type;
|
||||
GetPropertyValue(defaultPropertyValue);
|
||||
}
|
||||
|
||||
protected abstract void GetPropertyValue(string defaultValue);
|
||||
|
||||
public void SetValue(string value)
|
||||
{
|
||||
_propertyValue = value;
|
||||
StoreInDB();
|
||||
}
|
||||
|
||||
protected void StoreInDB()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_SettingsUpdateInsert.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@PropertyId", SqlDbType.NVarChar, 255) { Value = PropertyId });
|
||||
cmd.Parameters.Add(new SqlParameter("@PropertyType", SqlDbType.Int) { Value = _propertyType });
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@PropertyValue", SqlDbType.NVarChar, 255) { Value = PropertyValue });
|
||||
cmd.Parameters.Add(new SqlParameter("@UserId", SqlDbType.NVarChar, 255) { Value = UserId });
|
||||
var newIdParam =
|
||||
new SqlParameter("@new_id", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(newIdParam);
|
||||
var errorNumberParam =
|
||||
new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumberParam);
|
||||
var errorMessageParam =
|
||||
new SqlParameter("@errorMessage", SqlDbType.NVarChar, 250)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cmd.Parameters.Add(errorMessageParam);
|
||||
|
||||
#endregion params
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) {/* APILogger.LogException(ex);*/ }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user