/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> private void btnSave_Click(object sender, EventArgs e) { DateTime datetimeFrom = GetDateTimeFrom(); DateTime datetimeTo = GetDateTimeTo(); if (datetimeFrom >= datetimeTo) { MessageBox.Show("Meeting end time must be later than the meeting start time.", "Problem with input", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MeetingDataContext mdc = new MeetingDataContext( ConfigurationManager.ConnectionStrings["hamwicConnectionString"].ConnectionString); Meeting newMeeting = new Meeting { DateTimeFrom = this.dtpTimeFrom.Value, DateTimeTo = this.dtpTimeTo.Value, Location_ = this.txtLocation.Text, SubGroupId = (cbSubgroup.SelectedItem as Subgroup).Id }; mdc.Meetings.InsertOnSubmit(newMeeting); try { mdc.SubmitChanges(); MessageBox.Show("Changes saved successfully", "The database has been updated.", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch (Exception) { MessageBox.Show("Failed to save Changes", "Problem committing to database", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Initializes a new instance of the <see cref="MeetingForm" /> class. /// </summary> /// <param name="meeting">The meeting to display</param> public MeetingForm(Meeting meeting) { InitializeComponent(); }