Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6696 was 6696, checked in by ascheibe, 13 years ago

#1233

  • some cleanups
  • removed unused code
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      {   
49          dateFrom = DateTime.Parse(dtpStart.Text + " " + dtpFromTime.Text);
50          dateTo = DateTime.Parse(dtpEnd.Text + " " + dtpToTime.Text);
51
52          RecurrentEvent recurrentEvent = new RecurrentEvent()
53          {
54              DateFrom = dateFrom,
55              DateTo = dateTo,
56              AllDay = chbade.Checked,
57              WeekDays = days             
58          };
59
60          //fire delegate and close the dialog
61          dialogClosedDelegate(recurrentEvent);
62          this.Close();
63      }
64      else
65      {
66          MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
67      }
68    }
69
70    private HashSet<DayOfWeek> GetDays() {
71      HashSet<DayOfWeek> days = new HashSet<DayOfWeek>();
72
73      if (cbMonday.Checked)
74        days.Add(DayOfWeek.Monday);
75      if (cbTuesday.Checked)
76        days.Add(DayOfWeek.Tuesday);
77      if (cbWednesday.Checked)
78        days.Add(DayOfWeek.Wednesday);
79      if (cbThursday.Checked)
80        days.Add(DayOfWeek.Thursday);
81      if (cbFriday.Checked)
82        days.Add(DayOfWeek.Friday);
83      if (cbSaturday.Checked)
84        days.Add(DayOfWeek.Saturday);
85      if (cbSunday.Checked)
86        days.Add(DayOfWeek.Sunday);
87
88      return days;
89    }
90
91    private bool InputIsValid() {
92      DateTime dateFrom, dateTo;     
93
94      dateFrom = DateTime.Parse(dtpStart.Text + " " + dtpFromTime.Text);
95      dateTo = DateTime.Parse(dtpEnd.Text + " " + dtpToTime.Text);
96
97      if (dateFrom < dateTo && dateFrom.TimeOfDay < dateTo.TimeOfDay)
98        return true;
99      else
100        return false;
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.