public void UpdateVerse(Verse verse) { connection.Open(); SqlCommand command = connection.CreateCommand(); command.CommandText = String.Format("UPDATE Verses SET BestTime = {0} WHERE (Id={1})", verse.GetBestTime(), verse.GetId()); command.ExecuteNonQuery(); connection.Close(); }
public Verse GetVerseById(int id) { connection.Open(); SqlCommand command = connection.CreateCommand(); command.CommandText = String.Format("SELECT * FROM Verses WHERE (Id = {0})", id); SqlDataReader reader = command.ExecuteReader(); Verse result = null; if (reader.Read()) { result = new Verse(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), (float)reader.GetDouble(3)); } connection.Close(); return(result); }
protected void Page_Load(object sender, EventArgs e) { user = (User)Session["userObj"]; if (user == null) { Response.Redirect("Main.aspx"); return; } dbUtil = new DBUtil(); verse = dbUtil.GetRandomVerse(); GenVerseText(); GenClearArray(); GenRawArray(); Session["verseId"] = verse.GetId(); }
protected void Page_Load(object sender, EventArgs e) { user = (User)Session["userObj"]; if (user == null) { Response.Redirect("Main.aspx"); return; } dbUtil = new DBUtil(); string state = Request.Form["state"]; if (state == "failure") { msg = "אופס....."; speech = "הדרך לגאולה עוד ארוכה....."; user.SetFailCount(user.GetFailCount() + 1); dbUtil.UpdateUser(user); return; } else { msg = "ישתבח שמו לעד!"; speech = "המשך כך!"; } double delta = double.Parse(Request.Form["delta"]); myTimeStr = "הזמן שלך: " + delta.ToString() + " שניות"; int verseId = int.Parse(Session["verseId"].ToString()); Session["verseId"] = null; Verse verse = dbUtil.GetVerseById(verseId); double bestTime = verse.GetBestTime(); bestTimeStr = "זמן שיא: " + (float)((int)(bestTime * 1000)) / 1000 + " שניות"; double ratio = delta / bestTime; if (delta < bestTime) { verse.SetBestTime((float)delta); dbUtil.UpdateVerse(verse); } int prize = CalculatePrize(ratio); prizeStr = "זכית ב-" + prize.ToString() + " סוכריות טופי!"; user.SetTofiCount(user.GetTofiCount() + prize); int rank = dbUtil.GetRankFromTofiCount(user.GetTofiCount()); user.SetRank(rank); user.SetSolveCount(user.GetSolveCount() + 1); dbUtil.UpdateUser(user); }