Ejemplo n.º 1
0
        private static void Click_TimetableSaveButton(object sender, EventArgs e)
        {
            // find the controls again based on the tag
            Button button = (Button)sender;

            Control[]      allControls        = (Control[])button.Tag;
            ListView       activitiesListView = (ListView)allControls[0];
            DateTimePicker datePicker         = (DateTimePicker)allControls[1];
            ComboBox       timePicker         = (ComboBox)allControls[2];

            // make sure we have a selected activity
            if (activitiesListView.SelectedItems.Count != 1)
            {
                MessageBox.Show("Please select exactly one activity.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // find the new values from the controls
            int      activityId = int.Parse(activitiesListView.SelectedItems[0].Text);
            DateTime date       = datePicker.Value.Date;
            int      startTime  = 9 + (timePicker.SelectedIndex * 2);
            int      endTime    = startTime + 2;

            // store in database
            SomerenDB.DB_setTimeslotForActivity(activityId, date, startTime, endTime);
        }