// Opdater Tournement public void updateTournement(Tournement tournement, string beforetournement) { string allEmployeesQuery = $"SELECT Id, PhoneNumber, JudgeLevel FROM Employees WHERE Name = '{tournement.Refname}'"; string allPlayersQuery = $"SELECT Id, PhoneNumber FROM Players WHERE Name = '{tournement.Playername}'"; // Eksikver query og gemmer i en variabel DataSet resultSet = Execute(allEmployeesQuery); DataSet playerResultSet = Execute(allPlayersQuery); // Får første table af data sættet og gemmer i en variabel DataTable employeeTable = resultSet.Tables[0]; DataTable playerTable = playerResultSet.Tables[0]; foreach (DataRow employeeRow in employeeTable.Rows) { int refId = (int)employeeRow["Id"]; int refPhonenumber = (int)employeeRow["PhoneNumber"]; int refLevel = (int)employeeRow["JudgeLevel"]; foreach (DataRow playerRow in playerTable.Rows) { int playerId = (int)playerRow["Id"]; int playerPhonenumber = (int)playerRow["PhoneNumber"]; string addupdateTournementQuery = $"UPDATE Tournements SET TournermentName = '{tournement.Tournermentname}', PlayerId = {playerId}, PlayersName = '{tournement.Playername}', PlayersPhoneNumber = {playerPhonenumber}, RefId = {refId}, RefName = '{tournement.Refname}', RefPhoneNumber = {refPhonenumber}, RefLevel = {refLevel} WHERE TournermentName = '{beforetournement}'"; try { Execute(addupdateTournementQuery); } catch (Exception e) { MessageBox.Show(e.ToString()); } } } }
// Getting Tournements information from database public List <Tournement> GetTournements() { List <Tournement> TournementsList = new List <Tournement>(); string allTournementsQuery = "SELECT * FROM Tournements"; // Eksikver query og gemmer i en variabel DataSet resultSet = Execute(allTournementsQuery); // Får første table af data sættet og gemmer i en variabel DataTable tournementTable = resultSet.Tables[0]; foreach (DataRow tournementRow in tournementTable.Rows) { string tournementname = (string)tournementRow["TournermentName"]; int playerid = (int)tournementRow["PlayerId"]; string playername = (string)tournementRow["PlayersName"]; int playerphonenumber = (int)tournementRow["PlayersPhoneNumber"]; int refif = (int)tournementRow["RefId"]; string refname = (string)tournementRow["RefName"]; int refphonenumber = (int)tournementRow["RefPhoneNumber"]; int reflevel = (int)tournementRow["RefLevel"]; Tournement tournement = new Tournement(tournementname, playerid, playername, playerphonenumber, refif, refname, refphonenumber, reflevel); TournementsList.Add(tournement); } return(TournementsList); }
// Making a mothod where there will be added a new tournement in the database table Tournements public void AddNewTournement(Tournement tournement) { string allEmployeesQuery = $"SELECT Id, PhoneNumber, JudgeLevel, JobType FROM Employees WHERE Name = '{tournement.Refname}'"; string allPlayersQuery = $"SELECT Id, PhoneNumber FROM Players WHERE Name = '{tournement.Playername}'"; // Eksikver query og gemmer i en variabel DataSet resultSet = Execute(allEmployeesQuery); DataSet playerResultSet = Execute(allPlayersQuery); // Får første table af data sættet og gemmer i en variabel DataTable employeeTable = resultSet.Tables[0]; DataTable playerTable = playerResultSet.Tables[0]; foreach (DataRow employeeRow in employeeTable.Rows) { int refId = (int)employeeRow["Id"]; int refPhonenumber = (int)employeeRow["PhoneNumber"]; int refLevel = (int)employeeRow["JudgeLevel"]; string jobtype = (string)employeeRow["JobType"]; foreach (DataRow playerRow in playerTable.Rows) { int playerId = (int)playerRow["Id"]; int playerPhonenumber = (int)playerRow["PhoneNumber"]; string addNewTournementQuery = $"INSERT INTO Tournements (TournermentName, PlayerId, PlayersName, PlayersPhoneNumber, RefId, RefName, RefPhoneNumber, RefLevel) VALUES ('{tournement.Tournermentname}', {playerId}, '{tournement.Playername}', {playerPhonenumber}, {refId}, '{tournement.Refname}', {refPhonenumber}, {refLevel})"; try { if (jobtype == "Ref" || jobtype == "Judge") { Execute(addNewTournementQuery); } else { MessageBox.Show("Denne Ansat er ikke en dommer."); } } catch (Exception e) { MessageBox.Show(e.ToString()); } } } }