private void fMain_FormClosing(object sender, FormClosingEventArgs e) { // check if there were changes in the machine list if (_machinesChanged) { // show a dialog box if (MessageBox.Show("You made changes in the machine list. Do you want to save these changes?", "Please confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { // write the file MachineParameters.WriteMachineParametersToFile(_machines, _machinesConfigFile); } catch (Exception ex) { // something went wrong MessageBox.Show("Error writing " + _machinesConfigFile + ". Error message is: " + ex.Message, "Error", MessageBoxButtons.OK); } } } // save defaults Properties.Settings.Default.SelectedMachineIndex = cbMachines.SelectedIndex; Properties.Settings.Default.WheelDiameter = double.Parse(txtWheelDiameter.Text); Properties.Settings.Default.JigProjectionLength = double.Parse(txtJigProjectionLength.Text); Properties.Settings.Default.TargetAngle = double.Parse(txtTargetAngle.Text); Properties.Settings.Default.Save(); }
private void miSaveMachineList_Click(object sender, EventArgs e) { // execute the save file dialog if (sfd.ShowDialog() == DialogResult.OK) { try { // save the database MachineParameters.WriteMachineParametersToFile(_machines, sfd.FileName); } catch (Exception ex) { // display a hint MessageBox.Show("Error saving machine database: " + ex.Message, "Error writing file!"); } } }
private void fMain_Load(object sender, EventArgs e) { // the filename for our settings file _machinesConfigFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "cmbTea\\MachineParameters.machinedb"); // try to load it _machines = MachineParameters.ReadMachineParametersFromFile(_machinesConfigFile); // if it fails, build the default list if (_machines == null) { _machines = MachineParameters.BuildDefaultMachineList(); // and save it try { // write the file MachineParameters.WriteMachineParametersToFile(_machines, _machinesConfigFile); } catch (Exception ex) { // something went wrong MessageBox.Show("Error writing " + _machinesConfigFile + ". Error message is: " + ex.Message, "Error", MessageBoxButtons.OK); } } // create a custom machine MachineParameters custom = new MachineParameters("Custom", 50, 29, 12); // add it to the list _machines.Add(custom); // add the machines to the combo box foreach (MachineParameters machine in _machines) { cbMachines.Items.Add(machine.Name); } // load defaults cbMachines.SelectedIndex = Properties.Settings.Default.SelectedMachineIndex; txtWheelDiameter.Text = Properties.Settings.Default.WheelDiameter.ToString("0.0"); txtJigProjectionLength.Text = Properties.Settings.Default.JigProjectionLength.ToString("0.0"); txtTargetAngle.Text = Properties.Settings.Default.TargetAngle.ToString("0.0"); // calculate it Calculate(); }