Exemple #1
0
        /// <summary>
        /// Применение изменений после получения события от формы редактирования задачи
        /// </summary>
        /// <param name="sender">Объект события</param>
        /// <param name="e">Аргумент сохранения</param>
        private void EditPoint(object sender, EditTask.SaveArgs e)
        {
            this.Enabled = true;
            NetPoint point = new NetPoint(e.Name, e.Description, e.Lenght, e.Type, editnow.Location);

            point.Connections = editnow.Task.Connections;
            foreach (TaskUI tk in TasksPanel.Controls)
            {
                for (int i = 0; i < tk.Task.Connections.Count; i++)
                {
                    NetPoint np = tk.Task.Connections[i];
                    if (np == editnow.Task)
                    {
                        tk.Task.Connections[i] = point;
                    }
                }
            }
            int pos = points.IndexOf(editnow.Task);

            points[pos]  = point;
            editnow.Task = point;
            way          = null;
            UpdateTable();
            StartPaintTrace();
        }
Exemple #2
0
 private void Trace(NetPoint startnp, NetPoint endnp, int time, Stack <NetPoint> way)
 {
     Bar.Value++;
     if (startnp != endnp && !way.Contains(startnp))
     {
         way.Push(startnp);
         time += startnp.Time;
         foreach (NetPoint np in startnp.Connections)
         {
             Trace(np, endnp, time, way);
         }
     }
     else
     {
         way.Push(endnp);
         time    += endnp.Time;
         everseen = true;
         if (time < record)
         {
             recordlist = way.ToList();
             recordlist.Reverse();
             record = time;
         }
     }
     way.Pop();
     return;
 }
Exemple #3
0
 public TaskUI(NetPoint point)
 {
     InitializeComponent();
     Task                     = point;
     LocationChanged         += ChangeTask;
     Task.ConnectionsChanged += connectchanged;
     Task.TypeChanged        += Recolor;
     WireAllControls(this);
 }
Exemple #4
0
        /// <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();
        }
Exemple #5
0
 public EditTask(NetPoint point)
 {
     InitializeComponent();
     if (point.PointType == TaskType.end)
     {
         endType.Checked = true;
     }
     else if (point.PointType == TaskType.start)
     {
         StartTypeTask.Checked = true;
     }
     else
     {
         centerType.Checked = true;
     }
     nametxtbox.Text  = point.Name;
     descrtxtbox.Text = point.Description;
     timenud.Value    = point.Time;
 }
Exemple #6
0
        /// <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();
        }
Exemple #7
0
        /// <summary>
        /// Обработчик события нажатия "Удалить задачу" из контекстного меню
        /// </summary>
        /// <param name="sender">Объект события</param>
        /// <param name="e">Аргумент события</param>
        private void Delete_Click(object sender, EventArgs e)
        {
            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();
        }
Exemple #8
0
        public List <NetPoint> Open(string fileName)
        {
            try
            {
                List <NetPoint> nplist = new List <NetPoint>();
                FileStream      fs     = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                XmlDocument     xml    = new XmlDocument();
                xml.Load(fs);
                XmlNode doc = xml.DocumentElement;
                Dictionary <string, string> links = new Dictionary <string, string>();
                foreach (XmlNode node in doc)
                {
                    if (node.Name == "task")
                    {
                        NetPoint point = new NetPoint();
                        foreach (XmlNode param in node)
                        {
                            if (param.Name == "id")
                            {
                                point.InstallID(param.InnerText);
                            }
                            if (param.Name == "name")
                            {
                                point.Name = param.InnerText;
                            }
                            if (param.Name == "description")
                            {
                                point.Description = param.InnerText;
                            }
                            if (param.Name == "type")
                            {
                                switch (param.InnerText)
                                {
                                case "start":
                                    point.PointType = TaskType.start;
                                    break;

                                case "end":
                                    point.PointType = TaskType.end;
                                    break;

                                default:
                                    point.PointType = TaskType.center;
                                    break;
                                }
                            }
                            if (param.Name == "time")
                            {
                                point.Time = Convert.ToInt32(param.InnerText);
                            }
                            if (param.Name == "location")
                            {
                                Point import = new Point(0, 0);
                                foreach (XmlNode loc in param)
                                {
                                    if (loc.Name == "X")
                                    {
                                        import.X = Convert.ToInt32(loc.InnerText);
                                    }
                                    if (loc.Name == "Y")
                                    {
                                        import.Y = Convert.ToInt32(loc.InnerText);
                                    }
                                }
                                point.Location = import;
                            }
                            if (param.Name == "connections")
                            {
                                string cons = "";
                                foreach (XmlNode tsk in param)
                                {
                                    if (tsk.Name == "taskID")
                                    {
                                        cons += tsk.InnerText + '|';
                                    }
                                }
                                if (cons.Length > 0)
                                {
                                    cons = cons.Substring(0, cons.Length - 1);
                                }
                                links.Add(point.ID, cons);
                            }
                        }
                        nplist.Add(point);
                    }
                }
                List <NetPoint> connections = new List <NetPoint>();
                foreach (NetPoint point in nplist)
                {
                    NetPoint np = point;
                    foreach (string key in links.Keys)
                    {
                        if (key == np.ID)
                        {
                            List <string> cons = new List <string>();
                            cons = links[key].Split('|').ToList();
                            foreach (NetPoint pont in nplist)
                            {
                                if (cons.Contains(pont.ID))
                                {
                                    np.Connections.Add(pont);
                                }
                            }
                        }
                    }
                    connections.Add(np);
                }
                fs.Close();
                return(connections);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
Exemple #9
0
 /// <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();
     }
 }
Exemple #10
0
        public void Start()
        {
            bool     start   = false;
            bool     end     = false;
            NetPoint startnp = null;
            NetPoint endnp   = null;

            OperationName.Text = "Проверка";
            int count = 1;

            try
            {
                Bar.Maximum   = points.Count();
                TraceNum.Text = "Операция 0 из " + points.Count();

                foreach (NetPoint np in points)
                {
                    if (np.PointType == TaskType.start && start == true)
                    {
                        throw new Exception("Присутствует более 1 начальной задачи");
                    }
                    if (np.PointType == TaskType.start && start == false)
                    {
                        start   = true;
                        startnp = np;
                    }
                    if (np.PointType == TaskType.end && end == true)
                    {
                        throw new Exception("Присутствует более 1 конечной задачи");
                    }
                    if (np.PointType == TaskType.end && end == false)
                    {
                        end   = true;
                        endnp = np;
                    }
                    TraceNum.Text = $"Операция {count} из {points.Count}";
                    Bar.Value     = count;
                }
                if (start == false)
                {
                    throw new Exception("Отсутствует начальная задача");
                }
                if (end == false)
                {
                    throw new Exception("Отсутствует конечная задача");
                }
                if (startnp.Connections.Count == 0)
                {
                    throw new Exception("Стартовая задача изолирована");
                }
                bool isolated = true;
                foreach (NetPoint np in points)
                {
                    if (np.Connections.Contains(endnp))
                    {
                        isolated = false;
                        break;
                    }
                }
                if (isolated)
                {
                    throw new Exception("Конечная задача изолирована");
                }
            }
            catch (Exception ex)
            {
                if (MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) == DialogResult.OK)
                {
                    return;
                }
                ;
            }
            count = 1;
            OperationName.Text = "Просчет";
            TraceNum.Text      = $"Операция {count} из {points.Count * points.Count}";
            Bar.Maximum        = 100000;
            Bar.Value          = 0;
            Stack <NetPoint> way = new Stack <NetPoint>();

            Trace(startnp, endnp, 0, way);
            if (!everseen)
            {
                if (MessageBox.Show("Конечные задачи не связаны промежуточными задачами", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) == DialogResult.OK)
                {
                    return;
                }
            }
            ResultCalculated?.Invoke(recordlist);
            return;
        }