Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Console/3.2/Recurrence.cs @ 3051

Last change on this file since 3051 was 3022, checked in by kgrading, 15 years ago

added the calendar in the dal and the server console. Works on every Resource (Group / Client) (#908)

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