public void RefreshGameLB() { genreShowNum = GenreCB.SelectedIndex; GameLB.Items.Clear(); Cheats.Clear(); using (GCDBContext _dbc = new GCDBContext(ConString)) { IQueryable <Cheat> req; if (genreShowNum == 0) { req = from VAR in _dbc.Cheats select VAR; } else { req = from VAR in _dbc.Cheats where VAR.Genre == genreShowNum select VAR; } foreach (var cheat in req) { Cheats.Add(cheat); } foreach (var cheat in Cheats) { GameLB.Items.Add(cheat.GameName); } if (GameLB.Items.Count > 0) { GameLB.SelectedIndex = 0; } } }
public void AddToDB(GCDBContext _dbc) { using (_dbc = new GCDBContext(ConString)) { _dbc.Cheats.Add(CurCheat); _dbc.SaveChanges(); } }
public void DBSave() { using (GCDBContext dbc = new GCDBContext(CfgData2.ConStr)) { Cheat cheat = new Cheat() { FileName = @"c:\test" }; dbc.Cheats.Add(cheat); dbc.SaveChanges(); } }
public void BackupDB() { string BackupCmd = @"BACKUP DATABASE [{0}] TO DISK = N'{1}' WITH NOFORMAT, NOINIT, NAME = N'MyGCDB backup!', SKIP, NOREWIND, NOUNLOAD, STATS = 10"; using (GCDBContext dbc = new GCDBContext(ConString)) { string dbName = dbc.Database.Connection.Database; dbc.Database.ExecuteSqlCommand(System.Data.Entity.TransactionalBehavior.DoNotEnsureTransaction, String.Format(BackupCmd, dbName, Path.Combine(dirInfo.FullName, "GCDBBackup"))); } }
public void RemoveGame() { /*var rreq = from game in Cheats * where game.GameName == SelectGameName * select game;*/ using (GCDBContext _dbc = new GCDBContext(ConString)) { var RR = _dbc.Cheats.FirstOrDefault(c => c.GameName == SelectGameName); if (RR != null) { _dbc.Cheats.Remove(RR); _dbc.SaveChanges(); RefreshGameLB(); } } }
private void UpdateContent() { Type gType = typeof(GenrEnum); int im = 0; GameLB.Items.Clear(); GenreCB.Items.Clear(); foreach (var g in gType.GetFields()) { _genresStr.Add(g.Name); GenreCB.Items.Add(g.Name); im++; } GenreCB.Items[0] = "Все"; if (GenreCB.Items.Count > 1) { GenreCB.SelectedIndex = 0; } _genresNum = new int[im]; for (int i = 0; i < im; i++) { _genresNum[i] = i; } using (GCDBContext _dbc = new GCDBContext(ConString)) { dbSL1.Text = _dbc.Database.Connection.Database;//SELECT DB_NAME() AS [Current Database]; var GCheatsLoad = from c in _dbc.Cheats //where c.Id>2 select c; /*foreach (var cheat in GCheatsLoad) * { * GameLB.Items.Add(cheat.GameName); * }*/ RefreshGameLB(); } }
public void ClearDB(GCDBContext _dbc) { using (_dbc = new GCDBContext(ConString)) { var all = _dbc.Cheats;//.Where(c => c.Id > -1); if (all.Any()) { /* using (SqlConnection s1=new SqlConnection(ConString)) * { * * using (SqlCommand cmd = new SqlCommand()) * { * * cmd.Connection = s1; * cmd.CommandType = CommandType.Text; * cmd.CommandText = "DELETE FROM Cheats"; * * } * * * }*/ _dbc.Database.ExecuteSqlCommand("DELETE FROM Cheats"); /*foreach (var cheat in all) * { * _dbc.Cheats.Remove(cheat); * }*/ _dbc.Database.ExecuteSqlCommand("DBCC CHECKIDENT('Cheats', RESEED, -1)"); _dbc.SaveChanges(); MessageBox.Show("Game cheat база очищена"); } else { MessageBox.Show("Game cheat база пустая"); } } }
public void EditGame() { if (CCFName.Length != 0) { using (GCDBContext _dbc = new GCDBContext(ConString)) { var EGR = _dbc.Cheats.FirstOrDefault(c => c.GameName == SelectGameName); if (EGR != null) { EGR.GameName = GameNameTB.Text; CurCheat.FileName = CCFName; EGR.FileName = CurCheat.FileName; EGR.Genre = GenreCB.SelectedIndex; } _dbc.SaveChanges(); RefreshGameLB(); } } else { MessageBox.Show("Необходимо привязать cheat file"); return; } }
public void ClearDB(GCDBContext _dbc) { using (_dbc=new GCDBContext(ConString)) { var all = _dbc.Cheats;//.Where(c => c.Id > -1); if (all.Any()) { /* using (SqlConnection s1=new SqlConnection(ConString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = s1; cmd.CommandType = CommandType.Text; cmd.CommandText = "DELETE FROM Cheats"; } }*/ _dbc.Database.ExecuteSqlCommand("DELETE FROM Cheats"); /*foreach (var cheat in all) { _dbc.Cheats.Remove(cheat); }*/ _dbc.Database.ExecuteSqlCommand("DBCC CHECKIDENT('Cheats', RESEED, -1)"); _dbc.SaveChanges(); MessageBox.Show("Game cheat база очищена"); } else { MessageBox.Show("Game cheat база пустая"); } } }
public void DBSave() { using (GCDBContext dbc=new GCDBContext(CfgData2.ConStr)) { Cheat cheat = new Cheat() { FileName = @"c:\test" }; dbc.Cheats.Add(cheat); dbc.SaveChanges(); } }
public void DBLoad() { using (GCDBContext dbc = new GCDBContext(ConString)) { } }
public void RefreshGameLB() { genreShowNum = GenreCB.SelectedIndex; GameLB.Items.Clear(); Cheats.Clear(); using (GCDBContext _dbc = new GCDBContext(ConString)) { IQueryable<Cheat> req; if (genreShowNum == 0) { req = from VAR in _dbc.Cheats select VAR; } else { req = from VAR in _dbc.Cheats where VAR.Genre == genreShowNum select VAR; } foreach (var cheat in req) { Cheats.Add(cheat); } foreach (var cheat in Cheats) { GameLB.Items.Add(cheat.GameName); } if (GameLB.Items.Count>0) GameLB.SelectedIndex = 0; } }
public void RemoveGame() { /*var rreq = from game in Cheats where game.GameName == SelectGameName select game;*/ using (GCDBContext _dbc = new GCDBContext(ConString)) { var RR = _dbc.Cheats.FirstOrDefault(c => c.GameName == SelectGameName); if (RR != null) { _dbc.Cheats.Remove(RR); _dbc.SaveChanges(); RefreshGameLB(); } } }
public void DBLoad() { using (GCDBContext dbc=new GCDBContext(ConString)) { } }
public void BackupDB() { string BackupCmd = @"BACKUP DATABASE [{0}] TO DISK = N'{1}' WITH NOFORMAT, NOINIT, NAME = N'MyGCDB backup!', SKIP, NOREWIND, NOUNLOAD, STATS = 10"; using (GCDBContext dbc=new GCDBContext(ConString)) { string dbName = dbc.Database.Connection.Database; dbc.Database.ExecuteSqlCommand(System.Data.Entity.TransactionalBehavior.DoNotEnsureTransaction, String.Format(BackupCmd, dbName, Path.Combine(dirInfo.FullName,"GCDBBackup"))); } }
public void AddToDB(GCDBContext _dbc) { using (_dbc=new GCDBContext(ConString)) { _dbc.Cheats.Add(CurCheat); _dbc.SaveChanges(); } }
private void UpdateContent() { Type gType = typeof (GenrEnum); int im = 0; GameLB.Items.Clear(); GenreCB.Items.Clear(); foreach (var g in gType.GetFields()) { _genresStr.Add(g.Name); GenreCB.Items.Add(g.Name); im++; } GenreCB.Items[0] = "Все"; if (GenreCB.Items.Count>1) GenreCB.SelectedIndex = 0; _genresNum=new int[im]; for (int i = 0; i < im; i++) { _genresNum[i] = i; } using (GCDBContext _dbc =new GCDBContext(ConString)) { dbSL1.Text = _dbc.Database.Connection.Database;//SELECT DB_NAME() AS [Current Database]; var GCheatsLoad = from c in _dbc.Cheats //where c.Id>2 select c; /*foreach (var cheat in GCheatsLoad) { GameLB.Items.Add(cheat.GameName); }*/ RefreshGameLB(); } }