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> 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. 2
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. 3
0
        private void cbPreset_SelectedIndexChanged(object sender, EventArgs e)
        {
            PresetDBHelper.ConnectToDatabase();

            string preset = "";

            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 pnCheckBoxes.Controls.OfType <CheckBox>())
            {
                cb.Checked = false;
            }

            Dictionary <int, CheckBox> NumberedCheckBoxNames = LookUpCheckBoxes();

            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;
                    }
                }
            }
        }
Esempio n. 4
0
 private void RefreshPresetComboBox()
 {
     cbPreset.Items.Clear();
     PresetDBHelper.ConnectToDatabase();
     PresetDBHelper.PrintPresetsComboBox(cbPreset);
 }