示例#1
0
		public void DefaultConstructor_ToString ()
		{
			SelectionRange sr = new SelectionRange ();
			// "9999-12-31 00:00:00", note not 23:59:59.
			Assert.AreEqual (string.Format ("SelectionRange: Start: {0}, End: {1}", new DateTime (1, 1, 1).ToString (), new DateTime (9999, 12, 31).ToString ()),
			   sr.ToString (), "ToString");
		}
示例#2
0
		public void TwoDatesConstructor_WithTime ()
		{
			// Apparenly any time value is stripped, found while testing PropertyGrid.
			SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11, 13, 14, 15), new DateTime (2008, 2, 17));
			Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
			Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
		}
 public SelectionRange(SelectionRange range)
 {
     this.start = DateTime.MinValue.Date;
     this.end = DateTime.MaxValue.Date;
     this.start = range.start;
     this.end = range.end;
 }
示例#4
0
    /// <summary>
    /// Gets the dates indexed.
    /// </summary>
    /// <param name="start">The start.</param>
    /// <param name="end">The end.</param>
    /// <returns></returns>
    public static DateTime[] GetDatesIndexed(SelectionRange dateRange){
      DateTime[] result       = new DateTime[(dateRange.End.Day - dateRange.Start.Day) + 1];

      for (int ct = 0; ct < result.Length; ct++) {
        result[ct]            = dateRange.Start.AddDays(ct);
      }
      return result;
    }
示例#5
0
		public void DefaultConstructor ()
		{
			SelectionRange sr = new SelectionRange ();
			Assert.AreEqual (DateTime.MinValue, sr.Start, "Start");
			// "9999-12-31 00:00:00", note not 23:59:59.
			Assert.AreEqual (DateTime.MaxValue.Date, sr.End, "End");

			Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
			Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
		}
        private void InitDateRange()
        {
            Logger.Enter();
            m_rng = monthCalendar.GetDisplayRange(true);
            String where = String.Format("id >= '{0}' and id <= '{1}'"
                , m_rng.Start
                , m_rng.End);

            foreach (dbDataSet.trainersScheduleRow tsr in Db.Instance.dSet.trainersSchedule.Select(where))
            {
                m_date2TrainerMap[tsr.id] = tsr.trainerId;
            }

            for (DateTime dt = m_rng.Start; dt <= m_rng.End; dt = dt.AddDays(1))
            {
                if (!m_date2TrainerMap.ContainsKey(dt))
                {
                    monthCalendar.AddAnnuallyBoldedDate(dt);
                }
            }
            monthCalendar.UpdateBoldedDates();
            Logger.Leave();
        }
示例#7
0
      /// <summary>
      /// Raises the <see cref="System.Windows.Forms.Control.MouseDown"/> event.
      /// </summary>
      /// <param name="e">A <see cref="MouseEventArgs"/> that contains the event data.</param>
      protected override void OnMouseDown(MouseEventArgs e)
      {
         base.OnMouseDown(e);

         this.Focus();

         this.Capture = true;

         // reset the selection range where selection started
         this.selectionStartRange = null;

         if (e.Button == MouseButtons.Left)
         {
            // perform hit test
            MonthCalendarHitTest hit = this.HitTest(e.Location);

            // set current bounds
            this.currentMoveBounds = hit.Bounds;

            // set current hit type
            this.currentHitType = hit.Type;

            switch (hit.Type)
            {
               case MonthCalendarHitType.Day:
                  {
                     // save old selection range
                     SelectionRange oldRange = this.SelectionRange;

                     if (!this.extendSelection || this.daySelectionMode != MonthCalendarSelectionMode.Manual)
                     {
                        // clear all selection ranges
                        this.selectionRanges.Clear();
                     }

                     switch (this.daySelectionMode)
                     {
                        case MonthCalendarSelectionMode.Day:
                           {
                              this.OnDateClicked(new DateEventArgs(hit.Date));

                              // only single days are selectable
                              if (this.selectionStart != hit.Date)
                              {
                                 this.SelectionStart = hit.Date;

                                 this.RaiseDateSelected();
                              }

                              break;
                           }

                        case MonthCalendarSelectionMode.WorkWeek:
                           {
                              // only single work week is selectable
                              // get first day of week
                              DateTime firstDay = new MonthCalendarDate(this.CultureCalendar, hit.Date).GetFirstDayInWeek(this.formatProvider).Date;

                              // get work days
                              List<DayOfWeek> workDays = DateMethods.GetWorkDays(this.nonWorkDays);

                              // reset selection start and end
                              this.selectionEnd = DateTime.MinValue;
                              this.selectionStart = DateTime.MinValue;

                              // current range
                              SelectionRange currentRange = null;

                              // build selection ranges for work days
                              for (int i = 0; i < 7; i++)
                              {
                                 DateTime toAdd = firstDay.AddDays(i);

                                 if (workDays.Contains(toAdd.DayOfWeek))
                                 {
                                    if (currentRange == null)
                                    {
                                       currentRange = new SelectionRange(DateTime.MinValue, DateTime.MinValue);
                                    }

                                    if (currentRange.Start == DateTime.MinValue)
                                    {
                                       currentRange.Start = toAdd;
                                    }
                                    else
                                    {
                                       currentRange.End = toAdd;
                                    }
                                 }
                                 else if (currentRange != null)
                                 {
                                    this.selectionRanges.Add(currentRange);

                                    currentRange = null;
                                 }
                              }

                              if (this.selectionRanges.Count >= 1)
                              {
                                 // set first selection range
                                 this.SelectionRange = this.selectionRanges[0];
                                 this.selectionRanges.RemoveAt(0);

                                 // if selection range changed, raise event
                                 if (this.SelectionRange != oldRange)
                                 {
                                    this.RaiseDateSelected();
                                 }
                              }
                              else
                              {
                                 this.Refresh();
                              }

                              break;
                           }

                        case MonthCalendarSelectionMode.FullWeek:
                           {
                              // only a full week is selectable
                              // get selection start and end
                              MonthCalendarDate dt =
                                 new MonthCalendarDate(this.CultureCalendar, hit.Date).GetFirstDayInWeek(
                                    this.formatProvider);

                              this.selectionStart = dt.Date;
                              this.selectionEnd = dt.GetEndDateOfWeek(this.formatProvider).Date;

                              // if range changed, raise event
                              if (this.SelectionRange != oldRange)
                              {
                                 this.RaiseDateSelected();

                                 this.Refresh();
                              }

                              break;
                           }

                        case MonthCalendarSelectionMode.Month:
                           {
                              // only a full month is selectable
                              MonthCalendarDate dt = new MonthCalendarDate(this.CultureCalendar, hit.Date).FirstOfMonth;

                              // get selection start and end
                              this.selectionStart = dt.Date;
                              this.selectionEnd = dt.AddMonths(1).AddDays(-1).Date;

                              // if range changed, raise event
                              if (this.SelectionRange != oldRange)
                              {
                                 this.RaiseDateSelected();

                                 this.Refresh();
                              }

                              break;
                           }

                        case MonthCalendarSelectionMode.Manual:
                           {
                              if (this.extendSelection)
                              {
                                 var range = this.selectionRanges.Find(r => hit.Date >= r.Start && hit.Date <= r.End);

                                 if (range != null)
                                 {
                                    this.selectionRanges.Remove(range);
                                 }
                              }

                              // manual mode - selection ends when user is releasing the left mouse button
                              this.selectionStarted = true;
                              this.backupRange = this.SelectionRange;
                              this.selectionEnd = DateTime.MinValue;
                              this.SelectionStart = hit.Date;

                              break;
                           }
                     }

                     break;
                  }

               case MonthCalendarHitType.Week:
                  {
                     this.selectionRanges.Clear();

                     if (this.maxSelectionCount > 6 || this.maxSelectionCount == 0)
                     {
                        this.backupRange = this.SelectionRange;
                        this.selectionStarted = true;
                        this.selectionEnd = new MonthCalendarDate(this.CultureCalendar, hit.Date).GetEndDateOfWeek(this.formatProvider).Date;
                        this.SelectionStart = hit.Date;

                        this.selectionStartRange = this.SelectionRange;
                     }

                     break;
                  }

               case MonthCalendarHitType.MonthName:
                  {
                     this.monthSelected = hit.Date;
                     this.mouseMoveFlags.HeaderDate = hit.Date;

                     this.Invalidate(hit.InvalidateBounds);
                     this.Update();

                     this.monthMenu.Tag = hit.Date;
                     this.UpdateMonthMenu(this.CultureCalendar.GetYear(hit.Date));

                     this.showingMenu = true;

                     // show month menu
                     this.monthMenu.Show(this, hit.Bounds.Right, e.Location.Y);

                     break;
                  }

               case MonthCalendarHitType.MonthYear:
                  {
                     this.yearSelected = hit.Date;
                     this.mouseMoveFlags.HeaderDate = hit.Date;

                     this.Invalidate(hit.InvalidateBounds);
                     this.Update();

                     this.UpdateYearMenu(this.CultureCalendar.GetYear(hit.Date));

                     this.yearMenu.Tag = hit.Date;

                     this.showingMenu = true;

                     // show year menu
                     this.yearMenu.Show(this, hit.Bounds.Right, e.Location.Y);

                     break;
                  }

               case MonthCalendarHitType.Arrow:
                  {
                     // an arrow was pressed
                     // set new start date
                     if (this.SetStartDate(hit.Date))
                     {
                        // update months
                        this.UpdateMonths();

                        // raise event
                        this.RaiseDateChanged();

                        this.mouseMoveFlags.HeaderDate = this.leftArrowRect.Contains(e.Location) ?
                           this.months[0].Date : this.months[this.calendarDimensions.Width - 1].Date;

                        this.Refresh();
                     }

                     break;
                  }

               case MonthCalendarHitType.Footer:
                  {
                     // footer was pressed
                     this.selectionRanges.Clear();

                     bool raiseDateChanged = false;

                     SelectionRange range = this.SelectionRange;

                     // determine if date changed event has to be raised
                     if (DateTime.Today < this.months[0].FirstVisibleDate || DateTime.Today > this.lastVisibleDate)
                     {
                        // set new start date
                        if (this.SetStartDate(DateTime.Today))
                        {
                           // update months
                           this.UpdateMonths();

                           raiseDateChanged = true;
                        }
                        else
                        {
                           break;
                        }
                     }

                     // set new selection start and end values
                     this.selectionStart = DateTime.Today;
                     this.selectionEnd = DateTime.Today;

                     this.SetSelectionRange(this.daySelectionMode);

                     this.OnDateClicked(new DateEventArgs(DateTime.Today));

                     // raise events if necessary
                     if (range != this.SelectionRange)
                     {
                        this.RaiseDateSelected();
                     }

                     if (raiseDateChanged)
                     {
                        this.RaiseDateChanged();
                     }

                     this.Refresh();

                     break;
                  }

               case MonthCalendarHitType.Header:
                  {
                     // header was pressed
                     this.Invalidate(hit.Bounds);
                     this.Update();

                     break;
                  }
            }
         }
      }
示例#8
0
		public void TwoDatesConstructor_WithTime2 ()
		{
			// Apparenly any time value is stripped, found while testing PropertyGrid.
			SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17, 1, 2, 3));
			Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
			Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
#if NET_2_0
			Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
			Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
#endif
		}
示例#9
0
        /// <include file='doc\MonthCalendar.uex' path='docs/doc[@for="MonthCalendar.GetMonthRange"]/*' />
        /// <devdoc>
        /// </devdoc>
        /// <internalonly/>
        private SelectionRange GetMonthRange(int flag) {
            NativeMethods.SYSTEMTIMEARRAY sa = new NativeMethods.SYSTEMTIMEARRAY();
            SelectionRange range = new SelectionRange();
            UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.MCM_GETMONTHRANGE, flag, sa);

            NativeMethods.SYSTEMTIME st = new NativeMethods.SYSTEMTIME();
            st.wYear = sa.wYear1;
            st.wMonth = sa.wMonth1;
            st.wDayOfWeek = sa.wDayOfWeek1;
            st.wDay = sa.wDay1;

            range.Start = DateTimePicker.SysTimeToDateTime(st);
            st.wYear = sa.wYear2;
            st.wMonth = sa.wMonth2;
            st.wDayOfWeek = sa.wDayOfWeek2;
            st.wDay = sa.wDay2;
            range.End = DateTimePicker.SysTimeToDateTime(st);

            return range;
        }
示例#10
0
		// constructor that receives another range, copies it's Start and End values
		public SelectionRange (SelectionRange range) {
			end = range.End;
			start = range.Start;
		}
 public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
 {
     object obj2;
     try
     {
         obj2 = new SelectionRange((DateTime) propertyValues["Start"], (DateTime) propertyValues["End"]);
     }
     catch (InvalidCastException exception)
     {
         throw new ArgumentException(System.Windows.Forms.SR.GetString("PropertyValueInvalidEntry"), exception);
     }
     catch (NullReferenceException exception2)
     {
         throw new ArgumentException(System.Windows.Forms.SR.GetString("PropertyValueInvalidEntry"), exception2);
     }
     return obj2;
 }
 public MonCal(DateTime mes,List<HighlightedDates> HighlightedDates,Horario horario)
 {
     this.horario = horario;
     this.ShowTodayCircle = false;
     this.SelectionStart = mes;
     this.highlightedDates = HighlightedDates;
     range = GetDisplayRange(false);
     SetDayBoxSize();
     SetPosition(this.highlightedDates);
 }
		public void SelectionRange()
		{
			SelectionRange expectedRange = new SelectionRange(new DateTime(2009, 8, 4, 0, 0, 0, 0), new DateTime(2009, 8, 5, 0, 0, 0, 0));
			Assert.AreEqual(expectedRange.ToString(), Calendar.SelectionRange.ToString());
		}
示例#14
0
 public CSchedulTimes(int Hours, int Minutes, SelectionRange Dates)
 {
     if (Hours < 0 || Hours > 23 || Minutes < 0 || Minutes > 59)
         throw new Exception("Время указано неверно");
     this.Hours = Hours;
     this.Minutes = Minutes;
     this.Dates = Dates;
 }
示例#15
0
		public void GetDisplayRangeTest ()
		{
			Form myForm = new Form ();
			myForm.ShowInTaskbar = false;
			MonthCalendar myMonthCal = new MonthCalendar ();
			myForm.Controls.Add (myMonthCal);
			SelectionRange mySelRange = new SelectionRange ();
			mySelRange.Start = new DateTime (DateTime.Now.Year, DateTime.Now.Month, 1);
			mySelRange.End = mySelRange.Start.AddMonths (1).AddDays (-1);
			Assert.AreEqual (mySelRange.Start, myMonthCal.GetDisplayRange (true).Start, "#Get1");
			Assert.AreEqual (mySelRange.End, myMonthCal.GetDisplayRange (true).End, "#Get22");
			myForm.Dispose ();
		}
示例#16
0
		// called in response to users seletion with shift key
		private void AddTimeToSelection (int delta, bool isDays)
		{
			DateTime cursor_point;
			DateTime end_point;
			// okay we add the period to the date that is not the same as the 
			// start date when shift was first clicked.
			if (SelectionStart != first_select_start_date) {
				cursor_point = SelectionStart;
			} else {
				cursor_point = SelectionEnd;
			}
			// add the days
			if (isDays) {
				end_point = cursor_point.AddDays (delta);
			} else {
				// delta must be months
				end_point = cursor_point.AddMonths (delta);
			}
			// set the new selection range
			SelectionRange range = new SelectionRange (first_select_start_date, end_point);
			if (range.Start.AddDays (MaxSelectionCount-1) < range.End) {
				// okay the date is beyond what is allowed, lets set the maximum we can
				if (range.Start != first_select_start_date) {
					range.Start = range.End.AddDays ((MaxSelectionCount-1)*-1);
				} else {
					range.End = range.Start.AddDays (MaxSelectionCount-1);
				}
			}

			// Avoid re-setting SelectionRange to the same value and fire an extra DateChanged event
			if (range.Start != selection_range.Start || range.End != selection_range.End)
				SelectionRange = range;
		}
示例#17
0
 public bool InRange(SelectionRange what)
 {
     DateTime dStart = Dates.Start;
     if (what.End.Year == dStart.Year)
     {
         if (what.End.Month == dStart.Month)
         {
             if (what.End.Day < dStart.Day)
                 return false;
             else
                 if (what.End.Day == dStart.Day)
                     return true;
         }
         else
             if (what.End.Month < dStart.Month)
                 return false;
     }
     else
         if (what.End.Year < dStart.Year)
             return false;
     DateTime dEnd = Dates.End;
     if (what.Start.Year == dEnd.Year)
     {
         if (what.Start.Month == dEnd.Month)
         {
             if (what.Start.Day > dEnd.Day)
                 return false;
         }
         else
             if (what.Start.Month > dEnd.Month)
                 return false;
     }
     else
         if (what.Start.Year > dEnd.Year)
             return false;
     return true;
 }
示例#18
0
		public MonthCalendar () {
			// set up the control painting
			SetStyle (ControlStyles.UserPaint | ControlStyles.StandardClick, false);
			
			// mouse down timer
			timer = new Timer ();
			timer.Interval = 500;
			timer.Enabled = false;
			
			// initialise default values 
			DateTime now = DateTime.Now.Date;
			selection_range = new SelectionRange (now, now);
			today_date = now;
			current_month = new DateTime (now.Year , now.Month, 1);

			// iniatialise local members
			annually_bolded_dates = null;
			bolded_dates = null;
			calendar_dimensions = new Size (1,1);
			first_day_of_week = Day.Default;
			max_date = new DateTime (9998, 12, 31);
			max_selection_count = 7;
			min_date = new DateTime (1753, 1, 1);
			monthly_bolded_dates = null;
			scroll_change = 0;
			show_today = true;
			show_today_circle = true;
			show_week_numbers = false;
			title_back_color = ThemeEngine.Current.ColorActiveCaption;
			title_fore_color = ThemeEngine.Current.ColorActiveCaptionText;
			today_date_set = false;
			trailing_fore_color = SystemColors.GrayText;
			bold_font = new Font (Font, Font.Style | FontStyle.Bold);
			centered_format = new StringFormat (StringFormat.GenericTypographic);
			centered_format.FormatFlags = centered_format.FormatFlags | StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox;
			centered_format.FormatFlags &= ~StringFormatFlags.NoClip;
			centered_format.LineAlignment = StringAlignment.Center;
			centered_format.Alignment = StringAlignment.Center;
			
			// Set default values
			ForeColor = SystemColors.WindowText;
			BackColor = ThemeEngine.Current.ColorWindow;
		
			// intiailise internal variables used
			button_x_offset = 5;
			button_size = new Size (22, 17);
			// default settings based on 8.25 pt San Serif Font
			// Not sure of algorithm used to establish this
			date_cell_size = new Size (24, 16);		// default size at san-serif 8.25
			divider_line_offset = 4;
			calendar_spacing = new Size (4, 5);		// horiz and vert spacing between months in a calendar grid

			// set some state info
			clicked_date = now;
			is_date_clicked = false;
			is_previous_clicked = false;
			is_next_clicked = false;
			is_shift_pressed = false;
			click_state = new bool [] {false, false, false};
			first_select_start_date = now;
			month_title_click_location = Point.Empty;

			// set up context menus
			SetUpTodayMenu ();
			SetUpMonthMenu ();
			
			// event handlers
			timer.Tick += new EventHandler (TimerHandler);
			MouseMove += new MouseEventHandler (MouseMoveHandler);
			MouseDown += new MouseEventHandler (MouseDownHandler);
			KeyDown += new KeyEventHandler (KeyDownHandler);
			MouseUp += new MouseEventHandler (MouseUpHandler);
			KeyUp += new KeyEventHandler (KeyUpHandler);
			
			// this replaces paint so call the control version
			base.Paint += new PaintEventHandler (PaintHandler);
			
			Size = DefaultSize;
		}
示例#19
0
 // constructor that receives another range, copies it's Start and End values
 public SelectionRange(SelectionRange range)
 {
     end   = range.End;
     start = range.Start;
 }
示例#20
0
 public static Range <DateTime> ToEto(this swf.SelectionRange range)
 {
     return(new Range <DateTime>(range.Start, range.End));
 }
示例#21
0
      /// <summary>
      /// Raises the <see cref="System.Windows.Forms.Control.MouseMove"/> event.
      /// </summary>
      /// <param name="e">A <see cref="MouseEventArgs"/> that contains the event data.</param>
      protected override void OnMouseMove(MouseEventArgs e)
      {
         base.OnMouseMove(e);

         if (e.Location == this.mouseLocation)
         {
            return;
         }

         this.mouseLocation = e.Location;

         // backup and reset mouse move flags
         this.mouseMoveFlags.BackupAndReset();

         // perform hit test
         MonthCalendarHitTest hit = this.HitTest(e.Location);

         if (e.Button == MouseButtons.Left)
         {
            // if selection started - only in manual selection mode
            if (this.selectionStarted)
            {
               // if selection started with hit type Day and mouse is over new date
               if (hit.Type == MonthCalendarHitType.Day
                  && this.currentHitType == MonthCalendarHitType.Day
                  && this.currentMoveBounds != hit.Bounds)
               {
                  this.currentMoveBounds = hit.Bounds;

                  // set new selection end
                  this.SelectionEnd = hit.Date;
               }
               else if (hit.Type == MonthCalendarHitType.Week
                  && this.currentHitType == MonthCalendarHitType.Week)
               {
                  // set indicator that a week header element is selected
                  this.mouseMoveFlags.WeekHeader = true;

                  // get new end date
                  DateTime endDate = new MonthCalendarDate(this.CultureCalendar, hit.Date).AddDays(6).Date;

                  // if new week header element
                  if (this.currentMoveBounds != hit.Bounds)
                  {
                     this.currentMoveBounds = hit.Bounds;

                     // check if selection is switched
                     if (this.selectionStart == this.selectionStartRange.End)
                     {
                        // are we after the original end date?
                        if (endDate > this.selectionStart)
                        {
                           // set original start date
                           this.selectionStart = this.selectionStartRange.Start;

                           // set new end date
                           this.SelectionEnd = endDate;
                        }
                        else
                        {
                           // going backwards - set new "end" date - it's now the start date
                           this.SelectionEnd = hit.Date;
                        }
                     }
                     else
                     {
                        // we are after the start date
                        if (endDate > this.selectionStart)
                        {
                           // set end date
                           this.SelectionEnd = endDate;
                        }
                        else
                        {
                           // switch start and end
                           this.selectionStart = this.selectionStartRange.End;
                           this.SelectionEnd = hit.Date;
                        }
                     }
                  }
               }
            }
            else
            {
               switch (hit.Type)
               {
                  case MonthCalendarHitType.MonthName:
                     {
                        this.mouseMoveFlags.MonthName = hit.Date;
                        this.mouseMoveFlags.HeaderDate = hit.Date;

                        this.Invalidate(hit.InvalidateBounds);

                        break;
                     }

                  case MonthCalendarHitType.MonthYear:
                     {
                        this.mouseMoveFlags.Year = hit.Date;
                        this.mouseMoveFlags.HeaderDate = hit.Date;

                        this.Invalidate(hit.InvalidateBounds);

                        break;
                     }

                  case MonthCalendarHitType.Header:
                     {
                        this.mouseMoveFlags.HeaderDate = hit.Date;
                        this.Invalidate(hit.InvalidateBounds);

                        break;
                     }

                  case MonthCalendarHitType.Arrow:
                     {
                        bool useRTL = this.UseRTL;

                        if (this.leftArrowRect.Contains(e.Location))
                        {
                           this.mouseMoveFlags.LeftArrow = !useRTL;
                           this.mouseMoveFlags.RightArrow = useRTL;

                           this.mouseMoveFlags.HeaderDate = this.months[0].Date;
                        }
                        else
                        {
                           this.mouseMoveFlags.LeftArrow = useRTL;
                           this.mouseMoveFlags.RightArrow = !useRTL;

                           this.mouseMoveFlags.HeaderDate = this.months[this.calendarDimensions.Width - 1].Date;
                        }

                        this.Invalidate(hit.InvalidateBounds);

                        break;
                     }

                  case MonthCalendarHitType.Footer:
                     {
                        this.mouseMoveFlags.Footer = true;

                        this.Invalidate(hit.InvalidateBounds);

                        break;
                     }

                  default:
                     {
                        this.Invalidate();

                        break;
                     }
               }
            }
         }
         else if (e.Button == MouseButtons.None)
         {
            // no mouse button is pressed
            // set flags and invalidate corresponding region
            switch (hit.Type)
            {
               case MonthCalendarHitType.Day:
                  {
                     this.mouseMoveFlags.Day = hit.Date;

                     var bold = this.GetBoldedDates().Contains(hit.Date) || this.boldDatesCollection.Exists(d => d.Value.Date == hit.Date.Date);

                     this.OnActiveDateChanged(new ActiveDateChangedEventArgs(hit.Date, bold));

                     this.InvalidateMonth(hit.Date, true);

                     break;
                  }

               case MonthCalendarHitType.Week:
                  {
                     this.mouseMoveFlags.WeekHeader = true;

                     break;
                  }

               case MonthCalendarHitType.MonthName:
                  {
                     this.mouseMoveFlags.MonthName = hit.Date;
                     this.mouseMoveFlags.HeaderDate = hit.Date;

                     break;
                  }

               case MonthCalendarHitType.MonthYear:
                  {
                     this.mouseMoveFlags.Year = hit.Date;
                     this.mouseMoveFlags.HeaderDate = hit.Date;

                     break;
                  }

               case MonthCalendarHitType.Header:
                  {
                     this.mouseMoveFlags.HeaderDate = hit.Date;

                     break;
                  }

               case MonthCalendarHitType.Arrow:
                  {
                     bool useRTL = this.UseRTL;

                     if (this.leftArrowRect.Contains(e.Location))
                     {
                        this.mouseMoveFlags.LeftArrow = !useRTL;
                        this.mouseMoveFlags.RightArrow = useRTL;

                        this.mouseMoveFlags.HeaderDate = this.months[0].Date;
                     }
                     else if (this.rightArrowRect.Contains(e.Location))
                     {
                        this.mouseMoveFlags.LeftArrow = useRTL;
                        this.mouseMoveFlags.RightArrow = !useRTL;

                        this.mouseMoveFlags.HeaderDate = this.months[this.calendarDimensions.Width - 1].Date;
                     }

                     break;
                  }

               case MonthCalendarHitType.Footer:
                  {
                     this.mouseMoveFlags.Footer = true;

                     break;
                  }
            }

            // if left arrow state changed
            if (this.mouseMoveFlags.LeftArrowChanged)
            {
               this.Invalidate(this.UseRTL ? this.rightArrowRect : this.leftArrowRect);

               this.Update();
            }

            // if right arrow state changed
            if (this.mouseMoveFlags.RightArrowChanged)
            {
               this.Invalidate(this.UseRTL ? this.leftArrowRect : this.rightArrowRect);

               this.Update();
            }

            // if header state changed
            if (this.mouseMoveFlags.HeaderDateChanged)
            {
               this.Invalidate();
            }
            else if (this.mouseMoveFlags.MonthNameChanged || this.mouseMoveFlags.YearChanged)
            {
               // if state of month name or year in header changed
               SelectionRange range1 = new SelectionRange(this.mouseMoveFlags.MonthName, this.mouseMoveFlags.Backup.MonthName);

               SelectionRange range2 = new SelectionRange(this.mouseMoveFlags.Year, this.mouseMoveFlags.Backup.Year);

               this.Invalidate(this.months[this.GetIndex(range1.End)].TitleBounds);

               if (range1.End != range2.End)
               {
                  this.Invalidate(this.months[this.GetIndex(range2.End)].TitleBounds);
               }
            }

            // if day state changed
            if (this.mouseMoveFlags.DayChanged)
            {
               // invalidate current day
               this.InvalidateMonth(this.mouseMoveFlags.Day, false);

               // invalidate last day
               this.InvalidateMonth(this.mouseMoveFlags.Backup.Day, false);
            }

            // if footer state changed
            if (this.mouseMoveFlags.FooterChanged)
            {
               this.Invalidate(this.footerRect);
            }
         }

         // if mouse is over a week header, change cursor
         if (this.mouseMoveFlags.WeekHeaderChanged)
         {
            this.Cursor = this.mouseMoveFlags.WeekHeader ? Cursors.UpArrow : Cursors.Default;
         }
      }
示例#22
0
 public TextEditor(int capacity)
 {
     selection = new SelectionRange(0, 0);
     buffer = new StringBuilder(capacity);
 }
示例#23
0
		// attempts to add the date to the selection without throwing exception
		private void SelectDate (DateTime date) {
			// try and add the new date to the selction range
			SelectionRange range = null;
			if (is_shift_pressed || (click_state [0])) {
				range = new SelectionRange (first_select_start_date, date);
				if (range.Start.AddDays (MaxSelectionCount-1) < range.End) {
					// okay the date is beyond what is allowed, lets set the maximum we can
					if (range.Start != first_select_start_date) {
						range.Start = range.End.AddDays ((MaxSelectionCount-1)*-1);
					} else {
						range.End = range.Start.AddDays (MaxSelectionCount-1);
					}
				}
			} else {
				if (date >= MinDate && date <= MaxDate) {
					range = new SelectionRange (date, date);
					first_select_start_date = date;
				}
			}
				
			// Only set if we re actually getting a different range (avoid an extra DateChanged event)
			if (range != null && range.Start != selection_range.Start || range.End != selection_range.End)
				SelectionRange = range;
		}
示例#24
0
      /// <summary>
      /// Populates the time sheet tab. (Subject to Options settings)
      /// </summary>
      /// <param name="start">The start.</param>
      /// <param name="end">The end.</param>
      private void PopulateTimeSheetTab(SelectionRange dateRange){
        DateTime[] dates            = Utilities.GetDatesIndexed(dateRange);
        int[] dayIndexes            = _timeSheetControl.GetIndexFromDate(dates);
        dgvTimeSheet.Rows.Clear();

        for (int ct1 = 0; ct1 < dayIndexes.Length; ct1++) {
          if (dayIndexes[ct1] != -1){
            if (Persistence.Persist.Data.TimeSheetDayList[dayIndexes[ct1]].TimeSheetList.Count > 0){
              int rows              = dgvTimeSheet.Rows.Count - 1;
              dgvTimeSheet.Rows.Add(Persistence.Persist.Data.TimeSheetDayList[dayIndexes[ct1]].TimeSheetList.Count);
              calTimeSheet.Tag      = Persistence.Persist.Data.TimeSheetDayList[dayIndexes[ct1]];

              for (int ct2 = 0; ct2 < Persistence.Persist.Data.TimeSheetDayList[dayIndexes[ct1]].TimeSheetList.Count; ct2++) {
                if (Persistence.Persist.Data.TimeSheetDayList[ct1].TimeSheetList[ct2].TodoTaskGuid != "") {
                  dgvTimeSheet.Rows[ct2 + rows].DefaultCellStyle.Font                   = new Font(Font, FontStyle.Bold);
                }
                dgvTimeSheet.Rows[ct2 + rows].Cells["TimeSheetDate"].Value              = Persistence.Persist.Data.TimeSheetDayList[dayIndexes[ct1]].TimeSheetList[ct2].Date.Day + "/" + Persistence.Persist.Data.TimeSheetDayList[dayIndexes[ct1]].TimeSheetList[ct2].Date.Month + "/" + Persistence.Persist.Data.TimeSheetDayList[dayIndexes[ct1]].TimeSheetList[ct2].Date.Year;
                dgvTimeSheet.Rows[ct2 + rows].Cells["TimeSheetTask"].Value              = _timeSheetControl.GetTimeSheetDisplayName(Persistence.Persist.Data.TimeSheetDayList[dayIndexes[ct1]].TimeSheetList[ct2]);
                dgvTimeSheet.Rows[ct2 + rows].Cells["TimeSheetStartTime"].Value         = Persistence.Persist.Data.TimeSheetDayList[dayIndexes[ct1]].TimeSheetList[ct2].StartTime.TimeOfDay.ToString().Substring(0, 8);
                dgvTimeSheet.Rows[ct2 + rows].Cells["TimeSheetEndTime"].Value           = Persistence.Persist.Data.TimeSheetDayList[dayIndexes[ct1]].TimeSheetList[ct2].EndTime.TimeOfDay.ToString().Substring(0, 8);
                dgvTimeSheet.Rows[ct2 + rows].Cells["TimeSheetJobTime"].Value           = Persistence.Persist.Data.TimeSheetDayList[dayIndexes[ct1]].TimeSheetList[ct2].JobTime.Substring(0, 8);
                dgvTimeSheet.Rows[ct2 + rows].Cells["TimeSheetMainCategory"].Value      = CategoriesControl.FindMainCategory(Persistence.Persist.Data.TimeSheetDayList[dayIndexes[ct1]].TimeSheetList[ct2].MainCategoryGuid);
                dgvTimeSheet.Rows[ct2 + rows].Cells["TimeSheetSubCategory"].Value       = CategoriesControl.FindSubCategory(Persistence.Persist.Data.TimeSheetDayList[dayIndexes[ct1]].TimeSheetList[ct2].SubCategoryGuid);
                dgvTimeSheet.Rows[ct2 + rows].Tag                                       = Persistence.Persist.Data.TimeSheetDayList[dayIndexes[ct1]].TimeSheetList[ct2];
              }
            }

          } else {
            TimeSheetDay timeSheetDay       = new TimeSheetDay();
            timeSheetDay.GUID               = Utilities.GetNewGUID();
            timeSheetDay.Day                = calTimeSheet.SelectionStart;
            timeSheetDay.TimeSheetList      = new List<TimeSheet>();
            calTimeSheet.Tag                = timeSheetDay;
          }
        }

        if (Settings.Default.Planner_CalcTotalTime) {
          lblTotal.Text                     = GetTotalTime();

        } else {
          lblTotal.Text                     = "...";
        }

        txtQuickAddTask.Text                = string.Empty;
      }
示例#25
0
		public void TwoDatesConstructor_Backwards () // start > end
		{
			SelectionRange sr = new SelectionRange (new DateTime (2008, 2, 17), new DateTime (2001, 1, 11));
			Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
			Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
		}
示例#26
0
		// returns the region of the control that needs to be redrawn 
		private void InvalidateDateRange (SelectionRange range) {
			SelectionRange bounds = this.GetDisplayRange (false);

			if (range.End < bounds.Start || range.Start > bounds.End) {
				// don't invalidate anything, as the modified date range
				// is outside the visible bounds of this control
				return;
			}
			// adjust the start and end to be inside the visible range
			if (range.Start < bounds.Start) {
				range = new SelectionRange (bounds.Start, range.End);
			}
			if (range.End > bounds.End) {
				range = new SelectionRange (range.Start, bounds.End);
			}
			// now invalidate the date rectangles as series of rows
			DateTime last_month = this.current_month.AddMonths ((CalendarDimensions.Width * CalendarDimensions.Height)).AddDays (-1);
			DateTime current = range.Start;
			while (current <= range.End) {
				DateTime month_end = new DateTime (current.Year, current.Month, 1).AddMonths (1).AddDays (-1);;
				Rectangle start_rect;
				Rectangle end_rect;
				// see if entire selection is in this current month
				if (range.End <= month_end && current < last_month)	{
					// the end is the last date
					if (current < this.current_month) {
						start_rect = GetDateRowRect (current_month, current_month);
					} else {
						start_rect = GetDateRowRect (current, current);
					}
					end_rect = GetDateRowRect (current, range.End);
				} else if (current < last_month) {
					// otherwise it simply means we have a selection spaning
					// multiple months simply set rectangle inside the current month
					start_rect = GetDateRowRect (current, current);
					end_rect = GetDateRowRect (month_end, month_end);
				} else {
					// it's outside the visible range
					start_rect = GetDateRowRect (last_month, last_month.AddDays (1));
					end_rect = GetDateRowRect (last_month, range.End);
				}
				// push to the next month
				current = month_end.AddDays (1);
				// invalidate from the start row to the end row for this month				
				this.Invalidate (
					new Rectangle (
						start_rect.X,
						start_rect.Y,
						start_rect.Width,
						Math.Max (end_rect.Bottom - start_rect.Y, 0)));
				}
		} 
示例#27
0
		public void TwoDatesConstructor_WithTimeWithKindLocal ()
		{
			// Apparenly any time value is stripped, found while testing PropertyGrid.
			SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11, 13, 14, 15, DateTimeKind.Local), new DateTime (2008, 2, 17));
			Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
			Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
			//
			Assert.AreEqual (DateTimeKind.Local, sr.Start.Kind, "Start Kind");
			Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
		}
示例#28
0
 public SelectionRange(SelectionRange range)
 {
     start = range.start;
     end   = range.end;
 }
示例#29
0
		public void TestSelectionRangeConverter() {
			SelectionRangeConverter	conv;
			SelectionRange		sel;
			DateTime		start;
			DateTime		end;

			start = new DateTime(1969, 2, 1, 18, 0, 0, 0);
			end = new DateTime(1977, 5, 27, 0, 0, 0, 0);

			conv = new SelectionRangeConverter();
			sel = new SelectionRange(start, end);

			CheckConvert(1, 1, conv, typeof(SelectionRange));
			CheckConversion(sel, "1969-02-01, 1977-05-27", conv, typeof(string), CultureInfo.InvariantCulture);
			CheckConversion(sel, "01.02.1969; 27.05.1977", conv, typeof(string), CultureInfo.CreateSpecificCulture("de-de"));
		}
示例#30
0
 /// <include file='doc\SelectionRange.uex' path='docs/doc[@for="SelectionRange.SelectionRange2"]/*' />
 /// <devdoc>
 ///     Create a new SelectionRange object given an existing SelectionRange object.
 /// </devdoc>
 public SelectionRange(SelectionRange range)
 {
     this.start = range.start;
     this.end   = range.end;
 }
示例#31
0
 /// <summary>
 ///   Constructor to create the instance.
 /// </summary>
 /// <param name="highlightedDates"> Highlighted dates. </param>
 public CustomCalendar(List<HighlightedDates> highlightedDates)
 {
     ShowTodayCircle = true;
     _highlightedDates = highlightedDates;
     _range = GetDisplayRange(false);
     SetDayBoxSize();
     SetPosition(highlightedDates);
 }
示例#32
0
        private void DrawCell(Graphics graphics, int dayBoxWidth, float dayBoxHeight, int firstWeekPosition, SelectionRange calendarRange, Brush brushWarning, DateTime visDate)
        {
            int row = 0;
            int col = 0;

            TimeSpan span = visDate.Subtract(calendarRange.Start);
            row = span.Days / 7;
            col = span.Days % 7;

            int x = (col + (ShowWeekNumbers ? 1 : 0)) * dayBoxWidth + 2;
            int y = firstWeekPosition + Convert.ToInt32(row * dayBoxHeight) + 1;

            if (HitTest(x + 3, y + 3).HitArea != HitArea.Date) return;

            Rectangle fillRect = new Rectangle(x, y, dayBoxWidth - 2, Convert.ToInt32(dayBoxHeight) - 2);
            graphics.FillRectangle(brushWarning, fillRect);

            // Check if the date is in the bolded dates array
            bool makeDateBolded = false;
            foreach (DateTime boldDate in BoldedDates)
            {
                if (boldDate == visDate)
                {
                    makeDateBolded = true;
                }
            }

            using (Font textFont = new Font(Font, (makeDateBolded ? FontStyle.Bold : FontStyle.Regular)))
            {
                TextRenderer.DrawText(graphics, visDate.Day.ToString(), textFont, fillRect, Color.FromArgb(255, 128, 0, 0), TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
            }

            if ((ShowTodayCircle) && (visDate == TimeProvider.Today))
            {
                graphics.DrawRectangle(Pens.Red, x - 1, y - 1, dayBoxWidth , Convert.ToInt32(dayBoxHeight));
                graphics.DrawRectangle(Pens.Red, x - 2, y - 2, dayBoxWidth, Convert.ToInt32(dayBoxHeight));
            }
        }
示例#33
0
 private void FindNextSelection(int position)
 {
     _nextSelection = new SelectionRange(int.MaxValue, int.MaxValue);
     foreach (SelectionRange range in _ranges)
     {
         if (range.End >= position && (range.Start < _nextSelection.Start || (range.Start == _nextSelection.Start && range.End > _nextSelection.End)))
             _nextSelection = range;
     }
 }
 /// <include file='doc\SelectionRange.uex' path='docs/doc[@for="SelectionRange.SelectionRange2"]/*' />
 /// <devdoc>
 ///     Create a new SelectionRange object given an existing SelectionRange object.
 /// </devdoc>
 public SelectionRange(SelectionRange range) {
     this.start = range.start;
     this.end = range.end;
 }