示例#1
0
        private void SettingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //TODO: Fix the way to pass parameters.
            using (var formSettings = new FormSettings(TimeBatteryCheck, AuxTimeBatteryCheck, PcIdle.MaxIdleTime, Battery.LowBatteryLvl, Battery.HighBatteryLvl, Voice, NotifyWind, NotifyVoice, Battery.AlertStatus))
            {
                //Recall for check if there is an installed voice.
                Voice.GetVoices();
                // SHOW Form
                formSettings.ShowDialog();
                // Check if the user make any change.
                if (!formSettings.HasChanges)
                {
                    return;
                }
                #region Notification
                //Stop timers.
                // Save the Status of the Timer.
                //var isTmCheckPowerEnabled = TmCheckPower.Enabled;
                AlertChecked(false);
                TmCheckPower.Stop();
                TmWaitForResp.Stop();
                //
                Battery.ChangeAlertStatus(new[] { formSettings.ChBoxLowBat, formSettings.ChBoxHighBat });
                Battery.ChangePrevAlert(Any);
                Battery.ResetAlert();
                //Get formSettings values.
                NotifyWind          = formSettings.NotifyWind;
                NotifyVoice         = formSettings.NotifyVoice;
                TimeBatteryCheck    = formSettings.TimeBatChk;
                AuxTimeBatteryCheck = formSettings.AuxTimeBatChk;
                Battery.ChangeLowBatteryLvl(formSettings.LowBattery);
                Battery.ChangeHighBatteryLvl(formSettings.HighBattery);
                PcIdle.ChangeMaxIdleTime(formSettings.IdleTime);

                //Save in properties
                Settings.Default.BatteryHigh    = Battery.HighBatteryLvl;
                Settings.Default.BatteryLow     = Battery.LowBatteryLvl;
                Settings.Default.PcIdleTime     = PcIdle.MaxIdleTime;
                Settings.Default.TimeBattChk    = TimeBatteryCheck;
                Settings.Default.TimeAuxBattChk = AuxTimeBatteryCheck;
                Settings.Default.NotifyWind     = NotifyWind;
                Settings.Default.NotifyVoice    = NotifyVoice;
                Settings.Default.AlertStatus    = string.Join(",", Battery.AlertStatus);
                //Changes timer intervals.
                TmCheckPower.Interval    = (int)TimeBatteryCheck * 1000;
                AuxAlertTime             = (int)(AuxTimeBatteryCheck * 60);
                ProgBarNextAlert.Maximum = AuxAlertTime;
                //Restart timers.
                //TmCheckPower.Enabled = isTmCheckPowerEnabled;
                TmCheckPower.Start();
                #endregion
                #region Voz
                try
                {
                    Settings.Default.VoiceName = formSettings.CurrentVoice;
                    Settings.Default.VolNot    = formSettings.NotifyVolume;
                    Voice.ChangeCurrentVoice(formSettings.CurrentVoice);
                    Voice.ChangeNotVolume(formSettings.NotifyVolume);
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message, @"Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                #endregion
                Voice?.ChangePcName(formSettings.PcName);
                Settings.Default.PcName = formSettings.PcName;
                Settings.Default.Save();
            }
        }