Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Clients.Hive.Administrator/3.3/Views/Recurrence.cs @ 9363

Last change on this file since 9363 was 9363, checked in by spimming, 11 years ago

#1888:

  • Merged revisions from trunk
File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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          DowntimeType = appointmentTypeView.DowntimeType
57        };
58
59        //fire delegate and close the dialog
60        dialogClosedDelegate(recurrentEvent);
61        this.Close();
62      } else {
63        MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
64      }
65    }
66
67    private HashSet<DayOfWeek> GetDays() {
68      HashSet<DayOfWeek> days = new HashSet<DayOfWeek>();
69
70      if (cbMonday.Checked)
71        days.Add(DayOfWeek.Monday);
72      if (cbTuesday.Checked)
73        days.Add(DayOfWeek.Tuesday);
74      if (cbWednesday.Checked)
75        days.Add(DayOfWeek.Wednesday);
76      if (cbThursday.Checked)
77        days.Add(DayOfWeek.Thursday);
78      if (cbFriday.Checked)
79        days.Add(DayOfWeek.Friday);
80      if (cbSaturday.Checked)
81        days.Add(DayOfWeek.Saturday);
82      if (cbSunday.Checked)
83        days.Add(DayOfWeek.Sunday);
84
85      return days;
86    }
87
88    private bool InputIsValid() {
89      DateTime dateFrom, dateTo;
90
91      dateFrom = DateTime.Parse(dtpStart.Text + " " + dtpFromTime.Text);
92      dateTo = DateTime.Parse(dtpEnd.Text + " " + dtpToTime.Text);
93
94      if (chbade.Checked && dateFrom < dateTo) {
95        return true;
96      }
97
98      if (!chbade.Checked && dateFrom < dateTo && dateFrom.TimeOfDay < dateTo.TimeOfDay) {
99        return true;
100      }
101
102      return false;
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.