Пример #1
0
        /// <summary>
        /// New GMForm
        /// </summary>
        /// <param name="game">GameForm reference</param>
        /// <param name="main">MainForm reference</param>
        public GMForm(GameForm game, MainMenuFrom main)
        {
            InitializeComponent();
            notes = new List <Note>();
            MessageIDText.Text = "0/0";
            gameForm           = game;
            mainMenu           = main;
            FormClosed        += delegate
            {
                gameForm.Close();
                main.Show();
            };

            NameForm nameForm = new NameForm();

            nameForm.ShowDialog();
            if (nameForm.DialogResult == DialogResult.OK)
            {
                SqlConnection connection = new SqlConnection(conString);
                connection.Open();

                SqlCommand command = new SqlCommand("INSERT INTO Games (Name) VALUES (@gameName); SELECT SCOPE_IDENTITY()", connection);
                command.Parameters.AddWithValue("@gameName", nameForm.NewName);

                gameID = Convert.ToInt32(command.ExecuteScalar());

                command.Dispose();
                connection.Close();
            }
            else
            {
                Show();
                Close();
            }
        }
Пример #2
0
        /// <summary>
        /// New GMForm
        /// </summary>
        /// <param name="game">GameForm reference</param>
        /// <param name="main">MainForm reference</param>
        /// <param name="GameID">GameId for excisting game</param>
        public GMForm(GameForm game, MainMenuFrom main, int GameID)
        {
            InitializeComponent();
            notes = new List <Note>();
            MessageIDText.Text = "0/0";
            gameForm           = game;
            mainMenu           = main;
            gameID             = GameID;
            FormClosed        += delegate
            {
                gameForm.Close();
                main.Show();
            };

            SqlConnection connection = new SqlConnection(conString);

            connection.Open();

            SqlCommand command = new SqlCommand("SELECT Path FROM Levels WHERE GameID = @gameId", connection);

            command.Parameters.AddWithValue("@gameId", gameID);

            using (SqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    try
                    {
                        Level lvl = FileHandler.LoadLevel(reader["Path"].ToString());
                        lvl.Name = (levelCombo.Items.Count + 1).ToString();
                        levelCombo.Items.Add(lvl);
                        levelCombo.DisplayMember = "Name";
                    }
                    catch { }
                }
            }

            command = new SqlCommand("SELECT Content FROM Notes WHERE GameID = @gameId", connection);
            command.Parameters.AddWithValue("@gameId", gameID);

            using (SqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    AddANote(reader["Content"].ToString());
                }
            }

            command.Dispose();
            connection.Close();
        }