Esempio n. 1
0
 public void GetUsersFromDB()
 {
     using (SQLConnectionManager manager = new SQLConnectionManager())
     {
         manager.Open();
         string           sql     = "select * from user";
         SQLiteCommand    command = new SQLiteCommand(sql, manager.DbConnection);
         SQLiteDataReader reader  = command.ExecuteReader();
         Users.Clear();
         while (reader.Read())
         {
             Users.Add(new User((string)reader["Name"], (string)reader["Rank"]));
         }
     }
 }
Esempio n. 2
0
 public void DeleteUserFromDB(User user)
 {
     using (SQLConnectionManager manager = new SQLConnectionManager())
     {
         manager.Open();
         string        sql          = "delete from user where Name='" + user.Name + "' and Rank = '" + user.Rank + "'";
         SQLiteCommand command      = new SQLiteCommand(sql, manager.DbConnection);
         int           rowsAffected = command.ExecuteNonQuery();
         if (rowsAffected == 0)
         {
             MessageBox.Show("Nu s-a putut efectua stergerea!");
         }
         else
         {
             MessageBox.Show("Utilizatorul a fost sters!");
         }
     }
 }
Esempio n. 3
0
 public void AddUserInDB(User user)
 {
     using (SQLConnectionManager manager = new SQLConnectionManager())
     {
         manager.Open();
         string        sql          = "insert into user (Name,Rank) values('" + user.Name + "','" + user.Rank + "');";
         SQLiteCommand command      = new SQLiteCommand(sql, manager.DbConnection);
         int           rowsAffected = command.ExecuteNonQuery();
         if (rowsAffected == 0)
         {
             MessageBox.Show("Nu s-a putut efectua adaugarea!");
         }
         else
         {
             MessageBox.Show("Utilizatorul a fost inserat!");
         }
     }
 }
Esempio n. 4
0
 public void UpdateUserInDB(User newUser, User oldUser)
 {
     using (SQLConnectionManager manager = new SQLConnectionManager())
     {
         manager.Open();
         string sql = "update User set Name = '" + newUser.Name + "', Rank = '" +
                      newUser.Rank + "' where Name='" + oldUser.Name + "' and Rank = '" + oldUser.Rank + "'";
         SQLiteCommand command      = new SQLiteCommand(sql, manager.DbConnection);
         int           rowsAffected = command.ExecuteNonQuery();
         if (rowsAffected == 0)
         {
             MessageBox.Show("Nu s-a putut efectua modificarea!");
         }
         else
         {
             MessageBox.Show("Utilizatorul a fost modificat!");
         }
     }
 }