Esempio n. 1
0
        public ConstructionReportViewModel(
            IMillReportsRepository repo,
            IJointRepository repoJoint,
            IUserNotify notify)
        {
            this.repo   = repo;
            this.notify = notify;

            this.data = repo.GetPipelineElements(SQLProvider.GetQuery(SQLProvider.SQLStatic.GetWeldedParts).ToString());
            if (this.data == null || this.data.Rows.Count <= 0)
            {
                log.Warn("Report at Construction: Data Table of Pieces is NULL or empty.");
            }

            this.partDataList = FormWeldedParts(data);

            this.Joints = repoJoint.GetAll()
                          .Where <construct.Joint>(x => x.FirstElement != null && x.SecondElement != null)
                          .ToList <construct.Joint>();
            if (this.Joints == null || this.Joints.Count <= 0)
            {
                log.Warn("Report at Construction: List of Joints is NULL or empty.");
            }


            createCommand = ViewModelSource
                            .Create <CreateReportCommand>(() => new CreateReportCommand(this, repo, notify));

            previewCommand = ViewModelSource
                             .Create <PreviewReportCommand>(() => new PreviewReportCommand(this, repo, notify));

            reportCommand = ViewModelSource
                            .Create <ReportCommand>(() => new ReportCommand(this, repo, notify));
        }
Esempio n. 2
0
        private void GetUsedProduct()
        {
            try
            {
                if (viewModel.Types.Count > 0)
                {
                    StringBuilder GetAllUsedProducts = new StringBuilder();
                    foreach (var item in viewModel.Types)
                    {
                        if (!string.IsNullOrWhiteSpace(GetAllUsedProducts.ToString()))
                        {
                            GetAllUsedProducts.Append(" UNION ");
                        }

                        switch (item)
                        {
                        case PartType.Undefined:
                            GetAllUsedProducts.Append(" ");
                            break;

                        case PartType.Pipe:
                            GetAllUsedProducts.Append(SQLProvider.GetQuery(SQLProvider.SQLStatic.GetAllUsedPipe));
                            GetAllUsedProducts.Append(" ");
                            break;

                        case PartType.Spool:
                            GetAllUsedProducts.Append(SQLProvider.GetQuery(SQLProvider.SQLStatic.GetAllUsedSpool));
                            GetAllUsedProducts.Append(" ");
                            break;

                        case PartType.Component:
                            GetAllUsedProducts.Append(" ");
                            GetAllUsedProducts.Append(SQLProvider.GetQuery(SQLProvider.SQLStatic.GetAllUsedComponent));
                            break;

                        default:
                            GetAllUsedProducts.Append(" ");
                            break;
                        }
                    }

                    data = repo.GetUsedProducts(viewModel.StartPK, viewModel.EndPK, GetAllUsedProducts.ToString());
                }
            }
            catch (RepositoryException ex)
            {
                log.Error(string.Concat(ex.InnerException.Message, ex.Message));
                notify.ShowFailure(ex.InnerException.Message, ex.Message);
            }
        }
Esempio n. 3
0
        private void PipelineTracing()
        {
            try
            {
                usedProductList = new List <PartData>();
                if (joints == null)
                {
                    this.joints = repoJoint.GetJointsForTracing().ToList <construct.Joint>();
                    if (this.joints == null || this.joints.Count <= 0)
                    {
                        log.Warn("Report at Construction: List of Joints is NULL or empty.");
                    }
                }
                if (partDataList == null)
                {
                    var data = repo.GetPipelineElements(SQLProvider.GetQuery(SQLProvider.SQLStatic.GetWeldedParts).ToString());
                    if (data == null || data.Rows.Count <= 0)
                    {
                        log.Warn("Report at Construction: Data Table of Pieces is NULL or empty.");
                    }

                    this.partDataList = this.FormWeldedParts(data);
                }

                graph           = new PipelineGraph(partDataList.Count);
                tracingDataList = new List <TracingData>();

                if (partDataList != null)
                {
                    foreach (var partData in partDataList)
                    {
                        graph.AddPipelineVertex(partData);
                    }
                    foreach (var joint in this.joints)
                    {
                        graph.AddJointEdge(joint);
                    }

                    construct.Joint startJoint = null;
                    construct.Joint endJoint   = null;

                    if (viewModel.TracingMode == TracingModeEnum.TracingByKP &&
                        viewModel.AllKP.Contains(viewModel.StartPK) &&
                        viewModel.AllKP.Contains(viewModel.EndPK))
                    {
                        startJoint = joints.First <construct.Joint>(
                            x => x.NumberKP == viewModel.StartPK && x.DistanceFromKP == joints
                            .Where <construct.Joint>(y => y.NumberKP == viewModel.StartPK)
                            .Min <construct.Joint>(z => z.DistanceFromKP));

                        endJoint = joints.Last <construct.Joint>(
                            x => x.NumberKP == viewModel.EndPK && x.DistanceFromKP == joints
                            .Where <construct.Joint>(y => y.NumberKP == viewModel.EndPK)
                            .Max <construct.Joint>(z => z.DistanceFromKP));
                    }

                    if (endJoint == null && startJoint == null)
                    {
                        startJoint = joints.First <construct.Joint>(x => x.Id == viewModel.StartJoint.Id);
                        endJoint   = joints.First <construct.Joint>(x => x.Id == viewModel.EndJoint.Id);
                    }

                    var paths = graph.Pathfinder(startJoint.FirstElement, endJoint.FirstElement);

                    if (paths.Count != 0)
                    {
                        path = graph.ShortestPath(paths);

                        path = graph.RemovalExternalComponents(startJoint, endJoint, path);

                        for (int i = path.Count - 1; i > 0; --i)
                        {
                            var tracingDataItem = new TracingData(path[i].Data, path[i - 1].Data);

                            var commonJoint = path[i].GetCommonJoint(path[i - 1]);

                            tracingDataItem.JointNumber = commonJoint.Data.Number;
                            tracingDataItem.WeldingDate = GetWeldDate(commonJoint.Data);

                            tracingDataList.Add(tracingDataItem);
                        }

                        for (int i = 0; i < path.Count; ++i)
                        {
                            usedProductList.Add(path[i].Data);
                        }

                        PartData firstElement = partDataList.Where(_ => _.Id == startJoint.FirstElement.Id).FirstOrDefault();

                        PartData secondElement = partDataList.Where(_ => _.Id == endJoint.SecondElement.Id).FirstOrDefault();

                        var firstTracingDataItem = new TracingData(firstElement, path.Last().Data);
                        firstTracingDataItem.JointNumber = startJoint.Number;
                        firstTracingDataItem.WeldingDate = GetWeldDate(startJoint);
                        tracingDataList.Insert(0, firstTracingDataItem);

                        usedProductList.Add(firstElement);

                        var lastTracingDataItem = new TracingData(path.First().Data, secondElement);
                        lastTracingDataItem.JointNumber = endJoint.Number;
                        lastTracingDataItem.WeldingDate = GetWeldDate(endJoint);
                        tracingDataList.Add(lastTracingDataItem);

                        usedProductList.Add(secondElement);

                        PipelineLenghtCalculation();
                    }
                }
                else
                {
                    log.Warn(string.Format("List of Pipeline elements is NULL for construction report type: {0}", viewModel.ReportType));
                }
            }
            catch (RepositoryException ex)
            {
                log.Warn(this.GetType().Name + " | " + ex.ToString());
                notify.ShowWarning(Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Message),
                                   Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Header));
            }
        }