Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/28/12 09:57:35 (11 years ago)
Author:
ascheibe
Message:

#1986 merged SlaveShutdown branch back into trunk

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources

  • trunk/sources/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ScheduleView.cs

    r8075 r8957  
    9191    }
    9292
    93     private bool CreateAppointment() {
     93    private bool CreateAppointment(DowntimeType dtType) {
    9494      DateTime from, to;
    9595
     
    9898          //whole day appointment, only dates are visible
    9999          if (DateTime.TryParse(dtpFrom.Text, out from) && DateTime.TryParse(dtpTo.Text, out to) && from <= to)
    100             offlineTimes.Add(CreateAppointment(from, to.AddDays(1), true));
     100            offlineTimes.Add(CreateAppointment(from, to.AddDays(1), true, dtType));
    101101          else
    102102            MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     
    105105          if (DateTime.TryParse(dtpFrom.Text + " " + txttimeFrom.Text, out from) && DateTime.TryParse(dtpTo.Text + " " + txttimeTo.Text, out to) && from < to) {
    106106            if (from.Date == to.Date)
    107               offlineTimes.Add(CreateAppointment(from, to, false));
     107              offlineTimes.Add(CreateAppointment(from, to, false, dtType));
    108108            else {
    109109              //more than 1 day selected
    110110              while (from.Date != to.Date) {
    111                 offlineTimes.Add(CreateAppointment(from, new DateTime(from.Year, from.Month, from.Day, to.Hour, to.Minute, 0, 0), false));
     111                offlineTimes.Add(CreateAppointment(from, new DateTime(from.Year, from.Month, from.Day, to.Hour, to.Minute, 0, 0), false, dtType));
    112112                from = from.AddDays(1);
    113113              }
    114               offlineTimes.Add(CreateAppointment(from, new DateTime(from.Year, from.Month, from.Day, to.Hour, to.Minute, 0, 0), false));
     114              offlineTimes.Add(CreateAppointment(from, new DateTime(from.Year, from.Month, from.Day, to.Hour, to.Minute, 0, 0), false, dtType));
    115115            }
    116116          } else
     
    125125    }
    126126
    127     private HiveAppointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay) {
     127    private HiveAppointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay, DowntimeType downtimeType) {
    128128      HiveAppointment app = new HiveAppointment();
    129129      app.StartDate = startDate;
     
    132132      app.BorderColor = Color.Red;
    133133      app.Locked = true;
    134       app.Subject = "Offline";
     134      app.Subject = downtimeType.ToString();
    135135      app.Recurring = false;
    136136      return app;
    137137    }
    138138
    139     private HiveAppointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay, bool recurring, Guid recurringId) {
     139    private HiveAppointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay, bool recurring, Guid recurringId, DowntimeType downtimeType) {
    140140      HiveAppointment app = new HiveAppointment();
    141141      app.StartDate = startDate;
     
    144144      app.BorderColor = Color.Red;
    145145      app.Locked = true;
    146       app.Subject = "Offline";
     146      app.Subject = downtimeType.ToString();
    147147      app.Recurring = recurring;
    148148      app.RecurringId = recurringId;
     
    164164      recurringAppointments.ForEach(appointment => appointment.StartDate = new DateTime(appointment.StartDate.Year, appointment.StartDate.Month, appointment.StartDate.Day, hourfrom, 0, 0));
    165165      recurringAppointments.ForEach(appointment => appointment.EndDate = new DateTime(appointment.EndDate.Year, appointment.EndDate.Month, appointment.EndDate.Day, hourTo, 0, 0));
    166 
    167       DeleteRecurringAppointment(recurringId);
    168       offlineTimes.AddRange(recurringAppointments);
    169166    }
    170167
    171168    public void DialogClosed(RecurrentEvent e) {
    172       CreateDailyRecurrenceAppointments(e.DateFrom, e.DateTo, e.AllDay, e.WeekDays);
    173     }
    174 
    175     private void CreateDailyRecurrenceAppointments(DateTime dateFrom, DateTime dateTo, bool allDay, HashSet<DayOfWeek> daysOfWeek) {
     169      CreateDailyRecurrenceAppointments(e.DateFrom, e.DateTo, e.AllDay, e.WeekDays, e.AppointmentType);
     170    }
     171
     172    private void CreateDailyRecurrenceAppointments(DateTime dateFrom, DateTime dateTo, bool allDay, HashSet<DayOfWeek> daysOfWeek, DowntimeType appointmentType) {
    176173      DateTime incDate = dateFrom;
    177174      Guid guid = Guid.NewGuid();
     
    179176      while (incDate.Date <= dateTo.Date) {
    180177        if (daysOfWeek.Contains(incDate.Date.DayOfWeek))
    181           offlineTimes.Add(CreateAppointment(incDate, new DateTime(incDate.Year, incDate.Month, incDate.Day, dateTo.Hour, dateTo.Minute, 0), allDay, true, guid));
     178          offlineTimes.Add(CreateAppointment(incDate, new DateTime(incDate.Year, incDate.Month, incDate.Day, dateTo.Hour, dateTo.Minute, 0), allDay, true, guid, appointmentType));
    182179        incDate = incDate.AddDays(1);
    183180      }
     
    284281    private void btCreate_Click(object sender, EventArgs e) {
    285282      if (dvOnline.Selection != SelectionType.Appointment) {
    286         CreateAppointment();
     283        DowntimeType dtType;
     284        DialogResult result;
     285        AppointmentTypeDialog dialog = new AppointmentTypeDialog();
     286        result = dialog.ShowDialog(this);
     287        dtType = dialog.AppointmentType;
     288        dialog.Dispose();
     289        if (result == DialogResult.Cancel) return;
     290        CreateAppointment(dtType);
    287291      } else {
    288292        //now we want to change an existing appointment
    289293        if (!dvOnline.SelectedAppointment.Recurring) {
    290           if (CreateAppointment())
     294          if (CreateAppointment(GetDowntimeTypeOfSelectedAppointment()))
    291295            DeleteAppointment();
    292296        } else {
     
    295299          DialogResult res = MessageBox.Show("Change all events in this series?", "Change recurrences", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
    296300          if (res != DialogResult.Yes) {
    297             if (CreateAppointment())
     301            if (CreateAppointment(GetDowntimeTypeOfSelectedAppointment()))
    298302              DeleteAppointment();
    299303          } else
     
    339343        BorderColor = Color.Red,
    340344        Locked = true,
    341         Subject = "Offline",
     345        Subject = downtime.DowntimeType.ToString(),
    342346        Changed = downtime.Modified,
    343347        Id = downtime.Id
     
    354358        RecurringId = app.RecurringId,
    355359        ResourceId = HiveAdminClient.Instance.DowntimeForResourceId,
    356         Id = app.Id
     360        Id = app.Id,
     361        DowntimeType = (DowntimeType)Enum.Parse(typeof(DowntimeType), app.Subject)
    357362      };
    358363      return downtime;
    359364    }
     365
     366    private DowntimeType GetDowntimeTypeOfSelectedAppointment() {
     367      return (DowntimeType)Enum.Parse(typeof(DowntimeType), ((HiveAppointment)dvOnline.SelectedAppointment).Subject);
     368    }
    360369  }
    361370}
Note: See TracChangeset for help on using the changeset viewer.