public List <string> GetAnswersFromDB(int question) { Postgre conn = new Postgre(); string sql = "SELECT * FROM answers WHERE question=:question"; List <string> answers = new List <string>(); string answer = null; try { conn._cmd = new NpgsqlCommand(sql, conn._conn); conn._cmd.Parameters.AddWithValue("question", question); conn._dr = conn._cmd.ExecuteReader(); while (conn._dr.Read()) { answer = conn._dr["answer"] as string ?? ""; answers.Add(answer); } return(answers); } catch (Exception e) { Debug.Write(e); throw; } finally { conn.CloseConnection(); } }
public XmlDocument DbToXml(string username) { XmlDocument doc = new XmlDocument(); Postgre conn = new Postgre(); string sql = "SELECT * FROM examresult WHERE username=:username"; try { conn._cmd = new NpgsqlCommand(sql, conn._conn); conn._cmd.Parameters.AddWithValue("username", username); conn._dr = conn._cmd.ExecuteReader(); while (conn._dr.Read()) { doc.LoadXml(conn._dr["xml"].ToString()); } return(doc); } catch (NpgsqlException e) { Debug.Write(e); return(null); } finally { conn.CloseConnection(); } }
public string GetQuestionFromDB(int question_id) { Postgre conn = new Postgre(); string sql = "SELECT * FROM exam WHERE question_id=:question_id"; try { conn._cmd = new NpgsqlCommand(sql, conn._conn); conn._cmd.Parameters.AddWithValue("question_id", question_id); conn._dr = conn._cmd.ExecuteReader(); while (conn._dr.Read()) { question = conn._dr["question"] as string ?? ""; } return(question); } catch (NpgsqlException e) { Debug.Write(e); throw; } finally { conn.CloseConnection(); } }
public string GetCategory(int question_id) { Postgre conn = new Postgre(); string sql = "select * from exam where question_id = @question_id"; try { conn._cmd = new NpgsqlCommand(sql, conn._conn); conn._cmd.Parameters.AddWithValue("question_id", question_id); conn._dr = conn._cmd.ExecuteReader(); while (conn._dr.Read()) { category = conn._dr["category"] as string ?? ""; } return(category); } catch (Exception e) { Debug.Write(e); throw; } finally { conn.CloseConnection(); } }
public string GetCorrectAnswerTemp(int question) { Postgre conn = new Postgre(); string sql = "select * from answers a where a.question = @question and a.correct = true"; try { conn._cmd = new NpgsqlCommand(sql, conn._conn); conn._cmd.Parameters.AddWithValue("question", question); conn._dr = conn._cmd.ExecuteReader(); while (conn._dr.Read()) { answer = conn._dr["answer"] as string ?? ""; } return(answer); } catch (Exception e) { Debug.Write(e); throw; } finally { conn.CloseConnection(); } }
public bool GetLicenseApproved(string username) { Postgre conn = new Postgre(); string sql = "select * from person where username = @username"; bool approved = false; try { conn._cmd = new NpgsqlCommand(sql, conn._conn); conn._cmd.Parameters.AddWithValue("username", username); conn._dr = conn._cmd.ExecuteReader(); while (conn._dr.Read()) { approved = conn._dr["licensed"] as bool? ?? default(bool); } return(approved); } catch (Exception e) { Debug.Write(e); return(false); } finally { conn.CloseConnection(); } }
/// <summary> /// Method to get all question IDs. /// </summary> /// <returns>List of all Question IDs</returns> public List <int> GetQuestionIDs(int examType) { Postgre conn = new Postgre(); string sql = ""; if (examType == 1 || examType == null) { sql = "select question_id from exam order by random() limit 25"; } else if (examType == 2) { sql = "select question_id from exam order by random() limit 15"; } List <int> ids = new List <int>(); int id = 0; try { conn._cmd = new NpgsqlCommand(sql, conn._conn); conn._dr = conn._cmd.ExecuteReader(); while (conn._dr.Read()) { id = conn._dr["question_id"] as int? ?? default(int); ids.Add(id); } return(ids); } catch (Exception e) { Debug.Write(e); throw; } finally { conn.CloseConnection(); } }