public static void InsertDurchgang(Durchgang durchgang, Leg leg) { int finishBereich = 0; if (durchgang.IsFinishBereich()) { finishBereich = 1; } string query = "INSERT INTO durchgang (`id_durchgang`, `id_leg`, `durchgangNummer`, `anzahlWurfe`, `finishBereich`) VALUES ('" + durchgang.GetId() + "', '" + leg.GetId() + "', '" + durchgang.GetDurchgangNummer() + "', '" + durchgang.GetAnzahlWürfe() + "', '" + finishBereich + "')"; //open connection if (OpenConnection() == true) { try { //create command and assign the query and connection from the constructor MySqlCommand cmd = new MySqlCommand(query, connection); //Execute command cmd.ExecuteNonQuery(); } catch (Exception e) { Console.WriteLine("Durchgang: " + e.Message); Console.ReadLine(); } //close connection CloseConnection(); } }
public static void InsertWurf(Wurf w, Durchgang durchgang) { string query = "INSERT INTO wurf (`id_wurf`, `id_durchgang`, `wurfNummer`, `multiplikator`, `wert`, `multiZiel`, `wertZiel`) VALUES ('" + w.GetId() + "', '" + durchgang.GetId() + "', '" + w.GetWurfNummer() + "', '" + w.GetMulti() + "', '" + w.GetWert() + "', '" + w.GetMultiZiel() + "', '" + w.GetWertZiel() + "')"; //open connection if (OpenConnection() == true) { try { //create command and assign the query and connection from the constructor MySqlCommand cmd = new MySqlCommand(query, connection); //Execute command cmd.ExecuteNonQuery(); } catch (Exception e) { Console.WriteLine("Wurf:" + e.Message); Console.ReadLine(); } //close connection CloseConnection(); } else { Console.WriteLine("NO"); Console.ReadLine(); } }
/// <summary> /// speichert alle Würfe eines übergebenen Durchgangs in der DB /// </summary> /// <param name="d">Durchgang dessen Würfe gespeichert werden sollen</param> public static void SaveWürfeToDB(Durchgang d) { for (int y = 0; y < d.GetAnzahlWürfe(); y++) { DBConnect.InsertWurf(d.GetWürfe().ElementAt(y), d); } }
public static double Avg_Durchgang(Durchgang d) { if (d.GetAnzahlWürfe() == 0) { return(0); } return(d.GetDurchgangWert() / d.GetAnzahlWürfe()); }
/// <summary> /// holt alle Durchgänge des Legs mit der übergebenen id aus der Datenbank, erstellt die Objekte und fügt sie zu einer List hinzu, welche dann übergeben wird /// </summary> /// <param name="id">id des Legs aus welchem alle Durchgänge geholt werden sollen</param> /// <returns>List mit allen geholten Durchgängen</returns> public static List <Durchgang> GetDurchgängeOfLeg(int id) { List <Durchgang> durchgänge = new List <Durchgang>(); List <string>[] list = DBConnect.SelectDurchgangLegID(id); for (int y = 0; y < list[0].Count && y < list[2].Count && y < list[3].Count && y < list[4].Count; y++) { Durchgang d = new Durchgang(int.Parse(list[0].ElementAt(y)), int.Parse(list[2].ElementAt(y)), int.Parse(list[3].ElementAt(y)), int.Parse(list[4].ElementAt(y))); d.SetWürfe(GetWürfeOfDurchgang(d.GetId())); durchgänge.Add(d); } return(durchgänge); }
public static int[] GetTrefferquoteDurchgang(Durchgang d, int feldMulti, int wurfEigenschaft = 0) { int getroffen = 0; int versucht = 0; if (feldMulti == 0) { versucht = d.GetAnzahlWürfe(); } else { for (int i = 0; i < d.GetAnzahlWürfe(); i++) { switch (feldMulti) { case 1: if (d.GetWürfe()[i].GetMultiZiel() == 1) { versucht++; } break; case 2: if (d.GetWürfe()[i].GetMultiZiel() == 2) { versucht++; } break; case 3: if (d.GetWürfe()[i].GetMultiZiel() == 3) { versucht++; } break; default: throw new Exception(); } } } for (int i = 0; i < versucht; i++) { switch (feldMulti) { case 0: if (d.GetWürfe()[i].IsGetroffenExakt()) { getroffen++; } break; case 1: if (d.GetWürfe()[i].GetMultiZiel() == 1 && d.GetWürfe()[i].IsGetroffenExakt()) { getroffen++; } break; case 2: if (d.GetWürfe()[i].GetMultiZiel() == 2 && d.GetWürfe()[i].IsGetroffenExakt()) { getroffen++; } break; case 3: if (d.GetWürfe()[i].GetMultiZiel() == 3 && d.GetWürfe()[i].IsGetroffenExakt()) { getroffen++; } break; default: throw new Exception(); } } return(new int[] { getroffen, versucht }); }