fixed CREW/PAS import for variable locode selection

This commit is contained in:
Daniel Schick 2022-10-11 08:53:58 +02:00
parent a3019b7a30
commit d96979a939
3 changed files with 54 additions and 29 deletions

View File

@ -25,7 +25,7 @@
<TextBlock FontWeight="DemiBold" VerticalAlignment="Center" Name="textBlockType" Grid.Row="0" Grid.Column="1">bla</TextBlock> <TextBlock FontWeight="DemiBold" VerticalAlignment="Center" Name="textBlockType" Grid.Row="0" Grid.Column="1">bla</TextBlock>
<TextBlock FontWeight="DemiBold" VerticalAlignment="Center" Name="textBlockValue" Grid.Row="1" Grid.Column="1">bla</TextBlock> <TextBlock FontWeight="DemiBold" VerticalAlignment="Center" Name="textBlockValue" Grid.Row="1" Grid.Column="1">bla</TextBlock>
<xctk:WatermarkComboBox Grid.Column="1" Grid.Row="2" x:Name="comboBoxValues" IsTextSearchEnabled="True" SelectedValuePath="Key" DisplayMemberPath="Value" Margin="2" IsEditable="True" Watermark="Select an appropriate value" /> <xctk:WatermarkComboBox Grid.Column="1" Grid.Row="2" x:Name="comboBoxValues" IsTextSearchEnabled="True" SelectedValuePath="Key" DisplayMemberPath="Value" Margin="2" IsEditable="True" Watermark="Select an appropriate value" />
<enictrl:LocodeControl Grid.Column="1" Grid.Row="2" x:Name="locodeControl" Visibility="Hidden" />
</Grid> </Grid>
</enictrl:EditWindowBase> </enictrl:EditWindowBase>

View File

@ -18,10 +18,21 @@ namespace ENI2.EditControls
InitializeComponent(); InitializeComponent();
} }
public bool LocodeMode
{
get { return this.locodeControl.Visibility == Visibility.Visible; }
set
{
this.locodeControl.Visibility = value ? Visibility.Visible : Visibility.Hidden;
this.comboBoxValues.Visibility = value ? Visibility.Hidden : Visibility.Visible;
}
}
public string SelectedValue public string SelectedValue
{ {
get get
{ {
if (LocodeMode) return this.locodeControl.LocodeValue;
return this.comboBoxValues.SelectedValue as string; return this.comboBoxValues.SelectedValue as string;
} }
} }

View File

@ -2521,11 +2521,13 @@ namespace ENI2.Excel
val = val.ToUpper(); val = val.ToUpper();
if (val.IsNullOrEmpty()) return val;
// check if this is a legitimate Locode
if (!LocodeDB.LocationNameFromLocode(val).IsNullOrEmpty()) return val; if (!LocodeDB.LocationNameFromLocode(val).IsNullOrEmpty()) return val;
string portName = LocodeDB.PortNameFromLocode(val); // check if it is a port that we already know
if (portName.IsNullOrEmpty())
{
// _log.WarnFormat("unknown Locode {0}", val); // _log.WarnFormat("unknown Locode {0}", val);
// reverse search: if this is a name lookup port code // reverse search: if this is a name lookup port code
List<string> possibleLocodes = LocodeDB.AllLocodesForCityName(val); List<string> possibleLocodes = LocodeDB.AllLocodesForCityName(val);
@ -2546,6 +2548,7 @@ namespace ENI2.Excel
_locodeImportDict[val] = fid.SelectedValue; _locodeImportDict[val] = fid.SelectedValue;
} }
} }
if(_locodeImportDict.ContainsKey(val))
result = _locodeImportDict[val]; result = _locodeImportDict[val];
} }
else if(possibleLocodes.Count == 1) else if(possibleLocodes.Count == 1)
@ -2554,14 +2557,25 @@ namespace ENI2.Excel
} }
else else
{ {
// nothing found if (!_locodeImportDict.ContainsKey(val))
{
// nothing found, let the user pick a locode by himself
FixImportDialog fid = new FixImportDialog();
fid.Value = val;
fid.ValueType = "Locode";
fid.LocodeMode = true;
if (fid.ShowDialog() ?? false)
{
_locodeImportDict[val] = fid.SelectedValue;
} }
} }
if (_locodeImportDict.ContainsKey(val))
result = _locodeImportDict[val];
}
return result; return result;
} }
#endregion #endregion
} }
} }