1 | namespace 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 |
|
---|
12 | /// <summary>
|
---|
13 | /// This class is reponsible for rendering the Calendar Grid.
|
---|
14 | /// </summary>
|
---|
15 | public class CalendarGrid : ScrollableControl
|
---|
16 | {
|
---|
17 | private IContainer 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; // Timeer used in Drag and Drop Operations
|
---|
52 | private ToolTip m_toolTip;
|
---|
53 | private const int WM_HSCROLL = 0x114; // Horizontal Scrolling Windows Message
|
---|
54 | private const int WM_VSCROLL = 0x115; // Vertical Scrolling Windows Message
|
---|
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(2003, 1, 27);
|
---|
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 = 24 * 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 | ////smh new code -- select cell
|
---|
291 | //int nRow = -1;
|
---|
292 | //int nCol = -1;
|
---|
293 |
|
---|
294 | ////Is the mouse over a known cell? If so, highlight cell
|
---|
295 | //if (this.HitTest(x, y, ref nRow, ref nCol))
|
---|
296 | //{
|
---|
297 | // CGCell cellFromRowCol = this.m_gridCells.GetCellFromRowCol(nRow, nCol);
|
---|
298 | // if (cellFromRowCol != null)
|
---|
299 | // {
|
---|
300 | // this.m_currentCell = cellFromRowCol;
|
---|
301 | // this.m_selectedRange.StartCell = null;
|
---|
302 | // this.m_selectedRange.EndCell = null;
|
---|
303 | // this.m_selectedRange.CreateRange(this.m_gridCells, cellFromRowCol, cellFromRowCol);
|
---|
304 | // this.m_bSelectingRange = true;
|
---|
305 | // cellFromRowCol.IsSelected = true;
|
---|
306 | // base.Invalidate(this.m_currentCell.CellRectangle);
|
---|
307 | // //base.Invalidate();
|
---|
308 | // }
|
---|
309 | //}
|
---|
310 |
|
---|
311 |
|
---|
312 | }
|
---|
313 | }
|
---|
314 |
|
---|
315 | private void CalendarGrid_MouseUp(object Sender, MouseEventArgs e)
|
---|
316 | {
|
---|
317 | if (this.m_bAutoDrag)
|
---|
318 | {
|
---|
319 | this.m_bAutoDrag = false;
|
---|
320 | this.AutoDragStop();
|
---|
321 | }
|
---|
322 | this.m_bMouseDown = false;
|
---|
323 | if (this.m_bSelectingRange)
|
---|
324 | {
|
---|
325 | CGSelectionChangedArgs args = new CGSelectionChangedArgs();
|
---|
326 | args.StartTime = this.GetTimeFromCell(this.m_selectedRange.StartCell);
|
---|
327 | args.EndTime = this.GetTimeFromCell(this.m_selectedRange.EndCell);
|
---|
328 | args.Resource = this.GetResourceFromColumn(this.m_selectedRange.StartCell.CellColumn);
|
---|
329 | if (args.EndTime < args.StartTime)
|
---|
330 | {
|
---|
331 | DateTime startTime = args.StartTime;
|
---|
332 | args.StartTime = args.EndTime;
|
---|
333 | args.EndTime = startTime;
|
---|
334 | }
|
---|
335 | TimeSpan span = new TimeSpan(0, 0, this.m_nTimeScale, 0, 0);
|
---|
336 | args.EndTime += span;
|
---|
337 | this.CGSelectionChanged(this, args);
|
---|
338 | this.m_bSelectingRange = false;
|
---|
339 | }
|
---|
340 | }
|
---|
341 |
|
---|
342 | private void CalendarGrid_Paint(object sender, PaintEventArgs e)
|
---|
343 | {
|
---|
344 | if (e.Graphics != null)
|
---|
345 | {
|
---|
346 | this.DrawGrid(e.Graphics);
|
---|
347 | if (!this.m_bInitialUpdate)
|
---|
348 | {
|
---|
349 | this.SetAppointmentTypes();
|
---|
350 | base.Invalidate();
|
---|
351 | this.m_bInitialUpdate = true;
|
---|
352 | }
|
---|
353 | }
|
---|
354 | }
|
---|
355 |
|
---|
356 | public void CloseGrid()
|
---|
357 | {
|
---|
358 | foreach (CGAppointment appointment in this.m_Appointments.AppointmentTable.Values)
|
---|
359 | {
|
---|
360 | appointment.Selected = false;
|
---|
361 | }
|
---|
362 | this.m_nSelectID = 0;
|
---|
363 | }
|
---|
364 |
|
---|
365 | protected override void Dispose(bool disposing)
|
---|
366 | {
|
---|
367 | if (disposing && (this.components != null))
|
---|
368 | {
|
---|
369 | this.components.Dispose();
|
---|
370 | }
|
---|
371 | base.Dispose(disposing);
|
---|
372 | }
|
---|
373 |
|
---|
374 | private void DrawAppointments(Graphics g, int col0Width, int cellWidth, int cellHeight)
|
---|
375 | {
|
---|
376 | if (!base.DesignMode && (this.m_Appointments != null))
|
---|
377 | {
|
---|
378 | int num = 0;
|
---|
379 | int num2 = 0;
|
---|
380 | int x = 0;
|
---|
381 | ArrayList list = new ArrayList();
|
---|
382 | foreach (CGAppointment appointment in this.m_Appointments.AppointmentTable.Values)
|
---|
383 | {
|
---|
384 | bool bRet = false;
|
---|
385 | Rectangle rect = this.GetAppointmentRect(appointment, col0Width, cellWidth, cellHeight, out bRet);
|
---|
386 | if (bRet && (!appointment.WalkIn || this.m_bDrawWalkIns))
|
---|
387 | {
|
---|
388 | rect.Inflate(-10, 0);
|
---|
389 | num = (int) this.m_ApptOverlapTable[appointment.m_nKey];
|
---|
390 | num2 = rect.Right - rect.Left;
|
---|
391 | x = num2 / (num + 1);
|
---|
392 | rect.Width = x;
|
---|
393 | if (num > 0)
|
---|
394 | {
|
---|
395 | foreach (object obj2 in list)
|
---|
396 | {
|
---|
397 | Rectangle rectangle2 = (Rectangle) obj2;
|
---|
398 | if (rect.IntersectsWith(rectangle2))
|
---|
399 | {
|
---|
400 | rect.Offset(x, 0);
|
---|
401 | }
|
---|
402 | }
|
---|
403 | }
|
---|
404 | appointment.GridRectangle = rect;
|
---|
405 | if (appointment.Selected)
|
---|
406 | {
|
---|
407 | Pen pen = new Pen(Brushes.Black, 5f);
|
---|
408 | g.DrawRectangle(pen, rect);
|
---|
409 | pen.Dispose();
|
---|
410 | }
|
---|
411 | else
|
---|
412 | {
|
---|
413 | g.DrawRectangle(Pens.Blue, rect);
|
---|
414 | }
|
---|
415 | string s = appointment.ToString();
|
---|
416 | Rectangle rectangle3 = new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 1, rect.Height - 1);
|
---|
417 | g.FillRectangle(Brushes.White, rectangle3);
|
---|
418 | Brush black = Brushes.Black;
|
---|
419 | if (appointment.CheckInTime.Ticks > 0L)
|
---|
420 | {
|
---|
421 | black = Brushes.Green;
|
---|
422 | g.FillRectangle(Brushes.LightGreen, rectangle3);
|
---|
423 | }
|
---|
424 | if (appointment.NoShow)
|
---|
425 | {
|
---|
426 | black = Brushes.Red;
|
---|
427 | g.FillRectangle(Brushes.LightPink, rectangle3);
|
---|
428 | }
|
---|
429 | if (appointment.WalkIn)
|
---|
430 | {
|
---|
431 | black = Brushes.Blue;
|
---|
432 | g.FillRectangle(Brushes.LightSteelBlue, rectangle3);
|
---|
433 | }
|
---|
434 | g.DrawString(s, this.fontArial8, black, rectangle3);
|
---|
435 | list.Add(rect);
|
---|
436 | }
|
---|
437 | }
|
---|
438 | }
|
---|
439 | }
|
---|
440 |
|
---|
441 | private void DrawGrid(Graphics g)
|
---|
442 | {
|
---|
443 | //Default color of grid lines is black
|
---|
444 | Pen pen = new Pen(Color.Black);
|
---|
445 |
|
---|
446 | //each cell's height is Height of Arial Font 10pt + 10 pixels (by default 26 pixels)
|
---|
447 | SizeF ef = g.MeasureString("Test", this.m_fCell);
|
---|
448 | int num = 10;
|
---|
449 | this.m_cellHeight = ((int) ef.Height) + num;
|
---|
450 |
|
---|
451 | // Number of columns is dynamic based on user of Grid. See Property Columns. Default 5 in init.
|
---|
452 | int nColumns = this.m_nColumns;
|
---|
453 |
|
---|
454 | //Time scale is also dynamic. Property TimeScale. Default 20 (minutes)
|
---|
455 | //num3 stands for number of cells per hour
|
---|
456 | int num3 = 60 / this.m_nTimeScale;
|
---|
457 | //num4 stands for number of cells per day (aka rows in the grid)
|
---|
458 | int num4 = 24 * num3;
|
---|
459 | //Add extra column to hold time in the left hand corner
|
---|
460 | nColumns++;
|
---|
461 | //add extra row to represent dates or resources (depending on which view we are in)
|
---|
462 | //Not sure of which variable controls view yet.
|
---|
463 | num4++;
|
---|
464 |
|
---|
465 | // 100 px is reserved no matter our column sizes for displaying the time scale
|
---|
466 |
|
---|
467 | // Minimum cell width is 600/columns (100 px by default)
|
---|
468 | this.m_cellWidth = 600 / nColumns;
|
---|
469 |
|
---|
470 | // if we happen to have more than 600 pixels in our Client Window then cell
|
---|
471 | // is (Width-100) / (number of date columns)
|
---|
472 | if (base.ClientRectangle.Width > 600)
|
---|
473 | {
|
---|
474 | this.m_cellWidth = (base.ClientRectangle.Width - this.m_col0Width) / (nColumns - 1);
|
---|
475 | }
|
---|
476 |
|
---|
477 | // If we have one column, the cell width is the itself - 100
|
---|
478 | if (this.m_nColumns == 1)
|
---|
479 | {
|
---|
480 | this.m_cellWidth = base.ClientRectangle.Width - this.m_col0Width;
|
---|
481 | }
|
---|
482 |
|
---|
483 | // Our rectangle will start scrolling if width is less than 600 and height less than height of all cells comb
|
---|
484 | // Of course Height will scroll all the time unless you have a humungous screen
|
---|
485 | base.AutoScrollMinSize = new Size(600, this.m_cellHeight * num4);
|
---|
486 |
|
---|
487 | // Default Rectangle is Gray
|
---|
488 | g.FillRectangle(Brushes.LightGray, base.ClientRectangle);
|
---|
489 |
|
---|
490 | int num5 = 0; //Minutes (start at 0)
|
---|
491 | int num6 = 0; //Hour (starts at 0)
|
---|
492 |
|
---|
493 | // flag is true only if there are no cells what so ever in the screen
|
---|
494 | // Only true when no resource is selected.
|
---|
495 | bool flag = this.m_gridCells.CellCount == 0;
|
---|
496 |
|
---|
497 | // Move the base point from the client screen to the scrolling region top-left corner.
|
---|
498 | g.TranslateTransform((float) base.AutoScrollPosition.X, (float) base.AutoScrollPosition.Y);
|
---|
499 |
|
---|
500 | // This for loop draws the time scale (although I haven't completely traced it out)
|
---|
501 | // For each row except the first one (i starts from 1 rather than zero)
|
---|
502 | for (int i = 1; i < num4; i++)
|
---|
503 | {
|
---|
504 | int x = 0;
|
---|
505 | //point is (0, 1st Cell Start) then (0, 2nd Cell Start) until we run out
|
---|
506 | Point point = new Point(x, i * this.m_cellHeight);
|
---|
507 | //rectangle2 represents each cell rectangle
|
---|
508 | Rectangle rectangle2 = new Rectangle(point.X, point.Y, this.m_cellWidth, this.m_cellHeight);
|
---|
509 | //rect stands for the time scale rectangle; width is 100px; Height is length of the hour on grid
|
---|
510 | Rectangle rect = new Rectangle(0, rectangle2.Y, this.m_col0Width, rectangle2.Height * num3);
|
---|
511 | //height is length of hour
|
---|
512 | int height = rect.Height;
|
---|
513 | //Min font height is 25 pixels (100/4)--see below where it's used
|
---|
514 | height = (height > (this.m_col0Width / 4)) ? (this.m_col0Width / 4) : height;
|
---|
515 |
|
---|
516 | //if we are the top of the time scale (at hour:00) -- num5 is min
|
---|
517 | if (num5 == 0)
|
---|
518 | {
|
---|
519 | // Fill time scale triangle with Gray (remember, this is the whole hour!)
|
---|
520 | g.FillRectangle(Brushes.LightGray, rect);
|
---|
521 | // Draw Rectangle
|
---|
522 | g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
|
---|
523 | //Pad time with at least one zero to make it 2 digits
|
---|
524 | string str = string.Format("{0}", num6).PadLeft(2, '0');
|
---|
525 | //Font height using pixels. Min is 25 pixels
|
---|
526 | Font font = new Font("Arial", (float) height, FontStyle.Bold, GraphicsUnit.Pixel);
|
---|
527 | // rectangle3 is the left half of the time rectangle
|
---|
528 | Rectangle rectangle3 = new Rectangle(rect.X, rect.Y, rect.Width / 2, rect.Height);
|
---|
529 | // In this left half, draw the hours (m_sfHour is the stringformat:
|
---|
530 | // Horizontal Center and Right Justified to rectangle3
|
---|
531 | g.DrawString(str, font, Brushes.Black, rectangle3, this.m_sfHour);
|
---|
532 | // Increment hour
|
---|
533 | num6++;
|
---|
534 | font.Dispose();
|
---|
535 | }
|
---|
536 |
|
---|
537 | // Pad minutes with zeros to be 2 digits long
|
---|
538 | string s = string.Format("{0}", num5);
|
---|
539 | s = ":" + s.PadLeft(2, '0');
|
---|
540 | // Rectangle starts at
|
---|
541 | // X: 2/3rds of width of Time Rectangle
|
---|
542 | // Y: Top of the current time slot cell
|
---|
543 | // Width: 1/3rd of the width of the Time Rectangle
|
---|
544 | // Height: Height of a time slot
|
---|
545 | Rectangle layoutRectangle = new Rectangle(rect.X + ((rect.Width * 2) / 3), rectangle2.Top, rect.Width / 3, rectangle2.Height);
|
---|
546 | // At in this rectangle, write the minutes. Horizontal Ctr and Right Justified to Rectangle
|
---|
547 | g.DrawString(s, this.m_fCell, Brushes.Black, layoutRectangle, this.m_sfRight);
|
---|
548 | // Draw Line from two points, just under the time we have just written
|
---|
549 | Point point2 = new Point(rect.X + ((rect.Width * 2) / 3), rectangle2.Bottom);
|
---|
550 | Point point3 = new Point(rect.Right, rectangle2.Bottom);
|
---|
551 | g.DrawLine(pen, point2, point3);
|
---|
552 | // Increment the minutes with the time scale
|
---|
553 | num5 += this.m_nTimeScale;
|
---|
554 | // If miniutes reaches 60, reset to zero
|
---|
555 | num5 = (num5 >= 60) ? 0 : num5;
|
---|
556 | // When we reach the bottom (num4 - 1 is # of rows) and we are not scrolling
|
---|
557 | if ((i == (num4 - 1)) && !this.m_bScroll)
|
---|
558 | {
|
---|
559 | // Fill the last cell with Gray (?)
|
---|
560 | g.TranslateTransform((float) -base.AutoScrollPosition.X, (float) -base.AutoScrollPosition.Y);
|
---|
561 | rect = new Rectangle(0, 0, this.m_col0Width, this.m_cellHeight);
|
---|
562 | g.FillRectangle(Brushes.LightGray, rect);
|
---|
563 | g.DrawRectangle(pen, rect);
|
---|
564 | g.TranslateTransform((float) base.AutoScrollPosition.X, (float) base.AutoScrollPosition.Y);
|
---|
565 | }
|
---|
566 | }
|
---|
567 |
|
---|
568 | //This for loop draws the cells
|
---|
569 | //Start from the bottom (num4 is # of rows) and go down to the zeroth row (ie date row/resource row)
|
---|
570 | for (int j = num4; j > -1; j--)
|
---|
571 | {
|
---|
572 | // For each column - 1 (we start at 1, not zero-->We drew the first column anyways in the 1st loop)
|
---|
573 | for (int k = 1; k < nColumns; k++)
|
---|
574 | {
|
---|
575 | int num12 = 0; // X-axis position
|
---|
576 | if (k == 1) // If we are at the first column, start at 100px (default)
|
---|
577 | {
|
---|
578 | num12 = this.m_col0Width;
|
---|
579 | }
|
---|
580 | if (k > 1) //
|
---|
581 | {
|
---|
582 | num12 = this.m_col0Width + (this.m_cellWidth * (k - 1));
|
---|
583 | }
|
---|
584 | Point point4 = new Point(num12, j * this.m_cellHeight);
|
---|
585 | Rectangle r = new Rectangle(point4.X, point4.Y, this.m_cellWidth, this.m_cellHeight);
|
---|
586 | if (j != 0)
|
---|
587 | {
|
---|
588 | CGCell cellFromRowCol = null;
|
---|
589 | if (flag)
|
---|
590 | {
|
---|
591 | cellFromRowCol = new CGCell(r, j, k);
|
---|
592 | this.m_gridCells.AddCell(cellFromRowCol);
|
---|
593 | }
|
---|
594 | else
|
---|
595 | {
|
---|
596 | cellFromRowCol = this.m_gridCells.GetCellFromRowCol(j, k);
|
---|
597 | cellFromRowCol.CellRectangle = r;
|
---|
598 | }
|
---|
599 | if (this.m_sResourcesArray.Count > 0)
|
---|
600 | {
|
---|
601 | if (this.m_selectedRange.CellIsInRange(cellFromRowCol))
|
---|
602 | {
|
---|
603 | g.FillRectangle(Brushes.Aquamarine, r);
|
---|
604 | }
|
---|
605 | else
|
---|
606 | {
|
---|
607 | g.FillRectangle(cellFromRowCol.AppointmentTypeColor, r);
|
---|
608 | }
|
---|
609 | g.DrawRectangle(pen, r.X, r.Y, r.Width, r.Height);
|
---|
610 | if (j == 1)
|
---|
611 | {
|
---|
612 | this.DrawAppointments(g, this.m_col0Width, this.m_cellWidth, this.m_cellHeight);
|
---|
613 | }
|
---|
614 | }
|
---|
615 | continue;
|
---|
616 | }
|
---|
617 | if (!this.m_bScroll)
|
---|
618 | {
|
---|
619 | g.TranslateTransform(0f, (float) -base.AutoScrollPosition.Y);
|
---|
620 | Rectangle rectangle6 = r;
|
---|
621 | g.FillRectangle(Brushes.LightBlue, rectangle6);
|
---|
622 | g.DrawRectangle(pen, rectangle6.X, rectangle6.Y, rectangle6.Width, rectangle6.Height);
|
---|
623 | string str3 = "";
|
---|
624 | if (this.m_sResourcesArray.Count > 1)
|
---|
625 | {
|
---|
626 | foreach (DictionaryEntry entry in this.m_ColumnInfoTable)
|
---|
627 | {
|
---|
628 | int num13 = (int) entry.Value;
|
---|
629 | num13++;
|
---|
630 | if (num13 == k)
|
---|
631 | {
|
---|
632 | str3 = entry.Key.ToString();
|
---|
633 | break;
|
---|
634 | }
|
---|
635 | }
|
---|
636 | }
|
---|
637 | else
|
---|
638 | {
|
---|
639 | DateTime dtStart = this.m_dtStart;
|
---|
640 | if (k > 1)
|
---|
641 | {
|
---|
642 | dtStart = dtStart.AddDays((double) (k - 1));
|
---|
643 | }
|
---|
644 | string format = "ddd, MMM d";
|
---|
645 | str3 = dtStart.ToString(format, DateTimeFormatInfo.InvariantInfo);
|
---|
646 | }
|
---|
647 | g.DrawString(str3, this.m_fCell, Brushes.Black, rectangle6, this.m_sf);
|
---|
648 | g.TranslateTransform(0f, (float) base.AutoScrollPosition.Y);
|
---|
649 | }
|
---|
650 | }
|
---|
651 | }
|
---|
652 | this.m_bScroll = false;
|
---|
653 | pen.Dispose();
|
---|
654 | }
|
---|
655 |
|
---|
656 | public Rectangle GetAppointmentRect(CGAppointment a, int col0Width, int cellWidth, int cellHeight, out bool bRet)
|
---|
657 | {
|
---|
658 | DateTime startTime = a.StartTime;
|
---|
659 | DateTime endTime = a.EndTime;
|
---|
660 | string resource = a.Resource;
|
---|
661 | int originX = 0;
|
---|
662 | int originY = 0;
|
---|
663 | int recHeight = 0;
|
---|
664 | int recWidth = 0;
|
---|
665 | int columnToPutAppt = 0;
|
---|
666 | Rectangle rectangle = new Rectangle();
|
---|
667 | int startTotalMinutesoffset = (int) startTime.TimeOfDay.TotalMinutes;
|
---|
668 | int endTotalMinutesoffset = (int) endTime.TimeOfDay.TotalMinutes;
|
---|
669 |
|
---|
670 | // To fix a bug with 1 day view: if the start time of appt is before Calendar Start Date, don't draw anything.
|
---|
671 | if (startTime < this.m_dtStart)
|
---|
672 | {
|
---|
673 | bRet = false;
|
---|
674 | return rectangle;
|
---|
675 | }
|
---|
676 |
|
---|
677 | // if grid has more than one reource
|
---|
678 | if (this.m_sResourcesArray.Count > 1)
|
---|
679 | {
|
---|
680 | // get zero based index
|
---|
681 | columnToPutAppt = (int) this.m_ColumnInfoTable[resource];
|
---|
682 | // increment to 1 based index
|
---|
683 | columnToPutAppt++;
|
---|
684 | }
|
---|
685 | else
|
---|
686 | {
|
---|
687 | columnToPutAppt = (startTime - this.m_dtStart).Days + 1;
|
---|
688 | }
|
---|
689 | // this if should not get tripped; it did the same function as the new first if check.
|
---|
690 | //if (columnToPutAppt < 1)
|
---|
691 | //{
|
---|
692 | // bRet = false;
|
---|
693 | // return rectangle;
|
---|
694 | //}
|
---|
695 | originX = col0Width + (cellWidth * (columnToPutAppt - 1));
|
---|
696 | int num8 = startTotalMinutesoffset + this.m_nTimeScale;
|
---|
697 | int num9 = (endTotalMinutesoffset > 0) ? endTotalMinutesoffset : 0x5a0;
|
---|
698 | num9 -= startTotalMinutesoffset;
|
---|
699 | originY = (cellHeight * num8) / this.m_nTimeScale;
|
---|
700 | recHeight = (cellHeight * num9) / this.m_nTimeScale;
|
---|
701 | recWidth = cellWidth;
|
---|
702 | rectangle.X = originX;
|
---|
703 | rectangle.Y = originY;
|
---|
704 | rectangle.Width = recWidth;
|
---|
705 | rectangle.Height = recHeight;
|
---|
706 | bRet = true;
|
---|
707 | return rectangle;
|
---|
708 | }
|
---|
709 |
|
---|
710 | public bool GetCellFromTime(DateTime dDate, ref int nRow, ref int nCol, bool bStartCell, string sResource)
|
---|
711 | {
|
---|
712 | int num = (dDate.Hour * 60) + dDate.Minute;
|
---|
713 | nRow = num / this.m_nTimeScale;
|
---|
714 | if (bStartCell)
|
---|
715 | {
|
---|
716 | nRow++;
|
---|
717 | }
|
---|
718 | if (this.m_sResourcesArray.Count > 1)
|
---|
719 | {
|
---|
720 | if (sResource == "")
|
---|
721 | {
|
---|
722 | sResource = this.m_sResourcesArray[0].ToString();
|
---|
723 | }
|
---|
724 | nCol = (int) this.m_ColumnInfoTable[sResource];
|
---|
725 | nCol++;
|
---|
726 | return true;
|
---|
727 | }
|
---|
728 | DateTime time = new DateTime(dDate.Year, dDate.Month, dDate.Day);
|
---|
729 | TimeSpan span = (TimeSpan) (time - this.StartDate);
|
---|
730 | int totalDays = 0;
|
---|
731 | totalDays = (int) span.TotalDays;
|
---|
732 | nCol = totalDays;
|
---|
733 | nCol++;
|
---|
734 | return true;
|
---|
735 | }
|
---|
736 |
|
---|
737 | private string GetResourceFromColumn(int nCol)
|
---|
738 | {
|
---|
739 | if (this.m_sResourcesArray.Count == 1)
|
---|
740 | {
|
---|
741 | return this.m_sResourcesArray[0].ToString();
|
---|
742 | }
|
---|
743 | foreach (DictionaryEntry entry in this.m_ColumnInfoTable)
|
---|
744 | {
|
---|
745 | int num = (int) entry.Value;
|
---|
746 | num++;
|
---|
747 | if (num == nCol)
|
---|
748 | {
|
---|
749 | return entry.Key.ToString();
|
---|
750 | }
|
---|
751 | }
|
---|
752 | return "";
|
---|
753 | }
|
---|
754 |
|
---|
755 | public bool GetSelectedTime(out DateTime dStart, out DateTime dEnd, out string sResource)
|
---|
756 | {
|
---|
757 | if (this.m_selectedRange.Cells.CellCount == 0)
|
---|
758 | {
|
---|
759 | dEnd = new DateTime();
|
---|
760 | dStart = dEnd;
|
---|
761 | sResource = "";
|
---|
762 | return false;
|
---|
763 | }
|
---|
764 | CGCell startCell = this.m_selectedRange.StartCell;
|
---|
765 | CGCell endCell = this.m_selectedRange.EndCell;
|
---|
766 | if (startCell.CellRow > endCell.CellRow)
|
---|
767 | {
|
---|
768 | CGCell cell3 = startCell;
|
---|
769 | startCell = endCell;
|
---|
770 | endCell = cell3;
|
---|
771 | }
|
---|
772 | dStart = this.GetTimeFromCell(startCell);
|
---|
773 | dEnd = this.GetTimeFromCell(endCell);
|
---|
774 | dEnd = dEnd.AddMinutes((double) this.m_nTimeScale);
|
---|
775 | sResource = this.GetResourceFromColumn(startCell.CellColumn);
|
---|
776 | return true;
|
---|
777 | }
|
---|
778 |
|
---|
779 | public bool GetSelectedType(out int nAccessTypeID)
|
---|
780 | {
|
---|
781 | nAccessTypeID = 0;
|
---|
782 | if (this.m_selectedRange.Cells.CellCount == 0)
|
---|
783 | {
|
---|
784 | return false;
|
---|
785 | }
|
---|
786 | CGCell startCell = this.m_selectedRange.StartCell;
|
---|
787 | CGCell endCell = this.m_selectedRange.EndCell;
|
---|
788 | if (startCell.CellRow > endCell.CellRow)
|
---|
789 | {
|
---|
790 | CGCell cell3 = startCell;
|
---|
791 | startCell = endCell;
|
---|
792 | endCell = cell3;
|
---|
793 | }
|
---|
794 | DateTime timeFromCell = this.GetTimeFromCell(startCell);
|
---|
795 | DateTime time2 = this.GetTimeFromCell(endCell).AddMinutes((double) this.m_nTimeScale);
|
---|
796 | foreach (CGAvailability availability in this.m_pAvArray)
|
---|
797 | {
|
---|
798 | if (this.TimesOverlap(availability.StartTime, availability.EndTime, timeFromCell, time2))
|
---|
799 | {
|
---|
800 | nAccessTypeID = availability.AvailabilityType;
|
---|
801 | break;
|
---|
802 | }
|
---|
803 | }
|
---|
804 | return (nAccessTypeID > 0);
|
---|
805 | }
|
---|
806 |
|
---|
807 | public DateTime GetTimeFromCell(CGCell cgCell)
|
---|
808 | {
|
---|
809 | int cellRow = cgCell.CellRow;
|
---|
810 | int cellColumn = cgCell.CellColumn;
|
---|
811 | DateTime dtStart = this.m_dtStart;
|
---|
812 | int num3 = (cellRow - 1) * this.m_nTimeScale;
|
---|
813 | int num4 = num3 / 60;
|
---|
814 | if (num4 > 0)
|
---|
815 | {
|
---|
816 | num3 = num3 % (num4 * 60);
|
---|
817 | }
|
---|
818 | dtStart = dtStart.AddHours((double) num4).AddMinutes((double) num3);
|
---|
819 | if (this.m_sResourcesArray.Count == 1)
|
---|
820 | {
|
---|
821 | dtStart = dtStart.AddDays((double) (cellColumn - 1));
|
---|
822 | }
|
---|
823 | return dtStart;
|
---|
824 | }
|
---|
825 |
|
---|
826 | public bool GetTypeFromCell(CGCell cgCell, out int nAccessTypeID)
|
---|
827 | {
|
---|
828 | nAccessTypeID = 0;
|
---|
829 | CGCell cell = cgCell;
|
---|
830 | CGCell cell2 = cgCell;
|
---|
831 | if (cell.CellRow > cell2.CellRow)
|
---|
832 | {
|
---|
833 | CGCell cell3 = cell;
|
---|
834 | cell = cell2;
|
---|
835 | cell2 = cell3;
|
---|
836 | }
|
---|
837 | DateTime timeFromCell = this.GetTimeFromCell(cell);
|
---|
838 | DateTime time2 = this.GetTimeFromCell(cell2).AddMinutes((double) this.m_nTimeScale);
|
---|
839 | foreach (CGAvailability availability in this.m_pAvArray)
|
---|
840 | {
|
---|
841 | if (this.TimesOverlap(availability.StartTime, availability.EndTime, timeFromCell, time2))
|
---|
842 | {
|
---|
843 | nAccessTypeID = availability.AvailabilityType;
|
---|
844 | break;
|
---|
845 | }
|
---|
846 | }
|
---|
847 | return (nAccessTypeID > 0);
|
---|
848 | }
|
---|
849 |
|
---|
850 | private bool HitTest(int X, int Y, ref int nRow, ref int nCol)
|
---|
851 | {
|
---|
852 | Y -= base.AutoScrollPosition.Y;
|
---|
853 | X -= base.AutoScrollPosition.X;
|
---|
854 | foreach (DictionaryEntry entry in this.m_gridCells)
|
---|
855 | {
|
---|
856 | CGCell cell = (CGCell) entry.Value;
|
---|
857 | if (cell.CellRectangle.Contains(X, Y))
|
---|
858 | {
|
---|
859 | nRow = cell.CellRow;
|
---|
860 | nCol = cell.CellColumn;
|
---|
861 | return true;
|
---|
862 | }
|
---|
863 | }
|
---|
864 | return false;
|
---|
865 | }
|
---|
866 |
|
---|
867 | public void InitializeCalendarGrid()
|
---|
868 | {
|
---|
869 | this.AllowDrop = true;
|
---|
870 | }
|
---|
871 |
|
---|
872 | private void InitializeComponent()
|
---|
873 | {
|
---|
874 | this.components = new System.ComponentModel.Container();
|
---|
875 | this.m_toolTip = new System.Windows.Forms.ToolTip(this.components);
|
---|
876 | this.SuspendLayout();
|
---|
877 | //
|
---|
878 | // CalendarGrid
|
---|
879 | //
|
---|
880 | this.AutoScroll = true;
|
---|
881 | this.AutoScrollMinSize = new System.Drawing.Size(600, 400);
|
---|
882 | this.BackColor = System.Drawing.SystemColors.Window;
|
---|
883 | this.Paint += new System.Windows.Forms.PaintEventHandler(this.CalendarGrid_Paint);
|
---|
884 | this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.CalendarGrid_MouseMove);
|
---|
885 | this.DragDrop += new System.Windows.Forms.DragEventHandler(this.CalendarGrid_DragDrop);
|
---|
886 | this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.CalendarGrid_MouseDown);
|
---|
887 | this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.CalendarGrid_MouseUp);
|
---|
888 | this.DragEnter += new System.Windows.Forms.DragEventHandler(this.CalendarGrid_DragEnter);
|
---|
889 | this.ResumeLayout(false);
|
---|
890 |
|
---|
891 | }
|
---|
892 |
|
---|
893 | private int MinSince80(DateTime d)
|
---|
894 | {
|
---|
895 | DateTime time = new DateTime(1980, 1, 1, 0, 0, 0);
|
---|
896 | TimeSpan span = (TimeSpan) (d - time);
|
---|
897 | return (int) span.TotalMinutes;
|
---|
898 | }
|
---|
899 |
|
---|
900 | private void OnLButtonDown(int X, int Y, bool bStart)
|
---|
901 | {
|
---|
902 | this.m_bDragDropStart = false;
|
---|
903 | this.m_nSelectID = 0;
|
---|
904 | if (!this.m_bSelectingRange)
|
---|
905 | {
|
---|
906 | int y = Y - base.AutoScrollPosition.Y;
|
---|
907 | int x = X - base.AutoScrollPosition.X;
|
---|
908 | Point pt = new Point(x, y);
|
---|
909 | if (Control.ModifierKeys == Keys.Control)
|
---|
910 | {
|
---|
911 | this.m_bMouseDown = false;
|
---|
912 | foreach (CGAppointment appointment in this.m_Appointments.AppointmentTable.Values)
|
---|
913 | {
|
---|
914 | if (!appointment.GridRectangle.Contains(pt))
|
---|
915 | {
|
---|
916 | continue;
|
---|
917 | }
|
---|
918 | if (this.m_SelectedAppointments.AppointmentTable.ContainsKey(appointment.AppointmentKey))
|
---|
919 | {
|
---|
920 | this.m_SelectedAppointments.RemoveAppointment(appointment.AppointmentKey);
|
---|
921 | if (this.m_SelectedAppointments.AppointmentTable.Count == 0)
|
---|
922 | {
|
---|
923 | this.m_nSelectID = 0;
|
---|
924 | }
|
---|
925 | else
|
---|
926 | {
|
---|
927 | foreach (CGAppointment appointment2 in this.m_Appointments.AppointmentTable.Values)
|
---|
928 | {
|
---|
929 | this.m_nSelectID = appointment2.AppointmentKey;
|
---|
930 | }
|
---|
931 | }
|
---|
932 | }
|
---|
933 | else
|
---|
934 | {
|
---|
935 | this.m_SelectedAppointments.AddAppointment(appointment);
|
---|
936 | this.m_nSelectID = appointment.AppointmentKey;
|
---|
937 | }
|
---|
938 | appointment.Selected = !appointment.Selected;
|
---|
939 | break;
|
---|
940 | }
|
---|
941 | base.Invalidate();
|
---|
942 | return;
|
---|
943 | }
|
---|
944 | foreach (CGAppointment appointment3 in this.m_Appointments.AppointmentTable.Values)
|
---|
945 | {
|
---|
946 | if (!appointment3.GridRectangle.Contains(pt))
|
---|
947 | {
|
---|
948 | continue;
|
---|
949 | }
|
---|
950 | this.m_bMouseDown = false;
|
---|
951 | if (appointment3.Selected)
|
---|
952 | {
|
---|
953 | appointment3.Selected = false;
|
---|
954 | this.m_SelectedAppointments.ClearAllAppointments();
|
---|
955 | this.m_nSelectID = 0;
|
---|
956 | }
|
---|
957 | else
|
---|
958 | {
|
---|
959 | foreach (CGAppointment appointment4 in this.m_Appointments.AppointmentTable.Values)
|
---|
960 | {
|
---|
961 | appointment4.Selected = false;
|
---|
962 | }
|
---|
963 | this.m_SelectedAppointments.ClearAllAppointments();
|
---|
964 | this.m_SelectedAppointments.AddAppointment(appointment3);
|
---|
965 | appointment3.Selected = true;
|
---|
966 | this.m_nSelectID = appointment3.AppointmentKey;
|
---|
967 | this.m_bMouseDown = true;
|
---|
968 | this.m_bGridEnter = true;
|
---|
969 | }
|
---|
970 | base.Invalidate();
|
---|
971 | return;
|
---|
972 | }
|
---|
973 | }
|
---|
974 | int nRow = -1;
|
---|
975 | int nCol = -1;
|
---|
976 | if (this.HitTest(X, Y, ref nRow, ref nCol))
|
---|
977 | {
|
---|
978 | CGCell cellFromRowCol = this.m_gridCells.GetCellFromRowCol(nRow, nCol);
|
---|
979 | if (cellFromRowCol != null)
|
---|
980 | {
|
---|
981 | if (bStart)
|
---|
982 | {
|
---|
983 | this.m_currentCell = cellFromRowCol;
|
---|
984 | this.m_selectedRange.StartCell = null;
|
---|
985 | this.m_selectedRange.EndCell = null;
|
---|
986 | this.m_selectedRange.CreateRange(this.m_gridCells, cellFromRowCol, cellFromRowCol);
|
---|
987 | bStart = false;
|
---|
988 | this.m_bMouseDown = true;
|
---|
989 | this.m_bSelectingRange = true;
|
---|
990 | }
|
---|
991 | else if (cellFromRowCol != this.m_currentCell)
|
---|
992 | {
|
---|
993 | if (!this.m_selectedRange.Cells.CellHashTable.ContainsKey(cellFromRowCol.Key))
|
---|
994 | {
|
---|
995 | this.m_selectedRange.AppendCell(this.m_gridCells, cellFromRowCol);
|
---|
996 | }
|
---|
997 | else
|
---|
998 | {
|
---|
999 | bool bUp = cellFromRowCol.CellRow < this.m_currentCell.CellRow;
|
---|
1000 | this.m_selectedRange.SubtractCell(this.m_gridCells, cellFromRowCol, bUp);
|
---|
1001 | }
|
---|
1002 | this.m_currentCell = cellFromRowCol;
|
---|
1003 | }
|
---|
1004 | cellFromRowCol.IsSelected = true;
|
---|
1005 | base.Invalidate();
|
---|
1006 | }
|
---|
1007 | }
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | public void OnUpdateArrays()
|
---|
1011 | {
|
---|
1012 | try
|
---|
1013 | {
|
---|
1014 | this.m_gridCells.ClearAllCells();
|
---|
1015 | this.SetColumnInfo();
|
---|
1016 | this.SetOverlapTable();
|
---|
1017 | Graphics g = base.CreateGraphics();
|
---|
1018 | this.BuildGridCellsArray(g);
|
---|
1019 | this.SetAppointmentTypes();
|
---|
1020 | }
|
---|
1021 | catch (Exception exception)
|
---|
1022 | {
|
---|
1023 | string message = exception.Message;
|
---|
1024 | }
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 | private void SetAppointmentTypes()
|
---|
1028 | {
|
---|
1029 | if (this.m_gridCells.CellCount != 0)
|
---|
1030 | {
|
---|
1031 | foreach (DictionaryEntry entry in this.m_gridCells.CellHashTable)
|
---|
1032 | {
|
---|
1033 | CGCell cell = (CGCell) entry.Value;
|
---|
1034 | cell.AppointmentTypeColor = (this.m_GridBackColor == "blue") ? Brushes.CornflowerBlue : Brushes.Khaki;
|
---|
1035 | }
|
---|
1036 | if ((this.m_pAvArray != null) && (this.m_pAvArray.Count != 0))
|
---|
1037 | {
|
---|
1038 | foreach (CGAvailability availability in this.m_pAvArray)
|
---|
1039 | {
|
---|
1040 | int nRow = 0;
|
---|
1041 | int nCol = 0;
|
---|
1042 | int num3 = 0;
|
---|
1043 | int num4 = 0;
|
---|
1044 | Brush brush = new SolidBrush(Color.FromArgb(availability.Red, availability.Green, availability.Blue));
|
---|
1045 | this.GetCellFromTime(availability.StartTime, ref nRow, ref nCol, true, availability.ResourceList);
|
---|
1046 | this.GetCellFromTime(availability.EndTime, ref num3, ref num4, false, availability.ResourceList);
|
---|
1047 | for (int i = nCol; i <= num4; i++)
|
---|
1048 | {
|
---|
1049 | for (int j = nRow; (i == num4) && (j <= num3); j++)
|
---|
1050 | {
|
---|
1051 | string str = "r" + j.ToString() + "c" + i.ToString();
|
---|
1052 | CGCell cell2 = (CGCell) this.m_gridCells.CellHashTable[str];
|
---|
1053 | if (cell2 != null)
|
---|
1054 | {
|
---|
1055 | cell2.AppointmentTypeColor = brush;
|
---|
1056 | }
|
---|
1057 | }
|
---|
1058 | }
|
---|
1059 | }
|
---|
1060 | }
|
---|
1061 | }
|
---|
1062 | }
|
---|
1063 |
|
---|
1064 | private void SetColumnInfo()
|
---|
1065 | {
|
---|
1066 | this.m_ColumnInfoTable.Clear();
|
---|
1067 | for (int i = 0; i < this.m_sResourcesArray.Count; i++)
|
---|
1068 | {
|
---|
1069 | this.m_ColumnInfoTable.Add(this.m_sResourcesArray[i], i);
|
---|
1070 | }
|
---|
1071 | if (this.m_sResourcesArray.Count > 1)
|
---|
1072 | {
|
---|
1073 | this.m_nColumns = this.m_sResourcesArray.Count;
|
---|
1074 | }
|
---|
1075 | }
|
---|
1076 |
|
---|
1077 | public void SetOverlapTable()
|
---|
1078 | {
|
---|
1079 | Hashtable hashtable = new Hashtable();
|
---|
1080 | int y = 0;
|
---|
1081 | int num2 = 0;
|
---|
1082 | int x = 0;
|
---|
1083 | foreach (CGAppointment appointment in this.m_Appointments.AppointmentTable.Values)
|
---|
1084 | {
|
---|
1085 | if (!appointment.WalkIn || this.m_bDrawWalkIns)
|
---|
1086 | {
|
---|
1087 | string resource = appointment.Resource;
|
---|
1088 | y = appointment.StartTime.Minute + (60 * appointment.StartTime.Hour);
|
---|
1089 | num2 = appointment.EndTime.Minute + (60 * appointment.EndTime.Hour);
|
---|
1090 | x = (this.m_sResourcesArray.Count > 1) ? (((int) this.m_ColumnInfoTable[resource]) + 1) : appointment.StartTime.DayOfYear;
|
---|
1091 | Rectangle rectangle = new Rectangle(x, y, 1, num2 - y);
|
---|
1092 | hashtable.Add(appointment.m_nKey, rectangle);
|
---|
1093 | }
|
---|
1094 | }
|
---|
1095 | this.m_ApptOverlapTable.Clear();
|
---|
1096 | foreach (int num4 in hashtable.Keys)
|
---|
1097 | {
|
---|
1098 | this.m_ApptOverlapTable.Add(num4, 0);
|
---|
1099 | }
|
---|
1100 | // Here it draws the Dates on Top
|
---|
1101 | if (this.m_ApptOverlapTable.Count != 0)
|
---|
1102 | {
|
---|
1103 | int num5 = (this.m_sResourcesArray.Count > 1) ? 1 : this.StartDate.DayOfYear;
|
---|
1104 | int num6 = (this.m_sResourcesArray.Count > 1) ? (this.m_sResourcesArray.Count + 1) : (this.Columns + this.StartDate.DayOfYear);
|
---|
1105 | for (int i = num5; i < num6; i++)
|
---|
1106 | {
|
---|
1107 | ArrayList list = new ArrayList();
|
---|
1108 | for (int j = 1; j < this.Rows; j++)
|
---|
1109 | {
|
---|
1110 | Rectangle rectangle2 = new Rectangle(i, j * this.m_nTimeScale, 1, this.m_nTimeScale);
|
---|
1111 | int num9 = -1;
|
---|
1112 | list.Clear();
|
---|
1113 | foreach (int num10 in hashtable.Keys)
|
---|
1114 | {
|
---|
1115 | Rectangle rect = (Rectangle) hashtable[num10];
|
---|
1116 | if (rectangle2.IntersectsWith(rect))
|
---|
1117 | {
|
---|
1118 | num9++;
|
---|
1119 | list.Add(num10);
|
---|
1120 | }
|
---|
1121 | }
|
---|
1122 | if (num9 > 0)
|
---|
1123 | {
|
---|
1124 | foreach (object obj2 in list)
|
---|
1125 | {
|
---|
1126 | int num11 = (int) obj2;
|
---|
1127 | if (((int) this.m_ApptOverlapTable[num11]) < num9)
|
---|
1128 | {
|
---|
1129 | this.m_ApptOverlapTable[num11] = num9;
|
---|
1130 | }
|
---|
1131 | }
|
---|
1132 | }
|
---|
1133 | }
|
---|
1134 | }
|
---|
1135 | }
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 | private void tickEventHandler(object o, EventArgs e)
|
---|
1139 | {
|
---|
1140 | Point point = new Point(base.AutoScrollPosition.X, base.AutoScrollPosition.Y);
|
---|
1141 | int x = point.X;
|
---|
1142 | int num = point.Y * -1;
|
---|
1143 | num = this.m_bScrollDown ? (num + 5) : (num - 5);
|
---|
1144 | point.Y = num;
|
---|
1145 | base.AutoScrollPosition = point;
|
---|
1146 | base.Invalidate();
|
---|
1147 | }
|
---|
1148 |
|
---|
1149 | private bool TimesOverlap(DateTime dStart1, DateTime dEnd1, DateTime dStart2, DateTime dEnd2)
|
---|
1150 | {
|
---|
1151 | long ticks = dEnd1.Ticks - dStart1.Ticks;
|
---|
1152 | TimeSpan ts = new TimeSpan(ticks);
|
---|
1153 | ticks = dEnd2.Ticks - dStart2.Ticks;
|
---|
1154 | new TimeSpan(ticks).Subtract(ts);
|
---|
1155 | Rectangle rect = new Rectangle();
|
---|
1156 | Rectangle rectangle2 = new Rectangle();
|
---|
1157 | rect.X = 0;
|
---|
1158 | rectangle2.X = 0;
|
---|
1159 | rect.Width = 1;
|
---|
1160 | rectangle2.Width = 1;
|
---|
1161 | rect.Y = this.MinSince80(dStart1);
|
---|
1162 | rect.Height = this.MinSince80(dEnd1) - rect.Y;
|
---|
1163 | rectangle2.Y = this.MinSince80(dStart2);
|
---|
1164 | rectangle2.Height = this.MinSince80(dEnd2) - rectangle2.Y;
|
---|
1165 | return rectangle2.IntersectsWith(rect);
|
---|
1166 | }
|
---|
1167 |
|
---|
1168 | /// <summary>
|
---|
1169 | /// The purpose of this is to properly draw the date boxes at the top of the calendar grid.
|
---|
1170 | /// Otherwise, when scrolling, it gets garbled.
|
---|
1171 | /// </summary>
|
---|
1172 | /// <param name="msg">Handles two messages:
|
---|
1173 | /// WM_VSCROLL (0x115 - Vertical Scrolling)
|
---|
1174 | /// WM_HSCROLL (0x114 - Horizontal Scrolling)
|
---|
1175 | /// </param>
|
---|
1176 | protected override void WndProc(ref Message msg)
|
---|
1177 | {
|
---|
1178 | try
|
---|
1179 | {
|
---|
1180 | if (msg.Msg == WM_VSCROLL)
|
---|
1181 | {
|
---|
1182 | this.m_bScroll = true;
|
---|
1183 | base.Invalidate(false);
|
---|
1184 | this.m_bScroll = false;
|
---|
1185 | }
|
---|
1186 | if (msg.Msg == WM_HSCROLL)
|
---|
1187 | {
|
---|
1188 | base.Invalidate(false);
|
---|
1189 | }
|
---|
1190 | base.WndProc(ref msg);
|
---|
1191 | }
|
---|
1192 | catch (Exception exception)
|
---|
1193 | {
|
---|
1194 | MessageBox.Show("CalendarGrid::WndProc: " + exception.Message + "\nStack: " + exception.StackTrace);
|
---|
1195 | }
|
---|
1196 | }
|
---|
1197 |
|
---|
1198 | public CGAppointments Appointments
|
---|
1199 | {
|
---|
1200 | get
|
---|
1201 | {
|
---|
1202 | return this.m_Appointments;
|
---|
1203 | }
|
---|
1204 | set
|
---|
1205 | {
|
---|
1206 | this.m_Appointments = value;
|
---|
1207 | }
|
---|
1208 | }
|
---|
1209 |
|
---|
1210 | public string ApptDragSource
|
---|
1211 | {
|
---|
1212 | get
|
---|
1213 | {
|
---|
1214 | return this.m_sDragSource;
|
---|
1215 | }
|
---|
1216 | set
|
---|
1217 | {
|
---|
1218 | this.m_sDragSource = value;
|
---|
1219 | }
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | public ArrayList AvailabilityArray
|
---|
1223 | {
|
---|
1224 | get
|
---|
1225 | {
|
---|
1226 | return this.m_pAvArray;
|
---|
1227 | }
|
---|
1228 | set
|
---|
1229 | {
|
---|
1230 | this.m_pAvArray = value;
|
---|
1231 | }
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | public int CellHeight
|
---|
1235 | {
|
---|
1236 | get
|
---|
1237 | {
|
---|
1238 | return this.m_cellHeight;
|
---|
1239 | }
|
---|
1240 | }
|
---|
1241 |
|
---|
1242 | public ToolTip CGToolTip
|
---|
1243 | {
|
---|
1244 | get
|
---|
1245 | {
|
---|
1246 | return this.m_toolTip;
|
---|
1247 | }
|
---|
1248 | }
|
---|
1249 |
|
---|
1250 | public int Columns
|
---|
1251 | {
|
---|
1252 | get
|
---|
1253 | {
|
---|
1254 | return this.m_nColumns;
|
---|
1255 | }
|
---|
1256 | set
|
---|
1257 | {
|
---|
1258 | if ((value > 0) && (value < 11))
|
---|
1259 | {
|
---|
1260 | this.m_nColumns = value;
|
---|
1261 | this.m_gridCells.ClearAllCells();
|
---|
1262 | this.m_selectedRange.Cells.ClearAllCells();
|
---|
1263 | Graphics g = base.CreateGraphics();
|
---|
1264 | this.BuildGridCellsArray(g);
|
---|
1265 | this.SetAppointmentTypes();
|
---|
1266 | base.Invalidate();
|
---|
1267 | }
|
---|
1268 | }
|
---|
1269 | }
|
---|
1270 |
|
---|
1271 | public bool DrawWalkIns
|
---|
1272 | {
|
---|
1273 | get
|
---|
1274 | {
|
---|
1275 | return this.m_bDrawWalkIns;
|
---|
1276 | }
|
---|
1277 | set
|
---|
1278 | {
|
---|
1279 | this.m_bDrawWalkIns = value;
|
---|
1280 | }
|
---|
1281 | }
|
---|
1282 |
|
---|
1283 | public string GridBackColor
|
---|
1284 | {
|
---|
1285 | get
|
---|
1286 | {
|
---|
1287 | return this.m_GridBackColor;
|
---|
1288 | }
|
---|
1289 | set
|
---|
1290 | {
|
---|
1291 | this.m_GridBackColor = value;
|
---|
1292 | }
|
---|
1293 | }
|
---|
1294 |
|
---|
1295 | public bool GridEnter
|
---|
1296 | {
|
---|
1297 | get
|
---|
1298 | {
|
---|
1299 | return this.m_bGridEnter;
|
---|
1300 | }
|
---|
1301 | set
|
---|
1302 | {
|
---|
1303 | this.m_bGridEnter = value;
|
---|
1304 | }
|
---|
1305 | }
|
---|
1306 |
|
---|
1307 | public ArrayList Resources
|
---|
1308 | {
|
---|
1309 | get
|
---|
1310 | {
|
---|
1311 | return this.m_sResourcesArray;
|
---|
1312 | }
|
---|
1313 | set
|
---|
1314 | {
|
---|
1315 | this.m_sResourcesArray = value;
|
---|
1316 | }
|
---|
1317 | }
|
---|
1318 |
|
---|
1319 | public int Rows
|
---|
1320 | {
|
---|
1321 | get
|
---|
1322 | {
|
---|
1323 | return (0x5a0 / this.m_nTimeScale);
|
---|
1324 | }
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | public int SelectedAppointment
|
---|
1328 | {
|
---|
1329 | get
|
---|
1330 | {
|
---|
1331 | return this.m_nSelectID;
|
---|
1332 | }
|
---|
1333 | set
|
---|
1334 | {
|
---|
1335 | this.m_nSelectID = value;
|
---|
1336 | }
|
---|
1337 | }
|
---|
1338 |
|
---|
1339 | public CGAppointments SelectedAppointments
|
---|
1340 | {
|
---|
1341 | get
|
---|
1342 | {
|
---|
1343 | return this.m_SelectedAppointments;
|
---|
1344 | }
|
---|
1345 | }
|
---|
1346 |
|
---|
1347 | public CGRange SelectedRange
|
---|
1348 | {
|
---|
1349 | get
|
---|
1350 | {
|
---|
1351 | return this.m_selectedRange;
|
---|
1352 | }
|
---|
1353 | }
|
---|
1354 |
|
---|
1355 | public DateTime StartDate
|
---|
1356 | {
|
---|
1357 | get
|
---|
1358 | {
|
---|
1359 | return this.m_dtStart;
|
---|
1360 | }
|
---|
1361 | set
|
---|
1362 | {
|
---|
1363 | this.m_dtStart = value;
|
---|
1364 | }
|
---|
1365 | }
|
---|
1366 |
|
---|
1367 | public int TimeScale
|
---|
1368 | {
|
---|
1369 | get
|
---|
1370 | {
|
---|
1371 | return this.m_nTimeScale;
|
---|
1372 | }
|
---|
1373 | set
|
---|
1374 | {
|
---|
1375 | if ((((value == 5) || (value == 10)) || ((value == 15) || (value == 20))) || ((value == 30) || (value == 60)))
|
---|
1376 | {
|
---|
1377 | this.m_nTimeScale = value;
|
---|
1378 | this.m_gridCells.ClearAllCells();
|
---|
1379 | this.m_selectedRange.Cells.ClearAllCells();
|
---|
1380 | Graphics g = base.CreateGraphics();
|
---|
1381 | this.BuildGridCellsArray(g);
|
---|
1382 | this.SetAppointmentTypes();
|
---|
1383 | base.Invalidate();
|
---|
1384 | }
|
---|
1385 | }
|
---|
1386 | }
|
---|
1387 |
|
---|
1388 | }
|
---|
1389 | }
|
---|
1390 |
|
---|