using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace GCHR.Model.Uebersetzung { class KontoTyp { enum Typ { S, Q, M, V, D }; enum Buchung { HH, HS, SH, SS }; public KontoTyp(string typ) { if (typ.Length > 0) { kontoTyp = tryParseKontoTyp(typ.Substring(0, 1)); negativ = typ.Contains('-'); alternativ = typ.Contains('A'); if (kontoTyp == Typ.V) { if (typ.Contains("HH")) buchung = Buchung.HH; if (typ.Contains("HS")) buchung = Buchung.HS; if (typ.Contains("SH")) buchung = Buchung.SH; if (typ.Contains("SS")) buchung = Buchung.SS; } } } private static Typ tryParseKontoTyp(string typ) { try { return (Typ)Enum.Parse(typeof(Typ), typ); } catch (Exception) { return Typ.S; } } private Typ kontoTyp = Typ.S; private bool negativ = false; private bool alternativ = false; private Buchung buchung = Buchung.SH; public decimal Faktor { get { return (negativ) ? -1m : 1m; } } public override bool Equals(object obj) { if (obj is KontoTyp) { return equals(((KontoTyp)obj).kontoTyp); } if (obj is Typ) { return equals((Typ)obj); } if (obj is string) { try { return equals((Typ)Enum.Parse(typeof(Typ), ((string)obj).Substring(0, 1))); } catch (Exception) { } } return base.Equals(obj); } private bool equals(Typ typ) { if (typ == kontoTyp) return true; if (typ == Typ.D || typ == Typ.D) return true; if ((typ == Typ.V && kontoTyp == Typ.S) || (typ == Typ.S && kontoTyp == Typ.V)) return true; return false; } public override string ToString() { return kontoTyp + ((alternativ) ? "A" : "") + ((kontoTyp == Typ.V) ? buchung.ToString() : "") + ((negativ) ? "-" : ""); } public override int GetHashCode() { return ToString().GetHashCode(); } } }