private void StartPaintTrace() { TasksPanel.CreateGraphics().Clear(Color.White); foreach (TaskUI tk in TasksPanel.Controls) { foreach (NetPoint np in tk.Task.Connections) { TaskUI link = null; foreach (TaskUI tik in TasksPanel.Controls) { if (tik.Task == np) { link = tik; break; } } if (link == null) { continue; } Graphics g = TasksPanel.CreateGraphics(); Pen p = new Pen(Color.Black, 3); g.DrawLine(p, tk.APoint, link.APoint); Point center = new Point((tk.APoint.X + link.APoint.X) / 2, (tk.APoint.Y + link.APoint.Y) / 2); AdjustableArrowCap bigArrow = new AdjustableArrowCap(5, 5); p.CustomEndCap = bigArrow; g.DrawLine(p, tk.APoint, center); } } DrawShortPath(); }
private void Unlink_Click(object sender, EventArgs e) { MessageBox.Show("Выберите задачу, с которой необходимо разорвать связь", "Подсказка", MessageBoxButtons.OK, MessageBoxIcon.Information); status = MapStat.unlinking; Cursor = Cursors.Hand; ALink = editnow; }
private void OpenedFile(string pathr, List <NetPoint> nplist) { TasksPanel.Controls.Clear(); if (pathr != null) { path = pathr; this.Text = "Сетевой график: " + pathr.Substring(pathr.LastIndexOf('\\') + 1); } else { this.Text = "Сетевой график: Безымянный"; } Tasks = nplist; foreach (NetPoint np in Tasks) { TaskUI tsk = new TaskUI(np); tsk.DoubleClick += EditTask; tsk.MouseClick += ClickPoint; tsk.MouseUp += MousePointUp; tsk.MouseMove += ReplacePoint; tsk.MouseDown += StartReplace; tsk.ConnectionsChanged += UpdateTableLink; tsk.Task.ConnectionsChanged += RedrawTasks; TasksPanel.Controls.Add(tsk); tsk.Location = np.Location; } StartPaintTrace(); }
/// <summary> /// Обработчик события нажатия "Связать с" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Link_Click(object sender, EventArgs e) { MessageBox.Show("Выберите задачу для связывания", "Подсказка", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Cursor = Cursors.Hand; status = MapStat.linking; ALink = editnow; }
private void DeleteLinkStripMenuItem1_Click(object sender, EventArgs e) { Cursor = Cursors.Hand; status = MapStat.unlinking; MessageBox.Show("Укажите задачу от которого будет происходить отвязка на карте", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); editnow = null; ALink = null; }
/// <summary> /// Обработчик события начала перемещения TaskUI /// </summary> /// <param name="sender">Объект события</param> /// <param name="e">Аргумент события</param> private void StartReplace(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { return; } if (status != MapStat.none) { return; } mousecorrection = e.Location; editnow = (TaskUI)sender; drag = true; }
/// <summary> /// Обработчик события нажатия "Редактировать задачу" из контекстного меню. /// </summary> /// <remarks>Копирует TaskUI и NetPoint и отображает форму с подпиской на сохранение.</remarks> /// <param name="sender">Объект события</param> /// <param name="e">Аргумент события</param> private void EditTask(object sender, EventArgs e) { TaskUI sen = (TaskUI)sender; editnow = sen; editnow.Task.PointType = sen.Task.PointType; NetPoint task = sen.Task; EditTask edit = new EditTask(task); edit.SavingChanges += EditPoint; edit.FormClosing += uxPlay; this.Enabled = false; edit.Show(); StartPaintTrace(); }
/// <summary> /// Обработчик события сохранения новой точки из дочерней формы. /// Создает новую задачу и регистрирует все события. /// </summary> /// <param name="sender">Объект события</param> /// <param name="e">Аргумент события</param> private void GetNewPoint(object sender, AddTask.SaveArgs e) { NetPoint pont = new NetPoint(e.Name, e.Description, e.Lenght, e.Type, mouseloc); pont.PointType = e.Type; List <NetPoint> np = Tasks; np.Add(pont); Tasks = np; TaskUI tsk = new TaskUI(pont); tsk.Location = mouseloc; tsk.DoubleClick += EditTask; tsk.MouseClick += ClickPoint; tsk.MouseUp += MousePointUp; tsk.MouseMove += ReplacePoint; tsk.MouseDown += StartReplace; tsk.ConnectionsChanged += UpdateTableLink; tsk.Task.ConnectionsChanged += RedrawTasks; TasksPanel.Controls.Add(tsk); StartPaintTrace(); }
/// <summary> /// Обработчик нажатия мышью по TaskUI /// </summary> /// <param name="sender">Объект события</param> /// <param name="e">Аргумент события</param> private void ClickPoint(object sender, MouseEventArgs e) { if (status == MapStat.none) { editnow = (TaskUI)sender; mousecorrection = e.Location; drag = true; if (e.Button == MouseButtons.Right) { foreach (ToolStripItem ts in contextPainter.Items) { ts.Enabled = false; } contextPainter.Items[2].Enabled = true; contextPainter.Items[1].Enabled = true; contextPainter.Items[3].Enabled = true; if (editnow.Task.Connections.Count > 0) { contextPainter.Items[5].Enabled = true; } if (points.Count > 1) { contextPainter.Items[4].Enabled = true; } if (points.Count > 0) { contextPainter.Items[6].Enabled = true; } contextPainter.Show(Cursor.Position); } } if (status == MapStat.delete) { editnow = (TaskUI)sender; Cursor = Cursors.Arrow; status = MapStat.none; List <NetPoint> np = Tasks; np.Remove(editnow.Task); Tasks = np; way = null; TasksPanel.Controls.Remove(editnow); List <NetPoint> update = new List <NetPoint>(); foreach (NetPoint nep in Tasks) { NetPoint updated = nep; if (updated.Connections.Contains(editnow.Task)) { updated.Connections.Remove(editnow.Task); } update.Add(updated); } Tasks = update; StartPaintTrace(); } if (status == MapStat.edit) { Cursor = Cursors.Default; status = MapStat.none; TaskUI sen = (TaskUI)sender; editnow = sen; editnow.Task.PointType = sen.Task.PointType; NetPoint task = sen.Task; EditTask edit = new EditTask(task); edit.SavingChanges += EditPoint; edit.FormClosing += uxPlay; this.Enabled = false; edit.Show(); StartPaintTrace(); } if (status == MapStat.linking) { if (editnow == null && ALink == null) { ALink = (TaskUI)sender; MessageBox.Show("Выберите задачу, с которой необходимо образовать связь", "Подсказка", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else if (editnow == null && ALink != null) { editnow = (TaskUI)sender; } way = null; NetPoint linked = ((TaskUI)sender).Task; if (((TaskUI)sender) != ALink) { ALink.Task.Connections.Add(linked); } else if (ALink.Task.Connections.Contains(linked)) { ALink.Task.Connections.Remove(linked); ALink.Task.Connections.Add(linked); MessageBox.Show("С данной задачей уже установлена связь", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } Cursor = Cursors.Default; status = MapStat.none; UpdateTable(); StartPaintTrace(); } if (status == MapStat.unlinking) { if (ALink == null && editnow == null) { ALink = (TaskUI)sender; MessageBox.Show("Выберите задачу, с которой необходимо разорвать связь", "Подсказка", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else if (ALink != null && editnow == null) { editnow = (TaskUI)sender; } way = null; NetPoint unlink = ((TaskUI)sender).Task; if (((TaskUI)sender) != ALink && ALink.Task.Connections.Contains(unlink)) { ALink.Task.Connections.Remove(unlink); List <NetPoint> nplist = new List <NetPoint>(); foreach (NetPoint np in points) { nplist.Add(np); if (np.ID == ALink.Task.ID) { nplist.Add(ALink.Task); break; } } } else { MessageBox.Show("С данным объектом не установлена связь", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } Cursor = Cursors.Default; status = MapStat.none; UpdateTable(); StartPaintTrace(); } }