Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Administrator/3.3/Views/Recurrence.cs @ 6943

Last change on this file since 6943 was 6943, checked in by ascheibe, 12 years ago

#1233 fixed a small bug in the Job Manager and the Administrator UI

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Windows.Forms;
25
26namespace HeuristicLab.Clients.Hive.Administrator.Views {
27
28  public partial class Recurrence : Form {
29
30    public ScheduleView.OnDialogClosedDelegate dialogClosedDelegate;
31
32    public Recurrence() {
33      InitializeComponent();
34    }
35
36    private void btCancelRecurrence_Click(object sender, EventArgs e) {
37      this.Close();
38    }
39
40    private void btSaveRecurrence_Click(object sender, EventArgs e) {
41      DateTime dateFrom, dateTo;
42      HashSet<DayOfWeek> days = new HashSet<DayOfWeek>();
43
44      days = GetDays();
45
46      //check if valid
47      if (InputIsValid()) {
48        dateFrom = DateTime.Parse(dtpStart.Text + " " + dtpFromTime.Text);
49        dateTo = DateTime.Parse(dtpEnd.Text + " " + dtpToTime.Text);
50
51        RecurrentEvent recurrentEvent = new RecurrentEvent() {
52          DateFrom = dateFrom,
53          DateTo = dateTo,
54          AllDay = chbade.Checked,
55          WeekDays = days
56        };
57
58        //fire delegate and close the dialog
59        dialogClosedDelegate(recurrentEvent);
60        this.Close();
61      } else {
62        MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
63      }
64    }
65
66    private HashSet<DayOfWeek> GetDays() {
67      HashSet<DayOfWeek> days = new HashSet<DayOfWeek>();
68
69      if (cbMonday.Checked)
70        days.Add(DayOfWeek.Monday);
71      if (cbTuesday.Checked)
72        days.Add(DayOfWeek.Tuesday);
73      if (cbWednesday.Checked)
74        days.Add(DayOfWeek.Wednesday);
75      if (cbThursday.Checked)
76        days.Add(DayOfWeek.Thursday);
77      if (cbFriday.Checked)
78        days.Add(DayOfWeek.Friday);
79      if (cbSaturday.Checked)
80        days.Add(DayOfWeek.Saturday);
81      if (cbSunday.Checked)
82        days.Add(DayOfWeek.Sunday);
83
84      return days;
85    }
86
87    private bool InputIsValid() {
88      DateTime dateFrom, dateTo;
89
90      dateFrom = DateTime.Parse(dtpStart.Text + " " + dtpFromTime.Text);
91      dateTo = DateTime.Parse(dtpEnd.Text + " " + dtpToTime.Text);
92
93      if (chbade.Checked && dateFrom < dateTo) {
94        return true;
95      }
96
97      if (!chbade.Checked && dateFrom < dateTo && dateFrom.TimeOfDay < dateTo.TimeOfDay) {
98        return true;
99      }
100
101      return false;
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.