/// <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)
        {
            SubGroupDataContext sdc = new SubGroupDataContext(
                ConfigurationManager.ConnectionStrings["hamwicConnectionString"].ConnectionString);

            Subgroup newSubgroup = new Subgroup
            {
                Name = txtSubgroupName.Text
            };

            sdc.Subgroups.InsertOnSubmit(newSubgroup);

            try
            {
                sdc.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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the Load event of the MeetingForm 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 MeetingForm_Load(object sender, EventArgs e)
        {
            SubGroupDataContext sgdc = new SubGroupDataContext(
                ConfigurationManager.ConnectionStrings["hamwicConnectionString"].ConnectionString);

            var subgroups = from s in sgdc.Subgroups select s;

            cbSubgroup.DataSource = subgroups;
            cbSubgroup.DisplayMember = "Name";
            cbSubgroup.ValueMember = "Id";
        }