Пример #1
0
 internal void Save() // сохранение изминений
 {
     if (MessageBox.Show("Сохранить изминения?", "Подтверждение", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
     {
         return;
     }
     else
     {
         if (Games.ToList().Exists(i => i.Id == Curent_game.Id))
         {
             using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["DB_Game"].ConnectionString))
             {
                 db.Open();
                 using (var transaction = db.BeginTransaction())
                 {
                     try
                     {
                         db.Execute("UPDATE [Game] SET Game_Name = @Game_Name," + "Game_Studio_id = @Game_Studio_id," +
                                    "Game_Style_id = @Game_Style_id," + "Game_Year_Releas = @Game_Year_Releas," +
                                    "Game_Mod_id = @Game_Mod_id," + "Game_Count_Sell = @Game_Count_Sell " +
                                    "WHERE Id = @Id",
                                    new
                         {
                             Id               = Curent_game.Id,
                             Game_Name        = Curent_game.Game_Name,
                             Game_Studio_id   = Curent_game.Studio.Id,
                             Game_Style_id    = Curent_game.Style.Id,
                             Game_Year_Releas = Curent_game.Game_Year_Releas,
                             Game_Mod_id      = Curent_game.Mod_Game.Id,
                             Game_Count_Sell  = Curent_game.Game_Count_Sell
                         }, transaction);
                         transaction.Commit();
                     }
                     catch (System.Exception ex)
                     {
                         transaction.Rollback();
                         throw ex;
                     }
                 }
                 Games = new ObservableCollection <Game>(db.Query <Game>("SELECT * FROM [Game]").ToList());
                 Games.ToList().ForEach(i => i.Studio   = Studios.ToList().Find(j => j.Id == i.Game_Studio_id));
                 Games.ToList().ForEach(i => i.Style    = Styles.ToList().Find(j => j.Id == i.Game_Style_id));
                 Games.ToList().ForEach(i => i.Mod_Game = Mod_s.ToList().Find(j => j.Id == i.Game_Mod_id));
                 OnPropertyChanged("Games");
             }
         }
         else
         {
             MessageBox.Show("Что-то пошло нет так", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }
Пример #2
0
 internal void Dell()
 {
     if (MessageBox.Show("Удалить игру?", "Подтверждение", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
     {
         return;
     }
     else
     {
         if (Games.ToList().Exists(i => i.Id == Curent_game.Id))
         {
             using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["DB_Game"].ConnectionString))
             {
                 db.Open();
                 using (var transaction = db.BeginTransaction())
                 {
                     try
                     {
                         db.Execute(" DELETE FROM [Game] WHERE Id = @Id",
                                    new { Id = Curent_game.Id }, transaction);
                         transaction.Commit();
                     }
                     catch (System.Exception ex)
                     {
                         transaction.Rollback();
                         throw ex;
                     }
                 }
             }
         }
         else
         {
             MessageBox.Show("Что-то пошло нет так", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["DB_Game"].ConnectionString))
     {
         Games = new ObservableCollection <Game>(db.Query <Game>("SELECT * FROM [Game]").ToList());
         Games.ToList().ForEach(i => i.Studio   = Studios.ToList().Find(j => j.Id == i.Game_Studio_id));
         Games.ToList().ForEach(i => i.Style    = Styles.ToList().Find(j => j.Id == i.Game_Style_id));
         Games.ToList().ForEach(i => i.Mod_Game = Mod_s.ToList().Find(j => j.Id == i.Game_Mod_id));
         OnPropertyChanged("Games");
     }
 }