Пример #1
0
        private void btnAddActivity_Click(object sender, EventArgs e)
        {
            try
            {
                Activity activity = new Activity();

                if (txtActivityDescription.Text == "")
                {
                    throw new Exception("Please enter a description!");
                }

                else
                {
                    activity.description = txtActivityDescription.Text;
                }

                if (txtActivityDate.Text == "")
                {
                    throw new Exception("Please enter an activity date! (format: MM/dd/yyyy)");
                }

                if (txtStartTime.Text == "")
                {
                    throw new Exception("Please enter a start time for the activity correctly (format: HH:mm)");
                }

                else
                {
                    activity.startDate = Convert.ToDateTime(txtActivityDate.Text + " " + txtStartTime.Text);
                }

                if (txtEndTime.Text == "")
                {
                    throw new Exception("Please enter an end time for the activity correctly (format: HH:mm)");
                }

                else
                {
                    activity.endDate = Convert.ToDateTime(txtActivityDate.Text + " " + txtEndTime.Text);
                }

                activityService.AddActivity(activity);
                MessageBox.Show($"Activity '{activity.description}' has been added");

                //refresh page
                RefreshActivityPanel();
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
Пример #2
0
        private void buttonActivitySave_Click(object sender, EventArgs e)
        {
            if (textBoxActivityDescription.Text != null && textBoxActivityName.Text != null && textBoxActivityStudents.Text != null && textBoxActivitySupervisors.Text != null)
            {
                Activity_Service activitydb = new Activity_Service();
                if (groupBoxEdit.Text == "Add")
                {
                    if (listViewActivities.Items.Contains(listViewActivities.FindItemWithText(textBoxActivityName.Text)))
                    {
                        MessageBox.Show("This Activity Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    Activity a = new Activity
                    {
                        ID                  = -1,
                        Name                = textBoxActivityName.Text,
                        Description         = textBoxActivityDescription.Text,
                        NumberOfStudents    = int.Parse(textBoxActivityStudents.Text),
                        NumberOfSupervisors = int.Parse(textBoxActivitySupervisors.Text),
                    };
                    activitydb.AddActivity(a);
                }
                else if (groupBoxEdit.Text == "Edit")
                {
                    ListViewItem item = listViewActivities.SelectedItems[0];
                    Activity     a    = new Activity
                    {
                        ID                  = int.Parse(item.SubItems[0].Text),
                        Name                = textBoxActivityName.Text,
                        Description         = textBoxActivityDescription.Text,
                        NumberOfStudents    = int.Parse(textBoxActivityStudents.Text),
                        NumberOfSupervisors = int.Parse(textBoxActivitySupervisors.Text),
                    };
                    activitydb.EditActivity(a);
                }

                showPanel("Activities");
            }
            else
            {
                MessageBox.Show("Fields cannot be empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #3
0
        private void btn_insert_Click(object sender, EventArgs e)
        {
            SomerenLogic.Activity_Service activity_Service = new Activity_Service();

            Activity activity = new Activity()
            {
                name                = txtname.Text,
                numberofstudents    = int.Parse(txtnrstud.Text),
                numberofsupervisors = int.Parse(txtnrsup.Text)
            };


            activity_Service.AddActivity(activity);

            showPanel("Activities");

            txtname.Clear();
            txtnrstud.Clear();
            txtnrsup.Clear();
        }
Пример #4
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            Activity_Service activityService = new Activity_Service();

            if (cmbActivityTypes.SelectedIndex <= 0 && txtCreateActivity.Text.Length == 0)
            {
                MessageBox.Show("You need to select an activity type!", "Select activity", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                bool          error = false;
                string        activityType;
                List <string> activityTypes = activityService.GetActivityTypes();

                // if there is nothing selected in the combo box or the index 0 is selected, use the text box as the activity type
                if (cmbActivityTypes.SelectedIndex <= 0)
                {
                    activityType = txtCreateActivity.Text;

                    foreach (string s in activityTypes) //check if that activity type already exists
                    {
                        if (s.ToLower() == activityType.ToLower())
                        {
                            MessageBox.Show("Activity type already exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            error = true;
                        }
                    }

                    if (!error) // if there are no errors, add the new activity type
                    {
                        activityService.AddActivityType(activityType);
                    }
                }

                else
                {
                    activityType = cmbActivityTypes.SelectedItem.ToString();
                }

                //format the activity date into a string
                string activityDate = calendarActivity.SelectionStart.Year.ToString() + "-"
                                      + calendarActivity.SelectionStart.Month.ToString("00") + "-"
                                      + calendarActivity.SelectionStart.Day.ToString("00");

                if (cmbHour.SelectedItem.ToString().Length < 2)
                {
                    activityDate += " 0" + cmbHour.SelectedItem.ToString();
                }
                else
                {
                    activityDate += " " + cmbHour.SelectedItem.ToString();
                }

                if (cmbMins.SelectedItem.ToString().Length < 2)
                {
                    activityDate += ":0" + cmbMins.SelectedItem.ToString();
                }
                else
                {
                    activityDate += ":" + cmbMins.SelectedItem.ToString();
                }


                if (!error)
                {
                    Activity _activity = new Activity(activityType, activityDate);
                    _activity.activity_Date = DateTime.ParseExact(activityDate, "yyyy-MM-dd HH:mm", null);

                    DateTime _startTime = _activity.activity_Date;
                    //create a random duration for the activity, between 30 minutes and 120 minutes(only divisible by 5)
                    Random rnd             = new Random();
                    int    activityMinutes = rnd.Next(6, 25) * 5;
                    //set the activity end time to the start time + the activity minutes
                    DateTime _endTime = _startTime.AddMinutes(activityMinutes);

                    activityService.AddActivity(_activity);
                    Activity  activityTime = activityService.GetBiggestId();
                    Timetable timetable    = new Timetable()
                    {
                        activity  = activityTime,
                        startTime = _startTime,
                        endTime   = _endTime
                    };
                    activityService.AddTimetable(timetable);

                    MessageBox.Show("New activity added!\nRefresh to see changes!", "Succes", MessageBoxButtons.OK);
                }
            }
        }