Exemplo n.º 1
0
        private void SavePreferences_Click(object sender, EventArgs e)
        {
            try
            {
                bool            one      = false;
                bool            two      = false;
                bool            three    = false;
                bool            four     = false;
                NumericUpDown[] controls = new NumericUpDown[]
                {
                    numericUpDown1, numericUpDown2, numericUpDown3, numericUpDown4
                };

                for (int i = 0; i < controls.Length; i = i + 1)
                {
                    switch (controls[i].Value)
                    {
                    case 1:
                        one = true;
                        break;

                    case 2:
                        two = true;
                        break;

                    case 3:
                        three = true;
                        break;

                    case 4:
                        four = true;
                        break;
                    }
                }

                if (one && two && three && four)
                {
                    #region sunny case
                    string     orientation = "";
                    ConfigJson config      = new ConfigJson();
                    config.SetTheme(new Color[] { ColorTranslator.FromHtml(FormBorderTextBox.Text), ColorTranslator.FromHtml(MainButtonColorTextbox.Text), ColorTranslator.FromHtml(SubButtonColorTextBox.Text), ColorTranslator.FromHtml(BackgroundColorTextbox.Text) });
                    config.SetButtonOrder($"{numericUpDown1.Value},{numericUpDown2.Value},{numericUpDown3.Value},{numericUpDown4.Value}");
                    config.SetCurrentPath(MapsetPathTextBox.Text);
                    if (Horizontal.Checked == true)
                    {
                        orientation = "1";
                    }
                    else
                    {
                        orientation = "0";
                    }
                    config.SetOrientation(orientation);

                    string str = JsonConvert.SerializeObject(config);
                    File.WriteAllText(@"Preferences.json", str);
                    #endregion

                    MessageBox.Show("Settings saved. Please restart the program to have its effect.");
                }
                else
                {
                    throw new Exception("Please arrange the button order appropriately.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }