Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Client.Console/3.2/Recurrence.cs @ 2508

Last change on this file since 2508 was 2062, checked in by whackl, 15 years ago

refactoring hive client console #663

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