示例#1
0
 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();
     }
 }
示例#2
0
        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);
        }
示例#3
0
        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;
        }
示例#4
0
        /// <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);
            }
        }
示例#5
0
        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);
        }
示例#6
0
 public void SaveGame(Guid idOfSave, string nameOfSave)
 {
     WorkWithSaves.SaveGame(idOfSave, nameOfSave, Cells, GameModelAreaSizeX, GameModelAreaSizeY, CellSize, UseToroid);
 }