Esempio n. 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {  // gather all user selected keys and look up in dictionary to get the int value
           // add int to list to make a user list saved as a string
           // put string and name of string into preset object and save to db

            try
            {
                List <int> saveUsersSelectedKeys = new List <int>();

                foreach (CheckBox cb in gbKeyBoard.Controls.OfType <CheckBox>())
                {
                    if (cb.CheckState == CheckState.Checked)
                    {
                        foreach (KeyValuePair <int, CheckBox> keyString in numberedCheckBoxNames)
                        {
                            // look up checkbox name in Dictionary and add number to list
                            if (cb == keyString.Value)
                            {
                                saveUsersSelectedKeys.Add(keyString.Key);
                            }
                        }
                    }
                    else if (cb.CheckState == CheckState.Indeterminate)
                    {
                        foreach (KeyValuePair <int, CheckBox> keyString in numberedCheckBoxNamesStateIndeterminate)
                        {  // look up tristate indeterminate checkbox name in Dictionary and add number to list
                            if (cb == keyString.Value)
                            {
                                saveUsersSelectedKeys.Add(keyString.Key);
                            }
                        }
                    }
                }

                string myPresetList = "";
                string name         = cbPreset.Text;

                foreach (int keyNum in saveUsersSelectedKeys)
                {
                    myPresetList += keyNum.ToString() + " ";
                }

                if (string.IsNullOrEmpty(name) || (string.IsNullOrEmpty(myPresetList)))
                {
                    throw new ApplicationException();  // to ensure that blank presets are not saved
                }

                Preset newPreset = new Preset(name, myPresetList);

                PresetDBHelper.connectToDatabase();
                PresetDBHelper.InsertPreset(newPreset);
                refreshPresetComboBox();
                MessageBox.Show("New Preset Created ");
            }
            catch (Exception exception)
            {
                MessageBox.Show("Saving preset requires a name and keys selected ");
            }
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {   // gather all user selected keys and look up in dictionary to get the int value
            // add int to list to make a user list saved as a string
            // put string and name of string into preset object and save to db

            try
            {
                List <int> usersSelectedKeys = new List <int>();

                foreach (CheckBox cb in pnCheckBoxes.Controls.OfType <CheckBox>())
                {
                    if (cb.Checked == true)
                    {
                        string cbParse = cb.Name;
                        cbParse = cbParse.Remove(0, 2);
                        int cbNumber = Convert.ToInt16(cbParse);
                        usersSelectedKeys.Add(cbNumber);
                    }
                }

                string myPresetList = "";
                string name         = cbPreset.Text;

                foreach (int keyNum in usersSelectedKeys)
                {
                    myPresetList += keyNum.ToString() + " ";
                }

                if (string.IsNullOrEmpty(name) || (string.IsNullOrEmpty(myPresetList)))
                {
                    throw new ApplicationException();  // to ensure that blank presets are not saved
                }

                Preset newPreset = new Preset(name, myPresetList);

                PresetDBHelper.ConnectToDatabase();
                PresetDBHelper.InsertPreset(newPreset);
                RefreshPresetComboBox();
                MessageBox.Show("New Preset Created ");
            }
            catch (Exception exception)
            {
                MessageBox.Show("Saving preset requires a name and keys selected ");
            }
        }
Esempio n. 3
0
 private void LoadPresetComboBox()
 {
     if (File.Exists("NoterizePresets.sqlite"))
     {
         PresetDBHelper.ConnectToDatabase();
         PresetDBHelper.PrintPresetsComboBox(cbPreset);
         cbPreset.Text = "Default";
     }
     else
     {
         PresetDBHelper.CreateNewDatabase();
         PresetDBHelper.ConnectToDatabase();
         PresetDBHelper.CreateTable();
         PresetDBHelper.InsertDefault();
         PresetDBHelper.PrintPresetsComboBox(cbPreset);
         cbPreset.Text = "Default";
     }
 }
Esempio n. 4
0
 private void loadPresetComboBox()
 {
     if (File.Exists("DvorakPresets.sqlite"))
     {
         PresetDBHelper.connectToDatabase();
         PresetDBHelper.printPresetsComboBox(cbPreset);
         cbPreset.Text = "Default";
     }
     else
     {
         PresetDBHelper.createNewDatabase();
         PresetDBHelper.connectToDatabase();
         PresetDBHelper.createTable();
         PresetDBHelper.InsertDefault();
         PresetDBHelper.printPresetsComboBox(cbPreset);
         cbPreset.Text = "Default";
     }
 }
Esempio n. 5
0
        private void cbPreset_SelectedIndexChanged(object sender, EventArgs e)
        {
            string preset = "";

            PresetDBHelper.connectToDatabase();
            preset = PresetDBHelper.getPresetList(cbPreset.Text);

            preset = preset.TrimEnd();
            string[] presetStrings = preset.Split();

            List <int> presetInts = new List <int>();

            foreach (string str in presetStrings)
            {
                presetInts.Add(Convert.ToInt32(str));
            }

            foreach (CheckBox cb in gbKeyBoard.Controls.OfType <CheckBox>())
            {
                cb.Checked = false;
            }

            foreach (int cbInt in presetInts)
            {
                foreach (KeyValuePair <int, CheckBox> keyString in numberedCheckBoxNames)
                {
                    // look up checkbox name in Dictionary and add number to list
                    if (cbInt == keyString.Key)
                    {
                        keyString.Value.Checked = true;
                    }
                }
                foreach (KeyValuePair <int, CheckBox> keyString in numberedCheckBoxNamesStateIndeterminate)
                {
                    // look up checkbox name in Dictionary and add number to list
                    if ((cbInt > 72) && (cbInt == keyString.Key))
                    {
                        keyString.Value.CheckState = CheckState.Indeterminate;
                    }
                }
            }
        }
Esempio n. 6
0
 private void RefreshPresetComboBox()
 {
     cbPreset.Items.Clear();
     PresetDBHelper.ConnectToDatabase();
     PresetDBHelper.PrintPresetsComboBox(cbPreset);
 }