private void Init() { try { if (ScorePropertyInfoItem == null) { return; } CurrentApp = ScorePropertyInfoItem.CurrentApp; ScorePropertyInfoItem.Editor = this; mScoreObject = ScorePropertyInfoItem.ScoreObject; ScoreProperty scoreProperty = ScorePropertyInfoItem.ScoreProperty; mScoreProperty = scoreProperty; if (scoreProperty != null) { ConvertFormat = scoreProperty.DataType; } if (mScoreObject != null && scoreProperty != null) { var objValue = scoreProperty.GetPropertyValue(mScoreObject); if (objValue != null) { Value = objValue.ToString(); if (objValue is Color) { ColorValue = (Color)objValue; } if (objValue is Boolean) { BoolValue = (bool)objValue; } } } InitSelectValueItems(); ShowValue(); } catch (Exception ex) { ShowException(ex.Message); } }
public int ScoreHandler(string user, ScoreProperty property) { int score = 0; string sqlElo; string sqlRatio = ""; try { if (property == ScoreProperty.Load) { sqlElo = "SELECT score FROM \"user\" WHERE username=@u LIMIT 1"; } else if (property == ScoreProperty.Lose) { sqlElo = "UPDATE \"user\" SET score=score-5 WHERE username=@u"; sqlRatio = "UPDATE \"user\" SET lose=lose+1 WHERE username=@u"; } else if (property == ScoreProperty.Tie) { // sqlElo = "UPDATE \"user\" SET score=score WHERE username=@u"; return(1); } else if (property == ScoreProperty.Win) { sqlElo = "UPDATE \"user\" SET score=score+3 WHERE username=@u"; sqlRatio = "UPDATE \"user\" SET wins=wins+1 WHERE username=@u"; } else { return(-1); } _conn.Open(); NpgsqlCommand cmd = new NpgsqlCommand(sqlElo, _conn); cmd.Parameters.AddWithValue("u", user); cmd.Prepare(); if (property == ScoreProperty.Load) { NpgsqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { score = Int32.Parse(reader[0].ToString() !); } } else { cmd.ExecuteNonQuery(); cmd = new NpgsqlCommand(sqlRatio, _conn); cmd.Parameters.AddWithValue("u", user); cmd.Prepare(); cmd.ExecuteNonQuery(); } } catch (Exception e) { Console.WriteLine(e); throw; } _conn.Close(); return(score); }
set => SetValue(ScoreProperty, value);