/// <summary> /// Einen neuen Benutzer hinzufügen /// </summary> /// <param name="user">einzufügender Benutzer</param> /// <returns></returns> internal bool Insert(User user) { string com = $"INSERT INTO User_Base VALUES('{user.Nutzername}');"; bool result = StaticDB.RunSQL(com); if (result == false) { return(false); } com = $"INSERT INTO User_Info (Nutzername, ErstelltAm, Infotext, OnlyCustomName, CustomName) VALUES('{user.Nutzername}', '{user.ErstelltAm:yyyy-MM-dd HH:mm:ss}', '{user.InfoText}', '0', '{user.Nutzername}')"; result = StaticDB.RunSQL(com); if (result == false) { return(false); } com = $"INSERT INTO User_Password VALUES('{user.Nutzername}', '{user.Passwort}')"; result = StaticDB.RunSQL(com); if (result == false) { return(false); } result = UploadProfilBild(user, user.ProfilBild); if (result == false) { return(false); } return(true); }
/// <summary> /// Fügt eine Bewertung zu einem Trainingsplan in der Datenbank hinzu /// </summary> /// <param name="bewertung">Hinzuzufügende Bewertung (Typ BewertungTrainingsplan)</param> /// <param name="trainingsplan">Zur Bewertung zugehöriger Trainingsplan (Typ Trainingsplan)</param> /// <returns>Gibt bei erfolgreichem Ausführen true zurück und bei einem Fehler false</returns> public bool AddBewertung(Bewertung bewertung, Trainingsplan trainingsplan) { try { StaticDB.Connect(); string insertBew = $"INSERT INTO TP_Bewertung ([User], Bewertung) VALUES ('{bewertung.Bewerter.Nutzername}', '{bewertung.Rating}');" + "SELECT CAST(SCOPE_IDENTITY() AS INT)"; StaticDB.Connection.Open(); SqlCommand command = new SqlCommand(insertBew, StaticDB.Connection); int lastID = (int)command.ExecuteScalar(); StaticDB.Connection.Close(); string insertLink = $"INSERT INTO TP_Link_BaseBewertung (ID_TP_Base, ID_TP_Bewertung) VALUES ({trainingsplan.ID}, {lastID})"; StaticDB.RunSQL(insertLink); trainingsplan.Bewertungen.Add(bewertung); return(true); } catch (Exception ex) { _ = ex.Message; if (StaticDB.Connection != null) { if (StaticDB.Connection.State != ConnectionState.Closed) { StaticDB.Connection.Close(); } } return(false); } }
/// <summary> /// Plan aus Favoritenliste löschen /// </summary> /// <param name="classid">Bezeichner aus MenuItem.ClassID (Typ;Id)</param> /// <param name="user">Benutzer</param> /// <returns></returns> internal bool DeleteFavo(string classid, User user) { string[] keys = classid.Split(';'); string com = $"DELETE FROM User_Favo WHERE Nutzername = '{user.Nutzername}' AND Typ = '{keys[0]}' AND Plan_ID = '{keys[1]}'"; return(StaticDB.RunSQL(com)); }
/// <summary> /// Plan in Favoritenliste einfügen /// </summary> /// <param name="classid">Bezeichner aus MenuItem.ClassID (Typ;Id)</param> /// <param name="user">Benutzer</param> /// <returns></returns> internal bool AddFavo(string classid, User user) { string[] keys = classid.Split(';'); string com = $"INSERT INTO User_Favo (Nutzername, Typ, Plan_ID) VALUES('{user.Nutzername}', '{keys[0]}', '{keys[1]}')"; return(StaticDB.RunSQL(com)); }
/// <summary> /// Löscht einen Trainingsplan, inklusive der Bewertungen, aus der Datenbank. /// </summary> /// <param name="trainingsplan">Nimmt den zu löschenden Trainingsplan entgegen (Typ Trainingsplan)</param> /// <returns>Gibt bei erfolgreichem Ausführen true zurück und bei einem Fehler false</returns> public bool Delete(Trainingsplan trainingsplan) { try { foreach (var item in trainingsplan.Bewertungen) { string command = $"DELETE FROM TP_Bewertung WHERE ID={item.ID}"; StaticDB.RunSQL(command); } string com = $"DELETE FROM TP_Base WHERE ID={trainingsplan.ID}"; StaticDB.RunSQL(com); return(true); } catch (Exception ex) { _ = ex.Message; if (StaticDB.Connection != null) { if (StaticDB.Connection.State != ConnectionState.Closed) { StaticDB.Connection.Close(); } } return(false); } }
internal bool ChangePW(string nutzername, string hpw) { string com = $"UPDATE User_Password " + $"SET Password = '******' " + $"WHERE Nutzername = '{nutzername}';"; return(StaticDB.RunSQL(com)); }
/// <summary> /// Löschen des Benutzers /// </summary> /// <param name="user">Benutzer</param> /// <returns></returns> internal bool Delete(User user) { try { string com = $"DELETE FROM User_Info WHERE Nutzername = '{user.Nutzername}';" + $"DELETE FROM User_Bild WHERE Nutzername = '{user.Nutzername}';" + $"DELETE FROM User_Favo WHERE Nutzername = '{user.Nutzername}';" + $"DELETE FROM User_Password WHERE Nutzername = '{user.Nutzername}';" + $"DELETE FROM User_Follows WHERE User_ID = '{user.Nutzername}' OR Follow_ID = '{user.Nutzername}';" + $"DELETE FROM User_Base WHERE Nutzername = '{user.Nutzername}';"; bool result = StaticDB.RunSQL(com); if (result == false) { return(result); } List <News> news = AllVM.Datenbank.Feed.GetByUser(user); List <Trainingsplan> tlist = AllVM.Datenbank.Trainingsplan.GetList(user.Nutzername); List <Ernährungsplan> elist = AllVM.Datenbank.Ernährungsplan.GetList(user.Nutzername); foreach (var item in news) { AllVM.Datenbank.Feed.Delete(item); } foreach (var item in tlist) { item.Ersteller = new User() { Nutzername = "fitness_bot" }; item.GeAendertAm = DateTime.Now; AllVM.Datenbank.Trainingsplan.Edit(item); } foreach (var item in elist) { item.Ersteller = new User() { Nutzername = "fitness_bot" }; item.GeAendertAm = DateTime.Now; AllVM.Datenbank.Ernährungsplan.Edit(item); } return(true); } catch (Exception ex) { _ = ex.Message; return(false); } }
// in arbeit /// <summary> /// Ändert einen Trainingsplan in der Datenbank /// </summary> /// <param name="trainingsplan">Nimmt den bearbeiteten Trainingsplan entgegen (Typ Trainingsplan)</param> /// <returns>Gibt bei erfolgreichem Ausführen true zurück und bei einem Fehler false</returns> public bool Edit(Trainingsplan trainingsplan) { try { StaticDB.Connect(); string editTP_Base = $"UPDATE TP_Base SET Titel = '{trainingsplan.Titel}' WHERE ID={trainingsplan.ID}"; StaticDB.RunSQL(editTP_Base); string delLink = $"DELETE FROM TP_Link_BaseUebung WHERE ID_Base={trainingsplan.ID}"; StaticDB.RunSQL(delLink); foreach (var item in trainingsplan.UebungList) { string com = $"SELECT * FROM TP_Uebungen WHERE Name='{item.Name}' AND Gewicht='{item.Menge.ToString().Replace(",", ".")}' AND Repetition={item.Wiederholungen} AND Sets={item.Sätze}"; if (StaticDB.CheckExistenz(com) == true) { SqlCommand sqlCommand = new SqlCommand(com, StaticDB.Connection); StaticDB.Connection.Open(); int ID = (int)sqlCommand.ExecuteScalar(); StaticDB.Connection.Close(); com = $"INSERT INTO TP_Link_BaseUebung (ID_Base, ID_Uebung) VALUES('{trainingsplan.ID}', '{ID}')"; StaticDB.RunSQL(com); } else { com = $"INSERT INTO TP_Uebungen (Name, Gewicht, Repetition, Sets) VALUES ('{item.Name}', '{item.Menge.ToString().Replace(",", ".")}', '{item.Wiederholungen}', '{item.Sätze}'); " + "SELECT CAST(SCOPE_IDENTITY() AS INT)"; StaticDB.Connection.Open(); SqlCommand command = new SqlCommand(com, StaticDB.Connection); int ID = (int)command.ExecuteScalar(); StaticDB.Connection.Close(); com = $"INSERT INTO TP_Link_BaseUebung (ID_Base, ID_Uebung) VALUES('{trainingsplan.ID}', '{ID}')"; StaticDB.RunSQL(com); } } string editTP_Info = $"UPDATE TP_Info SET GeaendertAm='{DateTime.Now}' WHERE ID={trainingsplan.ID}"; StaticDB.RunSQL(editTP_Info); return(true); } catch (Exception ex) { _ = ex.Message; if (StaticDB.Connection != null) { if (StaticDB.Connection.State != ConnectionState.Closed) { StaticDB.Connection.Close(); } } return(false); } }
public bool Edit(Ernährungsplan ernährungsplan) { try { StaticDB.Connect(); string editEP_Base = $"UPDATE EP_Base SET Titel='{ernährungsplan.Titel}' WHERE ID={ernährungsplan.ID}"; StaticDB.RunSQL(editEP_Base); string delLink = $"DELETE FROM EP_Link_BaseMahlzeiten WHERE ID_Base={ernährungsplan.ID}"; StaticDB.RunSQL(delLink); foreach (var item in ernährungsplan.MahlzeitenList) { string com = $"SELECT * FROM EP_Mahlzeiten WHERE Nahrungsmittel='{item.Nahrungsmittel}' AND Menge='{item.Menge.ToString().Replace(",", ".")}' AND Einheit='{item.Einheit}'"; if (StaticDB.CheckExistenz(com) == true) { SqlCommand sqlCommand = new SqlCommand(com, StaticDB.Connection); StaticDB.Connection.Open(); int ID = (int)sqlCommand.ExecuteScalar(); StaticDB.Connection.Close(); com = $"INSERT INTO EP_Link_BaseMahlzeiten (ID_Base, ID_Mahlzeit) VALUES('{ernährungsplan.ID}', '{ID}')"; StaticDB.RunSQL(com); } else { com = $"INSERT INTO EP_Mahlzeiten (Nahrungsmittel, Menge, Einheit) VALUES ('{item.Nahrungsmittel}', '{item.Menge.ToString().Replace(",", ".")}', '{item.Einheit}');" + $"SELECT CAST(SCOPE_IDENTITY() AS INT)"; StaticDB.Connection.Open(); SqlCommand sqlCommand = new SqlCommand(com, StaticDB.Connection); int ID = (int)sqlCommand.ExecuteScalar(); StaticDB.Connection.Close(); com = $"INSERT INTO EP_Link_BaseMahlzeiten (ID_Base, ID_Mahlzeit) VALUES('{ernährungsplan.ID}', '{ID}')"; StaticDB.RunSQL(com); } } string editEP_Info = $"UPDATE EP_Info SET GeaendertAm='{DateTime.Now}' WHERE ID={ernährungsplan.ID}"; StaticDB.RunSQL(editEP_Info); return(true); } catch (Exception ex) { _ = ex.Message; if (StaticDB.Connection != null) { if (StaticDB.Connection.State != ConnectionState.Closed) { StaticDB.Connection.Close(); } } return(false); } }
/// <summary> /// Aktualisieren der neuen Werte für einen Benutzer /// </summary> /// <param name="user">zu aktualisierender Benutzer</param> /// <returns></returns> internal bool Update(User user) { string com = $"UPDATE User_Info SET " + $"GeaendertAm = '{DateTime.Now:yyyy-MM-dd HH:mm:ss}', " + $"Infotext = '{user.InfoText}'," + $"OnlyCustomName = '{StaticDB.ConvertBoolToByte(user.OnlyCustomName)}'," + $"CustomName = '{user.CustomName}' " + $"WHERE Nutzername = '{user.Nutzername}';"; bool result = StaticDB.RunSQL(com); if (result == false) { return(result); } try { com = $"UPDATE User_Bild SET " + $"Bild = @bild " + $"WHERE Nutzername = '{user.Nutzername}';"; StaticDB.Connect(); SqlCommand command = new SqlCommand(com, StaticDB.Connection); StaticDB.Connection.Open(); command.Parameters.Add("@bild", System.Data.SqlDbType.VarBinary).Value = user.ProfilBild; command.ExecuteNonQuery(); StaticDB.Connection.Close(); return(true); } catch (Exception ex) { _ = ex.Message; if (StaticDB.Connection != null) { if (StaticDB.Connection.State != System.Data.ConnectionState.Closed) { StaticDB.Connection.Close(); } } return(false); } }
/// <summary> /// Einfügen eines Status /// </summary> /// <param name="status">Der einzufügende Status</param> /// <returns></returns> public bool Insert(Status status) { string com = $"INSERT INTO Feed_Base VALUES('{status.Beschreibung}');"; bool result = StaticDB.RunSQL(com); if (result == false) { return(false); } int id = StaticDB.GetID($"SELECT ID FROM Feed_Base WHERE Beschreibung = '{status.Beschreibung}'"); com = $"INSERT INTO Feed_Info VALUES('{id}', '{status.ErstelltAm:yyyy-MM-dd HH:mm:ss}', '{status.ErstelltVon.Nutzername}')"; result = StaticDB.RunSQL(com); if (result == false) { return(false); } if (status.Foto != null) { com = $"INSERT INTO Feed_Fotos VALUES('{id}', @bild);"; StaticDB.Connect(); SqlCommand command = new SqlCommand(com, StaticDB.Connection); command.Parameters.Add("@bild", System.Data.SqlDbType.VarBinary).Value = status.Foto; StaticDB.Connection.Open(); int count = command.ExecuteNonQuery(); StaticDB.Connection.Close(); if (count > 0) { return(true); } else { return(false); } } return(true); }
/// <summary> /// Löscht eine Bewertung aus der Datenbank. /// </summary> /// <param name="bewertung">Zu löschende Bewertung (Typ BewertungTrainingsplan)</param> /// <returns>Gibt bei erfolgreichem Ausführen true zurück und bei einem Fehler false</returns> public bool DeleteBewertung(Bewertung bewertung) { try { string delBew = $"DELETE FROM TP_Bewertung WHERE ID={bewertung.ID}"; StaticDB.RunSQL(delBew); return(true); } catch (Exception ex) { _ = ex.Message; if (StaticDB.Connection != null) { if (StaticDB.Connection.State != ConnectionState.Closed) { StaticDB.Connection.Close(); } } return(false); } }
/// <summary> /// Einen Beitrag liken /// </summary> /// <param name="id">ID des Beitrages</param> /// <param name="user">Benutzer, der den Beitrag geliked hat</param> /// <returns></returns> public bool?Like(string id, User user) { bool isdone = false; string com = $"SELECT Feed_ID FROM Feed_Likes WHERE Feed_ID = '{id}' AND [User] = '{user.Nutzername}'"; int result = StaticDB.GetID(com); if (result == -1) { com = $"INSERT INTO Feed_Likes VALUES('{id}', '{user.Nutzername}')"; isdone = StaticDB.RunSQL(com); if (isdone == true) { return(true); } else { return(null); } } else if (result > 0) { com = $"DELETE FROM Feed_Likes WHERE Feed_ID = '{id}' AND [User] = '{user.Nutzername}'"; isdone = StaticDB.RunSQL(com); if (isdone == true) { return(false); } else { return(null); } } else { return(null); } }
/// <summary> /// Entfolgen /// </summary> /// <param name="profil">Benutzer, dem zu entfolgen ist</param> /// <param name="follower">Benutzer, der entfolgen möchte</param> /// <returns></returns> internal bool UnFollow(User profil, User follower) { string com = $"DELETE FROM User_Follows WHERE User_ID = '{profil.Nutzername}' AND Follow_ID = '{follower.Nutzername}'"; return(StaticDB.RunSQL(com)); }
/// <summary> /// Benutzer verfolgen /// </summary> /// <param name="profil">Benutzer, dem zu folgen ist</param> /// <param name="follower">Benutzer, der folgen möchte</param> /// <returns></returns> internal bool Follow(User profil, User follower) { string com = $"INSERT INTO User_Follows VALUES ('{profil.Nutzername}', '{follower.Nutzername}', '{DateTime.Now:yyyy-MM-dd HH:mm:ss}')"; return(StaticDB.RunSQL(com)); }
/// <summary> /// Löschen eines Feed-Beitrages /// </summary> /// <param name="news">Der zulöschende Beitrag</param> /// <returns></returns> internal bool Delete(News news) { string com = null; bool result = false; List <Like> listLikes = GetLikesWithNames(news.ID.ToString()); if (news.IsFoto) { com = $"DELETE FROM Feed_Fotos WHERE ID = '{news.ID}'"; result = StaticDB.RunSQL(com); if (!result) { return(false); } } com = $"DELETE FROM Feed_Likes WHERE Feed_ID = '{news.ID}'"; result = StaticDB.RunSQL(com); if (!result) { if (news.IsFoto) { com = $"INSERT INTO Feed_Fotos VALUES('{news.ID}', @bild);"; StaticDB.Connect(); SqlCommand command = new SqlCommand(com, StaticDB.Connection); command.Parameters.Add("@bild", System.Data.SqlDbType.VarBinary).Value = news.Foto; StaticDB.Connection.Open(); int count = command.ExecuteNonQuery(); StaticDB.Connection.Close(); } return(false); } com = $"DELETE FROM Feed_Info WHERE ID = '{news.ID}'"; result = StaticDB.RunSQL(com); if (!result) { foreach (var item in listLikes) { com = $"INSERT INTO Feed_Likes VALUES('{news.ID}', '{item.User.Nutzername}')"; StaticDB.RunSQL(com); } if (news.IsFoto) { com = $"INSERT INTO Feed_Fotos VALUES('{news.ID}', @bild);"; StaticDB.Connect(); SqlCommand command = new SqlCommand(com, StaticDB.Connection); command.Parameters.Add("@bild", System.Data.SqlDbType.VarBinary).Value = news.Foto; StaticDB.Connection.Open(); int count = command.ExecuteNonQuery(); StaticDB.Connection.Close(); } return(false); } com = $"DELETE FROM Feed_Base WHERE ID = '{news.ID}'"; result = StaticDB.RunSQL(com); if (!result) { com = $"INSERT INTO Feed_Info VALUES('{news.ID}', '{news.ErstelltAm:yyyy-MM-dd HH:mm:ss}', '{news.Ersteller.Nutzername}')"; result = StaticDB.RunSQL(com); if (news.IsFoto) { com = $"INSERT INTO Feed_Fotos VALUES('{news.ID}', @bild);"; StaticDB.Connect(); SqlCommand command = new SqlCommand(com, StaticDB.Connection); command.Parameters.Add("@bild", System.Data.SqlDbType.VarBinary).Value = news.Foto; StaticDB.Connection.Open(); int count = command.ExecuteNonQuery(); StaticDB.Connection.Close(); } return(false); } return(true); }
/// <summary> /// Fügt einen Trainingsplan zu der Datenbank hinzu. /// </summary> /// <param name="trainingsplan">Objekt vom Typ Trainingsplan</param> /// <returns>Gibt bei erfolgreichem Ausführen true zurück und bei einem Fehler false</returns> public bool AddTrainingsplan(Trainingsplan trainingsplan) { try { StaticDB.Connect(); string com = $"INSERT INTO TP_Base (Titel) values ('{trainingsplan.Titel}'); " + "SELECT CAST(SCOPE_IDENTITY() AS INT)"; SqlCommand command = new SqlCommand(com, StaticDB.Connection); StaticDB.Connection.Open(); int lastID = (int)command.ExecuteScalar(); StaticDB.Connection.Close(); if (trainingsplan.GeAendertAm != default) { com = $"INSERT INTO TP_Info (ID, ErstelltAm, ErstelltVon, GeaendertAm, Kategorie) VALUES ({lastID}, '{trainingsplan.ErstelltAm:yyyy-dd-MM HH:mm:ss}', '{trainingsplan.Ersteller.Nutzername}', '{trainingsplan.GeAendertAm:yyyy-dd-MM HH:mm:ss}', '{trainingsplan.Kategorie}');"; } else { com = $"INSERT INTO TP_Info (ID, ErstelltAm, ErstelltVon, Kategorie) VALUES ({lastID}, '{trainingsplan.ErstelltAm:yyyy-dd-MM HH:mm:ss}', '{trainingsplan.Ersteller.Nutzername}', '{trainingsplan.Kategorie}');"; } bool result = StaticDB.RunSQL(com); if (result == false) { com = $"DELETE FROM TP_Base WHERE ID = '{lastID}'"; StaticDB.RunSQL(com); return(false); } foreach (var uebung in trainingsplan.UebungList) { string checkEx = $"SELECT * FROM TP_Uebungen WHERE Name='{uebung.Name}' AND Gewicht={uebung.Menge.ToString().Replace(",", ".")} AND Repetition={uebung.Wiederholungen} AND Sets={uebung.Sätze}"; if (StaticDB.CheckExistenz(checkEx) == true) { int uebID = StaticDB.GetID(checkEx); string comTpLink = $"INSERT INTO TP_Link_BaseUebung (ID_Base, ID_Uebung) VALUES({lastID}, {uebID})"; StaticDB.RunSQL(comTpLink); } else { com = $"INSERT INTO TP_Uebungen (Name, Gewicht, Repetition, Sets, Einheit) VALUES ('{uebung.Name}', {uebung.Menge.ToString().Replace(",", ".")}, {uebung.Wiederholungen}, {uebung.Sätze}, '{uebung.Einheit}'); " + "SELECT CAST(SCOPE_IDENTITY() AS INT)"; SqlCommand insertUeb = new SqlCommand(com, StaticDB.Connection); StaticDB.Connection.Open(); int lastUebID = (int)insertUeb.ExecuteScalar(); StaticDB.Connection.Close(); string comTpLink = $"INSERT INTO TP_Link_BaseUebung (ID_Base, ID_Uebung) VALUES({lastID}, {lastUebID})"; StaticDB.RunSQL(comTpLink); } } StaticDB.Connection.Close(); return(true); } catch (Exception ex) { _ = ex.Message; if (StaticDB.Connection != null) { if (StaticDB.Connection.State != ConnectionState.Closed) { StaticDB.Connection.Close(); } } return(false); } }
public bool AddErnährungsplan(Ernährungsplan ernährungsplan) { try { StaticDB.Connect(); StaticDB.Connection.Open(); string com = $"INSERT INTO EP_Base (Titel) VALUES ('{ernährungsplan.Titel}'); SELECT CAST(SCOPE_IDENTITY() AS INT)"; SqlCommand sqlCommand = new SqlCommand(com, StaticDB.Connection); int ID = (int)sqlCommand.ExecuteScalar(); StaticDB.Connection.Close(); if (ernährungsplan.GeAendertAm != default) { com = $"INSERT INTO EP_Info (ID, ErstelltAm, ErstelltVon, GeaendertAm, Kategorie) VALUES ({ID}, '{ernährungsplan.ErstelltAm:yyyy-dd-MM HH:mm:ss}', '{ernährungsplan.Ersteller.Nutzername}', '{ernährungsplan.GeAendertAm:yyyy-dd-MM HH:mm:ss}', '{ernährungsplan.Kategorie}');"; } else { com = $"INSERT INTO EP_Info (ID, ErstelltAm, ErstelltVon, Kategorie) VALUES ({ID}, '{ernährungsplan.ErstelltAm:yyyy-dd-MM HH:mm:ss}', '{ernährungsplan.Ersteller.Nutzername}', '{ernährungsplan.Kategorie}');"; } bool result = StaticDB.RunSQL(com); if (result == false) { com = $"DELETE FROM EP_Base WHERE ID = '{ID}'"; StaticDB.RunSQL(com); return(false); } foreach (var mahlzeit in ernährungsplan.MahlzeitenList) { string checkEx = $"SELECT * FROM EP_Mahlzeiten WHERE Nahrungsmittel='{mahlzeit.Nahrungsmittel}' AND Menge={mahlzeit.Menge.ToString().Replace(",", ".")} AND Einheit='{mahlzeit.Einheit}'"; if (StaticDB.CheckExistenz(checkEx) == true) { int mahlID = StaticDB.GetID(checkEx); string comEpLink = $"INSERT INTO EP_Link_BaseMahlzeiten (ID_Base, ID_Mahlzeit) VALUES({ID}, {mahlID})"; StaticDB.RunSQL(comEpLink); } else { com = $"INSERT INTO EP_Mahlzeiten (Nahrungsmittel, Menge, Einheit) VALUES ('{mahlzeit.Nahrungsmittel}', {mahlzeit.Menge.ToString().Replace(",", ".")}, '{mahlzeit.Einheit}'); " + "SELECT CAST(SCOPE_IDENTITY() AS INT)"; SqlCommand insertMahl = new SqlCommand(com, StaticDB.Connection); StaticDB.Connection.Open(); int lastMahlID = (int)insertMahl.ExecuteScalar(); StaticDB.Connection.Close(); string comTpLink = $"INSERT INTO EP_Link_BaseMahlzeiten (ID_Base, ID_Mahlzeit) VALUES({ID}, {lastMahlID})"; StaticDB.RunSQL(comTpLink); } } StaticDB.Connection.Close(); return(true); } catch (Exception ex) { _ = ex.Message; if (StaticDB.Connection != null) { if (StaticDB.Connection.State != ConnectionState.Closed) { StaticDB.Connection.Close(); } } return(false); } }