示例#1
0
        /// <summary>
        /// Calculate the time slot bounds. This works out the size and
        /// shape that days will take up on the screen. This method
        /// is called from OnPaint only when the property BoundsValidTimeSlot
        /// is set to false (this property is set to false in cases such as
        /// when the control has been resized or the date shown has
        /// changed).
        /// </summary>
        protected override void CalculateTimeSlotBounds(Graphics g)
        {
            if (Width == 0 || Height == 0)
            {
                return;
            }

            //TODO: use a bigger font for month name header
            int monthNameHeight = (int)(RendererCache.Current.Header.GetTextInfo(g, Font).Height * 1.3);

            int dayNameHeight  = (int)(RendererCache.Current.Header.GetTextInfo(g, Font).Height * 1.3);
            int itemHeight     = (int)(RendererCache.Current.Item.GetTextInfo(g, Font).Height * 1.2);
            int dayHeight      = (Height - 1 - dayNameHeight - monthNameHeight) / 6; //take out borders - days will paint right and bottom border themselves
            int xCurrent       = 0;
            int yCurrent       = monthNameHeight + dayNameHeight;
            int dayWidth       = (Width - 1) / 6;
            int saturdayHeight = (dayHeight) / 2;
            int sundayHeight   = dayHeight - saturdayHeight;

            //  paintBorderWidth = dayWidth * 6 ;
            //  paintBorderHeight = dayHeight * 6 + dayNameHeight ;

            //clear previous days
            this.days.Clear();
            this.headers.Clear();

            //find a monday to start on
            DateTime currentDay = new DateTime(Date.Year, Date.Month, 1);

            while (currentDay.DayOfWeek != DayOfWeek.Monday)
            {
                currentDay = currentDay.AddDays(-1);
            }

            monthHeader        = new HeaderRegion();
            monthHeader.Name   = Date.ToString("MMMM");
            monthHeader.Bounds = new Rectangle(xCurrent, 0, dayWidth * 6, monthNameHeight);

            //set up the day titles
            int      xHeaderCurrent   = xCurrent;
            DateTime headerCurrentDay = currentDay;

            for (int i = 0; i < 6; i++)
            {
                HeaderRegion header = new HeaderRegion();
                if (headerCurrentDay.DayOfWeek == DayOfWeek.Saturday || headerCurrentDay.DayOfWeek == DayOfWeek.Sunday)
                {
                    header.Name = "Saturday/Sunday";
                }
                else
                {
                    header.Name = headerCurrentDay.DayOfWeek.ToString();
                }

                header.Bounds = new Rectangle(xHeaderCurrent, monthNameHeight, dayWidth, dayNameHeight);
                headers.Add(header);
                xHeaderCurrent  += dayWidth;
                headerCurrentDay = headerCurrentDay.AddDays(1);
            }

            //set up the days themselves
            for (int i = 0; i < 42; i++)
            {
                DayRegion day = new DayRegion();
                day.Date             = currentDay;
                day.IsInCurrentMonth = (currentDay.Month == Date.Month);

                //if we're up to end of slot, reset it
                if (day.Date.DayOfWeek == DayOfWeek.Monday)
                {
                    xCurrent = 0;
                }

                //Combine saturday and sunday with split bounds
                if (currentDay.DayOfWeek == DayOfWeek.Saturday)
                {
                    day.Bounds      = new Rectangle(xCurrent, yCurrent, dayWidth, saturdayHeight);
                    day.TitleBounds = new Rectangle(xCurrent + 1, yCurrent + 1, dayWidth - 2, itemHeight);
                    day.BodyBounds  = new Rectangle(day.Bounds.X, day.Bounds.Y + day.TitleBounds.Height, day.Bounds.Width, day.Bounds.Height - day.TitleBounds.Height);// day.Bounds;
                }
                else if (currentDay.DayOfWeek == DayOfWeek.Sunday)
                {
                    day.Bounds      = new Rectangle(xCurrent, yCurrent + saturdayHeight, dayWidth, sundayHeight);
                    day.TitleBounds = new Rectangle(xCurrent + 1, yCurrent + saturdayHeight + 1, dayWidth - 2, itemHeight);
                    day.BodyBounds  = new Rectangle(day.Bounds.X, day.Bounds.Y + day.TitleBounds.Height, day.Bounds.Width, day.Bounds.Height - day.TitleBounds.Height);// day.Bounds;
                }
                else
                {
                    day.Bounds      = new Rectangle(xCurrent, yCurrent, dayWidth, dayHeight);
                    day.TitleBounds = new Rectangle(xCurrent + 1, yCurrent + 1, dayWidth - 2, itemHeight);
                    day.BodyBounds  = new Rectangle(day.Bounds.X, day.Bounds.Y + day.TitleBounds.Height, day.Bounds.Width, day.Bounds.Height - day.TitleBounds.Height);// day.Bounds;
                    xCurrent       += dayWidth;
                }

                if (day.Date.DayOfWeek == DayOfWeek.Sunday)
                {
                    yCurrent += dayHeight;
                }
                days.Add(day);

                currentDay = currentDay.AddDays(1);
            }

            BoundsValidTimeSlot = true;
        }
示例#2
0
        /// <summary>
        /// Calculate the time slot bounds. This works out the size and
        /// shape that days will take up on the screen. This method
        /// is called from OnPaint only when the property BoundsValidTimeSlot
        /// is set to false (this property is set to false in cases such as
        /// when the control has been resized or the date shown has
        /// changed).
        /// </summary>
        protected override void CalculateTimeSlotBounds(Graphics g)
        {
            if (Width == 0 || Height == 0)
            {
                return;
            }

            DayRegions.Clear();
            hourHeaders.Clear();

            int numberOfDays = 1;

            //set up the start day
            if (!SingleDay)
            {
                //five days
                numberOfDays = 5;
                if (Date.DayOfWeek != DayOfWeek.Monday)
                {
                    //handle sunday being set - go forwards in that case
                    if (Date.DayOfWeek == DayOfWeek.Sunday)
                    {
                        Date = Date.AddDays(1);
                    }
                    else if (Date.DayOfWeek == DayOfWeek.Saturday)
                    {
                        Date = Date.AddDays(2);
                    }
                    else
                    {
                        DateTime temp = Date;
                        while (temp.DayOfWeek != DayOfWeek.Monday)
                        {
                            temp = temp.AddDays(-1);
                        }
                        Date = temp;
                    }
                }
            }

            //set up days
            for (int i = 0; i < numberOfDays; i++)
            {
                DayWithHourRegion day = new DayWithHourRegion();
                day.Date             = Date.AddDays(i);
                day.IsInCurrentMonth = true;
                this.DayRegions.Add(day);
            }

            int hourCount = 0;

            //set up hours
            for (int j = 0; j < DayRegions.Count; j++)
            {
                DayWithHourRegion day = DayRegions[j] as DayWithHourRegion;
                if (day != null)
                {
                    for (int i = 0; i < 24; i++)
                    {
                        if (RenderWorkingHoursOnly)
                        {
                            if (i >= (WorkStartHour - 1) && i < (WorkEndHour + 1))
                            {
                                HourRegion hour = new HourRegion();
                                hour.IsWorkingHour = (i >= WorkStartHour && i < WorkEndHour);
                                hour.Hour          = i;
                                day.Hours.Add(hour);
                            }
                        }
                        else
                        {
                            HourRegion hour = new HourRegion();
                            hour.IsWorkingHour = (i >= WorkStartHour && i < WorkEndHour);
                            hour.Hour          = i;
                            day.Hours.Add(hour);
                        }
                    }
                    if (j == 0)
                    {
                        hourCount = day.Hours.Count;
                    }
                }
            }

            int timeMarkerWidth = 0;

            if (this.Width > 120)
            {
                timeMarkerWidth = 80;
            }

            int dayHeaderHeight = (int)(RendererCache.Current.Header.GetTextInfo(g, this.Font).Height * 1.2);

            int hourHeight = ((Height - 1 - dayHeaderHeight) / hourCount);
            int xCurrent   = timeMarkerWidth;
            int hourWidth  = (Width - timeMarkerWidth - 1) / numberOfDays;

            int bounds15height = (hourHeight) / 4;

            //set up day and hour bounds
            for (int j = 0; j < DayRegions.Count; j++)
            {
                DayWithHourRegion day = DayRegions[j] as DayWithHourRegion;

                if (day != null)
                {
                    int yCurrent = dayHeaderHeight;
                    //set up day bounds
                    day.Bounds      = new Rectangle(xCurrent, 0, hourWidth, hourHeight * day.Hours.Count);
                    day.Name        = day.Date.DayOfWeek.ToString();
                    day.TitleBounds = new Rectangle(xCurrent, 0, hourWidth, dayHeaderHeight);
                    day.BodyBounds  = new Rectangle(day.Bounds.X, day.Bounds.Y, day.Bounds.Width, day.Bounds.Height);


                    foreach (HourRegion hour in day.Hours)
                    {
                        //work out the hour bounds
                        hour.Bounds = new Rectangle(xCurrent, yCurrent, hourWidth, hourHeight);

                        //work out the 15 minute divisions
                        hour.Bounds00 = new Rectangle(xCurrent, yCurrent, hourWidth, bounds15height);
                        hour.Bounds15 = new Rectangle(xCurrent, yCurrent + hour.Bounds00.Height, hourWidth,
                                                      bounds15height);
                        hour.Bounds30 = new Rectangle(xCurrent, yCurrent + hour.Bounds00.Height + hour.Bounds15.Height,
                                                      hourWidth, bounds15height);
                        hour.Bounds45 = new Rectangle(xCurrent,
                                                      yCurrent + hour.Bounds00.Height + hour.Bounds15.Height +
                                                      hour.Bounds30.Height, hourWidth,
                                                      bounds15height);

                        if (j == 0)
                        {
                            HeaderRegion header = new HeaderRegion();
                            header.Bounds = new Rectangle(0, yCurrent, timeMarkerWidth, hourHeight);
                            header.Name   = string.Format("{0}:00", hour.Hour);
                            hourHeaders.Add(header);
                        }
                        yCurrent += hourHeight;
                    }
                }
                xCurrent += hourWidth;
            }
            BoundsValidTimeSlot = true;
        }
示例#3
0
        protected override Region CreateEntity()
        {
            RegionTable table    = _regionTableElement.Entity;
            ProductRule prodRule = table.ProductRule;

            string tmpStr = _data.GetAttribute("type");

            if (string.IsNullOrEmpty(tmpStr))
            {
                return(null);
            }
            _entity = "corner".Equals(tmpStr.ToLower()) ? (Region) new CornerRegion(table) :
                      "rowheader".Equals(tmpStr.ToLower()) ? new RowHeaderRegion(table) :
                      "columnheader".Equals(tmpStr.ToLower()) ? (Region) new ColumnHeaderRegion(table) :
                      new BodyRegion(table);
            tmpStr = _data.GetAttribute("source");
            if (!string.IsNullOrEmpty(tmpStr))
            {
                string[] values = tmpStr.Split('.');
                if (values.Length > 1)
                {
                    _entity.Field = values[1];
                }
                _entity.Source = prodRule.RegistSource(values[0]);
            }
            _entity.EmptyFill = _data.GetAttribute("emptyFill");

            if (_entity is BodyRegion)
            {
                //暂无逻辑
            }
            else if (_entity is HeaderRegion)
            {
                HeaderRegion header = _entity as HeaderRegion;
                header.Source = parseTreeSource(tmpStr, _data.GetAttribute("innerMapping"), prodRule) ?? header.Source;

                tmpStr = _data.GetAttribute("headerBodyMapping");
                header.HeaderBodyRelation = parseRelation(header.Source, tmpStr, prodRule);
                //tmpStr = _data.GetAttribute("treeSource");
                //header.TreeSource = parseTreeSource(tmpStr, _data.GetAttribute("treeInnerMapping"), prodRule);
                ////header.IdField = element.GetAttribute("IdField");
                ////header.ParentField = element.GetAttribute("parentField");
                //tmpStr = _data.GetAttribute("headerTreeMapping");
                //header.HeaderTreeRelation = parseRelation(header.Source, tmpStr, prodRule);
                //if (header.HeaderTreeRelation != null)
                //{
                //    header.HeaderTreeRelation.ReferecedSource = header.TreeSource;
                header.MaxLevel     = ParseUtil.ParseInt(_data.GetAttribute("maxLevel"), -1);
                header.ColSpannable = ParseUtil.ParseBoolean(_data.GetAttribute("colSpannable"));
                header.RowSpannable = ParseUtil.ParseBoolean(_data.GetAttribute("rowSpannable"));
                header.IsBasedOn    = ParseUtil.ParseBoolean(_data.GetAttribute("basedSource"));
                //}
            }
            else if (_entity is CornerRegion)
            {
                tmpStr = _data.GetAttribute("spanRule");
                if (!string.IsNullOrEmpty(tmpStr))
                {
                    CornerSpanRule spanRule = CornerSpanRule.None;
                    if (!Enum.TryParse(tmpStr, true, out spanRule))
                    {
                        spanRule = "row".Equals(tmpStr.ToLower()) ? CornerSpanRule.BaseOnRowHeader :
                                   "column".Equals(tmpStr.ToLower()) ? CornerSpanRule.BaseOnColumnHeader :
                                   "one".Equals(tmpStr.ToLower()) ? CornerSpanRule.AllInOne : CornerSpanRule.None;
                    }
                    (_entity as CornerRegion).SpanRule = spanRule;
                }
            }
            return(_entity);
        }