/// <summary>
        /// Set the designated reservation label to the correspondent cell of table layout.
        /// </summary>
        /// <param name="calendarPanel"></param>
        /// <param name="reserv"></param>
        public void SetReservLabelToPanel(TableLayoutPanel calendarPanel, ReservationLabel reservLbl)
        {
            Reservation reserv   = reservLbl.reservation;
            int?        reservID = reserv.ReservationID;
            //Find the row number of the resource of the reservation
            int?reservRow = FindRowByResourceID(calendarPanel, reserv.ResourceID);

            if (reservRow != null)
            {
                int columnOfStartDate = FindColumnByDate(calendarPanel, reserv.StartDate);
                int columnOfEndDate   = FindColumnByDate(calendarPanel, reserv.EndDate);
                //if the reservation date is not in the current view
                if (columnOfStartDate == calendarPanel.ColumnCount ||
                    columnOfEndDate == 1)
                {
                    //if an existing reservation is modified out of view then remove the label
                    if (calendarPanel.Controls.Contains(reservLbl))
                    {
                        calendarPanel.Controls.Remove(reservLbl);
                    }
                    else //new reservation, but not in the view
                    {
                        AddReservation(reserv);
                    }
                    return;
                }
                //How many columns does the reservation label occupy
                int colspan = columnOfEndDate - columnOfStartDate;
                if (colspan == 0)
                {
                    return;
                }

                //Add the reservation label to the correct position in the view
                //Suspend layout to prevent the table from being messed up when redrawing reservation label
                calendarPanel.SuspendLayout();
                calendarPanel.SetColumnSpan(reservLbl, colspan);
                if (calendarPanel.Controls.Contains(reservLbl))
                { //existing reservation
                    calendarPanel.SetCellPosition(reservLbl, new TableLayoutPanelCellPosition(columnOfStartDate, reservRow.Value));
                }
                else //new reservation
                {
                    if (reservID == null)
                    {
                        reserv.ReservationID = Reservation.maxID++;
                    }
                    AddReservation(reserv);
                    //Save the ID to Name property of reservation label as key for search in the future
                    reservLbl.Name = reserv.ReservationID.ToString();
                    calendarPanel.Controls.Add(reservLbl, columnOfStartDate, reservRow.Value);
                }
                reservLbl.Text = reservLbl.ToString();
                //Resume layout to display result on calendar table
                calendarPanel.ResumeLayout();
            }
        }
示例#2
0
 /// <summary>
 /// Event triggered when a control on the table is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ControlLbl_Click(object sender, MouseEventArgs e)
 {
     //Labels apart from reservation labels should not respond
     if (sender is ReservationLabel)
     {
         currentReservLbl   = sender as ReservationLabel;
         currentReservation = currentReservLbl.reservation;
         //Display the selected reservation information in the edit panel
         DisplayReservationDetail();
         EnableEditPanel();
     }
 }
 /// <summary>
 /// Delete a reservation label from the calendar view and delete the underlying data as well.
 /// </summary>
 /// <param name="calendarPanel"></param>
 /// <param name="reservLbl"></param>
 public void DeleteReservation(TableLayoutPanel calendarPanel, ReservationLabel reservLbl)
 {
     //Return if the reservation is not saved yet
     if (!calendarPanel.Controls.Contains(reservLbl))
     {
         MessageBox.Show("Please save the reservation first.", "Error");
         return;
     }
     this.reservationList.Remove(reservLbl.reservation);
     calendarPanel.Controls.Remove(reservLbl);
     this.calendarView.ClearEditPanel();
 }
示例#4
0
 /// <summary>
 /// Clear the edit panel
 /// </summary>
 public void ClearEditPanel()
 {
     this.txtCustomer.Text    = "";
     this.dateStart.Value     = DateTime.Today;
     this.dateEnd.Value       = DateTime.Today.AddDays(1);
     this.txtCustomer.Enabled = false;
     this.dateEnd.Enabled     = false;
     this.dateStart.Enabled   = false;
     this.btnSave.Enabled     = false;
     this.btnDelete.Enabled   = false;
     this.currentReservation  = null;
     this.currentReservLbl    = null;
 }
示例#5
0
        /// <summary>
        /// An empty cell on the table is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void calendarPanel_MouseClick(object sender, MouseEventArgs e)
        {
            Point?position = calendarPanel.GetRowColIndex(new Point(e.X, e.Y));

            if (position == null || position.Value.X == 0 || position.Value.Y == 0)
            {
                return;
            }
            int           resourceID = position.Value.Y - 1;
            DateTimeLabel dtLbl      = calendarPanel.GetControlFromPosition(position.Value.X, 0) as DateTimeLabel;
            DateTime      startDate  = dtLbl.date;
            DateTime      endDate    = startDate.AddDays(1);

            this.currentReservation      = new Reservation(resourceID, startDate, endDate);
            this.currentReservLbl        = new ReservationLabel(currentReservation);
            currentReservLbl.MouseClick += this.ControlLbl_Click;
            DisplayReservationDetail();
            EnableEditPanel();
        }