// Addiert die Erfolgszähler aller Register, um den Gesamterfolg zu ermitteln und gibt int-Wert zurück public int countRegistersSuccess(CardBox cardBox) { List <Register> registers = connection.loadRegistersInCardboxFromDB(cardBox.cardBoxId); foreach (var Register in registers) { cardBoxSuccessCounter = cardBoxSuccessCounter + (10 / 5); } cardBoxSuccessCounter = cardBoxSuccessCounter / registers.Count; return(cardBoxSuccessCounter); }
//=================================================Cardboxes================================================== public List <CardBox> loadCardBoxesInUserFromDB(int userID) { MySqlConnection connection = getConnection("root", ""); string commandstring = "SELECT cardbox_ID, cardbox_name " + "FROM `cardbox` " + "WHERE user_ID = " + userID + ";"; if (connection.State.ToString() == "Open") { MySqlCommand command = new MySqlCommand(commandstring, connection); try { MySqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { List <CardBox> cardBoxes = new List <CardBox>(); while (reader.Read()) { CardBox cardBox = new CardBox(reader.GetInt32(0), reader.GetString(1)); cardBoxes.Add(cardBox); } connection.Close(); return(cardBoxes); } else { return(null); } } catch (Exception ex) { throw ex; } connection.Close(); } return(null); }
public void updateCardboxInDB(CardBox cardBox, string cardBoxName) { MySqlConnection connection = getConnection("root", ""); //Erstellen einer CardBox mit veränderten Werten, aber gleicher ID CardBox clone = new CardBox(cardBox.CardBoxId, cardBoxName); string commandstring = "UPDATE `cardbox` SET `cardbox_name` = '" + clone.CardBoxName + "' " + "WHERE `cardbox`.`cardbox_ID` = " + cardBox.CardBoxId + ";"; MySqlCommand command = new MySqlCommand(commandstring, connection); try { command.ExecuteNonQuery(); } catch (Exception) { throw; } connection.Close(); }
// Neues Register wird hinzugefügt (Soll es eine maximale Anzahl geben?) public void addRegister(CardBox cardBox, string name) { connection.saveRegisterInDB(cardBox.cardBoxId, name); }
// Der Name einer Card Box wird geändert public void changeName(CardBox cardBox, string newName) { connection.updateCardboxInDB(cardBox, newName); }