void GetStatusDone (IAsyncResult iar) { try { status = d.EndGetStatus (iar); war = null; if (status == null) state = State.GetStatusError; else state = State.Done; } catch (Exception e) { state = State.NetworkError; Console.WriteLine ("Error getting status: " + e); } if (tn != null) tn.WakeupMain (); }
public Status GetStatus (string login, string password) { IDbConnection conn = GetConnection (); conn.Open (); try { IDbCommand cmd = conn.CreateCommand(); cmd.CommandText = "select * from person where name=@name and password=@pass"; cmd.Parameters.Add( CreateParameter("@name",login)); cmd.Parameters.Add( CreateParameter("@pass",password)); IDataReader reader = cmd.ExecuteReader (); int id = -1; if (reader.Read()) id = (int)reader["person_id"]; reader.Close (); if (id == -1) return null; Status s = new Status (); cmd.CommandText = String.Format ("select count(*) from status where person_id='{0}'", id); s.Contributions = (int) cmd.ExecuteScalar (); cmd.CommandText = String.Format ("select count(*) from status where person_id='{0}' and status='0'", id); s.Pending = (int) cmd.ExecuteScalar (); cmd.CommandText = String.Format ("select count(*) from status where person_id='{0}' and status='1'", id); s.Commited = (int) cmd.ExecuteScalar (); return s; } finally { conn.Close (); } }