Example #1
0
        /// <summary>
        /// Display values stored in settings in controls.  Updates split grid.
        /// </summary>
        private void SystemSettings_LoadFields()
        {
            SplitsV2 settings = ZAMsettings.Settings.SplitsV2;

            ckbShowSplits.Checked = settings.ShowSplits;

            tbSplitDistance.Text = settings.SplitDistance.ToString();

            if (cbSplitUom.Items.Contains(settings.SplitDistanceUom))
            {
                cbSplitUom.SelectedItem = settings.SplitDistanceUom;
            }

            lblGoalDistanceUom.Text = settings.SplitDistanceUom.Value;

            ckbCalculateGoal.Checked = settings.CalculateGoal;

            dtpGoalTime.Value = new DateTime(2021, 1, 1, settings.GoalTime.Hours, settings.GoalTime.Minutes, settings.GoalTime.Seconds);

            tbGoalDistance.Text = settings.GoalDistance.ToString();

            lblGoalSpeed.Text      = $"Goal Speed {lblGoalDistanceUom.Text}/h:";
            lblGoalSpeedValue.Text = $"{settings.GoalSpeed}";

            ckbCustomized.Checked = settings.Customized;

            this.LoadSplitChart();
        }
Example #2
0
        private void SaveSplits()
        {
            DataTable table = (DataTable)dgvSplits.DataSource;

            SplitsV2 splits = ZAMsettings.Settings.SplitsV2;

            splits.Splits.Clear();

            foreach (DataRow row in ((DataTable)dgvSplits.DataSource).Rows)
            {
                if (this.IsNullorDBNull(row.Field <object>(SplitDistanceCol)) > 0 || this.IsNullorDBNull(row.Field <object>(SplitTimeCol)) > 0)
                {
                    continue;
                }

                ZAMsettings.Settings.SplitsV2.Splits.Add(new SplitV2(
                                                             row.Field <double>(SplitDistanceCol),
                                                             row.Field <TimeSpan>(SplitTimeCol),
                                                             row.Field <double>(SplitSpeedCol),
                                                             row.Field <double>(TotalDistanceCol),
                                                             row.Field <TimeSpan>(TotalTimeCol),
                                                             row.Field <double>(AverageSpeedCol),
                                                             splits.SplitDistanceUom.Key
                                                             ));
            }

            splits.Customized = true;

            // the last split row has the totals
            int lastSplitRow = splits.Splits.Count - 1;

            if (lastSplitRow >= 0)
            {
                SplitV2 lastSplit = splits.Splits[lastSplitRow];

                // Setting of these values to invalid numbers can throw an exception

                splits.GoalDistance = lastSplit.TotalDistance;
                splits.GoalTime     = lastSplit.TotalTime;
                splits.GoalSpeed    = lastSplit.AverageSpeed;
            }
            else
            {
                throw new FormatException("No goals entered.");
            }
        }