Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Administration/3.4/Views/Recurrence.cs @ 6688

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

#1233 some renaming to be more consistent with OKB

File size: 3.4 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 enum RecurrenceMode {
29    Daily,
30    Weekly
31  }
32
33  public partial class Recurrence : Form {
34
35    public ScheduleView.OnDialogClosedDelegate dialogClosedDelegate;
36
37    public Recurrence() {
38      InitializeComponent();
39    }
40
41    private void btCancelRecurrence_Click(object sender, EventArgs e) {
42      this.Close();
43    }
44
45    private void btSaveRecurrence_Click(object sender, EventArgs e) {
46      DateTime dateFrom, dateTo;
47      RecurrenceMode mode = RecurrenceMode.Daily;
48      int incWeek = 0;
49      HashSet<DayOfWeek> days = new HashSet<DayOfWeek>();
50
51      days = GetDays();
52
53      //check if valid
54      if (InputIsValid()) {
55        //set entity
56
57        dateFrom = DateTime.Parse(dtpStart.Text + " " + dtpFromTime.Text);
58        dateTo = DateTime.Parse(dtpEnd.Text + " " + dtpToTime.Text);
59
60        if (int.TryParse(txtDays.Text, out incWeek))
61          mode = RecurrenceMode.Weekly;
62        else
63          mode = RecurrenceMode.Daily;
64
65        RecurrentEvent recurrentEvent = new RecurrentEvent() {
66          DateFrom = dateFrom,
67          DateTo = dateTo,
68          AllDay = chbade.Checked,
69          WeekDays = days,
70          IncWeeks = incWeek,
71        };
72
73        //fire delegate and close the dialog
74        dialogClosedDelegate(recurrentEvent);
75        this.Close();
76      } else
77        MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
78    }
79
80    private HashSet<DayOfWeek> GetDays() {
81      HashSet<DayOfWeek> days = new HashSet<DayOfWeek>();
82
83      if (cbMonday.Checked)
84        days.Add(DayOfWeek.Monday);
85      if (cbTuesday.Checked)
86        days.Add(DayOfWeek.Tuesday);
87      if (cbWednesday.Checked)
88        days.Add(DayOfWeek.Wednesday);
89      if (cbThursday.Checked)
90        days.Add(DayOfWeek.Thursday);
91      if (cbFriday.Checked)
92        days.Add(DayOfWeek.Friday);
93      if (cbSaturday.Checked)
94        days.Add(DayOfWeek.Saturday);
95      if (cbSunday.Checked)
96        days.Add(DayOfWeek.Sunday);
97
98      return days;
99    }
100
101    private bool InputIsValid() {
102      DateTime dateFrom, dateTo;
103      int i = 0;
104
105      dateFrom = DateTime.Parse(dtpStart.Text + " " + dtpFromTime.Text);
106      dateTo = DateTime.Parse(dtpEnd.Text + " " + dtpToTime.Text);
107
108      if (dateFrom < dateTo && dateFrom.TimeOfDay < dateTo.TimeOfDay && int.TryParse(txtDays.Text, out i))
109        return true;
110      else
111        return false;
112    }
113  }
114}
Note: See TracBrowser for help on using the repository browser.