Ignore:
Timestamp:
01/21/09 17:03:41 (12 years ago)
Author:
whackl
Message:

added new scheduling features (#468)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Client.Console/HiveClientConsole.cs

    r1145 r1163  
    3535using System.Net;
    3636using Calendar;
     37using System.Globalization;
    3738
    3839namespace HeuristicLab.Hive.Client.Console {
     
    188189    }
    189190
    190     void DvOnline_OnResolveAppointments(object sender, ResolveAppointmentsEventArgs e) {
    191       List<Appointment> Apps = new List<Appointment>();
    192 
    193       foreach (Appointment m_App in onlineTimes)
    194         if ((m_App.StartDate >= e.StartDate) &&
    195             (m_App.StartDate <= e.EndDate))
    196           Apps.Add(m_App);
    197 
    198       e.Appointments = Apps;
    199     }
    200 
    201     void DvOnline_OnNewAppointment(object sender, NewAppointmentEventArgs e) {
    202       Appointment Appointment = new Appointment();
    203 
    204       Appointment.StartDate = e.StartDate;
    205       Appointment.EndDate = e.EndDate;
    206 
    207       onlineTimes.Add(Appointment);
     191    private Appointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay) {
     192      Appointment App = new Appointment();
     193      App.StartDate = startDate;
     194      App.EndDate = endDate;
     195      App.AllDayEvent = allDay;
     196      App.BorderColor = Color.Red;
     197      App.Locked = true;
     198      App.Subject = "Online";
     199      return App;
    208200    }
    209201
     
    356348    }
    357349
    358     #endregion
    359 
    360     private void mcOnline_DateChanged(object sender, DateRangeEventArgs e) {
    361       dvOnline.StartDate = mcOnline.SelectionStart;
    362     }
    363 
    364     private void btCreate_Click(object sender, EventArgs e) {
    365 
    366       if (string.IsNullOrEmpty(txtFrom.Text)) {
    367         Appointment App = new Appointment();
    368         App.StartDate = dvOnline.SelectionStart;
    369         App.EndDate = dvOnline.SelectionEnd;
    370         App.BorderColor = Color.Red;
    371         App.Locked = true;
    372         App.Subject = "Online";
    373         onlineTimes.Add(App);
    374       } else if (string.IsNullOrEmpty(txtTimeTo.Text)) {
    375         Appointment App = new Appointment();
    376         App.StartDate = DateTime.Parse(txtFrom.Text);
    377         App.EndDate = DateTime.Parse(txtTo.Text);
    378         App.BorderColor = Color.Red;
    379         App.Locked = true;
    380         App.Subject = "Online";
    381         onlineTimes.Add(App);
    382       } else {
    383         DateTime from = DateTime.Parse(txtFrom.Text);
    384         DateTime to = DateTime.Parse(txtTo.Text);
    385 
    386         while (from.Date != to.Date) {
    387           Appointment App = new Appointment();
    388           App.StartDate = new DateTime(from.Year, from.Month, from.Day, int.Parse(txttimeFrom.Text), 0,0);
    389           App.EndDate = new DateTime(from.Year, from.Month, from.Day, int.Parse(txtTimeTo.Text), 0, 0);
    390           App.BorderColor = Color.Red;
    391           App.Locked = true;
    392           App.Subject = "Online";
    393           onlineTimes.Add(App);
    394           from = from.AddDays(1);
    395         }
    396       }
    397      
    398       dvOnline.Invalidate();
    399     }
    400 
    401350    private void btbDelete_Click(object sender, EventArgs e) {
    402351      if (dvOnline.SelectedAppointment != null)
     
    405354    }
    406355
     356    private void chbade_CheckedChanged(object sender, EventArgs e) {
     357      if (chbade.Checked) {
     358        txttimeFrom.Visible = false;
     359        txtTimeTo.Visible = false;
     360      } else {
     361        txttimeFrom.Visible = true;
     362        txtTimeTo.Visible = true;
     363      }
     364    }
     365
     366    private void dvOnline_OnSelectionChanged(object sender, EventArgs e) {
     367      if (dvOnline.Selection == SelectionType.DateRange) {
     368        txtFrom.Text = dvOnline.SelectionStart.ToShortDateString();
     369        txtTo.Text = dvOnline.SelectionEnd.Date.ToShortDateString();
     370        txttimeFrom.Text = dvOnline.SelectionStart.ToShortTimeString();
     371        txtTimeTo.Text = dvOnline.SelectionEnd.ToShortTimeString();
     372      }
     373    }
     374
     375    private void Connection_KeyPress(object sender, KeyPressEventArgs e) {
     376      if (e.KeyChar == (char)Keys.Return)
     377        btConnect_Click(null, null);
     378    }
     379
     380    private void mcOnline_DateChanged(object sender, DateRangeEventArgs e) {
     381      dvOnline.StartDate = mcOnline.SelectionStart;
     382    }
     383
     384    private void btCreate_Click(object sender, EventArgs e) {
     385      DateTime from, to;
     386
     387      if (!string.IsNullOrEmpty(txtFrom.Text) && !string.IsNullOrEmpty(txtTo.Text)) {
     388        if (chbade.Checked) {
     389          //whole day appointment, only dates are visible
     390          if (DateTime.TryParse(txtFrom.Text + " " + txttimeFrom.Text, out from) && DateTime.TryParse(txtTo.Text + " " + txtTimeTo.Text, out to) && from < to)
     391            onlineTimes.Add(CreateAppointment(from, to.AddDays(1), true));
     392          else
     393            MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     394        } else if (!string.IsNullOrEmpty(txttimeFrom.Text) && !string.IsNullOrEmpty(txtTimeTo.Text)) {
     395          //Timeframe appointment
     396          if (DateTime.TryParse(txtFrom.Text + " " + txttimeFrom.Text, out from) && DateTime.TryParse(txtTo.Text + " " + txtTimeTo.Text, out to) && from < to) {
     397            if (from.Date == to.Date)
     398              onlineTimes.Add(CreateAppointment(from, to, false));
     399            else {
     400              //more than 1 day selected
     401              while (from.Date != to.Date) {
     402                onlineTimes.Add(CreateAppointment(from, new DateTime(from.Year, from.Month, from.Day, to.Hour, to.Minute, 0, 0), false));
     403                from = from.AddDays(1);
     404              }
     405              onlineTimes.Add(CreateAppointment(from, new DateTime(from.Year, from.Month, from.Day, to.Hour, to.Minute, 0, 0), false));
     406            }
     407          } else
     408            MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     409        }
     410        dvOnline.Invalidate();
     411      } else {
     412        MessageBox.Show("Error in create appointment, please fill out all textboxes!", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     413      }
     414    }
     415
     416    void DvOnline_OnResolveAppointments(object sender, ResolveAppointmentsEventArgs e) {
     417      List<Appointment> Apps = new List<Appointment>();
     418
     419      foreach (Appointment m_App in onlineTimes)
     420        if ((m_App.StartDate >= e.StartDate) &&
     421            (m_App.StartDate <= e.EndDate))
     422          Apps.Add(m_App);
     423
     424      e.Appointments = Apps;
     425    }
     426
     427    void DvOnline_OnNewAppointment(object sender, NewAppointmentEventArgs e) {
     428      Appointment Appointment = new Appointment();
     429
     430      Appointment.StartDate = e.StartDate;
     431      Appointment.EndDate = e.EndDate;
     432
     433      onlineTimes.Add(Appointment);
     434    }
     435
     436    #endregion
    407437  }
    408438}
Note: See TracChangeset for help on using the changeset viewer.