// loads settings and sets the values on the mainwindow
        public void LoadSettings(MainWindow window)
        {
            sql = "select * from settings";
            dbConnection.Open();
            command = new SQLiteCommand(sql, dbConnection);
            reader  = command.ExecuteReader();

            while (reader.Read())
            {
                window.DifficultyMode = reader.GetInt32(0);
                window.MineCount      = reader.GetInt32(1);
                window.RowCount       = reader.GetInt32(2);
                window.ColumnCount    = reader.GetInt32(3);
                window.Width          = reader.GetInt32(4);
                window.Height         = reader.GetInt32(5);
                if (reader.GetInt32(6) == 1)
                {
                    window.WindowState = System.Windows.WindowState.Maximized;
                }
                window.gridColor = reader.GetString(7);
                window.SetFlag(reader.GetString(7));
                window.backColor = reader.GetString(8);
            }
            dbConnection.Close();

            // create an options window just to get the colors for the mainwindow (lazy method)
            OptionsWindow ow = new OptionsWindow();

            window.Background = ow.GetColor(window.backColor);
            window.GridColor  = ow.GetColor(window.gridColor);
            ow.Close();
        }
Exemple #2
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (rbCustom.IsChecked == true)
            {
                // make sure all required fields have valid values
                if (txtHeight.Text == "" || txtHeight.Text == "0" || txtWidth.Text == "" || txtWidth.Text == "0" || txtMines.Text == "" || txtMines.Text == "0" ||
                    Convert.ToInt32(txtWidth.Text) < 3 || Convert.ToInt32(txtWidth.Text) < Convert.ToInt32(txtHeight.Text) || Convert.ToDouble(txtHeight.Text) < Convert.ToDouble(txtWidth.Text) / 1.875)
                {
                    return;
                }
                else
                {
                    main.ChangeOptions(Difficulty, GetGridColor(), GetBackgroundColor(), Convert.ToInt32(txtHeight.Text), Convert.ToInt32(txtWidth.Text), Convert.ToInt32(txtMines.Text));
                }
            }
            else
            {
                main.ChangeOptions(Difficulty, GetGridColor(), GetBackgroundColor());
            }

            main.SetFlag(comboGridColor.Text.ToLower());
            this.Close();
        }