using System.Linq; using GCHR.Model.Konto; namespace GCHR.Control { public class DepartmentCase { private readonly string[] _markenCase4 = new[] { "1", "2", "3" }; private readonly string _hauptbetrieb; private readonly string _hauptmarke; private readonly string _bilanzBetrieb = "07"; private readonly string _bilanzMarke = "0"; private readonly string _betriebWildcard; private readonly string _markeWildcard; private readonly int _kontoLaenge; public DepartmentCase(string marke, string betrieb, string bilanzMarke, string bilanzBetrieb, int kontoLaenge) { _hauptmarke = marke; _hauptbetrieb = betrieb; _bilanzMarke = bilanzMarke; _bilanzBetrieb = bilanzBetrieb; _markeWildcard = new string('?', _hauptmarke.Length); _betriebWildcard = new string('?', _hauptbetrieb.Length); _kontoLaenge = kontoLaenge; } public void DepartmentUmwandeln(HaendlerKonto konto) { if (konto.Case == null || konto.Case.Length <= 0) return; var departmentCase = konto.Case.Replace("-", ""); switch (departmentCase.Substring(0, 1)) { case "1": konto.Marke = MarkeAusCaseOderHauptmarke(departmentCase); konto.Betrieb = _hauptbetrieb; return; case "2": if (departmentCase.Length > 1) { konto.Marke = departmentCase.Substring(1); return; } break; case "3": konto.Marke = _hauptmarke; return; case "4": if (_markenCase4.Contains(konto.Marke)) { return; } konto.Marke = _hauptmarke; return; case "5": if (departmentCase.Length > 1 || konto.Kontonummer.Length > _kontoLaenge) { var dept = (departmentCase.Length > 1) ? departmentCase.Substring(1) : konto.Kontonummer; konto.Marke = Marke(dept); konto.Betrieb = Betrieb(dept); } konto.Marke = (konto.Marke == null || konto.Marke == _markeWildcard) ? _hauptmarke : konto.Marke; konto.Betrieb = (konto.Betrieb == null || konto.Betrieb == _betriebWildcard) ? _hauptbetrieb : konto.Betrieb; if (departmentCase.Length > 1 || konto.Kontonummer.Length <= _kontoLaenge) return; konto.Kontonummer = konto.Kontonummer.Substring(_hauptmarke.Length + _hauptbetrieb.Length); return; case "B": konto.Marke = _bilanzMarke; konto.Betrieb = _bilanzBetrieb; return; default: break; } } private string MarkeAusCaseOderHauptmarke(string departmentCase) { return (departmentCase.Length > 1) ? departmentCase.Substring(1, _hauptmarke.Length) : _hauptmarke; } private string Marke(string dept) { return dept.Substring(0, _hauptmarke.Length); } private string Betrieb (string dept) { return dept.Substring(_hauptmarke.Length, _hauptbetrieb.Length); } } }