Example #1
0
        /// <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);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Handles the Load event of the MeetingsViewerForm 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 MeetingsViewerForm_Load(object sender, EventArgs e)
        {
            MeetingDataContext mdc = new MeetingDataContext(
                ConfigurationManager.ConnectionStrings["hamwicConnectionString"].ConnectionString);

            DataLoadOptions dlo = new DataLoadOptions();

            dlo.LoadWith <Subgroup>(s => s.Name);
            dlo.AssociateWith <Subgroup>(s => s.Name);
            mdc.LoadOptions = dlo;

            var meetings = from m in mdc.Meetings
                           from s in mdc.Subgroups
                           select new
            {
                m.Id,
                m.Location_,
                s.Name,
                m.DateTimeFrom,
                m.DateTimeTo
            };

            SetupDataGridView(meetings);
        }