private void btnSave_Click(object sender, RoutedEventArgs e) { if (validateInputs()) { DateTime SegmentStartDateTime = eventDay_.StartDateTime.Date; DateTime SegmentEndDateTime = eventDay_.StartDateTime.Date; SegmentStartDateTime = SegmentStartDateTime .AddHours(int.Parse(cboStartHr.SelectedValue.ToString())) .AddMinutes(int.Parse(cboStartMin.SelectedValue.ToString())); int idx = cboBookDuration.SelectedIndex+1; //int duration = idx * 30; SegmentEndDateTime = SegmentStartDateTime.AddMinutes(idx * 30); ProgrammeHelper client = new ProgrammeHelper(); try { if (lstProgram.SelectedIndex != -1 && ((Program)lstProgram.SelectedItem).ProgramID != 0) { client.EditProgram(user, ((Program)lstProgram.SelectedItem).ProgramID, txtName.Text, SegmentStartDateTime, SegmentEndDateTime, txtDescription.Text, txtLocation.Text); } else { bool clashed = client.ValidateProgramTime(eventDay_.DayID, SegmentStartDateTime, SegmentEndDateTime); if (clashed) { MessageBox.Show("Program cannot be overlapped!", "Overlapping Program Detected", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } else { client.AddProgram(user, txtName.Text, SegmentStartDateTime, SegmentEndDateTime, txtDescription.Text, eventDay_.DayID, txtLocation.Text); } } MessageBox.Show("Operation succeeded!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); clearAll(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { client.Close(); } loadPrograms(); } }
private void Program_Swap(Program p1, Program p2) { DateTime tempstart; tempstart = p1.StartDateTime; TimeSpan p1ts = p1.EndDateTime - p1.StartDateTime; TimeSpan p2ts = p2.EndDateTime - p2.StartDateTime; p1.StartDateTime = p2.StartDateTime; p1.EndDateTime = p2.StartDateTime.AddMinutes(p1ts.TotalMinutes); p2.StartDateTime = tempstart; p2.EndDateTime = tempstart.AddMinutes(p2ts.TotalMinutes); List<Program> temp = new List<Program>(); if (p1.ProgramID != 0) temp.Add(p1); if (p2.ProgramID != 0) temp.Add(p2); for (int i = 0; i < lstProgram.Items.Count; i++) { if (((Program)lstProgram.Items[i]).ProgramID != 0 && ((Program)lstProgram.Items[i]).ProgramID != p1.ProgramID && ((Program)lstProgram.Items[i]).ProgramID != p2.ProgramID) temp.Add((Program)lstProgram.Items[i]); } if (Check_OverWrite(temp)) { MessageBox.Show("OverLap or is over the event time boundary"); return; } ProgrammeHelper client = new ProgrammeHelper(); try { if (p1.ProgramID != 0 && p2.ProgramID != 0) { client.SwapProgram(user, p1.ProgramID, p2.ProgramID); } else { if (p1.ProgramID != 0) { client.EditProgram(user, p1.ProgramID, p1.Name, p1.StartDateTime, p1.EndDateTime, p1.Description, p1.Location); } if (p2.ProgramID != 0) client.EditProgram(user, p2.ProgramID, p2.Name, p2.StartDateTime, p2.EndDateTime, p2.Description, p2.Location); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { client.Close(); } loadPrograms(); }