示例#1
0
            public override void OnDoubleClick(CellContext sender, EventArgs e)
            {
                base.OnDoubleClick(sender, e);

                if (sender.Cell is CellAppointment)
                {
                    CellAppointment cell = (CellAppointment)sender.Cell;
                    mPlanningGrid.OnAppointmentDoubleClick(new AppointmentEventArgs(cell.Appointment.DateTimeStart, cell.Appointment.DateTimeEnd, cell.Appointment));
                }
                else if (sender.Cell is CellEmpty)
                {
                    CellEmpty cell = (CellEmpty)sender.Cell;
                    mPlanningGrid.OnAppointmentDoubleClick(new AppointmentEventArgs(cell.Start, cell.End, null));
                }
            }
示例#2
0
        /// <summary>
        /// Load the grid using the parameters specified
        /// </summary>
        /// <param name="dateTimeStart"></param>
        /// <param name="dateTimeEnd"></param>
        /// <param name="minAppointmentLength"></param>
        public void LoadPlanning(DateTime dateTimeStart, DateTime dateTimeEnd, int minAppointmentLength)
        {
            m_DateTimeStart        = dateTimeStart;
            m_DateTimeEnd          = dateTimeEnd;
            m_MinAppointmentLength = minAppointmentLength;

            if (dateTimeStart >= dateTimeEnd)
            {
                throw new ApplicationException("Invalid Planning Range");
            }
            if (dateTimeStart.TimeOfDay >= dateTimeEnd.TimeOfDay)
            {
                throw new ApplicationException("Invalid Plannnin Range");
            }
            if (dateTimeStart.TimeOfDay.Minutes != 0 ||
                dateTimeEnd.TimeOfDay.Minutes != 0)
            {
                throw new ApplicationException("Invalid Start or End hours must be with 0 minutes");
            }
            if (minAppointmentLength <= 0 || minAppointmentLength > 60)
            {
                throw new ApplicationException("Invalid Minimum Appointment Length");
            }
            if (60 % minAppointmentLength != 0)
            {
                throw new ApplicationException("Invalid Minimum Appointment Length must be multiple of 60");
            }

            TimeSpan dayInterval  = dateTimeEnd - dateTimeStart;
            TimeSpan timeInterval = dateTimeEnd.TimeOfDay - dateTimeStart.TimeOfDay;
            int      partsForHour = 60 / minAppointmentLength;

            if (dayInterval.TotalDays > 30)
            {
                throw new ApplicationException("Range too big");
            }
            if (timeInterval.TotalMinutes < minAppointmentLength)
            {
                throw new ApplicationException("Invalid Minimum Appointment Length for current Planning Range");
            }

            //Redim Grid
            grid.Redim((int)((timeInterval.TotalHours + 1) * partsForHour + c_RowsHeader),
                       (int)(dayInterval.TotalDays + 1 + c_ColumnsHeader));

            //Load Header
            grid[0, 0]            = new Header00(null);
            grid[0, 0].RowSpan    = 2;
            grid[0, 0].ColumnSpan = 2;
            //create day caption
            DateTime captionDate = dateTimeStart;

            for (int c = c_ColumnsHeader; c < grid.ColumnsCount; c++)
            {
                grid[0, c] = new HeaderDay1(captionDate.ToShortDateString());
                grid[1, c] = new HeaderDay2(captionDate.ToString("dddd"));

                captionDate = captionDate.AddDays(1);
            }

            //create hour caption
            int hours = dateTimeStart.Hour;

            for (int r = c_RowsHeader; r < grid.RowsCount; r += partsForHour)
            {
                grid[r, 0]         = new HeaderHour1(hours);
                grid[r, 0].RowSpan = partsForHour;

                int minutes = 0;
                for (int rs = r; rs < (r + partsForHour); rs++)
                {
                    grid[rs, 1] = new HeaderHour2(minutes);
                    minutes    += minAppointmentLength;
                }
                hours++;
            }

            grid.FixedColumns = c_ColumnsHeader;
            grid.FixedRows    = c_RowsHeader;

            //Fix the width of the first 2 columns
            grid.Columns[0].Width        = 40;
            grid.Columns[0].AutoSizeMode = SourceGrid.AutoSizeMode.None;
            grid.Columns[1].Width        = 40;
            grid.Columns[1].AutoSizeMode = SourceGrid.AutoSizeMode.None;

            grid.AutoStretchColumnsToFitWidth = true;
            grid.AutoStretchRowsToFitHeight   = true;
            grid.AutoSizeCells();


            //Create Appointment Cells
            //Days
            for (int c = c_ColumnsHeader; c < grid.ColumnsCount; c++)
            {
                DateTime   currentTime      = dateTimeStart.AddDays(c - c_ColumnsHeader);
                int        indexAppointment = -1;
                Cells.Cell appointmentCell  = null;
                //Hours
                for (int r = c_RowsHeader; r < grid.RowsCount; r += partsForHour)
                {
                    //Minutes
                    for (int rs = r; rs < (r + partsForHour); rs++)
                    {
                        bool l_bFound = false;
                        //Appointments
                        for (int i = 0; i < m_Appointments.Count; i++)
                        {
                            if (m_Appointments[i].ContainsDateTime(currentTime))
                            {
                                l_bFound = true;

                                if (indexAppointment != i)
                                {
                                    appointmentCell      = new CellAppointment(m_Appointments[i]);
                                    appointmentCell.View = m_Appointments[i].View;
                                    if (m_Appointments[i].Controller != null)
                                    {
                                        appointmentCell.AddController(m_Appointments[i].Controller);
                                    }
                                    grid[rs, c]      = appointmentCell;
                                    indexAppointment = i;
                                }
                                else
                                {
                                    grid[rs, c] = null;
                                    appointmentCell.RowSpan++;
                                }

                                break;
                            }
                        }
                        if (l_bFound)
                        {
                        }
                        else
                        {
                            grid[rs, c]      = new CellEmpty(currentTime, currentTime.AddMinutes(minAppointmentLength));
                            indexAppointment = -1;
                            appointmentCell  = null;
                        }

                        currentTime = currentTime.AddMinutes(minAppointmentLength);
                    }
                }
            }
        }
示例#3
0
        public void LoadPlanning(DateTime p_DateTimeStart, DateTime p_DateTimeEnd, int p_MinimumAppointmentLength)
        {
            m_DateTimeStart            = p_DateTimeStart;
            m_DateTimeEnd              = p_DateTimeEnd;
            m_MinimumAppointmentLength = p_MinimumAppointmentLength;

            if (p_DateTimeStart >= p_DateTimeEnd)
            {
                throw new ApplicationException("Invalid Planning Range");
            }
            if (p_DateTimeStart.TimeOfDay >= p_DateTimeEnd.TimeOfDay)
            {
                throw new ApplicationException("Invalid Plannnin Range");
            }
            if (p_DateTimeStart.TimeOfDay.Minutes != 0 ||
                p_DateTimeEnd.TimeOfDay.Minutes != 0)
            {
                throw new ApplicationException("Invalid Start or End hours must be with 0 minutes");
            }
            if (p_MinimumAppointmentLength <= 0 || p_MinimumAppointmentLength > 60)
            {
                throw new ApplicationException("Invalid Minimum Appointment Length");
            }
            if (60 % p_MinimumAppointmentLength != 0)
            {
                throw new ApplicationException("Invalid Minimum Appointment Length must be multiple of 60");
            }

            TimeSpan l_TotalInterval = p_DateTimeEnd - p_DateTimeStart;
            TimeSpan l_DayInterval   = p_DateTimeEnd.TimeOfDay - p_DateTimeStart.TimeOfDay;
            int      l_PartPerHour   = 60 / p_MinimumAppointmentLength;

            if (l_TotalInterval.TotalDays > 30)
            {
                throw new ApplicationException("Range too big");
            }
            if (l_DayInterval.TotalMinutes < p_MinimumAppointmentLength)
            {
                throw new ApplicationException("Invalid Minimum Appointment Length for current Planning Range");
            }

            //Redim Grid
            grid.Redim((int)((l_DayInterval.TotalHours + 1) * l_PartPerHour + c_RowsHeader),
                       (int)(l_TotalInterval.TotalDays + 1 + c_ColumnsHeader));

            //Load Header
            grid[0, 0]            = new Header00(null);
            grid[0, 0].RowSpan    = 2;
            grid[0, 0].ColumnSpan = 2;
            //create day caption
            DateTime l_Start = p_DateTimeStart;

            for (int c = c_ColumnsHeader; c < grid.ColumnsCount; c++)
            {
                grid[0, c] = new HeaderDay1(l_Start.ToShortDateString());
                grid[1, c] = new HeaderDay2(l_Start.ToString("dddd"));

                l_Start = l_Start.AddDays(1);
            }

            //create hour caption
            int l_Hours = p_DateTimeStart.Hour;

            for (int r = c_RowsHeader; r < grid.RowsCount; r += l_PartPerHour)
            {
                grid[r, 0]         = new HeaderHour1(l_Hours);
                grid[r, 0].RowSpan = l_PartPerHour;

                int l_Minutes = 0;
                for (int rs = r; rs < (r + l_PartPerHour); rs++)
                {
                    grid[rs, 1] = new HeaderHour2(l_Minutes);
                    l_Minutes  += p_MinimumAppointmentLength;
                }
                l_Hours++;
            }

            grid.FixedColumns = c_ColumnsHeader;
            grid.FixedRows    = c_RowsHeader;
            grid.AutoStretchColumnsToFitWidth = true;
            grid.AutoStretchRowsToFitHeight   = true;
            grid.AutoSizeCells();


            //Create Appointment Cells
            //Days
            for (int c = c_ColumnsHeader; c < grid.ColumnsCount; c++)
            {
                DateTime   l_CurrentTime      = p_DateTimeStart.AddDays(c - c_ColumnsHeader);
                int        l_IndexAppointment = -1;
                Cells.Cell l_AppointmentCell  = null;
                //Hours
                for (int r = c_RowsHeader; r < grid.RowsCount; r += l_PartPerHour)
                {
                    //Minutes
                    for (int rs = r; rs < (r + l_PartPerHour); rs++)
                    {
                        bool l_bFound = false;
                        //Appointments
                        for (int i = 0; i < m_Appointments.Count; i++)
                        {
                            if (m_Appointments[i].ContainsDateTime(l_CurrentTime))
                            {
                                l_bFound = true;

                                if (l_IndexAppointment != i)
                                {
                                    l_AppointmentCell      = new CellAppointment(m_Appointments[i].Title);
                                    l_AppointmentCell.View = m_Appointments[i].View;
                                    if (m_Appointments[i].Controller != null)
                                    {
                                        l_AppointmentCell.AddController(m_Appointments[i].Controller);
                                    }
                                    grid[rs, c]        = l_AppointmentCell;
                                    l_IndexAppointment = i;
                                }
                                else
                                {
                                    grid[rs, c] = null;
                                    l_AppointmentCell.RowSpan++;
                                }

                                break;
                            }
                        }
                        if (l_bFound)
                        {
                        }
                        else
                        {
                            grid[rs, c]        = new CellEmpty(null);
                            l_IndexAppointment = -1;
                            l_AppointmentCell  = null;
                        }

                        l_CurrentTime = l_CurrentTime.AddMinutes(p_MinimumAppointmentLength);
                    }
                }
            }
        }