/// <summary>
        /// Finalizes editing
        /// </summary>
        public void FinalizeEditMode()
        {
            if (EditModeItem == null)
            {
                return;
            }

            WeekPlannerItem itemBuffer = _editModeItem;

            _editModeItem = null;

            itemBuffer.Subject = TextBox.Text.Trim();

            if (TextBox != null)
            {
                TextBox.Visible = false;
                Controls.Remove(TextBox);
                TextBox.Dispose();
            }

            if (_editModeItem != null)
            {
                Invalidate();
            }

            planner.OnItemTextEdited(new WeekPlannerItemEventArgs(itemBuffer));

            _textBox = null;

            if (State == PlannerState.EditingItemText)
            {
                SetState(PlannerState.Idle);
            }
        }
        /// <summary>
        /// Looks for the items which intersect with the provided item
        /// </summary>
        /// <param name="item">Item to be checked</param>
        /// <param name="items">List of items in which checks intersection</param>
        /// <returns>Collection of inersected items.</returns>
        public IEnumerable <WeekPlannerItem> IntersectedItems(WeekPlannerItem item, List <WeekPlannerItem> items)
        {
            foreach (var i in items)
            {
                if (item == i)
                {
                    continue;
                }
                var isIntersect  = isDatesIntersect(item.StartDate.Date, item.EndDate.Date, i.StartDate.Date, i.EndDate.Date);
                var isIntersect2 = isDatesIntersect(i.StartDate.Date, i.EndDate.Date, item.StartDate.Date, item.EndDate.Date);

                if ((isIntersect || isIntersect2) && item.Layer == i.Layer)
                {
                    yield return(i);
                }
            }
        }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (itemOnState != null)
            {
                itemOnState.SetIsResizingEndDate(false);
                itemOnState.SetIsResizingStartDate(false);
                planner.OnItemClick(new WeekPlannerItemEventArgs(itemOnState));
                if (itemOnStateChanged)
                {
                    planner.OnItemDatesChanged(new WeekPlannerItemEventArgs(itemOnState));
                }
                itemOnState = null;
            }

            SetState(PlannerState.Idle);
        }
        /// <summary>
        /// Activates the edit mode on the specified item
        /// </summary>
        /// <param name="item"></param>
        public void ActivateEditMode(WeekPlannerItem item)
        {
            _editModeItem      = item;
            TextBox            = new CalendarTextBox(this);
            TextBox.KeyDown   += TextBox_KeyDown;
            TextBox.LostFocus += TextBox_LostFocus;
            TextBox.Font       = ItemTextFont;
            Rectangle r = item.Rectangle;

            r.Location = r.Location + new Size(AutoScrollPosition);

            r.Inflate(-2, -2);
            TextBox.Bounds      = r;
            TextBox.BorderStyle = BorderStyle.None;
            TextBox.Text        = item.Subject;
            TextBox.Multiline   = true;

            Controls.Add(TextBox);
            TextBox.Visible = true;
            TextBox.Focus();
            TextBox.SelectionStart = TextBox.Text.Length;

            SetState(PlannerState.EditingItemText);
        }
        /// <summary>
        /// Invalidates the area of the specified item
        /// </summary>
        /// <param name="item"></param>
        public void Invalidate(WeekPlannerItem item)
        {
            Rectangle r = item.Rectangle;

            Invalidate(r);
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            //Cursor = Cursors.Hand;
            var mouseMovePosition       = new Point(e.X, e.Y);
            var mouseMoveScrollPosition = mouseMovePosition - new Size(AutoScrollPosition);

            var row     = RowCoord.Where(d => (isNumberInRange(mouseMoveScrollPosition.Y, d.FirstCoord, d.SecondCoord))).SingleOrDefault();
            var moveRow = row != null ? row.RowIndex : -1;

            var column =
                ColumnCoord.Where(d => (isNumberInRange(mouseMoveScrollPosition.X, d.FirstCoord, d.SecondCoord))).SingleOrDefault();

            WeekPlannerItem hittedItem = null;

            if (listRows.Count > 0 && moveRow != -1 && listRows.Count > moveRow)
            {
                var plannerRow = listRows.ElementAt(moveRow);

                if (plannerRow.LeftMarginBackColor != Color.White)
                {
                    plannerRow.LeftMarginOldBackColor = plannerRow.LeftMarginBackColor;
                }

                hittedItem = GetItemAt(mouseMoveScrollPosition, plannerRow.Items);
                if (outHittedItem != hittedItem && hittedItem != null)
                {
                    outHittedItem = hittedItem;
                }


                //to detect cursor movement above left margin column
                if (mouseMoveScrollPosition.X < LeftMargin)
                {
                    //to detect cursor movement during changing rows
                    if (outRow != moveRow)
                    {
                        plannerRow.LeftMarginBackColor = Color.White;
                        //sets row color when cursor moves above the row
                        if (plannerRow.IsCollapsible)
                        {
                            //plannerRow.LeftMarginBackColor = Color.White;
                            Cursor = Cursors.Hand;
                        }
                        else
                        {
                            Cursor = Cursors.Default;
                        }

                        //finds row which has left cursor and sets back color
                        if (outRow != -1)
                        {
                            var oRow = listRows.ElementAt(outRow);
                            oRow.LeftMarginBackColor = oRow.LeftMarginOldBackColor;
                            if (oRow.IsCollapsible)
                            {
                                //oRow.LeftMarginBackColor = oRow.LeftMarginOldBackColor;
                            }
                        }

                        outRow = moveRow;
                    }
                }

                //to detect when cursor leaves left margin column
                else
                {
                    if (plannerRow.IsCollapsible)
                    {
                        //plannerRow.LeftMarginBackColor = plannerRow.LeftMarginOldBackColor;
                    }
                    plannerRow.LeftMarginBackColor = plannerRow.LeftMarginOldBackColor;
                    outRow = -1;
                }
            }


            // to detect cursor movement below left margin column
            if (moveRow == -1 && outRow != -1)
            {
                var r = listRows.ElementAt(outRow);
                if (r.IsCollapsible)
                {
                    outRow = -1;
                    //r.LeftMarginBackColor = r.LeftMarginOldBackColor;
                    Cursor = Cursors.Default;
                }
                r.LeftMarginBackColor = r.LeftMarginOldBackColor;
            }


            switch (State)
            {
            case PlannerState.Idle:
                Cursor should = Cursors.Default;

                if (hittedItem != null)
                {
                    if ((hittedItem.ResizeEndDateZone(mouseMoveScrollPosition) || hittedItem.ResizeStartDateZone(mouseMoveScrollPosition)))
                    {
                        should = Cursors.SizeWE;
                    }

                    planner.OnItemMouseHover(new WeekPlannerItemEventArgs(hittedItem));
                }
                if (!Cursor.Equals(should) && mouseMoveScrollPosition.X > LeftMargin)
                {
                    Cursor = should;
                }

                if (hittedItem == null && outHittedItem != null)
                {
                    planner.OnItemMouseLeave(new WeekPlannerItemEventArgs(outHittedItem));
                    outHittedItem = null;
                }

                break;

            case PlannerState.DraggingItem:

                if (column != null)
                {
                    moveDate = column.DateValue;
                }

                itemOnState.StartDate = moveDate.AddDays(durationStart.Days);
                itemOnState.EndDate   = moveDate.AddDays(durationEnd.Days);

                if (rowNumer != moveRow && moveRow != -1 && IsAllowedDraggingBetweenRows)
                {
                    try
                    {
                        var oldRowNumber = rowNumer;
                        rowNumer = moveRow;

                        var newRow = Rows.ElementAt(rowNumer);
                        var oldRow = Rows.ElementAt(oldRowNumber);

                        var newItem = new WeekPlannerItem(this);
                        newItem = itemOnState;


                        var addedItem = newRow.Items.Add(newItem);
                        oldRow.Items.Remove(itemOnState);
                        _selectedItem = addedItem;
                        itemOnState   = addedItem;
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine("it did it again");
                    }
                }
                itemOnStateChanged = true;
                break;

            case PlannerState.ResizingItem:
                if (column != null)
                {
                    moveDate = column.DateValue;
                }

                if (itemOnState.IsResizingStartDate && moveDate <= itemOnState.EndDate.Date)
                {
                    itemOnState.StartDate = moveDate.AddDays(durationStart.Days);
                }
                else if (itemOnState.IsResizingEndDate && moveDate >= itemOnState.StartDate.Date)
                {
                    itemOnState.EndDate = moveDate.AddDays(durationEnd.Days);
                }
                itemOnStateChanged = true;
                break;

            case PlannerState.EditingItemText:
                break;
            }
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            mouseClickPosition       = new Point(e.X, e.Y);
            mouseClickScrollPosition = mouseClickPosition - new Size(AutoScrollPosition);

            if (!Focused)
            {
                Focus();
            }

            var row = RowCoord.Where(d => (isNumberInRange(mouseClickScrollPosition.Y, d.FirstCoord, d.SecondCoord))).SingleOrDefault();

            _selectedRow = row != null ? row.RowIndex : -1;

            var column =
                ColumnCoord.Where(d => (isNumberInRange(mouseClickScrollPosition.X, d.FirstCoord, d.SecondCoord))).SingleOrDefault();


            if (column != null)
            {
                _selectedColumn   = column.Column;
                _selectedCellDate = CurrentDate.AddDays(SelectedColumn);
            }

            if (listRows.Count > 0 && _selectedRow != -1)
            {
                var plannerRow = listRows.ElementAt(_selectedRow);
                _selectedItem = GetItemAt(mouseClickScrollPosition, plannerRow.Items);
            }

            switch (State)
            {
            case PlannerState.Idle:
                if (_selectedItem != null)
                {
                    itemOnState        = _selectedItem;
                    itemOnStateChanged = false;

                    durationStart = itemOnState.StartDate.Date.Subtract(column.DateValue.Date);
                    durationEnd   = itemOnState.EndDate.Date.Subtract(column.DateValue.Date);
                    if (itemOnState.ResizeStartDateZone(mouseClickScrollPosition))
                    {
                        SetState(PlannerState.ResizingItem);
                        itemOnState.SetIsResizingStartDate(true);
                    }
                    else if (itemOnState.ResizeEndDateZone(mouseClickScrollPosition))
                    {
                        SetState(PlannerState.ResizingItem);
                        itemOnState.SetIsResizingEndDate(true);
                    }
                    else
                    {
                        rowNumer = _selectedRow;
                        SetState(PlannerState.DraggingItem);
                    }
                }
                break;

            case PlannerState.DraggingItem:
                break;

            case PlannerState.ResizingItem:
                break;

            case PlannerState.EditingItemText:
                break;
            }


            if (row != null && column != null && listRows.Count > 0)
            {
                var rowClicked = listRows.ElementAt(_selectedRow);
                planner.OnRowClick(new RowEventArgs(rowClicked));
                Invalidate();
            }

            if (mouseClickScrollPosition.X < LeftMargin)
            {
                try
                {
                    var rowClicked = listRows.ElementAt(_selectedRow);
                    if (e.Button == MouseButtons.Left)
                    {
                        rowClicked.IsExpanded = !rowClicked.IsExpanded;
                    }
                    planner.OnRowLeftColumnClick(new RowClickEventArgs(rowClicked, e.Button), listRows.IndexOf(rowClicked));
                    rowClicked.LeftMarginBackColor = rowClicked.LeftMarginOldBackColor;
                }
                catch (System.ArgumentOutOfRangeException)
                {
                    Debug.WriteLine("It happened");
                }
            }

            base.OnMouseDown(e);
        }
Example #8
0
 /// <summary>
 /// Activates the edit mode on the specified item
 /// </summary>
 /// <param name="item"></param>
 public void ActivateEditMode(WeekPlannerItem item)
 {
     weekPlannerGrid.ActivateEditMode(item);
 }
Example #9
0
 /// <summary>
 /// Creates a new <see cref="WeekPlannerItem"/>
 /// </summary>
 /// <param name="item">Related Item</param>
 public WeekPlannerItemEventArgs(WeekPlannerItem item)
 {
     _item = item;
 }