Exemple #1
0
        public TBotUser GetUser(int id)
        {
            try
            {
                using (SQLiteConnection dbConn = new SQLiteConnection(string.Format("Data Source={0};Version=3;", myDB)))
                {
                    TBotUser user     = null;
                    var      userList = new List <TBotUser>();

                    string sqlCMD = @"select * from tblTBotUser WHERE ID = @ID;";

                    SQLiteCommand command = new SQLiteCommand(sqlCMD, dbConn);
                    dbConn.Open();

                    command.Parameters.Add(new SQLiteParameter("@ID")
                    {
                        Value = id
                    });
                    command.CommandType = System.Data.CommandType.Text;

                    SQLiteDataReader dr;
                    dr = command.ExecuteReader();

                    while (dr.Read())
                    {
                        user = new TBotUser();
                        user.SetID((long)dr["ID"]);
                        user.SetIsUsername((string)dr["Username"]);
                        user.SetIsAdmin(Convert.ToBoolean((int)dr["IsAdmin"]));
                    }
                    dbConn.Close();

                    return(user);
                }
            }
            catch (SQLiteException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
        public List <TBotUser> GetUserList()
        {
            try
            {
                using (SQLiteConnection dbConn = new SQLiteConnection(string.Format("Data Source={0};Version=3;", myDB)))
                {
                    var userList = new List <TBotUser>();

                    string        sqlCMD  = "select * from tblTBotUser;";
                    SQLiteCommand command = new SQLiteCommand(sqlCMD, dbConn);

                    dbConn.Open();

                    command = new SQLiteCommand(sqlCMD, dbConn);
                    command.ExecuteNonQueryAsync().Wait();
                    var dr = command.ExecuteReader();

                    while (dr.Read())
                    {
                        TBotUser user = new TBotUser();
                        user.SetID((long)dr["ID"]);
                        user.SetIsUsername((string)dr["Username"]);
                        user.SetIsAdmin(Convert.ToBoolean((int)dr["IsAdmin"]));
                        userList.Add(user);
                    }
                    dbConn.Close();

                    return(userList);
                }
            }
            catch (SQLiteException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }