Beispiel #1
0
        private void MouseClickManagement(MouseEventArgs e)
        {
            //reinit values
            List <string> ClickedValues = new List <string>();

            m_clickedItemsList = new List <string>();

            string ClickedValuesString = "";

            m_clickedItemsCSV = "";

            //get the Cell
            DataGridView.HitTestInfo hit = this.HitTest(e.X, e.Y);
            if (hit.Type == DataGridViewHitTestType.Cell)
            {
                clickedCell =
                    this.Rows[hit.RowIndex].Cells[hit.ColumnIndex];
            }


            //hour cell?
            try
            {
                HalfHourCell hhc = (HalfHourCell)clickedCell;
                for (int i = 0; i < hhc.CalendarItems.Count; i++)
                {
                    ClickedValues.Add(hhc.CalendarItems[i].Key);
                    ClickedValuesString += hhc.CalendarItems[i].Key + ",";
                }
            }
            catch { }


            //day cell?
            try
            {
                DayCell hhc = (DayCell)clickedCell;
                for (int i = 0; i < hhc.CalendarItems.Count; i++)
                {
                    ClickedValues.Add(hhc.CalendarItems[i].Key);
                    ClickedValuesString += hhc.CalendarItems[i].Key + ",";
                }
            }
            catch { }

            if (ClickedValues.Count > 0)
            {
                m_clickedItemsList = ClickedValues;
                //less the last ,
                m_clickedItemsCSV = Microsoft.VisualBasic.Strings.Left(ClickedValuesString, Microsoft.VisualBasic.Strings.Len(ClickedValuesString) - 1);

                //raise event Change List
                this.ListChanged(m_clickedItemsCSV);
            }
            else
            {
                this.ListChanged("");
            }
        }
        private int CountOfItemsOverlappingWithThisItem(CalendarItem item, ref int order)
        {
            try
            {
                // Find out how many maximum items this item overlaps with
                // for a given cell
                int overlapCount              = 0;
                List <CalendarItem> list      = new List <CalendarItem>();
                DateTime            startTime = item.StartTime;
                while (startTime.CompareTo(item.EndTime) < 0)
                {
                    HalfHourCell        cell  = this.DayColumn.GetHalfHourCell(startTime);
                    List <CalendarItem> items = cell.CalendarItems;
                    if (items == null)
                    {
                        continue;
                    }
                    if (items.Count - 1 > overlapCount)
                    {
                        overlapCount = items.Count - 1;
                        list         = items;
                    }
                    startTime = startTime.AddMinutes(30);
                }

                //// Now check this list to see the correct overlapCount -> this is
                //// bacause the items in the list may be overlapping already and
                //// we need to account for this.
                //for (int i = 0; i < list.Count; i++)
                //{
                //    // Only check items whose index is less that that of this item
                //    int indexOfThisItem = this.DayColumn.Calendar.CalendarItems.IndexOf(item);
                //    int indexOfOtherItem = this.DayColumn.Calendar.CalendarItems.IndexOf(list[i]);
                //    if (indexOfOtherItem >= indexOfThisItem)
                //        continue;

                //    int otherOverlap = this.DayColumn.Calendar.OverlapCount[list[i]];
                //    if (overlapCount <= otherOverlap)
                //        overlapCount = otherOverlap + 1;
                //}

                // Now overlapCount has the maximum number of items this item overlaps with.
                this.DayColumn.Calendar.OverlapCount[item] = overlapCount;

                if (overlapCount == 0)
                {
                    order = 0;
                    this.DayColumn.Calendar.OrderCount[item] = 0;
                    return(0);
                }

                // To find the order of this item we will go through the list
                // and figure out the order
                bool[] orders = new bool[overlapCount + 1];
                for (int i = 0; i < list.Count; i++)
                {
                    // Only check items whose index is less that that of this item
                    int indexOfThisItem  = this.DayColumn.Calendar.CalendarItems.IndexOf(item);
                    int indexOfOtherItem = this.DayColumn.Calendar.CalendarItems.IndexOf(list[i]);
                    if (indexOfOtherItem >= indexOfThisItem)
                    {
                        continue;
                    }

                    // If other item already has an order note it. If a previous
                    // order is available then take that
                    if (this.DayColumn.Calendar.OrderCount.ContainsKey(list[i]))
                    {
                        int itemOrder = this.DayColumn.Calendar.OrderCount[list[i]];
                        orders[itemOrder] = true;
                        for (int k = 0; k < itemOrder; k++)
                        {
                            if (!orders[k])
                            {
                                order     = k;
                                orders[k] = true;
                                this.DayColumn.Calendar.OrderCount[item] = k;
                                return(overlapCount);
                            }
                        }
                    }
                    else
                    {
                        // Item does not have an order. Give it the first available order
                        for (int k = 0; k < orders.Length; k++)
                        {
                            if (!orders[k])
                            {
                                this.DayColumn.Calendar.OrderCount[list[i]] = k;
                                orders[k] = true;
                            }
                        }
                    }
                }                // for

                // Now take the first available spot in orders
                for (int k = 0; k < orders.Length; k++)
                {
                    if (!orders[k])
                    {
                        order     = k;
                        orders[k] = true;
                        this.DayColumn.Calendar.OrderCount[item] = k;
                        return(overlapCount);
                    }
                }
                return(0);
            }
            catch (Exception exception)
            {
                Trace.WriteLine(exception.ToString());
                order = 0;
                return(0);
            }
        }