private void AddPeriodButton_Click(object sender, EventArgs e) { BootPeriod period = new BootPeriod(); BootPeriodView periodView = new BootPeriodView(Schedule.BootPeriods.Count, period); periodView.OnPeriodDeleted += BootPeriodView_OnPeriodDeleted; periodView.OnPeriodSplitted += PeriodView_OnPeriodSplitted; periodView.Top = ROW_HEIGHT * Schedule.BootPeriods.Count; BootPeriodsListWrapper.Controls.Add(periodView); Schedule.BootPeriods.Add(period); }
public BootPeriodSplitForm(BootPeriod period) { InitializeComponent(); Period = period; Splitted = new List <BootPeriod>() { Period }; FromTime.Value = DateTime.Now.Date + Period.TimeStart; ToTime.Value = DateTime.Now.Date + Period.TimeEnd; }
private void SplitButton_Click(object sender, EventArgs e) { double periodTotal = (Period.TimeEnd - Period.TimeStart).TotalMilliseconds; if (periodTotal < 0) { periodTotal += 86400000; } int splittedCount = (int)CountSelector.Value; int splittedDuration = (int)DurationSelector.Value * 1000; int splittedTotal = splittedCount * splittedDuration; if (splittedTotal > periodTotal) { MessageBox.Show("Specified count and duration take more time than the period lasts", "Error"); return; } double interval = (periodTotal - splittedTotal) / ((double)CountSelector.Value - 1); Splitted.Clear(); for (int i = 0; i < splittedCount; ++i) { BootPeriod period = new BootPeriod(); int dStart = (int)(i * (splittedDuration + interval)); period.TimeStart = Period.TimeStart + new TimeSpan(0, 0, 0, 0, dStart); period.TimeEnd = Period.TimeStart + new TimeSpan(0, 0, 0, 0, dStart + splittedDuration); Splitted.Add(period); } IEnumerable <string> stringPeriods = Splitted.Select( date => $"{date.TimeStart.Hours}:{date.TimeStart.Minutes}:{date.TimeStart.Seconds}:{date.TimeStart.Milliseconds} - " + $"{date.TimeEnd.Hours}:{date.TimeEnd.Minutes}:{date.TimeEnd.Seconds}:{date.TimeEnd.Milliseconds}" ); DialogResult result = MessageBox.Show( string.Join(", ", stringPeriods), "Split result", MessageBoxButtons.YesNo ); if (result == DialogResult.Yes) { this.Close(); } }
public BootPeriodView(int nubmer, BootPeriod period) { Number = nubmer; Period = period; InitializeComponent(); FromTime.Value = DateTime.Now.Date + Period.TimeStart; ToTime.Value = DateTime.Now.Date + Period.TimeEnd; DeleteButton.Click += (sender, e) => OnPeriodDeleted?.Invoke( this, new NumberEventArgs(Number) ); SplitButton.Click += (sender, e) => OnPeriodSplitted?.Invoke( this, new NumberEventArgs(Number) ); }