public void Read() { string sql = "SELECT groupid, group_name FROM Groups"; SQLiteDataReader reader; string result = ExecuteQuery(sql, null, out reader); this._alGroups.Clear(); if (result == string.Empty) { while (reader.Read()) { GroupDetails gd = new GroupDetails(); gd.GroupID = int.Parse(reader["groupid"].ToString()); gd.GroupName = reader["group_name"].ToString(); this._alGroups.Add(gd); } } else { CloseConnection(); System.Diagnostics.Debug.WriteLine(result); throw new Exception(result); } CloseConnection(); }
public void GetGroupsWithServerCount() { string sql = "select * from viewGroupsWithServerCount"; SQLiteDataReader reader; string result = ExecuteQuery(sql, null, out reader); if (result == string.Empty) { this._alGroups.Clear(); while (reader.Read()) { GroupDetails gd = new GroupDetails(); gd.GroupID = int.Parse(reader["groupid"].ToString()); gd.GroupName = reader["group_name"].ToString(); gd.ServerCount = int.Parse(reader["ServerCount"].ToString()); this._alGroups.Add(gd); } } else { CloseConnection(); throw new Exception(result); } CloseConnection(); }
private void Update(GroupDetails group_details) { string sql = "UPDATE Groups SET groupid = @gid, group_name = @gname WHERE groupid = @gid"; SQLiteParameter[] parameters = { new SQLiteParameter("@gid", group_details.GroupID), new SQLiteParameter("@gname", group_details.GroupName) }; string result = ExecuteNonQuery(sql, parameters); if (result == string.Empty) { } else { CloseConnection(); System.Diagnostics.Debug.WriteLine(result); if (result.Contains("Abort due to constraint violation")) { throw new DatabaseException(DatabaseException.ExceptionTypes.DUPLICATE_ENTRY); } else { throw new Exception(result); } } CloseConnection(); }
private void Save(GroupDetails group_details) { string sql = "INSERT INTO Groups(groupid, group_name) VALUES((select count(Groups.groupid) from groups) + 1, @gname);"; SQLiteParameter[] parameters = { new SQLiteParameter("@gname", group_details.GroupName) }; string result = ExecuteNonQuery(sql, parameters); if (result == string.Empty) { } else { CloseConnection(); System.Diagnostics.Debug.WriteLine(result); if (result.Contains("Abort due to constraint violation")) { throw new DatabaseException(DatabaseException.ExceptionTypes.DUPLICATE_ENTRY); } else { throw new Exception(result); } } CloseConnection(); }
public void Save(bool isNew, GroupDetails group_details) { if (isNew) { Save(group_details); } else { Update(group_details); } }