Beispiel #1
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            //Get workshop data
            string title       = tbxTitle.Text;
            string description = rtbDescription.Text;
            int    capacity    = (int)numCapacity.Value;

            //Create a new workshop

            try
            {
                Workshop ws = null;
                if (!String.IsNullOrEmpty(title) || !String.IsNullOrEmpty(description) || capacity > 0)
                {
                    if (rbInBuilding.Checked)
                    {
                        string address    = tbxAddress.Text;
                        int    roomNumber = (int)numRoomNumber.Value;
                        if (String.IsNullOrEmpty(address) || roomNumber <= 0)
                        {
                            throw new ArgumentException("Please provide valid address and room number values");
                        }
                        ws = new InBuildingWorkshop(title, description, capacity, address, roomNumber);
                    }
                    else if (rbOnline.Checked)
                    {
                        string url = tbxURL.Text;
                        if (String.IsNullOrEmpty(url))
                        {
                            throw new ArgumentException("URL cannot be null or empty");
                        }
                        ws = new OnlineWorkshop(title, description, capacity, url);
                    }
                    else
                    {
                        MessageBox.Show($"Please select a workshop type (Online/In Building)");
                        return;
                    }
                    //Add to list
                    this.workshops.Add(ws);
                    Data.UpdateWorkshops(this.workshops);
                    Dashboard dashboard = new Dashboard();
                    this.Hide();
                    dashboard.ShowDialog();
                }
                else
                {
                    MessageBox.Show($"Please fill all the required fields.");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
 public void Disenroll(Workshop ws)
 {
     if (this.enrolments.Any(w => w.Key.WorkshopCode == ws.WorkshopCode))
     {
         Workshop workshop = this.enrolments.Keys.First(e => e.WorkshopCode == ws.WorkshopCode);
         this.enrolments.Remove(workshop);
     }
     else
     {
         throw new WorkshopArgumentException($"Workshop not found.");
     }
 }
Beispiel #3
0
        private void btnRemoveWorkshop_Click(object sender, EventArgs e)
        {
            try
            {
                Workshop ws = (Workshop)lbxWorkshops.SelectedItem;

                Data.UpdatePeople(this.people);
                this.RemoveWorkshop(ws);
            }
            catch (NullReferenceException)
            {
                MessageBox.Show($"Please select a workshop first");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #4
0
 private void RemoveWorkshop(Workshop ws)
 {
     if (this.workshops.Any(w => w.WorkshopCode == ws.WorkshopCode))
     {
         ws = this.workshops.First(w => w.WorkshopCode == ws.WorkshopCode);
         foreach (var person in this.people)
         {
             if (person.Enrolments.Any(e => e.Key.WorkshopCode == ws.WorkshopCode))
             {
                 person.Disenroll(ws);
             }
         }
         this.workshops.Remove(ws);
         Data.UpdateWorkshops(this.workshops);
         Data.UpdatePeople(this.people);
         UpdateWorkshopsList();
     }
     else
     {
         throw new WorkshopNotFoundException($"{ws.Title} not found.");
     }
 }
Beispiel #5
0
 public void Enroll(Workshop ws)
 {
     this.enrolments.Add(ws, ws.WorkshopCode);
 }