public void Move(DateItem value, int index) { if (value == null) { throw new ArgumentNullException("value"); } if (index < 0) { index = 0; } else if (index > this.Count) { index = this.Count; } if (!this.Contains(value) || this.IndexOf(value) == index) { return; } this.List.Remove(value); if (index > this.Count) { this.List.Add(value); } else { this.List.Insert(index, value); } }
public void Remove(DateItem value) { if (value == null) { throw new ArgumentNullException("value"); } this.List.Remove(value); }
public bool Contains(DateItem dateItem) { if (dateItem == null) { throw new ArgumentNullException("dateItem"); } return(this.IndexOf(dateItem) != -1); }
private void AddSelectedDate(DateTime selectedDate) { var dateItem = new DateItem(); dateItem.Date = selectedDate; dateItem.BackColor1 = Color.Blue; if (!_selectedDates.Select(x => x.Date).Contains(selectedDate)) _selectedDates.Add(dateItem); UpdateSelectedDates(); }
protected virtual ImageList GetImageList(object component) { DateItem item = component as DateItem; if (item != null) { return(item.GetImageList()); } return(null); }
public DateItem[] AddInfo(DateItem dt, DateItem[] old) { int l = old.Length; int i; DateItem[] n = new DateItem[l + 1]; n.Initialize(); for (i = 0; i < l; i++) { n[i] = old[i]; } n[i] = dt; return(n); }
public int IndexOf(DateItem dateItem) { if (dateItem == null) { throw new ArgumentNullException("dateItem"); } for (int i = 0; i < this.Count; i++) { if (this[i] == dateItem) { return(i); } } return(-1); }
public void Add(DateItem value) { int index; if (value == null) { throw new ArgumentNullException("value"); } if ((MonthCalendar)value.Calendar == null) { value.Calendar = this.owner; } index = this.IndexOf(value); if (index == -1) { this.List.Add(value); } else { this.List[index] = value; } }
public void Move(DateItem value, int index) { if (value == null) throw new ArgumentNullException("value"); if (index < 0) { index = 0; } else if (index > this.Count) { index = this.Count; } if (!this.Contains(value) || this.IndexOf(value) == index) { return; } this.List.Remove(value); if (index > this.Count) { this.List.Add(value); } else { this.List.Insert(index, value); } }
internal void Draw(Graphics e) { int today = -1; string[] selectedDays; Brush bgBrush = new SolidBrush(Colors.BackColor1); Brush selBrush = new SolidBrush(Color.FromArgb(125,Colors.Selected.BackColor)); Brush focusBrush = new SolidBrush(Color.FromArgb(125,Colors.Focus.BackColor)); Pen todayPen = new Pen(Color.FromArgb(150,Calendar.TodayColor),2); try { if (BackgroundImage != null) e.DrawImage(BackgroundImage, Rect); else { if (Colors.GradientMode != mcGradientMode.None) m_calendar.DrawGradient(e, m_rect, Colors.BackColor1, Colors.BackColor2, Colors.GradientMode); else e.FillRectangle(bgBrush, m_rect); } // Draw days for (int i = 0;i<42;i++) { // only draw days that are visible... if ((m_days[i].Rectangle.Height > 0) && (m_days[i].Rectangle.Width > 0)) { // Create new graphics object Graphics d = m_calendar.CreateGraphics(); // Create bitmap.. Bitmap bmp = new Bitmap(m_days[i].Rectangle.Width, m_days[i].Rectangle.Height, d); // link graphics object to bitmap d = Graphics.FromImage(bmp); DayRenderEventArgs args = new DayRenderEventArgs(d, m_days[i].Rectangle, m_days[i].Date, m_days[i].State); DayRender(this, args); if (!args.OwnerDraw) { // day is not user drawn m_days[i].UserDrawn = false; DateItem dayInfo = new DateItem(); dayInfo.Calendar = m_calendar; DayQueryInfoEventArgs info = new DayQueryInfoEventArgs(dayInfo, m_days[i].Date, m_days[i].State); DayQueryInfo(this, info); if (!info.OwnerDraw) dayInfo = null; m_days[i].Draw(e, dayInfo); if (dayInfo != null) dayInfo.Dispose(); } else { // Draw user rendered day m_days[i].UserDrawn = true; e.DrawImage(bmp, m_days[i].Rectangle); } // Check if day has focus and if focus should be drawn if ((m_days[i].State == mcDayState.Focus) && (m_calendar.ShowFocus)) { e.FillRectangle(focusBrush, m_days[i].Rectangle); ControlPaint.DrawBorder(e, m_days[i].Rectangle, Colors.Focus.Border, BorderStyles.Focus); } if ((m_days[i].Date == DateTime.Today) && (!args.OwnerDraw)) today = i; d.Dispose(); bmp.Dispose(); } } // check if date is "today" and if it should be marked.. if ( (m_calendar.ShowToday) && (today !=-1) && ((m_calendar.ShowTrailingDates) || (m_days[today].Date.Month == m_calendar.ActiveMonth.Month)) ) { RectangleF dateRect = m_days[today].DateRegion[0].GetBounds(e); dateRect.Inflate(5, 5); e.DrawEllipse(todayPen, dateRect); } // Check if a selection exist selectedDays = DaysInSelection(NO_AREA); if (selectedDays.Length>0) { // Check how many selection areas there are if (m_selArea.Count<=1) { for (int i = 0;i<m_selArea.Count;i++) { SelectionArea area = (SelectionArea)m_selArea[i]; if ((area.Begin!=-1) && (area.End !=-1)) { // Get Coordinates for selection rectangle m_selRight = System.Math.Max(m_days[area.End].Rectangle.Right,m_days[area.Begin].Rectangle.Right); m_selLeft = System.Math.Min(m_days[area.End].Rectangle.Left,m_days[area.Begin].Rectangle.Left); m_selTop = System.Math.Min(m_days[area.End].Rectangle.Top,m_days[area.Begin].Rectangle.Top); m_selBottom = System.Math.Max(m_days[area.End].Rectangle.Bottom,m_days[area.Begin].Rectangle.Bottom); // Draw selection Rectangle selRect = new Rectangle(m_selLeft,m_selTop,m_selRight-m_selLeft,m_selBottom-m_selTop); e.FillRectangle(selBrush,selRect); ControlPaint.DrawBorder(e,selRect,Colors.Selected.Border,BorderStyles.Selected); } } } // Multiple selection areas, we dont use border so we // draw each day individually to not overlap regions else { for (int i =0;i<42;i++) { if ((m_days[i].State==mcDayState.Selected) && (m_days[i].SelectionArea!=-1)) { e.FillRectangle(selBrush,m_days[i].Rectangle); } } } } } catch (Exception) { } bgBrush.Dispose(); selBrush.Dispose(); todayPen.Dispose(); focusBrush.Dispose(); }
public DateItem[] GetDateInfo() { DateItem[] ret = new DateItem[0]; ret.Initialize(); for (int i = 0;i<Dates.Count;i++) { ret = Dates.AddInfo(Dates[i],ret); } return ret; }
private void FormatCalendar(int year, int month, bool loop) { int yearMonth = Convert.ToInt32(year + "" + month); int daysInMonth = DateTime.DaysInMonth(year, month); if (_formattedMonth.Contains(yearMonth) == false) { for (int i = 1; i <= daysInMonth; i++) { DateTime date = new DateTime(year, month, i); if(Util.CompareDate(date, DateTime.Today) == 0) //is today { DateItem dateItem = new DateItem(); dateItem.Date = date; dateItem.BoldedDate = true; dateItem.DateColor = Color.Red; mclWorkingCalendar.AddDateInfo(dateItem); } if (IsHoliday(date)) { DateItem dateItem = new DateItem(); dateItem.BackColor1 = _holidayColor; dateItem.Date = date; mclWorkingCalendar.AddDateInfo(dateItem); } else if (IsNonWorkDay(date)) { DateItem dateItem = new DateItem(); dateItem.BackColor1 = _nonWorkdayColor; dateItem.Date = date; mclWorkingCalendar.AddDateInfo(dateItem); } } _formattedMonth.Add(yearMonth); } if (loop) { if (month == 12) FormatCalendar(year + 1, 1, false); else FormatCalendar(year, month + 1, false); if (month == 1) FormatCalendar(year - 1, 12, false); else FormatCalendar(year, month - 1, false); } }
/// <summary> /// /// </summary> private void LoadWorkingCalendarByEmployee() { monthCalendar1.Dates.Clear(); int DeparmentID = (int)departmentTreeView.SelectedNode.Tag; dsEmployee = employeeDO.GetEmployeeByDepartment(DeparmentID); int employeeID = (int)dsEmployee.Tables[0].Rows[selectedRowIndex]["EmployeeID"]; workingTimeDO = new RegWorkingTimeDO(); dsWorkingTime = workingTimeDO.GetOverTimeByMonth(employeeID, CurrentMonth, CurrentYear); shiftDO = new ShiftDO(); DataSet dsShiftOver = new DataSet(); if (dsWorkingTime.Tables[0].Rows.Count > 0) { foreach (DataRow dr in dsWorkingTime.Tables[0].Rows) { DateTime Day = DateTime.Parse(dr["WorkingDay"].ToString()); int ShiftOverID = int.Parse(dr["ShiftOverID"].ToString()); dsShiftOver = shiftDO.GetShiftOverByID(ShiftOverID); DateItem dateItem = new DateItem(); dateItem.DateColor = lblOverTimeLegend.ForeColor; dateItem.BackColor = lblOverTimeLegend.BackColor; dateItem.Date = Day; if (dsShiftOver != null) dateItem.Text = dsShiftOver.Tables[0].Rows[0]["ShiftName"].ToString(); monthCalendar1.AddDateInfo(dateItem); } } monthCalendar1.Refresh(); monthCalendar1.ClearSelection(); }
public void MoveToBottom(DateItem value) { this.Move(value, this.Count); }
private void AddSelectedDate(DateTime selectedDate) { var dateItem = new DateItem(); dateItem.Date = selectedDate; dateItem.BackColor1 = Color.Blue; _selectedDates.Add(dateItem); UpdateSelectedDates(); }
public void AddRange(DateItem[] dateItems) { if (dateItems == null) throw new ArgumentNullException("dateItems"); for (int i=0; i<dateItems.Length; i++) { dateItems[i].Calendar = owner; this.Add(dateItems[i]); } }
public DayQueryInfoEventArgs(DateItem info, DateTime date, mcDayState state) { this.m_info = info; this.m_date = date; this.m_state = state; }
public void Remove(DateItem value) { if (value == null) throw new ArgumentNullException("value"); this.List.Remove(value); }
public int IndexOf(DateItem dateItem) { if (dateItem == null) throw new ArgumentNullException("dateItem"); for (int i=0; i<this.Count; i++) { if (this[i] == dateItem) { return i; } } return -1; }
public DateItem[] AddInfo(DateItem dt, DateItem[] old) { int l = old.Length; int i; DateItem[] n = new DateItem[l+1]; n.Initialize(); for (i = 0;i<l;i++) { n[i] = old[i]; } n[i] = dt; return n; }
public DateItem[] DateInfo(DateTime dt) { DateItem[] ret = new DateItem[0]; ret.Initialize(); for (int i = 0;i<this.Count;i++) { if ( ((this[i].Date <= dt) && (this[i].Range >=dt)) ) { switch (this[i].Pattern) { case mcDayInfoRecurrence.None: { if (this[i].Date.ToShortDateString() == dt.ToShortDateString()) { this[i].Index = i; ret = AddInfo(this[i],ret); } break; } case mcDayInfoRecurrence.Daily: { this[i].Index = i; ret = AddInfo(this[i],ret); break; } case mcDayInfoRecurrence.Weekly: { if ( (this[i].Date.DayOfWeek == dt.DayOfWeek) ) { this[i].Index = i; ret = AddInfo(this[i],ret); } break; } case mcDayInfoRecurrence.Monthly: { if ( (this[i].Date.Day == dt.Day)) { this[i].Index = i; ret = AddInfo(this[i],ret); } break; } case mcDayInfoRecurrence.Yearly: { if (this[i].Date.ToShortDateString().Substring(5) == dt.ToShortDateString().Substring(5)) { this[i].Index = i; ret = AddInfo(this[i],ret); } break; } } } } return ret; }
public bool Contains(DateItem dateItem) { if (dateItem == null) throw new ArgumentNullException("dateItem"); return (this.IndexOf(dateItem) != -1); }
public void AddDateInfo(DateItem[] info) { for (int i =0;i < info.Length;i++) { if (info[i]!=null) Dates.Add(info[i]); } Invalidate(); }
public void MoveToTop(DateItem value) { this.Move(value, 0); }
public void Add(DateItem value) { int index; if (value == null) throw new ArgumentNullException("value"); if ((MonthCalendar)value.Calendar==null) value.Calendar = this.owner; index = this.IndexOf(value); if (index == -1) this.List.Add(value); else this.List[index] = value; }
internal void Draw(Graphics e, DateItem queryInfo) { StringFormat dateAlign = new StringFormat(); StringFormat textAlign = new StringFormat(); Font boldFont = new Font(m_month.DateFont.Name, m_month.DateFont.Size, m_month.DateFont.Style | FontStyle.Bold); Color bgColor1 = m_month.Colors.Days.BackColor1; Color bgColor2 = m_month.Colors.Days.BackColor2; mcGradientMode gradientMode = m_month.Colors.Days.GradientMode; Color textColor = m_month.Colors.Days.Text; Color dateColor = m_month.Colors.Days.Date; Brush dateBrush = new SolidBrush(dateColor); Brush textBrush = new SolidBrush(textColor); Brush bgBrush = new SolidBrush(bgColor1); string dateString; m_imageRect = new Rectangle(); string text = ""; bool drawDay = false; bool enabled = true; Image bgImage = null; int i = -1; bool boldedDate = false; DateItem[] info; m_dayImage = null; dateAlign = GetStringAlignment(m_month.DateAlign); textAlign = GetStringAlignment(m_month.TextAlign); if ((m_month.SelectedMonth.Month == m_date.Month) || (m_month.Calendar.ShowTrailingDates)) { drawDay = true; } if (((m_date.DayOfWeek == DayOfWeek.Saturday) && (m_month.Colors.Weekend.Saturday)) || ((m_date.DayOfWeek == DayOfWeek.Sunday) && (m_month.Colors.Weekend.Sunday))) { bgColor1 = m_month.Colors.Weekend.BackColor1; bgColor2 = m_month.Colors.Weekend.BackColor2; dateColor = m_month.Colors.Weekend.Date; textColor = m_month.Colors.Weekend.Text; gradientMode = m_month.Colors.Weekend.GradientMode; } if (m_month.SelectedMonth.Month != m_date.Month) { bgColor1 = m_month.Colors.Trailing.BackColor1; bgColor2 = m_month.Colors.Trailing.BackColor2; gradientMode = m_month.Colors.Trailing.GradientMode; dateColor = m_month.Colors.Trailing.Date; textColor = m_month.Colors.Trailing.Text; } // Check if formatting should be applied if ((m_month.FormatTrailing) || (m_month.SelectedMonth.Month == m_date.Month)) { // check of there is formatting for this day if (queryInfo != null) { info = new DateItem[1]; info[0] = queryInfo; } else { info = m_calendar.GetDateInfo(this.Date); } if (info.Length > 0) { i = 0; } // go through the available dateitems while ((i < info.Length) && (drawDay)) { if (info.Length > 0) { DateItem dateInfo = info[i]; if (dateInfo.BackColor1 != Color.Empty) { bgColor1 = dateInfo.BackColor1; } if (dateInfo.BackColor2 != Color.Empty) { bgColor2 = dateInfo.BackColor2; } gradientMode = dateInfo.GradientMode; if (dateInfo.DateColor != Color.Empty) { dateColor = dateInfo.DateColor; } if (dateInfo.TextColor != Color.Empty) { textColor = dateInfo.TextColor; } text = dateInfo.Text; if (dateInfo.Weekend) { bgColor1 = m_month.Colors.Weekend.BackColor1; bgColor2 = m_month.Colors.Weekend.BackColor2; gradientMode = m_month.Colors.Weekend.GradientMode; dateColor = m_month.Colors.Weekend.Date; textColor = m_month.Colors.Weekend.Text; } boldedDate = dateInfo.BoldedDate; enabled = dateInfo.Enabled; if (!dateInfo.Enabled) { bgColor1 = m_month.Colors.Disabled.BackColor1; bgColor2 = m_month.Colors.Disabled.BackColor2; gradientMode = m_month.Colors.Disabled.GradientMode; dateColor = m_month.Colors.Disabled.Date; textColor = m_month.Colors.Disabled.Text; } m_dayImage = dateInfo.Image; if (m_dayImage != null) { m_imageRect = ImageRect(m_month.ImageAlign); } bgImage = dateInfo.BackgroundImage; } if (m_state == mcDayState.Selected) { dateColor = m_month.Colors.Selected.Date; textColor = m_month.Colors.Selected.Text; } if ((m_state == mcDayState.Focus) && (m_month.Calendar.ShowFocus)) { dateColor = m_month.Colors.Focus.Date; textColor = m_month.Colors.Focus.Text; } if (bgImage != null) { e.DrawImage(bgImage, m_rect); } else { if (gradientMode == mcGradientMode.None) { if (bgColor1 != Color.Transparent) { bgBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Background, bgColor1)); e.FillRectangle(bgBrush, m_rect); } } else { m_calendar.DrawGradient(e, Rectangle, bgColor1, bgColor2, gradientMode); } } ControlPaint.DrawBorder(e, m_rect, m_month.Colors.Days.Border, m_month.BorderStyles.Normal); if (m_dayImage != null) { if (enabled) { e.DrawImageUnscaled(m_dayImage, m_imageRect); } else { ControlPaint.DrawImageDisabled(e, m_dayImage, m_imageRect.X, m_imageRect.Y, m_month.Colors.Disabled.BackColor1); } } // Check if we should append month name to date if ((m_month.ShowMonthInDay) && ((m_date.AddDays(-1).Month != m_date.Month) || (m_date.AddDays(1).Month != m_date.Month))) { dateString = m_date.Day.ToString() + " " + m_calendar.m_dateTimeFormat.GetMonthName(m_date.Month); } else { dateString = m_date.Day.ToString(); } if (dateColor != Color.Transparent) { dateBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Text, dateColor)); CharacterRange[] characterRanges = { new CharacterRange(0, dateString.Length) }; dateAlign.SetMeasurableCharacterRanges(characterRanges); m_dateRgn = new Region[1]; // Should date be bolded ? if (!boldedDate) { e.DrawString(dateString, m_month.DateFont, dateBrush, m_rect, dateAlign); m_dateRgn = e.MeasureCharacterRanges(dateString, m_month.DateFont, m_rect, dateAlign); } else { e.DrawString(dateString, boldFont, dateBrush, m_rect, dateAlign); m_dateRgn = e.MeasureCharacterRanges(dateString, boldFont, m_rect, dateAlign); } } if ((text.Length > 0) && (textColor != Color.Transparent)) { textBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Text, textColor)); CharacterRange[] characterRanges = { new CharacterRange(0, text.Length) }; textAlign.SetMeasurableCharacterRanges(characterRanges); m_textRgn = new Region[1]; e.DrawString(text, m_month.TextFont, textBrush, m_rect, textAlign); m_textRgn = e.MeasureCharacterRanges(text, m_month.TextFont, m_rect, textAlign); } i++; } } dateBrush.Dispose(); bgBrush.Dispose(); textBrush.Dispose(); boldFont.Dispose(); dateAlign.Dispose(); textAlign.Dispose(); }
internal void Draw(Graphics e) { StringFormat dateAlign = new StringFormat(); StringFormat textAlign = new StringFormat(); Font boldFont = new Font(m_month.DateFont.Name, m_month.DateFont.Size, m_month.DateFont.Style | FontStyle.Bold); Color bgColor = m_month.Colors.Background; Color textColor = m_month.Colors.Text; Color dateColor = m_month.Colors.Date; Brush dateBrush = new SolidBrush(dateColor); Brush textBrush = new SolidBrush(textColor); Brush bgBrush = new SolidBrush(bgColor); string dateString; Rectangle imageRect = new Rectangle(); string text = ""; bool drawDay = false; bool enabled = true; int i = -1; bool boldedDate = false; DateItem[] info; m_dayImage = null; dateAlign = GetStringAlignment(m_month.DateAlign); textAlign = GetStringAlignment(m_month.TextAlign); if ((m_month.SelectedMonth.Month == m_date.Month) || (m_month.Calendar.ShowTrailingDates)) { drawDay = true; } if ((m_date.DayOfWeek == DayOfWeek.Saturday) || (m_date.DayOfWeek == DayOfWeek.Sunday)) { bgColor = m_month.Colors.WeekendBackground; dateColor = m_month.Colors.WeekendDate; textColor = m_month.Colors.WeekendText; } if (m_month.SelectedMonth.Month != m_date.Month) { bgColor = m_month.Colors.TrailingBackground; dateColor = m_month.Colors.TrailingDate; textColor = m_month.Colors.TrailingText; } // Check if formatting should be applied if ((m_month.FormatTrailing) || (m_month.SelectedMonth.Month == m_date.Month)) { // check of there is formatting for this day info = m_calendar.GetDateInfo(this.Date); if (info.Length > 0) { i = 0; } // go through the available dateitems while ((i < info.Length) && (drawDay)) { if (info.Length > 0) { DateItem dateInfo = info[i]; if (dateInfo.BackColor != Color.Empty) { bgColor = dateInfo.BackColor; } if (dateInfo.DateColor != Color.Empty) { dateColor = dateInfo.DateColor; } if (dateInfo.TextColor != Color.Empty) { textColor = dateInfo.TextColor; } text = dateInfo.Text; if (dateInfo.Weekend) { bgColor = m_month.Colors.WeekendBackground; dateColor = m_month.Colors.WeekendDate; textColor = m_month.Colors.WeekendText; } boldedDate = dateInfo.BoldedDate; enabled = dateInfo.Enabled; if (!dateInfo.Enabled) { bgColor = m_month.Colors.DisabledBackground; dateColor = m_month.Colors.DisabledDate; textColor = m_month.Colors.DisabledText; } m_dayImage = dateInfo.Image; if (m_dayImage != null) { imageRect = ImageRect(m_month.ImageAlign); } } if (m_state == mcDayState.Selected) { dateColor = m_month.Colors.SelectedDate; textColor = m_month.Colors.SelectedText; } if ((m_state == mcDayState.Focus) && (m_month.Calendar.ShowFocus)) { dateColor = m_month.Colors.FocusDate; textColor = m_month.Colors.FocusText; } if (bgColor != Color.Transparent) { bgBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Background, bgColor)); e.FillRectangle(bgBrush, m_rect); } ControlPaint.DrawBorder(e, m_rect, m_month.Colors.Border, m_month.BorderStyles.Normal); if (m_dayImage != null) { if (enabled) { e.DrawImageUnscaled(m_dayImage, imageRect); } else { ControlPaint.DrawImageDisabled(e, m_dayImage, imageRect.X, imageRect.Y, m_month.Colors.DisabledBackground); } } // Check if we should append month name to date if ((m_month.ShowMonthInDay) && ((m_date.AddDays(-1).Month != m_date.Month) || (m_date.AddDays(1).Month != m_date.Month))) { dateString = m_date.Day.ToString() + " " + m_calendar.m_dateTimeFormat.GetMonthName(m_date.Month); } else { dateString = m_date.Day.ToString(); } if (dateColor != Color.Transparent) { dateBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Text, dateColor)); // Should date be bolded ? if (!boldedDate) { e.DrawString(dateString, m_month.DateFont, dateBrush, m_rect, dateAlign); } else { e.DrawString(dateString, boldFont, dateBrush, m_rect, dateAlign); } } if ((text.Length > 0) && (textColor != Color.Transparent)) { textBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Text, textColor)); e.DrawString(text, m_month.TextFont, textBrush, m_rect, textAlign); } i++; } } dateBrush.Dispose(); bgBrush.Dispose(); textBrush.Dispose(); boldFont.Dispose(); dateAlign.Dispose(); textAlign.Dispose(); }
/// <summary> /// /// </summary> private void LoadWorkingCalendarByEmployee() { monthCalendar1.Dates.Clear(); int DeparmentID = (int) departmentTreeView.SelectedNode.Tag; dsEmployee = employeeDO.GetEmployeeByDepartment(DeparmentID); int employeeID = (int)dsEmployee.Tables[0].Rows[selectedRowIndex]["EmployeeID"]; dsWorkingTime = workingTimeDO.GetWorkingTimeByMonth(employeeID, CurrentMonth, CurrentYear); if (dsWorkingTime.Tables[0].Rows.Count > 0) { foreach (DataRow dr in dsWorkingTime.Tables[0].Rows) { DateTime Day = DateTime.Parse(dr["Day"].ToString()); int ShiftID = int.Parse(dr["ShiftID"].ToString()); if (ShiftID > 0) { DateItem dateItem = new DateItem(); dateItem.DateColor = lblWorkingDayLegend.ForeColor; dateItem.BackColor = lblWorkingDayLegend.BackColor; dateItem.Date = Day; dateItem.Text = dr["ShiftName"].ToString(); monthCalendar1.AddDateInfo(dateItem); } else if (ShiftID == 0) { DateItem dateItem = new DateItem(); dateItem.DateColor = lblNonWorkingDayLegend.ForeColor; dateItem.BackColor = lblNonWorkingDayLegend.BackColor; dateItem.Date = Day; monthCalendar1.AddDateInfo(dateItem); } else if (ShiftID == -1) { DateItem dateItem = new DateItem(); dateItem.DateColor = lblHolidayLegend.ForeColor; dateItem.BackColor = lblHolidayLegend.BackColor; dateItem.Date = Day; monthCalendar1.AddDateInfo(dateItem); } else { DateItem dateItem = new DateItem(); dateItem.DateColor = lblOverTimeLegend.ForeColor; dateItem.BackColor = lblOverTimeLegend.BackColor; dateItem.Date = Day; monthCalendar1.AddDateInfo(dateItem); } } } monthCalendar1.Refresh(); monthCalendar1.ClearSelection(); }
internal void Draw(Graphics e, DateItem queryInfo) { StringFormat dateAlign = new StringFormat(); StringFormat textAlign = new StringFormat(); Font boldFont = new Font(m_month.DateFont.Name,m_month.DateFont.Size,m_month.DateFont.Style | FontStyle.Bold); Color bgColor1 = m_month.Colors.Days.BackColor1; Color bgColor2 = m_month.Colors.Days.BackColor2; mcGradientMode gradientMode = m_month.Colors.Days.GradientMode; Color textColor = m_month.Colors.Days.Text; Color boldDateColor = Color.FromArgb(0, 127, 223); Color dateColor = m_month.Colors.Days.Date; Brush dateBrush = new SolidBrush(dateColor); Brush boldDateBrush = new SolidBrush(boldDateColor); Brush textBrush = new SolidBrush(textColor); Brush bgBrush = new SolidBrush(bgColor1); string dateString; m_imageRect = new Rectangle(); string text = ""; bool drawDay = false; bool enabled = true; Image bgImage = null; int i = -1; bool boldedDate = false; DateItem[] info; m_dayImage = null; dateAlign = GetStringAlignment(m_month.DateAlign); textAlign = GetStringAlignment(m_month.TextAlign); if ((m_month.SelectedMonth.Month == m_date.Month) || (m_month.Calendar.ShowTrailingDates)) drawDay = true; if ( ((m_date.DayOfWeek == DayOfWeek.Saturday) && (m_month.Colors.Weekend.Saturday)) || ((m_date.DayOfWeek == DayOfWeek.Sunday) && (m_month.Colors.Weekend.Sunday)) ) { bgColor1 = m_month.Colors.Weekend.BackColor1; bgColor2 = m_month.Colors.Weekend.BackColor2; dateColor= m_month.Colors.Weekend.Date; textColor= m_month.Colors.Weekend.Text; gradientMode = m_month.Colors.Weekend.GradientMode; } if (m_month.SelectedMonth.Month != m_date.Month) { bgColor1 = m_month.Colors.Trailing.BackColor1; bgColor2 = m_month.Colors.Trailing.BackColor2; gradientMode = m_month.Colors.Trailing.GradientMode; dateColor = m_month.Colors.Trailing.Date; boldDateColor = m_month.Colors.Trailing.Date; textColor = m_month.Colors.Trailing.Text; } // Check if formatting should be applied if ((m_month.FormatTrailing) || (m_month.SelectedMonth.Month == m_date.Month)) { // check of there is formatting for this day if (queryInfo != null) { info = new DateItem[1]; info[0] = queryInfo; } else info = m_calendar.GetDateInfo(this.Date); if (info.Length > 0) i = 0; // go through the available dateitems while ((i<info.Length) && (drawDay)) { if (info.Length>0) { DateItem dateInfo = info[i]; if (dateInfo.BackColor1!=Color.Empty) bgColor1 = dateInfo.BackColor1; if (dateInfo.BackColor2 != Color.Empty) bgColor2 = dateInfo.BackColor2; gradientMode = dateInfo.GradientMode; if (dateInfo.DateColor!=Color.Empty) dateColor = dateInfo.DateColor; if (dateInfo.TextColor!=Color.Empty) textColor = dateInfo.TextColor; text = dateInfo.Text; if (dateInfo.Weekend) { bgColor1 = m_month.Colors.Weekend.BackColor1; bgColor2 = m_month.Colors.Weekend.BackColor2; gradientMode = m_month.Colors.Weekend.GradientMode; dateColor = m_month.Colors.Weekend.Date; textColor = m_month.Colors.Weekend.Text; } boldedDate = dateInfo.BoldedDate; enabled = dateInfo.Enabled; if (!dateInfo.Enabled) { bgColor1 = m_month.Colors.Disabled.BackColor1; bgColor2 = m_month.Colors.Disabled.BackColor2; gradientMode = m_month.Colors.Disabled.GradientMode; dateColor = m_month.Colors.Disabled.Date; textColor = m_month.Colors.Disabled.Text; } m_dayImage = dateInfo.Image; if (m_dayImage!=null) m_imageRect = ImageRect(m_month.ImageAlign); bgImage = dateInfo.BackgroundImage; } if (m_state == mcDayState.Selected) { dateColor = m_month.Colors.Selected.Date; textColor = m_month.Colors.Selected.Text; } if ((m_state == mcDayState.Focus) && (m_month.Calendar.ShowFocus)) { dateColor = m_month.Colors.Focus.Date; textColor = m_month.Colors.Focus.Text; } if (bgImage != null) e.DrawImage(bgImage, m_rect); else { if (gradientMode == mcGradientMode.None) { if (bgColor1 != Color.Transparent) { bgBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Background, bgColor1)); e.FillRectangle(bgBrush, m_rect); } } else m_calendar.DrawGradient(e, Rectangle, bgColor1, bgColor2, gradientMode); } ControlPaint.DrawBorder(e,m_rect, m_month.Colors.Days.Border,m_month.BorderStyles.Normal); if (m_dayImage!=null) { if (enabled) e.DrawImageUnscaled(m_dayImage,m_imageRect); else ControlPaint.DrawImageDisabled(e,m_dayImage,m_imageRect.X,m_imageRect.Y,m_month.Colors.Disabled.BackColor1); } // Check if we should append month name to date if ((m_month.ShowMonthInDay) && ((m_date.AddDays(-1).Month != m_date.Month) || (m_date.AddDays(1).Month != m_date.Month))) dateString = m_date.Day.ToString()+" "+m_calendar.m_dateTimeFormat.GetMonthName(m_date.Month); else dateString = m_date.Day.ToString(); if (dateColor != Color.Transparent) { dateBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Text, dateColor)); // To show blue colour in selected dates with preserved transparency boldDateBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Text, boldDateColor)); CharacterRange[] characterRanges = { new CharacterRange(0, dateString.Length) }; dateAlign.SetMeasurableCharacterRanges(characterRanges); m_dateRgn = new Region[1]; // Should date be bolded ? if (!boldedDate) { e.DrawString(dateString, m_month.DateFont, dateBrush, m_rect, dateAlign); m_dateRgn = e.MeasureCharacterRanges(dateString, m_month.DateFont, m_rect, dateAlign); } else { e.DrawString(dateString, boldFont, boldDateBrush, m_rect, dateAlign); m_dateRgn = e.MeasureCharacterRanges(dateString, boldFont, m_rect, dateAlign); } } if ((text.Length > 0) && (textColor != Color.Transparent)) { textBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Text, textColor)); CharacterRange[] characterRanges = { new CharacterRange(0, text.Length) }; textAlign.SetMeasurableCharacterRanges(characterRanges); m_textRgn = new Region[1]; e.DrawString(text, m_month.TextFont, textBrush, m_rect, textAlign); m_textRgn = e.MeasureCharacterRanges(text, m_month.TextFont, m_rect, textAlign); } i++; } } boldDateBrush.Dispose(); dateBrush.Dispose(); bgBrush.Dispose(); textBrush.Dispose(); boldFont.Dispose(); dateAlign.Dispose(); textAlign.Dispose(); }
public void RemoveDateInfo(DateItem info) { Dates.Remove(info); }
/// <summary> /// Thiết lập những ngày được chọn là ngày làm việc /// </summary> //private void SetWorkingDay() //{ // foreach (string selectedDate in selectedDates) // { // // Thiết lập ngày làm việc // DateItem dateItem = new DateItem(); // dateItem.Date = DateTime.Parse(selectedDate); // dateItem.BackColor = lblWorkingDayLegend.BackColor; // dateItem.DateColor = lblWorkingDayLegend.ForeColor; // dateItem.Text = cboShift.Text; // monthCalendar1.AddDateInfo(dateItem); // } //} ///// <summary> ///// Thiết lập những ngày được chọn là ngày nghỉ ///// </summary> //private void SetNonWorkingDay() //{ // foreach (string selectedDate in selectedDates) // { // // Thiết lập ngày nghỉ // DateItem dateItem = new DateItem(); // dateItem.Date = DateTime.Parse(selectedDate); // dateItem.BackColor = lblNonWorkingDayLegend.BackColor; // dateItem.DateColor = lblNonWorkingDayLegend.ForeColor; // dateItem.Text = ""; // monthCalendar1.AddDateInfo(dateItem); // } //} ///// <summary> ///// Thiết lập những ngày được chọn là ngày nghỉ ///// </summary> //private void SetHoliday() //{ // foreach (string selectedDate in selectedDates) // { // // Thiết lập ngày lễ // DateItem dateItem = new DateItem(); // dateItem.Date = DateTime.Parse(selectedDate); // dateItem.BackColor = lblHolidayLegend.BackColor; // dateItem.DateColor = lblHolidayLegend.ForeColor; // dateItem.Text = ""; // monthCalendar1.AddDateInfo(dateItem); // } //} /// <summary> /// Thiết lập những ngày được chọn là ngày làm thêm hệ số 1 /// </summary> private void SetOverTime() { foreach (string selectedDate in selectedDates) { // Thiết lập ngày lễ DateItem dateItem = new DateItem(); dateItem.Date = DateTime.Parse(selectedDate); dateItem.BackColor = lblOverTimeLegend.BackColor; dateItem.DateColor = lblOverTimeLegend.ForeColor; dateItem.Text = cboShift.Text; monthCalendar1.AddDateInfo(dateItem); } }
public DateItem[] DateInfo(DateTime dt) { DateItem[] ret = new DateItem[0]; ret.Initialize(); for (int i = 0; i < this.Count; i++) { if (((this[i].Date <= dt) && (this[i].Range >= dt))) { switch (this[i].Pattern) { case mcDayInfoRecurrence.None: { if (this[i].Date.ToShortDateString() == dt.ToShortDateString()) { this[i].Index = i; ret = AddInfo(this[i], ret); } break; } case mcDayInfoRecurrence.Daily: { this[i].Index = i; ret = AddInfo(this[i], ret); break; } case mcDayInfoRecurrence.Weekly: { if ((this[i].Date.DayOfWeek == dt.DayOfWeek)) { this[i].Index = i; ret = AddInfo(this[i], ret); } break; } case mcDayInfoRecurrence.Monthly: { if ((this[i].Date.Day == dt.Day)) { this[i].Index = i; ret = AddInfo(this[i], ret); } break; } case mcDayInfoRecurrence.Yearly: { if (this[i].Date.ToShortDateString().Substring(5) == dt.ToShortDateString().Substring(5)) { this[i].Index = i; ret = AddInfo(this[i], ret); } break; } } } } return(ret); }
/// <summary> /// Thiết lập những ngày được chọn là ngày nghỉ /// </summary> private void SetNonWorkingDay() { foreach (string selectedDate in selectedDates) { // Thiết lập ngày nghỉ DateItem dateItem = new DateItem(); dateItem.Date = DateTime.Parse(selectedDate); dateItem.BackColor = lblNonWorkingDayLegend.BackColor; dateItem.DateColor = lblNonWorkingDayLegend.ForeColor; dateItem.Text = ""; monthCalendar1.AddDateInfo(dateItem); } }
public void AddDateInfo(DateItem info) { Dates.Add(info); Invalidate(); }