git_bsmd/ENI2/Util/GlobalStructures.cs

230 lines
8.5 KiB
C#

// Copyright (c) 2017 schick Informatik
// Description: hier sind mehrfach verwendete Strukturen abgelegt
//
using bsmd.database;
using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Data;
using ENI2.Locode;
namespace ENI2.Util
{
static class GlobalStructures
{
public static string[] GenderList =
{
Properties.Resources.textNotKnown,
Properties.Resources.textMale,
Properties.Resources.textFemale,
Properties.Resources.textNotApplicable
};
public static string[] IDDocTypeList =
{
Properties.Resources.textIdentityCard,
Properties.Resources.textPassport,
Properties.Resources.textMusterBook,
Properties.Resources.textPhotoId,
Properties.Resources.textResidencePermit,
Properties.Resources.textOtherLegalIdentityDocument
};
public static byte[] ShipSecurityLevels = { 1, 2, 3 };
public static Dictionary<int, string> Edifact8025 = new Dictionary<int, string> {
{1, "Cargo operations" },
{2, "Passenger movement" },
{3, "Taking bunkers" },
{4, "Changing crew" },
{5, "Goodwill visit" },
{6, "Taking supplies" },
{7, "Repair" },
{8, "Laid-up" },
{9, "Awaiting orders" },
{10, "Miscellaneous" },
{11, "Crew movement" },
{12, "Cruise, leisure and recreation" },
{13, "Under government order" },
{14, "Quarantine inspection" },
{15, "Refuge" },
{16, "Unloading cargo" },
{17, "Loading cargo" },
{18, "Repair in dry dock" },
{19, "Repair in wet dock" },
{20, "Cargo tank cleaning" },
{21, "Means of transport customs clearance" },
{22, "De-gassing" },
{23, "Waste disposal" },
{98, "Pass through" }
};
private static Dictionary<int, string> _edifact8025WithKey = null;
public static Dictionary<int, string> Edifact8025WithKey
{
get
{
if(_edifact8025WithKey == null)
{
_edifact8025WithKey = new Dictionary<int, string>();
foreach (int key in Edifact8025.Keys)
_edifact8025WithKey.Add(key, string.Format("{0} {1}", key, Edifact8025[key]));
}
return _edifact8025WithKey;
}
}
public static string[] vesselClasses =
{
"INF1",
"INF2",
"INF3"
};
public static string[] packingGroups =
{
// "NONE", // TODO! Ist das wirklich der erwünschte Effekt?
"I",
"II",
"III"
};
public static string[] imoHazardClasses =
{
"A",
"B",
"A and B"
};
public static string[] PackingGroups
{
get { return packingGroups; }
}
static bool IsNullable<T>(T obj)
{
if (obj == null) return true; // obvious
Type type = typeof(T);
if (!type.IsValueType) return true; // ref-type
if (Nullable.GetUnderlyingType(type) != null) return true; // Nullable<T>
return false; // value-type
}
internal static void FilterCombobox(ComboBox cmb, System.Windows.Input.Key key)
{
if (cmb == null) return;
if (cmb.ItemsSource == null) return;
bool ignoreSelect = ((key == System.Windows.Input.Key.Back) || (key == System.Windows.Input.Key.Delete));
CollectionView itemsViewOriginal = (CollectionView)CollectionViewSource.GetDefaultView(cmb.ItemsSource);
System.Diagnostics.Trace.WriteLine(cmb.Text);
if (ignoreSelect)
{
itemsViewOriginal.Filter = null;
}
else
{
itemsViewOriginal.Filter = ((o) =>
{
bool result = false;
if (String.IsNullOrEmpty(cmb.Text))
{
result = true;
}
else if (o is string)
{
if (((string)o).Contains(cmb.Text, StringComparison.OrdinalIgnoreCase)) result = true;
}
else if (o is System.Collections.Generic.KeyValuePair<string, string>)
{
if (((System.Collections.Generic.KeyValuePair<string, string>)o).Value.StartsWith(cmb.Text, StringComparison.OrdinalIgnoreCase))
result = true;
}
else if (o is System.Collections.Generic.KeyValuePair<int, string>)
{
if (((System.Collections.Generic.KeyValuePair<int, string>)o).Value.StartsWith(cmb.Text, StringComparison.OrdinalIgnoreCase))
result = true;
}
return result;
});
}
itemsViewOriginal.Refresh();
if (!ignoreSelect && (itemsViewOriginal.Count == 1))
{
// Treffer: Select?
cmb.SelectedItem = itemsViewOriginal.GetItemAt(0);
}
}
internal static byte? ParseGender(string val)
{
byte? result = null;
if (val != null)
{
if (val.Equals("m", StringComparison.CurrentCultureIgnoreCase) || val.Equals("male", StringComparison.CurrentCultureIgnoreCase))
{
result = 1;
}
else if (val.Equals("f", StringComparison.CurrentCultureIgnoreCase) || val.Equals("female", StringComparison.CurrentCultureIgnoreCase))
{
result = 2;
}
else if (val.Equals("d", StringComparison.CurrentCultureIgnoreCase) || val.Equals("diverse", StringComparison.CurrentCultureIgnoreCase) ||
val.Equals("n", StringComparison.CurrentCultureIgnoreCase) || val.Equals("not applicable", StringComparison.CurrentCultureIgnoreCase))
{
result = 9;
}
else
{
result = 0;
}
}
return result;
}
internal static byte? ReadIdentityDocumentType(string val)
{
byte? result = null;
if (val != null)
{
if (val.Equals("identity_card", StringComparison.CurrentCultureIgnoreCase)) result = 0;
if (val.Equals("passport", StringComparison.CurrentCultureIgnoreCase)) result = 1;
if (val.Equals("muster_book", StringComparison.CurrentCultureIgnoreCase)) result = 2;
if (val.Equals("picture_id", StringComparison.CurrentCultureIgnoreCase)) result = 3;
if (val.Equals("residental_permit", StringComparison.CurrentCultureIgnoreCase)) result = 4;
if (val.Equals("other_legal_identity_document", StringComparison.CurrentCultureIgnoreCase)) result = 5;
if (val.Equals("ic", StringComparison.CurrentCultureIgnoreCase)) result = 0;
}
return result;
}
internal static bool? ReadBoolean(string val)
{
if ((val == "y") || (val == "Y") || val.Equals("yes", StringComparison.OrdinalIgnoreCase) || (val == "1") || (val == "x") || (val == "X"))
return true;
return false;
}
public static bool IsValidLocode(string locode, RuleEngine.LocodeMode mode)
{
switch (mode)
{
case RuleEngine.LocodeMode.NO_PORT_FLAG:
return !LocodeDB.LocationNameFromLocode(locode).IsNullOrEmpty();
case RuleEngine.LocodeMode.SSN:
return !LocodeDB.SSNPortNameFromLocode(locode).IsNullOrEmpty();
default:
return !LocodeDB.PortNameFromLocode(locode).IsNullOrEmpty();
}
}
}
}