/// <summary> /// convert shortname from Lastname, firstname, title to another shortname format /// TODO: use partner key to get to the full name, resolve issues with couples that have different family names etc /// </summary> public static string FormatShortName(string AShortname, eShortNameFormat AFormat) { if (AShortname.Length == 0) { return(""); } StringCollection names = StringHelper.StrSplit(AShortname, ","); string resultValue = ""; if (AFormat == eShortNameFormat.eShortname) { return(AShortname); } else if (AFormat == eShortNameFormat.eReverseShortname) { foreach (string name in names) { if (resultValue.Length > 0) { resultValue = " " + resultValue; } resultValue = name + resultValue; } return(resultValue); } else if (AFormat == eShortNameFormat.eOnlyTitle) { // organisations&churches have no title, therefore we need to check if there are more than 2 names if (names.Count > 2) { return(names[names.Count - 1]); } // eg. Mustermann, Family if (names.Count > 1) { return(names[1]); } } else if (AFormat == eShortNameFormat.eOnlySurname) { return(names[0]); } else if (AFormat == eShortNameFormat.eOnlyFirstname) { if (names.Count > 1) { return(names[1]); } } else if (AFormat == eShortNameFormat.eOnlySurnameFirstNameInitial) { if (names.Count > 2) { // remove the title names.RemoveAt(names.Count - 1); } if (names.Count > 1) { return(names[0] + ", " + names[1].Substring(0, 1) + "."); } return(names[0]); } else if (AFormat == eShortNameFormat.eReverseWithoutTitle) { if (names.Count > 1) { // remove the title names.RemoveAt(names.Count - 1); } foreach (string name in names) { if (resultValue.Length > 0) { resultValue = " " + resultValue; } resultValue = name + resultValue; } return(resultValue); } else if (AFormat == eShortNameFormat.eReverseLastnameInitialsOnly) { if (names.Count > 1) { // remove the title names.RemoveAt(names.Count - 1); } if (names.Count > 1) { return(names[1] + " " + names[0].Substring(0, 1) + "."); } return(names[0].Substring(0, 1) + "."); } else if (AFormat == eShortNameFormat.eJustRemoveTitle) { if (names.Count > 1) { // remove the title names.RemoveAt(names.Count - 1); } if (names.Count > 1) { return(names[0] + ", " + names[1]); } return(names[0]); } return(""); }
/// <summary> /// convert shortname from Lastname, firstname, title to another shortname format /// TODO: use partner key to get to the full name, resolve issues with couples that have different family names etc /// </summary> public static string FormatShortName(string AShortname, eShortNameFormat AFormat) { if (AShortname.Length == 0) { return ""; } StringCollection names = StringHelper.StrSplit(AShortname, ","); string resultValue = ""; if (AFormat == eShortNameFormat.eShortname) { return AShortname; } else if (AFormat == eShortNameFormat.eReverseShortname) { foreach (string name in names) { if (resultValue.Length > 0) { resultValue = " " + resultValue; } resultValue = name + resultValue; } return resultValue; } else if (AFormat == eShortNameFormat.eOnlyTitle) { // organisations&churches have no title, therefore we need to check if there are more than 2 names if (names.Count > 2) { return names[names.Count - 1]; } // eg. Mustermann, Family if (names.Count > 1) { return names[1]; } } else if (AFormat == eShortNameFormat.eOnlySurname) { return names[0]; } else if (AFormat == eShortNameFormat.eOnlyFirstname) { if (names.Count > 1) { return names[1]; } } else if (AFormat == eShortNameFormat.eReverseWithoutTitle) { if (names.Count > 1) { // remove the title names.RemoveAt(names.Count - 1); } foreach (string name in names) { if (resultValue.Length > 0) { resultValue = " " + resultValue; } resultValue = name + resultValue; } return resultValue; } else if (AFormat == eShortNameFormat.eReverseLastnameInitialsOnly) { if (names.Count > 1) { // remove the title names.RemoveAt(names.Count - 1); } if (names.Count > 1) { return names[1] + " " + names[0].Substring(0, 1) + "."; } return names[0].Substring(0, 1) + "."; } return ""; }