Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone2/sources/HeuristicLab.Hive.Client.Console/3.2/Recurrence.cs @ 2273

Last change on this file since 2273 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

File size: 2.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Windows.Forms;
4
5namespace HeuristicLab.Hive.Client.Console
6{
7
8  public enum RecurrenceMode
9  {
10    Daily,
11    Weekly
12  }
13
14  public partial class Recurrence : Form
15  {
16
17    public OnDialogClosedDelegate dialogClosedDelegate;
18
19    public Recurrence()
20    {
21      InitializeComponent();
22    }
23
24    private void btCancelRecurrence_Click(object sender, EventArgs e)
25    {
26      this.Close();
27    }
28
29    private void btSaveRecurrence_Click(object sender, EventArgs e)
30    {
31      DateTime dateFrom, dateTo;
32      RecurrenceMode mode = RecurrenceMode.Daily;
33      int incWeek = 0;
34      HashSet<DayOfWeek> days = new HashSet<DayOfWeek>();
35
36      days = GetDays();
37
38      //check if valid
39      if (InputIsValid())
40      {
41        //set entity
42
43        dateFrom = DateTime.Parse(dtpStart.Text + " " + dtpFromTime.Text);
44        dateTo = DateTime.Parse(dtpEnd.Text + " " + dtpToTime.Text);
45
46        if (int.TryParse(txtDays.Text, out incWeek))
47          mode = RecurrenceMode.Weekly;
48        else
49          mode = RecurrenceMode.Daily;
50
51        RecurrentEvent recurrentEvent = new RecurrentEvent()
52        {
53          DateFrom = dateFrom,
54          DateTo = dateTo,
55          AllDay = chbade.Checked,
56          WeekDays = days,
57          IncWeeks = incWeek,
58        };
59
60        //fire delegate and close the dialog
61        dialogClosedDelegate(recurrentEvent);
62        this.Close();
63      }
64      else
65        MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
66    }
67
68    private HashSet<DayOfWeek> GetDays()
69    {
70      HashSet<DayOfWeek> days = new HashSet<DayOfWeek>();
71
72      if (cbMonday.Checked)
73        days.Add(DayOfWeek.Monday);
74      if (cbTuesday.Checked)
75        days.Add(DayOfWeek.Tuesday);
76      if (cbWednesday.Checked)
77        days.Add(DayOfWeek.Wednesday);
78      if (cbThursday.Checked)
79        days.Add(DayOfWeek.Thursday);
80      if (cbFriday.Checked)
81        days.Add(DayOfWeek.Friday);
82      if (cbSaturday.Checked)
83        days.Add(DayOfWeek.Saturday);
84      if (cbSunday.Checked)
85        days.Add(DayOfWeek.Sunday);
86
87      return days;
88    }
89
90    private bool InputIsValid()
91    {
92      DateTime dateFrom, dateTo;
93      int i = 0;
94
95      dateFrom = DateTime.Parse(dtpStart.Text + " " + dtpFromTime.Text);
96      dateTo = DateTime.Parse(dtpEnd.Text + " " + dtpToTime.Text);
97
98      if (dateFrom < dateTo && dateFrom.TimeOfDay < dateTo.TimeOfDay && int.TryParse(txtDays.Text, out i))
99        return true;
100      else
101        return false;
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.