Beispiel #1
0
        public void OpenGraphForm(ProjectDoc projectDoc)
        {
            List <object> paramList = new List <object>();

            paramList.Add(DockingManager);
            paramList.Add(projectDoc);
            ((ShellWindowViewModel)DataContext).OpenGraphViewWithDoc.Execute(paramList);
        }
Beispiel #2
0
        public DocWindow(ProjectDoc projectDoc)
        {
            InitializeComponent();
            DataContext = new ShellWindowViewModel();
            List <object> paramList = new List <object>();

            paramList.Add(DockingManager);
            paramList.Add(projectDoc);
            ((ShellWindowViewModel)DataContext).OpenGraphViewWithDoc.Execute(paramList);
        }
        public void ShowProject(object senderForm = null, ProjectDoc projectDoc = null)
        {
            if ((senderForm == null) && (projectDoc == null))
            {
                ShowDialog();
                return;
            }
            if (projectDoc == null)
            {
                sendForm  = senderForm;
                fromShell = true;
                ShowDialog();
                return;
            }
            else
            {
                sendForm  = senderForm;
                fromShell = true;

                Type3.IsChecked = projectDoc.calc_type == 0 ? true : false;
                Type5.IsChecked = projectDoc.calc_type == 1 ? true : false;

                edtName.Text = projectDoc.name;
                edtDesc.Text = projectDoc.description;
                indust_objectComboBox.SelectedValue = projectDoc.object_type;

                foreach (var item in projectDoc.list_of_warnings)
                {
                    warningsSelector.SelectedItems.Add(warningsSelector.Items.Cast <warnings>().Where(p => p.id == item.id).ToList <warnings>()[0]);
                }
                foreach (var item in projectDoc.list_of_protect_mech)
                {
                    protect_mechSelector.SelectedItems.Add(protect_mechSelector.Items.Cast <protect_mech>().Where(p => p.id == item.id).ToList <protect_mech>()[0]);
                }
                foreach (var item in projectDoc.list_of_barrier)
                {
                    barrierSelector.SelectedItems.Add(barrierSelector.Items.Cast <barrier>().Where(p => p.id == item.id).ToList <barrier>()[0]);
                }
                foreach (var item in projectDoc.list_of_weakness)
                {
                    weaknessSelector.SelectedItems.Add(weaknessSelector.Items.Cast <weakness>().Where(p => p.id == item.id).ToList <weakness>()[0]);
                }
                foreach (var item in projectDoc.list_of_objects)
                {
                    objectSelector.SelectedItems.Add(objectSelector.Items.Cast <@object>().Where(p => p.id == item.id).ToList <@object>()[0]);
                }



                ShowDialog();

                return;
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            _context.Configuration.ProxyCreationEnabled = false;
            var t          = warningsSelector.SelectedValue;
            var projectDoc = new ProjectDoc
            {
                list_of_barrier      = barrierSelector.SelectedItems.Cast <barrier>().ToList <barrier>(),
                list_of_protect_mech = protect_mechSelector.SelectedItems.Cast <protect_mech>().ToList <protect_mech>(),
                list_of_warnings     = warningsSelector.SelectedItems.Cast <warnings>().ToList <warnings>(),
                list_of_objects      = objectSelector.SelectedItems.Cast <@object>().ToList <@object>(),
                list_of_weakness     = weaknessSelector.SelectedItems.Cast <weakness>().ToList <weakness>(),

                calc_type   = Type3.IsChecked == false ? 1 : 0,
                name        = edtName.Text,
                description = edtDesc.Text,
                object_type = (int)indust_objectComboBox.SelectedValue
            };
            //если есть связь с окружением - оставляем
            //иначе - удаляем
            var tem = projectDoc.list_of_protect_mech.Select(pm => pm.id).ToList();

            projectDoc.list_of_warnings = projectDoc.list_of_warnings.Where <warnings>(w => _context.war_to_prot.Where(wtp => wtp.warcode == w.id && tem.Contains(wtp.protcode)).Count() > 0).ToList <warnings>();

            tem = projectDoc.list_of_warnings.Select(pm => pm.id).ToList();

            if (projectDoc.calc_type == 1)
            {
                var tem2 = projectDoc.list_of_barrier.Select(pm => pm.id).ToList();
                projectDoc.list_of_protect_mech = projectDoc.list_of_protect_mech.Where <protect_mech>(p => _context.war_to_prot.Where(wtp => wtp.protcode == p.id && tem.Contains(wtp.warcode)).Count() > 0 ||
                                                                                                       _context.prot_to_bar.Where(ptb => ptb.protcode == p.id && tem2.Contains(ptb.barcode)).Count() > 0
                                                                                                       ).ToList <protect_mech>();
                tem  = projectDoc.list_of_protect_mech.Select(pm => pm.id).ToList();
                tem2 = projectDoc.list_of_weakness.Select(pm => pm.id).ToList();
                projectDoc.list_of_barrier = projectDoc.list_of_barrier.Where <barrier>(b => _context.prot_to_bar.Where(ptb => ptb.barcode == b.id && tem.Contains(ptb.protcode)).Count() > 0 ||
                                                                                        _context.bar_to_weak.Where(btw => btw.barcode == b.id && tem2.Contains(btw.weakcode)).Count() > 0
                                                                                        ).ToList <barrier>();
                tem  = projectDoc.list_of_barrier.Select(pm => pm.id).ToList();
                tem2 = projectDoc.list_of_objects.Select(pm => pm.id).ToList();
                projectDoc.list_of_weakness = projectDoc.list_of_weakness.Where <weakness>(we => _context.bar_to_weak.Where(btw => btw.weakcode == we.id && tem.Contains(btw.barcode)).Count() > 0 ||
                                                                                           _context.weak_to_object.Where(wto => wto.weakcode == we.id && tem2.Contains(wto.objcode)).Count() > 0
                                                                                           ).ToList <weakness>();
                tem = projectDoc.list_of_weakness.Select(pm => pm.id).ToList();
                projectDoc.list_of_objects = projectDoc.list_of_objects.Where <@object>(o => _context.weak_to_object.Where(wto => wto.objcode == o.id && tem.Contains(wto.weakcode)).Count() > 0).ToList <@object>();
            }
            else
            {
                var tem2 = projectDoc.list_of_objects.Select(pm => pm.id).ToList();
                projectDoc.list_of_protect_mech = projectDoc.list_of_protect_mech.Where <protect_mech>(p => _context.war_to_prot.Where(wtp => wtp.protcode == p.id && tem.Contains(wtp.warcode)).Count() > 0 ||
                                                                                                       _context.prot_to_obj.Where(pto => pto.protcode == p.id && tem2.Contains(pto.objcode)).Count() > 0
                                                                                                       ).ToList <protect_mech>();
                tem = projectDoc.list_of_protect_mech.Select(pm => pm.id).ToList();
                projectDoc.list_of_objects = projectDoc.list_of_objects.Where <@object>(o => _context.prot_to_obj.Where(pto => pto.objcode == o.id && tem.Contains(pto.protcode)).Count() > 0).ToList <@object>();
            }

            this.Close();
            if (fromShell)
            {
                ((DocWindow)((Grid)((DockingManager)sendForm).Parent).Parent).OpenGraphForm(projectDoc);
            }
            else
            {
                var d = new DocWindow(projectDoc);
                d.ShowDialog();
            }
        }
        public void CreateGraph(ProjectDoc projectDoc)
        {
            currentDoc                       = projectDoc;
            currentGraph                     = new Graph(projectDoc.name);
            currentGraph.Directed            = false;
            currentGraph.Attr.LayerDirection = LayerDirection.LR;



            //form matrix
            //search max connect value
            int maxConnectCount = 0;

            foreach (var war in projectDoc.list_of_warnings)
            {
                var tem = projectDoc.list_of_protect_mech.Select(pm => pm.id).ToList();
                int currentConnectCount = _context.war_to_prot.Where(wtp => wtp.warcode == war.id &&
                                                                     tem.Contains(wtp.protcode)).Count <war_to_prot>();
                if (maxConnectCount < currentConnectCount)
                {
                    maxConnectCount = currentConnectCount;
                }
            }
            var dt = new DataTable();

            for (var i = 0; i < maxConnectCount; i++)
            {
                dt.Columns.Add(new DataColumn("c" + i, typeof(double)));
            }
            for (var i = 0; i < projectDoc.list_of_warnings.Count; i++)
            {
                var r = dt.NewRow();
                dt.Rows.Add(r);
                for (var c = 0; c < maxConnectCount; c++)
                {
                    r[c] = 0;
                }
            }

            foreach (var war in projectDoc.list_of_warnings)
            {
                foreach (var prot in projectDoc.list_of_protect_mech)
                {
                    if (_context.war_to_prot.Where(wtp => wtp.warcode == war.id && wtp.protcode == prot.id).Count <war_to_prot>() > 0)
                    {
                        currentGraph.AddEdge(war.name,
                                             _context.war_to_prot.Where(wtp => wtp.warcode == war.id && wtp.protcode == prot.id).ToList <war_to_prot>()[0].value.Value.ToString(),
                                             prot.name);
                        dt.Rows[projectDoc.list_of_warnings.IndexOf(war)][projectDoc.list_of_protect_mech.IndexOf(prot)] = _context.war_to_prot.Where(wtp => wtp.warcode == war.id && wtp.protcode == prot.id).ToList <war_to_prot>()[0].value.Value.ToString();
                    }
                }
            }

            dg1.DataContext = dt;
            maxConnectCount = 0;

            var resultDataTable = new DataTable();

            if (projectDoc.calc_type == 1)
            {
                foreach (var prot in projectDoc.list_of_protect_mech)
                {
                    var tem = projectDoc.list_of_barrier.Select(pm => pm.id).ToList();
                    int currentConnectCount = _context.prot_to_bar.Where(ptb => ptb.protcode == prot.id &&
                                                                         tem.Contains(ptb.barcode)).Count <prot_to_bar>();
                    if (maxConnectCount < currentConnectCount)
                    {
                        maxConnectCount = currentConnectCount;
                    }
                }
                var dt2 = new DataTable();
                for (var i = 0; i < maxConnectCount; i++)
                {
                    dt2.Columns.Add(new DataColumn("c" + i, typeof(double)));
                }
                for (var i = 0; i < projectDoc.list_of_protect_mech.Count; i++)
                {
                    var r = dt2.NewRow();
                    dt2.Rows.Add(r);
                    for (var c = 0; c < maxConnectCount; c++)
                    {
                        r[c] = 0;
                    }
                }

                foreach (var prot in projectDoc.list_of_protect_mech)
                {
                    foreach (var bar in projectDoc.list_of_barrier)
                    {
                        if (_context.prot_to_bar.Where(ptb => ptb.protcode == prot.id && ptb.barcode == bar.id).Count <prot_to_bar>() > 0)
                        {
                            currentGraph.AddEdge(prot.name,
                                                 _context.prot_to_bar.Where(ptb => ptb.protcode == prot.id && ptb.barcode == bar.id).ToList <prot_to_bar>()[0].value.Value.ToString(),
                                                 bar.name);
                            dt2.Rows[projectDoc.list_of_protect_mech.IndexOf(prot)][projectDoc.list_of_barrier.IndexOf(bar)] = _context.prot_to_bar.Where(ptb => ptb.protcode == prot.id && ptb.barcode == bar.id).ToList <prot_to_bar>()[0].value.Value.ToString();
                        }
                    }
                }

                dg2.DataContext = dt2;
                maxConnectCount = 0;

                var multy = Multiplication(To2DArray(dt), To2DArray(dt2));
                var dt5   = ToDataTable(multy);
                dg5.DataContext = dt5;

                foreach (var bar in projectDoc.list_of_barrier)
                {
                    var tem = projectDoc.list_of_weakness.Select(pm => pm.id).ToList();
                    int currentConnectCount = _context.bar_to_weak.Where(btw => btw.barcode == bar.id &&
                                                                         tem.Contains(btw.weakcode)).Count <bar_to_weak>();
                    if (maxConnectCount < currentConnectCount)
                    {
                        maxConnectCount = currentConnectCount;
                    }
                }
                var dt3 = new DataTable();
                for (var i = 0; i < maxConnectCount; i++)
                {
                    dt3.Columns.Add(new DataColumn("c" + i, typeof(double)));
                }
                for (var i = 0; i < projectDoc.list_of_barrier.Count; i++)
                {
                    var r = dt3.NewRow();
                    dt3.Rows.Add(r);
                    for (var c = 0; c < maxConnectCount; c++)
                    {
                        r[c] = 0;
                    }
                }

                foreach (var bar in projectDoc.list_of_barrier)
                {
                    foreach (var weak in projectDoc.list_of_weakness)
                    {
                        if (_context.bar_to_weak.Where(btw => btw.barcode == bar.id && btw.weakcode == weak.id).Count <bar_to_weak>() > 0)
                        {
                            currentGraph.AddEdge(bar.name,
                                                 _context.bar_to_weak.Where(btw => btw.barcode == bar.id && btw.weakcode == weak.id).ToList <bar_to_weak>()[0].value.Value.ToString(),
                                                 weak.name);
                            dt3.Rows[projectDoc.list_of_barrier.IndexOf(bar)][projectDoc.list_of_weakness.IndexOf(weak)] = _context.bar_to_weak.Where(btw => btw.barcode == bar.id && btw.weakcode == weak.id).ToList <bar_to_weak>()[0].value.Value.ToString();
                        }
                    }
                }

                dg3.DataContext = dt3;
                maxConnectCount = 0;

                multy = Multiplication(To2DArray(dt5), To2DArray(dt3));
                var dt6 = ToDataTable(multy);
                dg6.DataContext = dt6;

                foreach (var weak in projectDoc.list_of_weakness)
                {
                    var tem = projectDoc.list_of_objects.Select(pm => pm.id).ToList();
                    int currentConnectCount = _context.weak_to_object.Where(wto => wto.weakcode == weak.id &&
                                                                            tem.Contains(wto.objcode)).Count <weak_to_object>();
                    if (maxConnectCount < currentConnectCount)
                    {
                        maxConnectCount = currentConnectCount;
                    }
                }
                var dt4 = new DataTable();
                for (var i = 0; i < maxConnectCount; i++)
                {
                    dt4.Columns.Add(new DataColumn("c" + i, typeof(double)));
                }
                for (var i = 0; i < projectDoc.list_of_weakness.Count; i++)
                {
                    var r = dt4.NewRow();
                    dt4.Rows.Add(r);
                    for (var c = 0; c < maxConnectCount; c++)
                    {
                        r[c] = 0;
                    }
                }

                foreach (var weak in projectDoc.list_of_weakness)
                {
                    foreach (var obje in projectDoc.list_of_objects)
                    {
                        if (_context.weak_to_object.Where(wto => wto.weakcode == weak.id && wto.objcode == obje.id).Count <weak_to_object>() > 0)
                        {
                            currentGraph.AddEdge(weak.name,
                                                 _context.weak_to_object.Where(wto => wto.weakcode == weak.id && wto.objcode == obje.id).ToList <weak_to_object>()[0].value.Value.ToString(),
                                                 obje.name);
                            dt4.Rows[projectDoc.list_of_weakness.IndexOf(weak)][projectDoc.list_of_objects.IndexOf(obje)] = _context.weak_to_object.Where(wto => wto.weakcode == weak.id && wto.objcode == obje.id).ToList <weak_to_object>()[0].value.Value.ToString();
                        }
                    }
                }

                dg4.DataContext = dt4;
                maxConnectCount = 0;

                multy = Multiplication(To2DArray(dt6), To2DArray(dt4));
                var dt7 = ToDataTable(multy);
                dg7.DataContext = dt7;

                resultDataTable = dt7;
            }
            else
            {
                foreach (var prot in projectDoc.list_of_protect_mech)
                {
                    var tem = projectDoc.list_of_objects.Select(pm => pm.id).ToList();
                    int currentConnectCount = _context.prot_to_obj.Where(pto => pto.protcode == prot.id &&
                                                                         tem.Contains(pto.objcode)).Count <prot_to_obj>();
                    if (maxConnectCount < currentConnectCount)
                    {
                        maxConnectCount = currentConnectCount;
                    }
                }
                var dt2 = new DataTable();
                for (var i = 0; i < maxConnectCount; i++)
                {
                    dt2.Columns.Add(new DataColumn("c" + i, typeof(double)));
                }
                for (var i = 0; i < projectDoc.list_of_protect_mech.Count; i++)
                {
                    var r = dt2.NewRow();
                    dt2.Rows.Add(r);
                    for (var c = 0; c < maxConnectCount; c++)
                    {
                        r[c] = 0;
                    }
                }

                foreach (var prot in projectDoc.list_of_protect_mech)
                {
                    foreach (var obj in projectDoc.list_of_objects)
                    {
                        if (_context.prot_to_obj.Where(pto => pto.protcode == prot.id && pto.objcode == obj.id).Count <prot_to_obj>() > 0)
                        {
                            currentGraph.AddEdge(prot.name,
                                                 _context.prot_to_obj.Where(pto => pto.protcode == prot.id && pto.objcode == obj.id).ToList <prot_to_obj>()[0].value.Value.ToString(),
                                                 obj.name);
                            dt2.Rows[projectDoc.list_of_protect_mech.IndexOf(prot)][projectDoc.list_of_objects.IndexOf(obj)] = _context.prot_to_obj.Where(pto => pto.protcode == prot.id && pto.objcode == obj.id).ToList <prot_to_obj>()[0].value.Value.ToString();
                        }
                    }
                }

                dg2.DataContext = dt2;
                maxConnectCount = 0;

                var multy = Multiplication(To2DArray(dt), To2DArray(dt2));
                var dt5   = ToDataTable(multy);
                dg5.DataContext = dt5;

                resultDataTable = dt5;
            }

            var list_of_max = new List <double>();
            // в каждой строке ищем максимальное
            var damageTable = projectDoc.list_of_warnings;

            for (int i = 0; i < resultDataTable.Rows.Count; i++)
            {
                var max_in_row = 0.0;
                for (int j = 0; j < resultDataTable.Columns.Count; j++)
                {
                    if (max_in_row < (double)(resultDataTable.Rows[i][j]))
                    {
                        max_in_row = (double)(resultDataTable.Rows[i][j]);
                    }
                }
                list_of_max.Add(max_in_row);
                damageTable[i].damage_cost = damageTable[i].damage_cost * max_in_row;
                max_in_row = 0;
            }
            double result_mark = 0;

            for (int i = 0; i < projectDoc.list_of_warnings.Count; i++)
            {
                result_mark += (double)damageTable[i].damage_cost;//list_of_max[i] * (double)(projectDoc.list_of_warnings[i].damage_cost==null?0: projectDoc.list_of_warnings[i].damage_cost);
            }

            if (result_mark != 0)
            {
                result_mark          = 1 / result_mark;
                result_label.Content = result_mark;
            }
            else
            {
                result_label.Content = "ОШИБКА";
            }

            dg11.DataContext = damageTable.Select(s => new { s.name, s.damage_cost });
        }
        private void AddNewDocumentWithFile(Type type, string title, DockingManager dockingManager, ProjectDoc projectDoc)
        {
            var documentPane = dockingManager.Layout.Descendents().OfType <LayoutDocumentPane>().FirstOrDefault();

            if (documentPane != null)
            {
                var newDocument       = Activator.CreateInstance(type);
                var newDocumentLayout = new LayoutDocument
                {
                    Title   = title,
                    Content = newDocument
                };
                ((GraphView)newDocumentLayout.Content).CreateGraph(projectDoc);
                documentPane.Children.Add(newDocumentLayout);
            }
        }