public void WriteLogEndOfGame(Guid guidOfStartEntry) { using (SqlConnection cn = WorkWithSaves.DbConnectionFactory()) { SqlCommand command = new SqlCommand($"UPDATE [dbo].[Log] Set [End] = '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}' WHERE [dbo].[Log].[Id] = '{guidOfStartEntry}'", cn); command.ExecuteNonQuery(); } }
public Guid WriteLogStartOfGame() { Guid guidOfStartEntry = Guid.NewGuid(); using (SqlConnection cn = WorkWithSaves.DbConnectionFactory()) { SqlCommand command = new SqlCommand($"INSERT INTO [dbo].[Log] ([Id], [Start], [End]) " + $" VALUES ('{guidOfStartEntry}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}', '')", cn); command.ExecuteNonQuery(); } return(guidOfStartEntry); }
public void LoadGame(Guid idOfSave) { Cells.Clear(); SaveOfLiveGame save = WorkWithSaves.FetchSaveOfLiveGame(idOfSave); if (save.GameAreaSizeX != GameModelAreaSizeX || save.GameAreaSizeY != GameModelAreaSizeY || save.CellSize != CellSize) { throw new Exception("Не удается загрузить сохранение, т.к. у него другой размер поля"); } Cells = save.Cells; UseToroid = save.UseToroid; }
/// <summary> /// returns true is success /// </summary> /// <returns></returns> public bool LoadRandomSave() { List <Guid> resultIds = new List <Guid>(); Random rand = new Random(); using (SqlConnection cn = WorkWithSaves.DbConnectionFactory()) { var command = cn.CreateCommand(); command.CommandText = $@"Select [Saves].[Id] AS Id From [dbo].[Saves] As Saves Where [Saves].GameAreaSizeX = {GameModelAreaSizeX} AND [Saves].GameAreaSizeY = {GameModelAreaSizeY} AND [Saves].CellSize = {CellSize} ;" ; command.CommandType = CommandType.Text; command.Connection = cn; bool startOfReading = true; using (var dr = command.ExecuteReader()) { while (dr.Read()) { resultIds.Add((Guid)dr["Id"]); } } } if (resultIds.Count == 0) { MessageBox.Show("Нет ни одного сохранения для загрузки"); return(false); } else { LoadGame(resultIds[rand.Next(resultIds.Count)]); return(true); } }
public List <string> RetrieveAllLog() { List <string> result = new List <string>(); using (SqlConnection cn = WorkWithSaves.DbConnectionFactory()) { var command = cn.CreateCommand(); command.CommandText = $@"Select [Log].[Start] AS [Start], [Log].[End] AS [End] From [dbo].[Log] AS [Log] Order By [Start] DESC;" ; command.CommandType = CommandType.Text; command.Connection = cn; bool startOfReading = true; using (var dr = command.ExecuteReader()) { while (dr.Read()) { DateTime starTime = (DateTime)dr["Start"]; DateTime endTime = (DateTime)dr["End"]; if (endTime < DateTime.Parse("01/11/2000 00:00:00")) { result.Add($"Игра началась в {starTime}"); } else { result.Add($"Игра началась в {starTime} и закончилась в {endTime}"); } //var val1 = (string)dr["FieldName"]; } } } return(result); }
public void SaveGame(Guid idOfSave, string nameOfSave) { WorkWithSaves.SaveGame(idOfSave, nameOfSave, Cells, GameModelAreaSizeX, GameModelAreaSizeY, CellSize, UseToroid); }