source: Scheduling/branches/GUI1.2/CalendarGrid.cs@ 1154

Last change on this file since 1154 was 622, checked in by Sam Habiel, 15 years ago

This update does the following:

File size: 49.1 KB
Line 
1namespace IndianHealthService.ClinicalScheduling
2{
3 using System;
4 using System.Collections;
5 using System.ComponentModel;
6 using System.Drawing;
7 using System.Globalization;
8 using System.Runtime.CompilerServices;
9 using System.Runtime.InteropServices;
10 using System.Windows.Forms;
11 /// <summary>
12 /// This class was regenerated from Calendargrid.dll using Reflector.exe
13 /// by Sam Habiel for WorldVista. The original source code is lost.
14 /// </summary>
15 public class CalendarGrid : Panel
16 {
17 private Container components;
18 private Font fontArial10;
19 private Font fontArial8;
20 private CGAppointments m_Appointments;
21 private Hashtable m_ApptOverlapTable;
22 private bool m_bAutoDrag = true;
23 private bool m_bDragDropStart;
24 private bool m_bDrawWalkIns = true;
25 private bool m_bGridEnter;
26 private bool m_bInitialUpdate;
27 private bool m_bMouseDown;
28 private bool m_bScroll;
29 private bool m_bScrollDown;
30 private bool m_bSelectingRange;
31 private int m_cellHeight;
32 private int m_cellWidth;
33 private int m_col0Width;
34 private Hashtable m_ColumnInfoTable;
35 private CGCell m_currentCell;
36 private DateTime m_dtStart;
37 private Font m_fCell;
38 private string m_GridBackColor;
39 private CGCells m_gridCells;
40 private int m_nColumns = 5;
41 private int m_nSelectID;
42 private int m_nTimeScale = 20;
43 private ArrayList m_pAvArray;
44 private string m_sDragSource;
45 private CGAppointments m_SelectedAppointments;
46 private CGRange m_selectedRange;
47 private StringFormat m_sf;
48 private StringFormat m_sfHour;
49 private StringFormat m_sfRight;
50 private ArrayList m_sResourcesArray;
51 private Timer m_Timer;
52 private ToolTip m_toolTip;
53 private const int WM_HSCROLL = 0x114;
54 private const int WM_VSCROLL = 0x115;
55
56 public event CGAppointmentChangedHandler CGAppointmentAdded;
57
58 public event CGAppointmentChangedHandler CGAppointmentChanged;
59
60 public event CGSelectionChangedHandler CGSelectionChanged;
61
62 public CalendarGrid()
63 {
64 this.InitializeComponent();
65 base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
66 base.SetStyle(ControlStyles.UserPaint, true);
67 base.SetStyle(ControlStyles.DoubleBuffer, true);
68 this.m_nColumns = 5;
69 this.m_gridCells = new CGCells();
70 this.m_selectedRange = new CGRange();
71 this.m_SelectedAppointments = new CGAppointments();
72 this.m_dtStart = new DateTime(0x7d3, 1, 0x1b);
73 this.m_ApptOverlapTable = new Hashtable();
74 this.m_ColumnInfoTable = new Hashtable();
75 this.m_sResourcesArray = new ArrayList();
76 base.ResizeRedraw = true;
77 this.m_col0Width = 100;
78 this.fontArial8 = new Font("Arial", 8f);
79 this.fontArial10 = new Font("Arial", 10f);
80 this.m_fCell = this.fontArial10;
81 this.m_sf = new StringFormat();
82 this.m_sfRight = new StringFormat();
83 this.m_sfHour = new StringFormat();
84 this.m_sf.LineAlignment = StringAlignment.Center;
85 this.m_sfRight.LineAlignment = StringAlignment.Center;
86 this.m_sfRight.Alignment = StringAlignment.Far;
87 this.m_sfHour.LineAlignment = StringAlignment.Center;
88 this.m_sfHour.Alignment = StringAlignment.Far;
89 this.m_bInitialUpdate = false;
90 }
91
92 private Rectangle AdjustRectForOverlap()
93 {
94 return new Rectangle();
95 }
96
97 private void AutoDragStart()
98 {
99 this.m_bAutoDrag = true;
100 this.m_Timer = new Timer();
101 this.m_Timer.Interval = 5;
102 this.m_Timer.Tick += new EventHandler(this.tickEventHandler);
103 this.m_Timer.Start();
104 }
105
106 private void AutoDragStop()
107 {
108 this.m_bAutoDrag = false;
109 if (this.m_Timer != null)
110 {
111 this.m_Timer.Stop();
112 this.m_Timer.Dispose();
113 this.m_Timer = null;
114 }
115 }
116
117 private void BuildGridCellsArray(Graphics g)
118 {
119 try
120 {
121 SizeF ef = g.MeasureString("Test", this.m_fCell);
122 this.m_cellHeight = ((int) ef.Height) + 4;
123 int nColumns = this.m_nColumns;
124 int num2 = 60 / this.m_nTimeScale;
125 int num3 = 0x18 * num2;
126 nColumns++;
127 num3++;
128 this.m_cellWidth = 600 / nColumns;
129 if (base.ClientRectangle.Width > 600)
130 {
131 this.m_cellWidth = (base.ClientRectangle.Width - this.m_col0Width) / (nColumns - 1);
132 }
133 if (this.m_nColumns == 1)
134 {
135 this.m_cellWidth = base.ClientRectangle.Width - this.m_col0Width;
136 }
137 g.TranslateTransform((float) base.AutoScrollPosition.X, (float) base.AutoScrollPosition.Y);
138 for (int i = num3; i > -1; i--)
139 {
140 for (int j = 1; j < nColumns; j++)
141 {
142 int x = 0;
143 if (j == 1)
144 {
145 x = this.m_col0Width;
146 }
147 if (j > 1)
148 {
149 x = this.m_col0Width + (this.m_cellWidth * (j - 1));
150 }
151 Point point = new Point(x, i * this.m_cellHeight);
152 Rectangle r = new Rectangle(point.X, point.Y, this.m_cellWidth, this.m_cellHeight);
153 if (i != 0)
154 {
155 CGCell cell = null;
156 cell = new CGCell(r, i, j);
157 this.m_gridCells.AddCell(cell);
158 }
159 }
160 }
161 }
162 catch (Exception exception)
163 {
164 string message = exception.Message;
165 }
166 }
167
168 private void CalendarGrid_DragDrop(object Sender, DragEventArgs e)
169 {
170 CGAppointment data = (CGAppointment) e.Data.GetData(typeof(CGAppointment));
171 Point point = base.PointToClient(new Point(e.X, e.Y));
172 int x = point.X - base.AutoScrollPosition.X;
173 int y = point.Y - base.AutoScrollPosition.Y;
174 Point pt = new Point(x, y);
175 foreach (DictionaryEntry entry in this.m_gridCells.CellHashTable)
176 {
177 CGCell cgCell = (CGCell) entry.Value;
178 if (cgCell.CellRectangle.Contains(pt))
179 {
180 DateTime timeFromCell = this.GetTimeFromCell(cgCell);
181 string resourceFromColumn = this.GetResourceFromColumn(cgCell.CellColumn);
182 int duration = data.Duration;
183 TimeSpan span = new TimeSpan(0, duration, 0);
184 DateTime time2 = timeFromCell + span;
185 data.Selected = false;
186 this.m_nSelectID = 0;
187 CGAppointmentChangedArgs args = new CGAppointmentChangedArgs();
188 args.Appointment = data;
189 args.StartTime = timeFromCell;
190 args.EndTime = time2;
191 args.Resource = resourceFromColumn;
192 args.OldResource = data.Resource;
193 args.AccessTypeID = data.AccessTypeID;
194 args.Slots = data.Slots;
195 if (this.ApptDragSource == "grid")
196 {
197 this.CGAppointmentChanged(this, args);
198 }
199 else
200 {
201 this.CGAppointmentAdded(this, args);
202 }
203 break;
204 }
205 }
206 this.SetOverlapTable();
207 base.Invalidate();
208 }
209
210 private void CalendarGrid_DragEnter(object Sender, DragEventArgs e)
211 {
212 if (e.Data.GetDataPresent(typeof(CGAppointment)))
213 {
214 if ((e.KeyState & 8) == 8)
215 {
216 e.Effect = DragDropEffects.Copy;
217 }
218 else
219 {
220 e.Effect = DragDropEffects.Move;
221 }
222 }
223 else
224 {
225 e.Effect = DragDropEffects.None;
226 }
227 }
228
229 private void CalendarGrid_MouseDown(object sender, MouseEventArgs e)
230 {
231 if (e.Button == MouseButtons.Left)
232 {
233 foreach (DictionaryEntry entry in this.m_gridCells.CellHashTable)
234 {
235 CGCell cell = (CGCell) entry.Value;
236 cell.IsSelected = false;
237 }
238 this.m_selectedRange.Cells.ClearAllCells();
239 this.m_bMouseDown = true;
240 this.OnLButtonDown(e.X, e.Y, true);
241 }
242 }
243
244 private void CalendarGrid_MouseMove(object Sender, MouseEventArgs e)
245 {
246 if (this.m_bMouseDown)
247 {
248 if ((e.Y >= base.ClientRectangle.Bottom) || (e.Y <= base.ClientRectangle.Top))
249 {
250 this.m_bScrollDown = e.Y >= base.ClientRectangle.Bottom;
251 }
252 if ((e.Y < base.ClientRectangle.Bottom) && (e.Y > base.ClientRectangle.Top))
253 {
254 bool bAutoDrag = this.m_bAutoDrag;
255 }
256 if (this.m_bSelectingRange)
257 {
258 this.OnLButtonDown(e.X, e.Y, false);
259 }
260 if (this.m_nSelectID != 0)
261 {
262 if (this.m_bGridEnter)
263 {
264 this.m_bGridEnter = false;
265 }
266 else if (!this.m_bDragDropStart)
267 {
268 CGAppointment data = (CGAppointment) this.m_Appointments.AppointmentTable[this.m_nSelectID];
269 this.ApptDragSource = "grid";
270 base.DoDragDrop(data, DragDropEffects.Move);
271 this.m_bDragDropStart = true;
272 }
273 }
274 }
275 else
276 {
277 int y = e.Y - base.AutoScrollPosition.Y;
278 int x = e.X - base.AutoScrollPosition.X;
279 Point pt = new Point(x, y);
280 foreach (CGAppointment appointment2 in this.m_Appointments.AppointmentTable.Values)
281 {
282 if (appointment2.GridRectangle.Contains(pt))
283 {
284 this.m_toolTip.SetToolTip(this, appointment2.ToString());
285 return;
286 }
287 }
288 this.m_toolTip.RemoveAll();
289 }
290 }
291
292 private void CalendarGrid_MouseUp(object Sender, MouseEventArgs e)
293 {
294 if (this.m_bAutoDrag)
295 {
296 this.m_bAutoDrag = false;
297 this.AutoDragStop();
298 }
299 this.m_bMouseDown = false;
300 if (this.m_bSelectingRange)
301 {
302 CGSelectionChangedArgs args = new CGSelectionChangedArgs();
303 args.StartTime = this.GetTimeFromCell(this.m_selectedRange.StartCell);
304 args.EndTime = this.GetTimeFromCell(this.m_selectedRange.EndCell);
305 args.Resource = this.GetResourceFromColumn(this.m_selectedRange.StartCell.CellColumn);
306 if (args.EndTime < args.StartTime)
307 {
308 DateTime startTime = args.StartTime;
309 args.StartTime = args.EndTime;
310 args.EndTime = startTime;
311 }
312 TimeSpan span = new TimeSpan(0, 0, this.m_nTimeScale, 0, 0);
313 args.EndTime += span;
314 this.CGSelectionChanged(this, args);
315 this.m_bSelectingRange = false;
316 }
317 }
318
319 private void CalendarGrid_Paint(object sender, PaintEventArgs e)
320 {
321 if (e.Graphics != null)
322 {
323 this.DrawGrid(e.Graphics);
324 if (!this.m_bInitialUpdate)
325 {
326 this.SetAppointmentTypes();
327 base.Invalidate();
328 this.m_bInitialUpdate = true;
329 }
330 }
331 }
332
333 public void CloseGrid()
334 {
335 foreach (CGAppointment appointment in this.m_Appointments.AppointmentTable.Values)
336 {
337 appointment.Selected = false;
338 }
339 this.m_nSelectID = 0;
340 }
341
342 protected override void Dispose(bool disposing)
343 {
344 if (disposing && (this.components != null))
345 {
346 this.components.Dispose();
347 }
348 base.Dispose(disposing);
349 }
350
351 private void DrawAppointments(Graphics g, int col0Width, int cellWidth, int cellHeight)
352 {
353 if (!base.DesignMode && (this.m_Appointments != null))
354 {
355 int num = 0;
356 int num2 = 0;
357 int x = 0;
358 ArrayList list = new ArrayList();
359 foreach (CGAppointment appointment in this.m_Appointments.AppointmentTable.Values)
360 {
361 bool bRet = false;
362 Rectangle rect = this.GetAppointmentRect(appointment, col0Width, cellWidth, cellHeight, out bRet);
363 if (bRet && (!appointment.WalkIn || this.m_bDrawWalkIns))
364 {
365 rect.Inflate(-10, 0);
366 num = (int) this.m_ApptOverlapTable[appointment.m_nKey];
367 num2 = rect.Right - rect.Left;
368 x = num2 / (num + 1);
369 rect.Width = x;
370 if (num > 0)
371 {
372 foreach (object obj2 in list)
373 {
374 Rectangle rectangle2 = (Rectangle) obj2;
375 if (rect.IntersectsWith(rectangle2))
376 {
377 rect.Offset(x, 0);
378 }
379 }
380 }
381 appointment.GridRectangle = rect;
382 if (appointment.Selected)
383 {
384 Pen pen = new Pen(Brushes.Black, 5f);
385 g.DrawRectangle(pen, rect);
386 pen.Dispose();
387 }
388 else
389 {
390 g.DrawRectangle(Pens.Blue, rect);
391 }
392 string s = appointment.ToString();
393 Rectangle rectangle3 = new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 1, rect.Height - 1);
394 g.FillRectangle(Brushes.White, rectangle3);
395 Brush black = Brushes.Black;
396 if (appointment.CheckInTime.Ticks > 0L)
397 {
398 black = Brushes.Green;
399 g.FillRectangle(Brushes.LightGreen, rectangle3);
400 }
401 if (appointment.NoShow)
402 {
403 black = Brushes.Red;
404 g.FillRectangle(Brushes.LightPink, rectangle3);
405 }
406 if (appointment.WalkIn)
407 {
408 black = Brushes.Blue;
409 g.FillRectangle(Brushes.LightSteelBlue, rectangle3);
410 }
411 g.DrawString(s, this.fontArial8, black, rectangle3);
412 list.Add(rect);
413 }
414 }
415 }
416 }
417
418 private void DrawGrid(Graphics g)
419 {
420 try
421 {
422 Pen pen = new Pen(Color.Black);
423 SizeF ef = g.MeasureString("Test", this.m_fCell);
424 int num = 10;
425 this.m_cellHeight = ((int) ef.Height) + num;
426 int nColumns = this.m_nColumns;
427 int num3 = 60 / this.m_nTimeScale;
428 int num4 = 0x18 * num3;
429 nColumns++;
430 num4++;
431 this.m_cellWidth = 600 / nColumns;
432 if (base.ClientRectangle.Width > 600)
433 {
434 this.m_cellWidth = (base.ClientRectangle.Width - this.m_col0Width) / (nColumns - 1);
435 }
436 if (this.m_nColumns == 1)
437 {
438 this.m_cellWidth = base.ClientRectangle.Width - this.m_col0Width;
439 }
440 base.AutoScrollMinSize = new Size(600, this.m_cellHeight * num4);
441 g.FillRectangle(Brushes.LightGray, base.ClientRectangle);
442 int num5 = 0;
443 int num6 = 0;
444 bool flag = this.m_gridCells.CellCount == 0;
445 g.TranslateTransform((float) base.AutoScrollPosition.X, (float) base.AutoScrollPosition.Y);
446 for (int i = 1; i < num4; i++)
447 {
448 int x = 0;
449 Point point = new Point(x, i * this.m_cellHeight);
450 Rectangle rectangle2 = new Rectangle(point.X, point.Y, this.m_cellWidth, this.m_cellHeight);
451 Rectangle rect = new Rectangle(0, rectangle2.Y, this.m_col0Width, rectangle2.Height * num3);
452 int height = rect.Height;
453 height = (height > (this.m_col0Width / 4)) ? (this.m_col0Width / 4) : height;
454 if (num5 == 0)
455 {
456 g.FillRectangle(Brushes.LightGray, rect);
457 g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
458 string str = string.Format("{0}", num6).PadLeft(2, '0');
459 Font font = new Font("Arial", (float) height, FontStyle.Bold, GraphicsUnit.Pixel);
460 Rectangle rectangle3 = new Rectangle(rect.X, rect.Y, rect.Width / 2, rect.Height);
461 g.DrawString(str, font, Brushes.Black, rectangle3, this.m_sfHour);
462 num6++;
463 font.Dispose();
464 }
465 string s = string.Format("{0}", num5);
466 s = ":" + s.PadLeft(2, '0');
467 Rectangle layoutRectangle = new Rectangle(rect.X + ((rect.Width * 2) / 3), rectangle2.Top, rect.Width / 3, rectangle2.Height);
468 g.DrawString(s, this.m_fCell, Brushes.Black, layoutRectangle, this.m_sfRight);
469 Point point2 = new Point(rect.X + ((rect.Width * 2) / 3), rectangle2.Bottom);
470 Point point3 = new Point(rect.Right, rectangle2.Bottom);
471 g.DrawLine(pen, point2, point3);
472 num5 += this.m_nTimeScale;
473 num5 = (num5 >= 60) ? 0 : num5;
474 if ((i == (num4 - 1)) && !this.m_bScroll)
475 {
476 g.TranslateTransform((float) -base.AutoScrollPosition.X, (float) -base.AutoScrollPosition.Y);
477 rect = new Rectangle(0, 0, this.m_col0Width, this.m_cellHeight);
478 g.FillRectangle(Brushes.LightGray, rect);
479 g.DrawRectangle(pen, rect);
480 g.TranslateTransform((float) base.AutoScrollPosition.X, (float) base.AutoScrollPosition.Y);
481 }
482 }
483 for (int j = num4; j > -1; j--)
484 {
485 for (int k = 1; k < nColumns; k++)
486 {
487 int num12 = 0;
488 if (k == 1)
489 {
490 num12 = this.m_col0Width;
491 }
492 if (k > 1)
493 {
494 num12 = this.m_col0Width + (this.m_cellWidth * (k - 1));
495 }
496 Point point4 = new Point(num12, j * this.m_cellHeight);
497 Rectangle r = new Rectangle(point4.X, point4.Y, this.m_cellWidth, this.m_cellHeight);
498 if (j != 0)
499 {
500 CGCell cellFromRowCol = null;
501 if (flag)
502 {
503 cellFromRowCol = new CGCell(r, j, k);
504 this.m_gridCells.AddCell(cellFromRowCol);
505 }
506 else
507 {
508 cellFromRowCol = this.m_gridCells.GetCellFromRowCol(j, k);
509 cellFromRowCol.CellRectangle = r;
510 }
511 if (this.m_sResourcesArray.Count > 0)
512 {
513 if (this.m_selectedRange.CellIsInRange(cellFromRowCol))
514 {
515 g.FillRectangle(Brushes.Aquamarine, r);
516 }
517 else
518 {
519 g.FillRectangle(cellFromRowCol.AppointmentTypeColor, r);
520 }
521 g.DrawRectangle(pen, r.X, r.Y, r.Width, r.Height);
522 if (j == 1)
523 {
524 this.DrawAppointments(g, this.m_col0Width, this.m_cellWidth, this.m_cellHeight);
525 }
526 }
527 continue;
528 }
529 if (!this.m_bScroll)
530 {
531 g.TranslateTransform(0f, (float) -base.AutoScrollPosition.Y);
532 Rectangle rectangle6 = r;
533 g.FillRectangle(Brushes.LightBlue, rectangle6);
534 g.DrawRectangle(pen, rectangle6.X, rectangle6.Y, rectangle6.Width, rectangle6.Height);
535 string str3 = "";
536 if (this.m_sResourcesArray.Count > 1)
537 {
538 foreach (DictionaryEntry entry in this.m_ColumnInfoTable)
539 {
540 int num13 = (int) entry.Value;
541 num13++;
542 if (num13 == k)
543 {
544 str3 = entry.Key.ToString();
545 break;
546 }
547 }
548 }
549 else
550 {
551 DateTime dtStart = this.m_dtStart;
552 if (k > 1)
553 {
554 dtStart = dtStart.AddDays((double) (k - 1));
555 }
556 string format = "ddd, MMM d";
557 str3 = dtStart.ToString(format, DateTimeFormatInfo.InvariantInfo);
558 }
559 g.DrawString(str3, this.m_fCell, Brushes.Black, rectangle6, this.m_sf);
560 g.TranslateTransform(0f, (float) base.AutoScrollPosition.Y);
561 }
562 }
563 }
564 this.m_bScroll = false;
565 pen.Dispose();
566 }
567 catch (Exception)
568 {
569 }
570 }
571
572 public Rectangle GetAppointmentRect(CGAppointment a, int col0Width, int cellWidth, int cellHeight, out bool bRet)
573 {
574 DateTime startTime = a.StartTime;
575 DateTime endTime = a.EndTime;
576 string resource = a.Resource;
577 int num = 0;
578 int num2 = 0;
579 int num3 = 0;
580 int num4 = 0;
581 int num5 = 0;
582 Rectangle rectangle = new Rectangle();
583 int totalMinutes = (int) startTime.TimeOfDay.TotalMinutes;
584 int num7 = (int) endTime.TimeOfDay.TotalMinutes;
585 if (this.m_sResourcesArray.Count > 1)
586 {
587 num5 = (int) this.m_ColumnInfoTable[resource];
588 num5++;
589 }
590 else
591 {
592 num5 = ((int) (startTime.DayOfWeek - this.m_dtStart.DayOfWeek)) + 1;
593 }
594 if (num5 < 1)
595 {
596 bRet = false;
597 return rectangle;
598 }
599 num = col0Width + (cellWidth * (num5 - 1));
600 int num8 = totalMinutes + this.m_nTimeScale;
601 int num9 = (num7 > 0) ? num7 : 0x5a0;
602 num9 -= totalMinutes;
603 num2 = (cellHeight * num8) / this.m_nTimeScale;
604 num3 = (cellHeight * num9) / this.m_nTimeScale;
605 num4 = cellWidth;
606 rectangle.X = num;
607 rectangle.Y = num2;
608 rectangle.Width = num4;
609 rectangle.Height = num3;
610 bRet = true;
611 return rectangle;
612 }
613
614 public bool GetCellFromTime(DateTime dDate, ref int nRow, ref int nCol, bool bStartCell, string sResource)
615 {
616 int num = (dDate.Hour * 60) + dDate.Minute;
617 nRow = num / this.m_nTimeScale;
618 if (bStartCell)
619 {
620 nRow++;
621 }
622 if (this.m_sResourcesArray.Count > 1)
623 {
624 if (sResource == "")
625 {
626 sResource = this.m_sResourcesArray[0].ToString();
627 }
628 nCol = (int) this.m_ColumnInfoTable[sResource];
629 nCol++;
630 return true;
631 }
632 DateTime time = new DateTime(dDate.Year, dDate.Month, dDate.Day);
633 TimeSpan span = (TimeSpan) (time - this.StartDate);
634 int totalDays = 0;
635 totalDays = (int) span.TotalDays;
636 nCol = totalDays;
637 nCol++;
638 return true;
639 }
640
641 private string GetResourceFromColumn(int nCol)
642 {
643 if (this.m_sResourcesArray.Count == 1)
644 {
645 return this.m_sResourcesArray[0].ToString();
646 }
647 foreach (DictionaryEntry entry in this.m_ColumnInfoTable)
648 {
649 int num = (int) entry.Value;
650 num++;
651 if (num == nCol)
652 {
653 return entry.Key.ToString();
654 }
655 }
656 return "";
657 }
658
659 public bool GetSelectedTime(out DateTime dStart, out DateTime dEnd, out string sResource)
660 {
661 if (this.m_selectedRange.Cells.CellCount == 0)
662 {
663 dEnd = new DateTime();
664 dStart = dEnd;
665 sResource = "";
666 return false;
667 }
668 CGCell startCell = this.m_selectedRange.StartCell;
669 CGCell endCell = this.m_selectedRange.EndCell;
670 if (startCell.CellRow > endCell.CellRow)
671 {
672 CGCell cell3 = startCell;
673 startCell = endCell;
674 endCell = cell3;
675 }
676 dStart = this.GetTimeFromCell(startCell);
677 dEnd = this.GetTimeFromCell(endCell);
678 dEnd = dEnd.AddMinutes((double) this.m_nTimeScale);
679 sResource = this.GetResourceFromColumn(startCell.CellColumn);
680 return true;
681 }
682
683 public bool GetSelectedType(out int nAccessTypeID)
684 {
685 nAccessTypeID = 0;
686 if (this.m_selectedRange.Cells.CellCount == 0)
687 {
688 return false;
689 }
690 CGCell startCell = this.m_selectedRange.StartCell;
691 CGCell endCell = this.m_selectedRange.EndCell;
692 if (startCell.CellRow > endCell.CellRow)
693 {
694 CGCell cell3 = startCell;
695 startCell = endCell;
696 endCell = cell3;
697 }
698 DateTime timeFromCell = this.GetTimeFromCell(startCell);
699 DateTime time2 = this.GetTimeFromCell(endCell).AddMinutes((double) this.m_nTimeScale);
700 foreach (CGAvailability availability in this.m_pAvArray)
701 {
702 if (this.TimesOverlap(availability.StartTime, availability.EndTime, timeFromCell, time2))
703 {
704 nAccessTypeID = availability.AvailabilityType;
705 break;
706 }
707 }
708 return (nAccessTypeID > 0);
709 }
710
711 public DateTime GetTimeFromCell(CGCell cgCell)
712 {
713 int cellRow = cgCell.CellRow;
714 int cellColumn = cgCell.CellColumn;
715 DateTime dtStart = this.m_dtStart;
716 int num3 = (cellRow - 1) * this.m_nTimeScale;
717 int num4 = num3 / 60;
718 if (num4 > 0)
719 {
720 num3 = num3 % (num4 * 60);
721 }
722 dtStart = dtStart.AddHours((double) num4).AddMinutes((double) num3);
723 if (this.m_sResourcesArray.Count == 1)
724 {
725 dtStart = dtStart.AddDays((double) (cellColumn - 1));
726 }
727 return dtStart;
728 }
729
730 public bool GetTypeFromCell(CGCell cgCell, out int nAccessTypeID)
731 {
732 nAccessTypeID = 0;
733 CGCell cell = cgCell;
734 CGCell cell2 = cgCell;
735 if (cell.CellRow > cell2.CellRow)
736 {
737 CGCell cell3 = cell;
738 cell = cell2;
739 cell2 = cell3;
740 }
741 DateTime timeFromCell = this.GetTimeFromCell(cell);
742 DateTime time2 = this.GetTimeFromCell(cell2).AddMinutes((double) this.m_nTimeScale);
743 foreach (CGAvailability availability in this.m_pAvArray)
744 {
745 if (this.TimesOverlap(availability.StartTime, availability.EndTime, timeFromCell, time2))
746 {
747 nAccessTypeID = availability.AvailabilityType;
748 break;
749 }
750 }
751 return (nAccessTypeID > 0);
752 }
753
754 private bool HitTest(int X, int Y, ref int nRow, ref int nCol)
755 {
756 Y -= base.AutoScrollPosition.Y;
757 X -= base.AutoScrollPosition.X;
758 foreach (DictionaryEntry entry in this.m_gridCells)
759 {
760 CGCell cell = (CGCell) entry.Value;
761 if (cell.CellRectangle.Contains(X, Y))
762 {
763 nRow = cell.CellRow;
764 nCol = cell.CellColumn;
765 return true;
766 }
767 }
768 return false;
769 }
770
771 public void InitializeCalendarGrid()
772 {
773 this.AllowDrop = true;
774 }
775
776 private void InitializeComponent()
777 {
778 this.AutoScroll = true;
779 base.AutoScrollMinSize = new Size(600, 400);
780 this.BackColor = SystemColors.Window;
781 base.Paint += new PaintEventHandler(this.CalendarGrid_Paint);
782 base.MouseDown += new MouseEventHandler(this.CalendarGrid_MouseDown);
783 base.MouseUp += new MouseEventHandler(this.CalendarGrid_MouseUp);
784 base.MouseMove += new MouseEventHandler(this.CalendarGrid_MouseMove);
785 base.DragEnter += new DragEventHandler(this.CalendarGrid_DragEnter);
786 base.DragDrop += new DragEventHandler(this.CalendarGrid_DragDrop);
787 this.m_toolTip = new ToolTip();
788 }
789
790 private int MinSince80(DateTime d)
791 {
792 DateTime time = new DateTime(0x7bc, 1, 1, 0, 0, 0);
793 TimeSpan span = (TimeSpan) (d - time);
794 return (int) span.TotalMinutes;
795 }
796
797 private void OnLButtonDown(int X, int Y, bool bStart)
798 {
799 this.m_bDragDropStart = false;
800 this.m_nSelectID = 0;
801 if (!this.m_bSelectingRange)
802 {
803 int y = Y - base.AutoScrollPosition.Y;
804 int x = X - base.AutoScrollPosition.X;
805 Point pt = new Point(x, y);
806 if (Control.ModifierKeys == Keys.Control)
807 {
808 this.m_bMouseDown = false;
809 foreach (CGAppointment appointment in this.m_Appointments.AppointmentTable.Values)
810 {
811 if (!appointment.GridRectangle.Contains(pt))
812 {
813 continue;
814 }
815 if (this.m_SelectedAppointments.AppointmentTable.ContainsKey(appointment.AppointmentKey))
816 {
817 this.m_SelectedAppointments.RemoveAppointment(appointment.AppointmentKey);
818 if (this.m_SelectedAppointments.AppointmentTable.Count == 0)
819 {
820 this.m_nSelectID = 0;
821 }
822 else
823 {
824 foreach (CGAppointment appointment2 in this.m_Appointments.AppointmentTable.Values)
825 {
826 this.m_nSelectID = appointment2.AppointmentKey;
827 }
828 }
829 }
830 else
831 {
832 this.m_SelectedAppointments.AddAppointment(appointment);
833 this.m_nSelectID = appointment.AppointmentKey;
834 }
835 appointment.Selected = !appointment.Selected;
836 break;
837 }
838 base.Invalidate();
839 return;
840 }
841 foreach (CGAppointment appointment3 in this.m_Appointments.AppointmentTable.Values)
842 {
843 if (!appointment3.GridRectangle.Contains(pt))
844 {
845 continue;
846 }
847 this.m_bMouseDown = false;
848 if (appointment3.Selected)
849 {
850 appointment3.Selected = false;
851 this.m_SelectedAppointments.ClearAllAppointments();
852 this.m_nSelectID = 0;
853 }
854 else
855 {
856 foreach (CGAppointment appointment4 in this.m_Appointments.AppointmentTable.Values)
857 {
858 appointment4.Selected = false;
859 }
860 this.m_SelectedAppointments.ClearAllAppointments();
861 this.m_SelectedAppointments.AddAppointment(appointment3);
862 appointment3.Selected = true;
863 this.m_nSelectID = appointment3.AppointmentKey;
864 this.m_bMouseDown = true;
865 this.m_bGridEnter = true;
866 }
867 base.Invalidate();
868 return;
869 }
870 }
871 int nRow = -1;
872 int nCol = -1;
873 if (this.HitTest(X, Y, ref nRow, ref nCol))
874 {
875 CGCell cellFromRowCol = this.m_gridCells.GetCellFromRowCol(nRow, nCol);
876 if (cellFromRowCol != null)
877 {
878 if (bStart)
879 {
880 this.m_currentCell = cellFromRowCol;
881 this.m_selectedRange.StartCell = null;
882 this.m_selectedRange.EndCell = null;
883 this.m_selectedRange.CreateRange(this.m_gridCells, cellFromRowCol, cellFromRowCol);
884 bStart = false;
885 this.m_bMouseDown = true;
886 this.m_bSelectingRange = true;
887 }
888 else if (cellFromRowCol != this.m_currentCell)
889 {
890 if (!this.m_selectedRange.Cells.CellHashTable.ContainsKey(cellFromRowCol.Key))
891 {
892 this.m_selectedRange.AppendCell(this.m_gridCells, cellFromRowCol);
893 }
894 else
895 {
896 bool bUp = cellFromRowCol.CellRow < this.m_currentCell.CellRow;
897 this.m_selectedRange.SubtractCell(this.m_gridCells, cellFromRowCol, bUp);
898 }
899 this.m_currentCell = cellFromRowCol;
900 }
901 cellFromRowCol.IsSelected = true;
902 base.Invalidate();
903 }
904 }
905 }
906
907 public void OnUpdateArrays()
908 {
909 try
910 {
911 this.m_gridCells.ClearAllCells();
912 this.SetColumnInfo();
913 this.SetOverlapTable();
914 Graphics g = base.CreateGraphics();
915 this.BuildGridCellsArray(g);
916 this.SetAppointmentTypes();
917 }
918 catch (Exception exception)
919 {
920 string message = exception.Message;
921 }
922 }
923
924 private void SetAppointmentTypes()
925 {
926 if (this.m_gridCells.CellCount != 0)
927 {
928 foreach (DictionaryEntry entry in this.m_gridCells.CellHashTable)
929 {
930 CGCell cell = (CGCell) entry.Value;
931 cell.AppointmentTypeColor = (this.m_GridBackColor == "blue") ? Brushes.CornflowerBlue : Brushes.Khaki;
932 }
933 if ((this.m_pAvArray != null) && (this.m_pAvArray.Count != 0))
934 {
935 foreach (CGAvailability availability in this.m_pAvArray)
936 {
937 int nRow = 0;
938 int nCol = 0;
939 int num3 = 0;
940 int num4 = 0;
941 Brush brush = new SolidBrush(Color.FromArgb(availability.Red, availability.Green, availability.Blue));
942 this.GetCellFromTime(availability.StartTime, ref nRow, ref nCol, true, availability.ResourceList);
943 this.GetCellFromTime(availability.EndTime, ref num3, ref num4, false, availability.ResourceList);
944 for (int i = nCol; i <= num4; i++)
945 {
946 for (int j = nRow; (i == num4) && (j <= num3); j++)
947 {
948 string str = "r" + j.ToString() + "c" + i.ToString();
949 CGCell cell2 = (CGCell) this.m_gridCells.CellHashTable[str];
950 if (cell2 != null)
951 {
952 cell2.AppointmentTypeColor = brush;
953 }
954 }
955 }
956 }
957 }
958 }
959 }
960
961 private void SetColumnInfo()
962 {
963 this.m_ColumnInfoTable.Clear();
964 for (int i = 0; i < this.m_sResourcesArray.Count; i++)
965 {
966 this.m_ColumnInfoTable.Add(this.m_sResourcesArray[i], i);
967 }
968 if (this.m_sResourcesArray.Count > 1)
969 {
970 this.m_nColumns = this.m_sResourcesArray.Count;
971 }
972 }
973
974 public void SetOverlapTable()
975 {
976 Hashtable hashtable = new Hashtable();
977 int y = 0;
978 int num2 = 0;
979 int x = 0;
980 foreach (CGAppointment appointment in this.m_Appointments.AppointmentTable.Values)
981 {
982 if (!appointment.WalkIn || this.m_bDrawWalkIns)
983 {
984 string resource = appointment.Resource;
985 y = appointment.StartTime.Minute + (60 * appointment.StartTime.Hour);
986 num2 = appointment.EndTime.Minute + (60 * appointment.EndTime.Hour);
987 x = (this.m_sResourcesArray.Count > 1) ? (((int) this.m_ColumnInfoTable[resource]) + 1) : appointment.StartTime.DayOfYear;
988 Rectangle rectangle = new Rectangle(x, y, 1, num2 - y);
989 hashtable.Add(appointment.m_nKey, rectangle);
990 }
991 }
992 this.m_ApptOverlapTable.Clear();
993 foreach (int num4 in hashtable.Keys)
994 {
995 this.m_ApptOverlapTable.Add(num4, 0);
996 }
997 if (this.m_ApptOverlapTable.Count != 0)
998 {
999 int num5 = (this.m_sResourcesArray.Count > 1) ? 1 : this.StartDate.DayOfYear;
1000 int num6 = (this.m_sResourcesArray.Count > 1) ? (this.m_sResourcesArray.Count + 1) : (this.Columns + this.StartDate.DayOfYear);
1001 for (int i = num5; i < num6; i++)
1002 {
1003 ArrayList list = new ArrayList();
1004 for (int j = 1; j < this.Rows; j++)
1005 {
1006 Rectangle rectangle2 = new Rectangle(i, j * this.m_nTimeScale, 1, this.m_nTimeScale);
1007 int num9 = -1;
1008 list.Clear();
1009 foreach (int num10 in hashtable.Keys)
1010 {
1011 Rectangle rect = (Rectangle) hashtable[num10];
1012 if (rectangle2.IntersectsWith(rect))
1013 {
1014 num9++;
1015 list.Add(num10);
1016 }
1017 }
1018 if (num9 > 0)
1019 {
1020 foreach (object obj2 in list)
1021 {
1022 int num11 = (int) obj2;
1023 if (((int) this.m_ApptOverlapTable[num11]) < num9)
1024 {
1025 this.m_ApptOverlapTable[num11] = num9;
1026 }
1027 }
1028 }
1029 }
1030 }
1031 }
1032 }
1033
1034 private void tickEventHandler(object o, EventArgs e)
1035 {
1036 Point point = new Point(base.AutoScrollPosition.X, base.AutoScrollPosition.Y);
1037 int x = point.X;
1038 int num = point.Y * -1;
1039 num = this.m_bScrollDown ? (num + 5) : (num - 5);
1040 point.Y = num;
1041 base.AutoScrollPosition = point;
1042 base.Invalidate();
1043 }
1044
1045 private bool TimesOverlap(DateTime dStart1, DateTime dEnd1, DateTime dStart2, DateTime dEnd2)
1046 {
1047 long ticks = dEnd1.Ticks - dStart1.Ticks;
1048 TimeSpan ts = new TimeSpan(ticks);
1049 ticks = dEnd2.Ticks - dStart2.Ticks;
1050 new TimeSpan(ticks).Subtract(ts);
1051 Rectangle rect = new Rectangle();
1052 Rectangle rectangle2 = new Rectangle();
1053 rect.X = 0;
1054 rectangle2.X = 0;
1055 rect.Width = 1;
1056 rectangle2.Width = 1;
1057 rect.Y = this.MinSince80(dStart1);
1058 rect.Height = this.MinSince80(dEnd1) - rect.Y;
1059 rectangle2.Y = this.MinSince80(dStart2);
1060 rectangle2.Height = this.MinSince80(dEnd2) - rectangle2.Y;
1061 return rectangle2.IntersectsWith(rect);
1062 }
1063
1064 protected override void WndProc(ref Message msg)
1065 {
1066 try
1067 {
1068 if (msg.Msg == 0x115)
1069 {
1070 this.m_bScroll = true;
1071 base.Invalidate(false);
1072 this.m_bScroll = false;
1073 }
1074 if (msg.Msg == 0x114)
1075 {
1076 base.Invalidate(false);
1077 }
1078 base.WndProc(ref msg);
1079 }
1080 catch (Exception exception)
1081 {
1082 MessageBox.Show("CalendarGrid::WndProc: " + exception.Message + "\nStack: " + exception.StackTrace);
1083 }
1084 }
1085
1086 public CGAppointments Appointments
1087 {
1088 get
1089 {
1090 return this.m_Appointments;
1091 }
1092 set
1093 {
1094 this.m_Appointments = value;
1095 }
1096 }
1097
1098 public string ApptDragSource
1099 {
1100 get
1101 {
1102 return this.m_sDragSource;
1103 }
1104 set
1105 {
1106 this.m_sDragSource = value;
1107 }
1108 }
1109
1110 public ArrayList AvailabilityArray
1111 {
1112 get
1113 {
1114 return this.m_pAvArray;
1115 }
1116 set
1117 {
1118 this.m_pAvArray = value;
1119 }
1120 }
1121
1122 public int CellHeight
1123 {
1124 get
1125 {
1126 return this.m_cellHeight;
1127 }
1128 }
1129
1130 public ToolTip CGToolTip
1131 {
1132 get
1133 {
1134 return this.m_toolTip;
1135 }
1136 }
1137
1138 public int Columns
1139 {
1140 get
1141 {
1142 return this.m_nColumns;
1143 }
1144 set
1145 {
1146 if ((value > 0) && (value < 11))
1147 {
1148 this.m_nColumns = value;
1149 this.m_gridCells.ClearAllCells();
1150 this.m_selectedRange.Cells.ClearAllCells();
1151 Graphics g = base.CreateGraphics();
1152 this.BuildGridCellsArray(g);
1153 this.SetAppointmentTypes();
1154 base.Invalidate();
1155 }
1156 }
1157 }
1158
1159 public bool DrawWalkIns
1160 {
1161 get
1162 {
1163 return this.m_bDrawWalkIns;
1164 }
1165 set
1166 {
1167 this.m_bDrawWalkIns = value;
1168 }
1169 }
1170
1171 public string GridBackColor
1172 {
1173 get
1174 {
1175 return this.m_GridBackColor;
1176 }
1177 set
1178 {
1179 this.m_GridBackColor = value;
1180 }
1181 }
1182
1183 public bool GridEnter
1184 {
1185 get
1186 {
1187 return this.m_bGridEnter;
1188 }
1189 set
1190 {
1191 this.m_bGridEnter = value;
1192 }
1193 }
1194
1195 public ArrayList Resources
1196 {
1197 get
1198 {
1199 return this.m_sResourcesArray;
1200 }
1201 set
1202 {
1203 this.m_sResourcesArray = value;
1204 }
1205 }
1206
1207 public int Rows
1208 {
1209 get
1210 {
1211 return (0x5a0 / this.m_nTimeScale);
1212 }
1213 }
1214
1215 public int SelectedAppointment
1216 {
1217 get
1218 {
1219 return this.m_nSelectID;
1220 }
1221 set
1222 {
1223 this.m_nSelectID = value;
1224 }
1225 }
1226
1227 public CGAppointments SelectedAppointments
1228 {
1229 get
1230 {
1231 return this.m_SelectedAppointments;
1232 }
1233 }
1234
1235 public CGRange SelectedRange
1236 {
1237 get
1238 {
1239 return this.m_selectedRange;
1240 }
1241 }
1242
1243 public DateTime StartDate
1244 {
1245 get
1246 {
1247 return this.m_dtStart;
1248 }
1249 set
1250 {
1251 this.m_dtStart = value;
1252 }
1253 }
1254
1255 public int TimeScale
1256 {
1257 get
1258 {
1259 return this.m_nTimeScale;
1260 }
1261 set
1262 {
1263 if ((((value == 5) || (value == 10)) || ((value == 15) || (value == 20))) || ((value == 30) || (value == 60)))
1264 {
1265 this.m_nTimeScale = value;
1266 this.m_gridCells.ClearAllCells();
1267 this.m_selectedRange.Cells.ClearAllCells();
1268 Graphics g = base.CreateGraphics();
1269 this.BuildGridCellsArray(g);
1270 this.SetAppointmentTypes();
1271 base.Invalidate();
1272 }
1273 }
1274 }
1275 }
1276}
1277
Note: See TracBrowser for help on using the repository browser.