- Timestamp:
- Apr 14, 2011, 8:33:14 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Scheduling/trunk/cs/bsdx0200GUISourceCode/CalendarGrid.cs
r1123 r1143 9 9 using System.Runtime.InteropServices; 10 10 using System.Windows.Forms; 11 using System.Linq; 11 12 12 13 /// <summary> … … 125 126 try 126 127 { 128 //calculate each cell's height 127 129 SizeF ef = g.MeasureString("Test", this.m_fCell); 128 130 this.m_cellHeight = ((int) ef.Height) + 4; 129 int nColumns = this.m_nColumns; 130 int num2 = 60 / this.m_nTimeScale; 131 int num3 = 24 * num2; 132 nColumns++; 133 num3++; 134 this.m_cellWidth = 600 / nColumns; 131 132 int nColumns = this.m_nColumns; // columns set via property 133 int slotsPerHour = 60 / this.m_nTimeScale; //time scale set via property 134 int slotsPerDay = 24 * slotsPerHour; 135 nColumns++; // add extra column for time display 136 slotsPerDay++; // not sure here why that's don't 137 138 //calculate each cell's height 139 this.m_cellWidth = 600 / nColumns; // base size is 600 pixels 140 // if larger: 135 141 if (base.ClientRectangle.Width > 600) 136 142 { 137 143 this.m_cellWidth = (base.ClientRectangle.Width - this.m_col0Width) / (nColumns - 1); 138 144 } 145 // if only one column 139 146 if (this.m_nColumns == 1) 140 147 { 141 148 this.m_cellWidth = base.ClientRectangle.Width - this.m_col0Width; 142 149 } 150 //next line seems to be useless (we don't use X and Y below) 143 151 g.TranslateTransform((float) base.AutoScrollPosition.X, (float) base.AutoScrollPosition.Y); 144 for (int i = num3; i > -1; i--) 152 153 //now, build the grid cells 154 for (int i = slotsPerDay; i > -1; i--) 145 155 { 146 156 for (int j = 1; j < nColumns; j++) … … 233 243 } 234 244 245 void CalendarGrid_DragOver(object sender, DragEventArgs e) 246 { 247 //Translate point to client point 248 Point pt = this.PointToClient(new Point(e.X, e.Y)); 249 250 //clear selections 251 foreach (DictionaryEntry entry in this.m_gridCells.CellHashTable) 252 { 253 CGCell cell = (CGCell)entry.Value; 254 cell.IsSelected = false; 255 } 256 this.m_selectedRange.Cells.ClearAllCells(); 257 258 //select a cell based on current drag position to visually assist the user 259 int nRow = -1; 260 int nCol = -1; 261 if (this.HitTest(pt.X, pt.Y, ref nRow, ref nCol)) 262 { 263 CGCell cellFromRowCol = this.m_gridCells.GetCellFromRowCol(nRow, nCol); 264 if (cellFromRowCol != null) 265 { 266 this.m_currentCell = cellFromRowCol; 267 this.m_selectedRange.StartCell = null; 268 this.m_selectedRange.EndCell = null; 269 this.m_selectedRange.CreateRange(this.m_gridCells, cellFromRowCol, cellFromRowCol); 270 271 cellFromRowCol.IsSelected = true; 272 } 273 274 base.Invalidate(); 275 } 276 277 //if Y axis is outside the top or bottom 278 279 if ((pt.Y + 40 >= this.ClientRectangle.Bottom) || (pt.Y - 40 <= this.ClientRectangle.Top)) 280 { 281 //start auto scrolling. m_bScrollDown decides whether we scroll up or down. 282 this.m_bScrollDown = (pt.Y + 40) >= this.ClientRectangle.Bottom; 283 AutoDragStart(); 284 } 285 286 //if Y axis within client rectagle, stop dragging (whether you started or not) 287 if ((pt.Y + 40 < this.ClientRectangle.Bottom) && (pt.Y - 40 > this.ClientRectangle.Top)) 288 { 289 AutoDragStop(); 290 } 291 } 292 235 293 private void CalendarGrid_MouseDown(object sender, MouseEventArgs e) 236 294 { … … 247 305 this.OnLButtonDown(e.X, e.Y, true); 248 306 } 307 //new code!!! smh 4/13/2011 -- refactor later 308 309 else if (e.Button == MouseButtons.Right) 310 { 311 // clear all selected cells, but ONLY if the the pointer is NOT over one of the cells in 312 // the selected range 313 314 int nRow = -1; 315 int nCol = -1; 316 CGCell cellFromRowCol = null; 317 bool _isCellInRange = false; 318 if (this.HitTest(e.X, e.Y, ref nRow, ref nCol)) 319 { 320 cellFromRowCol = this.m_gridCells.GetCellFromRowCol(nRow, nCol); 321 } 322 323 if (cellFromRowCol != null) 324 _isCellInRange = this.m_selectedRange.CellIsInRange(cellFromRowCol); 325 326 if (!_isCellInRange) 327 { 328 foreach (DictionaryEntry entry in this.m_gridCells.CellHashTable) 329 { 330 CGCell cell = (CGCell)entry.Value; 331 cell.IsSelected = false; 332 } 333 this.m_selectedRange.Cells.ClearAllCells(); 334 } 335 336 // clear all selected appointments 337 this.m_SelectedAppointments.ClearAllAppointments(); 338 foreach (CGAppointment a in this.m_Appointments.AppointmentTable.Values) a.Selected = false; 339 this.m_nSelectID = 0; 340 341 OnRButtonDown(e.X, e.Y, _isCellInRange); 342 } 343 344 //end new code!!! /smh 4/13/2011 249 345 } 250 346 251 347 private void CalendarGrid_MouseMove(object Sender, MouseEventArgs e) 252 348 { 253 //test254 //System.Diagnostics.Debug.Write(watch.ElapsedMilliseconds + "\n");255 //test256 349 257 350 //if the left mouse button is down and we are moving the mouse... … … 288 381 this.m_bDragDropStart = true; 289 382 } 290 383 } 291 384 } 292 385 else 293 386 { 294 //test 295 AutoDragStop(); //is this needed? 296 //test 387 388 AutoDragStop(); //is this needed? //just in case maybe 389 390 //this code below displays the tooltip if we are moving the mouse over an appointment 297 391 int y = e.Y - base.AutoScrollPosition.Y; 298 392 int x = e.X - base.AutoScrollPosition.X; … … 307 401 } 308 402 this.m_toolTip.RemoveAll(); 309 310 ////smh new code -- select cell311 //int nRow = -1;312 //int nCol = -1;313 314 ////Is the mouse over a known cell? If so, highlight cell315 //if (this.HitTest(x, y, ref nRow, ref nCol))316 //{317 // CGCell cellFromRowCol = this.m_gridCells.GetCellFromRowCol(nRow, nCol);318 // if (cellFromRowCol != null)319 // {320 // this.m_currentCell = cellFromRowCol;321 // this.m_selectedRange.StartCell = null;322 // this.m_selectedRange.EndCell = null;323 // this.m_selectedRange.CreateRange(this.m_gridCells, cellFromRowCol, cellFromRowCol);324 // this.m_bSelectingRange = true;325 // cellFromRowCol.IsSelected = true;326 // base.Invalidate(this.m_currentCell.CellRectangle);327 // //base.Invalidate();328 // }329 //}330 331 332 403 } 333 404 } … … 515 586 // flag is true only if there are no cells what so ever in the screen 516 587 // Only true when no resource is selected. 517 bool flag = this.m_gridCells.CellCount == 0;588 bool noCellsFlag = this.m_gridCells.CellCount == 0; 518 589 519 590 // Move the base point from the client screen to the scrolling region top-left corner. … … 600 671 num12 = this.m_col0Width; 601 672 } 602 if (k > 1) // 673 if (k > 1) // if we are subsequent columns, adjust accordingly 603 674 { 604 675 num12 = this.m_col0Width + (this.m_cellWidth * (k - 1)); 605 676 } 677 //make a rectangle for the cell 606 678 Point point4 = new Point(num12, j * this.m_cellHeight); 607 679 Rectangle r = new Rectangle(point4.X, point4.Y, this.m_cellWidth, this.m_cellHeight); 608 if (j != 0) 609 { 610 CGCell cellFromRowCol = null; 611 if ( flag)680 if (j != 0) // if we are not at the top (we are starting from the bottom) 681 { 682 CGCell cellFromRowCol = null; 683 if (noCellsFlag) //if there are no cells, create the cell 612 684 { 613 685 cellFromRowCol = new CGCell(r, j, k); 614 686 this.m_gridCells.AddCell(cellFromRowCol); 615 687 } 616 else 688 else // otherwise, get the cell from the m_gridCells array 617 689 { 618 690 cellFromRowCol = this.m_gridCells.GetCellFromRowCol(j, k); 619 691 cellFromRowCol.CellRectangle = r; 620 692 } 621 if (this.m_sResourcesArray.Count > 0) 693 if (this.m_sResourcesArray.Count > 0) // if we have any resources open 622 694 { 623 695 //IMP 624 696 //this is the place where we the selected cells are drawn in Light Light Blue. 625 697 //IMP 698 // if cell is selected, draw it in Aquamarine (light light blue) 626 699 if (this.m_selectedRange.CellIsInRange(cellFromRowCol)) 627 700 { … … 629 702 //g.FillRectangle(Brushes.AntiqueWhite, r); 630 703 } 704 // otherwise, draw it from Appointment Type Color set by BuildGridCellsArray() 631 705 else 632 706 { 633 707 g.FillRectangle(cellFromRowCol.AppointmentTypeColor, r); 634 708 } 709 // finally the drawing 635 710 g.DrawRectangle(pen, r.X, r.Y, r.Width, r.Height); 711 // once done with availabilities, draw the appointments 636 712 if (j == 1) 637 713 { … … 641 717 continue; 642 718 } 719 720 //Below draws the top column either containing the dates or resources 643 721 if (!this.m_bScroll) 644 722 { … … 922 1000 this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.CalendarGrid_MouseUp); 923 1001 this.DragEnter += new System.Windows.Forms.DragEventHandler(this.CalendarGrid_DragEnter); 1002 this.DragOver += new DragEventHandler(CalendarGrid_DragOver); 924 1003 this.ResumeLayout(false); 925 1004 926 1005 } 927 1006 1007 928 1008 private static int MinSince80(DateTime d) 929 1009 { … … 931 1011 TimeSpan span = (TimeSpan) (d - time); 932 1012 return (int) span.TotalMinutes; 1013 } 1014 1015 //new code1!! smh 4/14/2011 1016 private void OnRButtonDown(int X, int Y, bool RangeAlreadySelected) 1017 { 1018 //if right mouse button is clicked, select an appointment if mouse hovers over one 1019 foreach (CGAppointment appointment3 in this.m_Appointments.AppointmentTable.Values) 1020 { 1021 int y = Y - base.AutoScrollPosition.Y; 1022 int x = X - base.AutoScrollPosition.X; 1023 Point pt = new Point(x, y); 1024 1025 if (!appointment3.GridRectangle.Contains(pt)) 1026 { 1027 continue; 1028 } 1029 this.m_bMouseDown = false; 1030 1031 this.m_SelectedAppointments.AddAppointment(appointment3); 1032 appointment3.Selected = true; 1033 this.m_nSelectID = appointment3.AppointmentKey; 1034 //this.m_bGridEnter = true; 1035 } 1036 1037 // if we find an appointment, redraw the grid 1038 if (this.m_SelectedAppointments.AppointmentCount > 0) 1039 { 1040 base.Invalidate(); 1041 return; 1042 } 1043 1044 // Otherwise, select a cell, but only if we don't don't have an existing range 1045 if (RangeAlreadySelected) return; 1046 1047 // Ok, select cell here 1048 int nRow = -1; 1049 int nCol = -1; 1050 if (this.HitTest(X, Y, ref nRow, ref nCol)) 1051 { 1052 CGCell cellFromRowCol = this.m_gridCells.GetCellFromRowCol(nRow, nCol); 1053 if (cellFromRowCol != null) 1054 { 1055 this.m_currentCell = cellFromRowCol; 1056 this.m_selectedRange.StartCell = null; 1057 this.m_selectedRange.EndCell = null; 1058 this.m_selectedRange.CreateRange(this.m_gridCells, cellFromRowCol, cellFromRowCol); 1059 1060 cellFromRowCol.IsSelected = true; 1061 } 1062 1063 base.Invalidate(); 1064 return; 1065 } 933 1066 } 934 1067 … … 1067 1200 if (this.m_gridCells.CellCount != 0) 1068 1201 { 1202 // this happens for the CGAVView Grid 1069 1203 foreach (DictionaryEntry entry in this.m_gridCells.CellHashTable) 1070 1204 { … … 1072 1206 cell.AppointmentTypeColor = (this.m_GridBackColor == "blue") ? Brushes.CornflowerBlue : Brushes.Khaki; 1073 1207 } 1208 // won't happen for CGAVView Grid b/c it has no availabilites 1209 // BUT, will happen for normal CGView Grid if there any availabilies 1074 1210 if ((this.m_pAvArray != null) && (this.m_pAvArray.Count != 0)) 1075 1211 { … … 1080 1216 int num3 = 0; 1081 1217 int num4 = 0; 1218 // pick the color from the availability 1082 1219 Brush brush = new SolidBrush(Color.FromArgb(availability.Red, availability.Green, availability.Blue)); 1220 // get starting and ending cell 1083 1221 this.GetCellFromTime(availability.StartTime, ref nRow, ref nCol, true, availability.ResourceList); 1084 1222 this.GetCellFromTime(availability.EndTime, ref num3, ref num4, false, availability.ResourceList); 1223 // for each of the range cells between starting and ending, change their color 1085 1224 for (int i = nCol; i <= num4; i++) 1086 1225 { … … 1328 1467 { 1329 1468 this.m_nColumns = value; 1330 this.m_gridCells.ClearAllCells(); 1331 this.m_selectedRange.Cells.ClearAllCells(); 1469 //new line 1470 this.SetColumnInfo(); // redoes the columns if we have multiple resources 1471 //end new line 1472 this.m_gridCells.ClearAllCells(); //remove all cells 1473 this.m_selectedRange.Cells.ClearAllCells(); //remove selected range 1332 1474 Graphics g = base.CreateGraphics(); 1333 this.BuildGridCellsArray(g); 1334 this.SetAppointmentTypes(); 1335 base.Invalidate(); 1475 this.BuildGridCellsArray(g); //rebuild the cells 1476 this.SetAppointmentTypes(); //set the colors on the cells for availabilities 1477 base.Invalidate(); //Fire paint to call DrawGrid 1336 1478 } 1337 1479 }
Note:
See TracChangeset
for help on using the changeset viewer.