public static string Password(string Name)
        {
            try
            {
                User st;

                using (fsbDB FSBDB = new fsbDB())
                {
                    st = (from x in FSBDB.User
                          where x.Name == Name
                          select x).FirstOrDefault();
                }

                return(st.Password);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return("");
            }
        }
        public static void DelTimer(int id)
        {
            try
            {
                DB.Timer te;

                using (fsbDB FSBDB = new fsbDB())
                {
                    te = (from x in FSBDB.Timer
                          where x.ID == id
                          select x).FirstOrDefault();

                    FSBDB.Timer.Remove(te);
                    FSBDB.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
            }
        }
        public static TGruppen Gruppe(int TurnierID, string gruppe)
        {
            try
            {
                TGruppen l;

                using (fsbDB FSBDB = new fsbDB())
                {
                    l = (from x in FSBDB.TGruppen
                         where x.TurnierID == TurnierID && x.Gruppe == gruppe
                         select x).FirstOrDefault();
                }

                return(l);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new TGruppen());
            }
        }
        public static DB.Timer Timer(int id)
        {
            try
            {
                DB.Timer te;

                using (fsbDB FSBDB = new fsbDB())
                {
                    te = (from x in FSBDB.Timer
                          where x.ID == id
                          select x).FirstOrDefault();
                }

                return(te);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new DB.Timer());
            }
        }
        public static void DelStrafe(string bezeichnung)
        {
            try
            {
                Strafen st;

                using (fsbDB FSBDB = new fsbDB())
                {
                    st = (from x in FSBDB.Strafen
                          where x.Bezeichnung == bezeichnung
                          select x).FirstOrDefault();

                    FSBDB.Strafen.Remove(st);
                    FSBDB.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
            }
        }
        public static void SaveRundenStatus(int TurnierID, int runde, int status)
        {
            try
            {
                TRunden e;

                using (fsbDB FSBDB = new fsbDB())
                {
                    e = (from g in FSBDB.TRunden
                         where g.TurnierID == TurnierID && g.Runde == runde
                         select g).FirstOrDefault();

                    e.status = status;
                    FSBDB.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
            }
        }
        ////public static void SaveFoul(TSpiele spiel)
        ////{
        ////    // es muss die datenbankklasse für Spiele erweitert werden
        ////    ////try
        ////    ////{
        ////    ////    TSpiele e;
        ////    ////
        ////    ////    using (fsbDB FSBDB = new fsbDB())
        ////    ////    {
        ////    ////        e = (from s in FSBDB.TSpiele where s.TurnierID == spiel.TurnierID && s.Spiel == spiel.Spiel select s).FirstOrDefault();
        ////    ////        e.FoulA = Convert.ToInt32(ClsVariablen.Instance.Foul1);
        ////    ////        e.FoulB = Convert.ToInt32(ClsVariablen.Instance.Foul2);
        ////    ////        FSBDB.SaveChanges();
        ////    ////    }
        ////    ////}
        ////    ////catch (Exception ex)
        ////    ////{
        ////    ////    ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
        ////    ////}
        ////}



        public static void SaveSpielStatus(TSpiele spiel, int status)
        {
            try
            {
                TSpiele e;

                using (fsbDB FSBDB = new fsbDB())
                {
                    e = (from s in FSBDB.TSpiele
                         where s.TurnierID == spiel.TurnierID && s.Spiel == spiel.Spiel
                         select s).Single();

                    e.Status = status;
                    FSBDB.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
            }
        }
        public static int TimerID(int TimerNr)
        {
            try
            {
                DB.Timer te;

                using (fsbDB FSBDB = new fsbDB())
                {
                    te = (from x in FSBDB.Timer
                          where x.Nr == TimerNr
                          select x).FirstOrDefault();
                }

                return((int)te.ID);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(0);
            }
        }
        public static List <TGruppen> Gruppen(int TurnierID, int runde)
        {
            try
            {
                List <TGruppen> l;

                using (fsbDB FSBDB = new fsbDB())
                {
                    l = (from x in FSBDB.TGruppen
                         where x.TurnierID == TurnierID && x.Runde == runde
                         select x).ToList();
                }

                return(l);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new TGruppen[0].ToList());
            }
        }
        public static Strafen Strafe(int ID)
        {
            try
            {
                Strafen st;

                using (fsbDB FSBDB = new fsbDB())
                {
                    st = (from x in FSBDB.Strafen
                          where x.ID == ID
                          select x).FirstOrDefault();
                }

                return(st);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new Strafen());
            }
        }
        public static TEreignisse Ereignis(int EreignisID)
        {
            try
            {
                TEreignisse t;

                using (fsbDB FSBDB = new fsbDB())
                {
                    t = (from x in FSBDB.TEreignisse
                         where x.ID == EreignisID
                         select x).First();
                }

                return(t);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new TEreignisse());
            }
        }
        ////----------------------------------------------------------------------------------

        public static List <Anzeigetabelle> AnzeigetabelleAll()
        {
            try
            {
                List <Anzeigetabelle> l;

                using (fsbDB FSBDB = new fsbDB())
                {
                    l = (from t in FSBDB.Anzeigetabelle
                         orderby t.Position
                         select t).ToList();
                }

                return(l);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new Anzeigetabelle[0].ToList());
            }
        }
        public static void DelAnzeigetabelle(int id)
        {
            try
            {
                Anzeigetabelle at;

                using (fsbDB FSBDB = new fsbDB())
                {
                    at = (from x in FSBDB.Anzeigetabelle
                          where x.ID == id
                          select x).FirstOrDefault();

                    FSBDB.Anzeigetabelle.Remove(at);
                    FSBDB.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
            }
        }
        ////-------------------------------------------------------------------------------

        public static List <TabellenSort> Tabellensortierung()
        {
            try
            {
                List <TabellenSort> ts;

                using (fsbDB FSBDB = new fsbDB())
                {
                    ts = (from x in FSBDB.TabellenSort
                          orderby x.Prio
                          select x).ToList();
                }

                return(ts);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new TabellenSort[0].ToList());
            }
        }
        public static TabellenSort Tabellensortierung(int id)
        {
            try
            {
                TabellenSort ts;

                using (fsbDB FSBDB = new fsbDB())
                {
                    ts = (from x in FSBDB.TabellenSort
                          where x.ID == id
                          select x).FirstOrDefault();
                }

                return(ts);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new TabellenSort());
            }
        }
        public static DB.Mannschaften Mannschaft(long MannschaftsID)
        {
            try
            {
                DB.Mannschaften lst;

                using (fsbDB FSBDB = new fsbDB())
                {
                    lst = (from s in FSBDB.Mannschaften
                           where s.ID == MannschaftsID
                           select s).FirstOrDefault();
                }

                return(lst);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new DB.Mannschaften());
            }
        }
        public static TKopf Turnier(int TurnierID)
        {
            try
            {
                TKopf stl;

                using (fsbDB FSBDB = new fsbDB())
                {
                    stl = (from x in FSBDB.TKopf
                           where x.ID == TurnierID
                           select x).FirstOrDefault();
                }

                return(stl);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new TKopf());
            }
        }
        public static Timerevent TimerEvent(int ID)
        {
            try
            {
                Timerevent te;

                using (fsbDB FSBDB = new fsbDB())
                {
                    te = (from x in FSBDB.Timerevent
                          where x.ID == ID
                          select x).FirstOrDefault();
                }

                return(te);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new Timerevent());
            }
        }
        public static void DelSpieler(int id)
        {
            try
            {
                Spieler ss;

                using (fsbDB FSBDB = new fsbDB())
                {
                    ss = (from s in FSBDB.Spieler
                          where s.ID == id
                          select s).FirstOrDefault();

                    FSBDB.Spieler.Remove(ss);
                    FSBDB.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
            }
        }
        public static Spieler Spieler(int id)
        {
            try
            {
                Spieler ss;

                using (fsbDB FSBDB = new fsbDB())
                {
                    ss = (from s in FSBDB.Spieler
                          where s.ID == id
                          select s).FirstOrDefault();
                }

                return(ss);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new Spieler());
            }
        }
        public static void DelMannschaft(long mannschaftsID)
        {
            try
            {
                DB.Mannschaften ma;

                using (fsbDB anzeigeDB = new fsbDB())
                {
                    ma = (from m in anzeigeDB.Mannschaften
                          where m.ID == mannschaftsID
                          select m).FirstOrDefault();

                    anzeigeDB.Mannschaften.Remove(ma);
                    anzeigeDB.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
            }
        }
        public static Options3 Options3(string option, string requestor = "")
        {
            try
            {
                Options3 o3;

                using (fsbDB FSBDB = new fsbDB())
                {
                    o3 = (from Options3 g2 in FSBDB.Options3
                          where g2.Prop == option
                          select g2).FirstOrDefault();
                }

                return(o3);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString() + " > " + requestor, ex);
                return(new Options3());
            }
        }
        /// <summary>
        /// Speichert nur das Feld DirekterErweiterterVergleich
        /// </summary>
        /// <param name="tabelle"></param>
        /// <param name="dV"></param>
        public static void SaveTabellenDVPV(TTabellen tabelle, int dV)
        {
            try
            {
                TTabellen l;

                using (fsbDB FSBDB = new fsbDB())
                {
                    l = (from x in FSBDB.TTabellen
                         where x.ID == tabelle.ID
                         select x).FirstOrDefault();

                    l.Direktererweitertervergleich = dV;

                    FSBDB.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
            }
        }
        public static int EreignisseMenge(int TurnierID)
        {
            try
            {
                int t;

                using (fsbDB FSBDB = new fsbDB())
                {
                    t = (from x in FSBDB.TEreignisse
                         where x.TurnierID == TurnierID
                         orderby x.Spiel, x.CPUZeit
                         select x).Count();
                }

                return(t);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(0);
            }
        }
        public static List <TEreignisse> Ereignisse(int TurnierID, int spielNr)
        {
            try
            {
                List <TEreignisse> t;

                using (fsbDB FSBDB = new fsbDB())
                {
                    t = (from x in FSBDB.TEreignisse
                         where x.TurnierID == TurnierID && x.Spiel == spielNr
                         orderby x.Spiel, x.CPUZeit
                         select x).ToList();
                }

                return(t);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new TEreignisse[0].ToList());
            }
        }
        public static List <ClsTorschuetze> TorschuetzenList(int TurnierID)
        {
            try
            {
                List <ClsTorschuetze> ret = new List <ClsTorschuetze>();
                using (fsbDB FSBDB = new fsbDB())
                {
                    var x = (
                        from TEreignisse e
                        in FSBDB.TEreignisse
                        where e.TurnierID == TurnierID && e.Ereignistyp == "05"
                        group e by new { e.Mannschaft, e.Spieler } into grp
                        select new
                    {
                        grp.Key.Mannschaft,
                        grp.Key.Spieler,
                        Tore = grp.Select(e => e.Ereignistyp).Count()
                    }

                        ).OrderByDescending(y => y.Tore).ToList();

                    for (int i = 0; i < x.Count; i++)
                    {
                        ClsTorschuetze nt = new ClsTorschuetze();
                        nt.Mannschaft = x[i].Mannschaft;
                        nt.Spieler    = x[i].Spieler;
                        nt.Tore       = x[i].Tore;
                        ret.Add(nt);
                    }
                }

                return(ret);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new ClsTorschuetze[0].ToList());
            }
        }
        public static TSpiele Spiel(int spielID)
        {
            try
            {
                TSpiele t;

                using (fsbDB FSBDB = new fsbDB())
                {
                    t = (from x in FSBDB.TSpiele
                         where x.ID == spielID
                         orderby x.Spiel
                         select x).FirstOrDefault();
                }

                return(t);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new TSpiele());
            }
        }
        public static ClsTurnier TurnierKomplett(int TurnierID)
        {
            try
            {
                ClsTurnier turn = new ClsTurnier();

                turn.Kopf         = Turnier(TurnierID);
                turn.Runden       = Runden(TurnierID);
                turn.Gruppen      = Gruppen(TurnierID);
                turn.Spiele       = Spiele(TurnierID);
                turn.Tabellen     = Tabellen(TurnierID);
                turn.Ereignisse   = ClsEreignisControler.Ereignisse(TurnierID);
                turn.Torschuetzen = TorschuetzenList(TurnierID);

                return(turn);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new ClsTurnier());
            }
        }
        public static List <TTabellen> Tabellen(int TurnierID, string gruppe)
        {
            try
            {
                List <TTabellen> t;

                using (fsbDB FSBDB = new fsbDB())
                {
                    t = (from x in FSBDB.TTabellen
                         where x.TurnierID == TurnierID && x.Gruppe == gruppe
                         orderby x.Platz, x.Mannschaft
                         select x).ToList();
                }

                return(t);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new TTabellen[0].ToList());
            }
        }
        public static List <TSpiele> Spiele(int TurnierID, string gruppe)
        {
            try
            {
                List <TSpiele> t;

                using (fsbDB FSBDB = new fsbDB())
                {
                    t = (from x in FSBDB.TSpiele
                         where x.TurnierID == TurnierID && x.Gruppe == gruppe
                         orderby x.Spiel
                         select x).ToList();
                }

                return(t);
            }
            catch (Exception ex)
            {
                ClsError.CoreError(Name, MethodBase.GetCurrentMethod().ToString(), ex);
                return(new TSpiele[0].ToList());
            }
        }