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