private void btnAdd_Click(object sender, EventArgs e)
        {
            //using (dbContext = new ConventionManagerDbContext())
            //{
            MethodController methodController = new MethodController();

            if (methodController.stallCapacityStatus((int)cbxStall.SelectedValue))
            {
                AttendeeStall attendeeStall = new AttendeeStall()
                {
                    AttendeeId  = (int)cbxAttendee.SelectedValue,
                    StallId     = (int)cbxStall.SelectedValue,
                    IsExhibitor = chkIsExhibitor.Checked
                };

                Stall stall = dbContext.Stalls.Find(attendeeStall.StallId);
                if (methodController.attendeeStatus(attendeeStall.AttendeeId, stall.StallStartDate, stall.StallEndDate))
                {
                    dbContext.AttendeeStalls.Add(attendeeStall);
                    try
                    {
                        dbContext.SaveChanges();

                        MessageBox.Show("Attendee added to the stall successfully!!!");
                        updateGBXStall((int)cbxStall.SelectedValue);
                        loadDGV();
                        return;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Duplicate entry!!!");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Attendee busy on other event or seminar or stall");
                }
            }
            else
            {
                MessageBox.Show("Stall full!!!");
                return;
            }
            //}
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //using (dbContext = new ConventionManagerDbContext())
            //{
            MethodController methodController = new MethodController();

            if (methodController.roomCapacityStatus((int)cbxEvent.SelectedValue, true))
            {
                AttendeeEvent attendeeEvent = new AttendeeEvent()
                {
                    AttendeeId = (int)cbxAttendee.SelectedValue,
                    EventId    = (int)cbxEvent.SelectedValue
                };

                Event _eve = dbContext.Events.Find(attendeeEvent.EventId);
                if (methodController.attendeeStatus(attendeeEvent.AttendeeId, _eve.EventStartDate, _eve.EventEndDate))
                {
                    dbContext.AttendeeEvents.Add(attendeeEvent);

                    try
                    {
                        dbContext.SaveChanges();

                        MessageBox.Show("Attendee added to the event successfully!!!");
                        updateGBXEvent((int)cbxEvent.SelectedValue);
                        loadDGV();
                        return;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Duplicate entry!!!");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Attendee busy on other event or seminar or stall");
                }
            }
            else
            {
                MessageBox.Show("Booking full!!!");
                return;
            }
            //}
        }
Beispiel #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //using (dbContext = new ConventionManagerDbContext())
            //{
            MethodController methodController = new MethodController();

            if (methodController.roomCapacityStatus((int)cbxSeminar.SelectedValue, false))
            {
                AttendeeSeminar attendeeSeminar = new AttendeeSeminar()
                {
                    AttendeeId  = (int)cbxAttendee.SelectedValue,
                    SeminarId   = (int)cbxSeminar.SelectedValue,
                    IsPresenter = chkIsPresenter.Checked
                };

                Seminar seminar = dbContext.Seminars.Find(attendeeSeminar.SeminarId);
                if (methodController.attendeeStatus(attendeeSeminar.AttendeeId, seminar.SeminarStartDate, seminar.SeminarEndDate))
                {
                    dbContext.AttendeeSeminars.Add(attendeeSeminar);
                    try
                    {
                        dbContext.SaveChanges();

                        MessageBox.Show("Attendee added to the seminar successfully!!!");
                        updateGBXSeminar((int)cbxSeminar.SelectedValue);
                        loadDGV();
                        return;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Duplicate entry!!!");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Attendee busy on other event or seminar or stall");
                }
            }
            else
            {
                MessageBox.Show("Booking full!!!");
                return;
            }
            //}
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtName.Text))
            {
                MessageBox.Show("Please enter event name!!!");
                txtName.Focus();
                return;
            }
            else if (String.IsNullOrEmpty(txtDescription.Text))
            {
                MessageBox.Show("Please enter event description!!!");
                txtDescription.Focus();
                return;
            }
            else if (DateTime.Compare(dtpStartDate.Value, DateTime.Now) < 0)
            {
                MessageBox.Show("Invalid start date: Date crossed already!!!");
                dtpStartDate.Focus();
                return;
            }
            else if (DateTime.Compare(dtpStartDate.Value, dtpEndDate.Value) >= 0)
            {
                MessageBox.Show("End date must be after start date!!!");
                dtpStartDate.Focus();
                return;
            }
            else
            {
                if (btnAdd.Text.Equals("ADD"))
                {
                    MethodController controller = new MethodController();
                    if (controller.roomStatus((int)cbxRoom.SelectedValue, dtpStartDate.Value, dtpEndDate.Value))
                    {
                        _event = new Event();
                    }
                    else
                    {
                        MessageBox.Show("Room unavailable in that time period!!!");
                        return;
                    }
                }
                else if (btnAdd.Text.Equals("UPDATE"))
                {
                    _event.EventId = eventCode;
                }

                _event.EventName        = txtName.Text.Trim();
                _event.EventDescription = txtDescription.Text.Trim();
                _event.EventStartDate   = dtpStartDate.Value;
                _event.EventEndDate     = dtpEndDate.Value;
                _event.RoomId           = Convert.ToInt32(cbxRoom.SelectedValue.ToString());

                try
                {
                    if (btnAdd.Text.Equals("ADD"))
                    {
                        dbContext.Events.Add(_event);
                    }

                    dbContext.SaveChanges();

                    MessageBox.Show(String.Format("Event {0} successfully!!!", btnAdd.Text.Equals("ADD") ? "added" : "updated"));
                    btnAdd.Text = "ADD";

                    txtName.Clear();
                    txtDescription.Clear();

                    loadDGV();
                    dtpStartDate.Enabled = dtpEndDate.Enabled = cbxRoom.Enabled = true;
                    txtName.Focus();
                    return;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }