/// <summary> /// Handles the click of the delete button to delete the current profile /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteProfileButton_Click(object sender, EventArgs e) { if (this.profileCombobox.SelectedItem is ProfileModel pm) { if (pm.GUID == "DEFAULT") { MessageBox.Show("You cannot delete the default profile."); return; } else { ProfileModel deleteModel = null; foreach (var profile in VoltageDisplayForm.SavedData.Profiles) { if (profile.GUID == pm.GUID) { deleteModel = profile; break; } } if (deleteModel != null) { VoltageDisplayForm.SavedData.Profiles.Remove(deleteModel); SavedDataModel.Write(VoltageDisplayForm.SavedData); SetupProfileList(); this.profileCombobox.SelectedIndex = 0; } } } }
/// <summary> /// Handles the click of the save button to save the current settings /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveProfileButton_Click(object sender, EventArgs e) { if (this.profileCombobox.SelectedItem is ProfileModel pm) { if (pm.GUID != "Default") { pm.ProfileName = this.profileNameTextbox.Text.Trim(); // Ensure a unique name foreach (var existingProfile in VoltageDisplayForm.SavedData.Profiles) { if (pm.ProfileName == existingProfile.ProfileName && pm.GUID != existingProfile.GUID) { pm.ProfileName += " (Copy)"; this.profileNameTextbox.Text = pm.ProfileName; break; } } if (!this.minValueTextbox.Text.Contains(".")) { this.minValueTextbox.Text += ".00"; } if (!this.maxValueTextbox.Text.Contains(".")) { this.maxValueTextbox.Text += ".00"; } float.TryParse(this.minValueTextbox.Text, out float minValue); float.TryParse(this.maxValueTextbox.Text, out float maxValue); this.minValueTextbox.Text = minValue.ToString("F2"); this.maxValueTextbox.Text = maxValue.ToString("F2"); pm.MinValue = minValue; pm.MaxValue = maxValue; if (pm.GUID == "New") { // we're adding a new item pm.GUID = Guid.NewGuid().ToString(); VoltageDisplayForm.SavedData.Profiles.Add(pm); } else { // we're updating an existing item foreach (var profile in VoltageDisplayForm.SavedData.Profiles) { if (profile.GUID == pm.GUID) { pm = profile; // overwrite all properties break; } } } } SavedDataModel.Write(VoltageDisplayForm.SavedData); SetupProfileList(); this.SelectByGUID(pm.GUID); } }