Ignore:
Timestamp:
May 5, 2011, 5:11:02 AM (13 years ago)
Author:
Sam Habiel
Message:

Lots of Documentation updates.
Absorption of all updates from trunk.
CGView: Changes in Appointment Menu; Handlers for these; Radiology Support
DRadExamSelect: Change in form design; auto print appointment slip implemented.

Location:
Scheduling/branches/Radiology-Support/cs/bsdx0200GUISourceCode
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Scheduling/branches/Radiology-Support/cs/bsdx0200GUISourceCode

  • Scheduling/branches/Radiology-Support/cs/bsdx0200GUISourceCode/CalendarGrid.cs

    r1140 r1168  
    99    using System.Runtime.InteropServices;
    1010    using System.Windows.Forms;
     11    using System.Linq;
    1112
    1213    /// <summary>
     
    125126            try
    126127            {
     128                //calculate each cell's height
    127129                SizeF ef = g.MeasureString("Test", this.m_fCell);
    128130                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:
    135141                if (base.ClientRectangle.Width > 600)
    136142                {
    137143                    this.m_cellWidth = (base.ClientRectangle.Width - this.m_col0Width) / (nColumns - 1);
    138144                }
     145                // if only one column
    139146                if (this.m_nColumns == 1)
    140147                {
    141148                    this.m_cellWidth = base.ClientRectangle.Width - this.m_col0Width;
    142149                }
     150                //next line seems to be useless (we don't use X and Y below)
    143151                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--)
    145155                {
    146156                    for (int j = 1; j < nColumns; j++)
     
    233243        }
    234244
     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
    235293        private void CalendarGrid_MouseDown(object sender, MouseEventArgs e)
    236294        {
     
    247305                this.OnLButtonDown(e.X, e.Y, true);
    248306            }
     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
    249345        }
    250346
    251347        private void CalendarGrid_MouseMove(object Sender, MouseEventArgs e)
    252348        {
    253             //test
    254             //System.Diagnostics.Debug.Write(watch.ElapsedMilliseconds + "\n");
    255             //test
    256349
    257350            //if the left mouse button is down and we are moving the mouse...
     
    292385            else
    293386            {
    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
    297391                int y = e.Y - base.AutoScrollPosition.Y;
    298392                int x = e.X - base.AutoScrollPosition.X;
     
    307401                }
    308402                this.m_toolTip.RemoveAll();
    309 
    310                 ////smh new code -- select cell
    311                 //int nRow = -1;
    312                 //int nCol = -1;
    313 
    314                 ////Is the mouse over a known cell? If so, highlight cell
    315                 //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 
    332403            }
    333404        }
     
    515586            // flag is true only if there are no cells what so ever in the screen
    516587            // Only true when no resource is selected.
    517             bool flag = this.m_gridCells.CellCount == 0;
     588            bool noCellsFlag = this.m_gridCells.CellCount == 0;
    518589
    519590            // Move the base point from the client screen to the scrolling region top-left corner.
     
    600671                        num12 = this.m_col0Width;
    601672                    }
    602                     if (k > 1)      //
     673                    if (k > 1)      // if we are subsequent columns, adjust accordingly
    603674                    {
    604675                        num12 = this.m_col0Width + (this.m_cellWidth * (k - 1));
    605676                    }
     677                    //make a rectangle for the cell
    606678                    Point point4 = new Point(num12, j * this.m_cellHeight);
    607679                    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
    612684                        {
    613685                            cellFromRowCol = new CGCell(r, j, k);
    614686                            this.m_gridCells.AddCell(cellFromRowCol);
    615687                        }
    616                         else
     688                        else // otherwise, get the cell from the m_gridCells array
    617689                        {
    618690                            cellFromRowCol = this.m_gridCells.GetCellFromRowCol(j, k);
    619691                            cellFromRowCol.CellRectangle = r;
    620692                        }
    621                         if (this.m_sResourcesArray.Count > 0)
     693                        if (this.m_sResourcesArray.Count > 0) // if we have any resources open
    622694                        {
    623695                            //IMP
    624696                            //this is the place where we the selected cells are drawn in Light Light Blue.
    625697                            //IMP
     698                            // if cell is selected, draw it in Aquamarine (light light blue)
    626699                            if (this.m_selectedRange.CellIsInRange(cellFromRowCol))
    627700                            {
     
    629702                                //g.FillRectangle(Brushes.AntiqueWhite, r);
    630703                            }
     704                            // otherwise, draw it from Appointment Type Color set by BuildGridCellsArray()
    631705                            else
    632706                            {
    633707                                g.FillRectangle(cellFromRowCol.AppointmentTypeColor, r);
    634708                            }
     709                            // finally the drawing
    635710                            g.DrawRectangle(pen, r.X, r.Y, r.Width, r.Height);
     711                            // once done with availabilities, draw the appointments
    636712                            if (j == 1)
    637713                            {
     
    641717                        continue;
    642718                    }
     719                   
     720                    //Below draws the top column either containing the dates or resources
    643721                    if (!this.m_bScroll)
    644722                    {
     
    9221000            this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.CalendarGrid_MouseUp);
    9231001            this.DragEnter += new System.Windows.Forms.DragEventHandler(this.CalendarGrid_DragEnter);
     1002            this.DragOver += new DragEventHandler(CalendarGrid_DragOver);
    9241003            this.ResumeLayout(false);
    9251004
    9261005        }
    9271006
     1007 
    9281008        private static int MinSince80(DateTime d)
    9291009        {
     
    9311011            TimeSpan span = (TimeSpan) (d - time);
    9321012            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            }
    9331066        }
    9341067
     
    10671200            if (this.m_gridCells.CellCount != 0)
    10681201            {
     1202                // this happens for the CGAVView Grid
    10691203                foreach (DictionaryEntry entry in this.m_gridCells.CellHashTable)
    10701204                {
     
    10721206                    cell.AppointmentTypeColor = (this.m_GridBackColor == "blue") ? Brushes.CornflowerBlue : Brushes.Khaki;
    10731207                }
     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
    10741210                if ((this.m_pAvArray != null) && (this.m_pAvArray.Count != 0))
    10751211                {
     
    10801216                        int num3 = 0;
    10811217                        int num4 = 0;
     1218                        // pick the color from the availability
    10821219                        Brush brush = new SolidBrush(Color.FromArgb(availability.Red, availability.Green, availability.Blue));
     1220                        // get starting and ending cell
    10831221                        this.GetCellFromTime(availability.StartTime, ref nRow, ref nCol, true, availability.ResourceList);
    10841222                        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
    10851224                        for (int i = nCol; i <= num4; i++)
    10861225                        {
     
    13281467                {
    13291468                    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
    13321474                    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
    13361478                }
    13371479            }
Note: See TracChangeset for help on using the changeset viewer.