Пример #1
0
        private CswNbtNode _getTargetNodeForGenerator(CswNbtNode CswNbtNodeGenerator, CswPrimaryKey ParentPk, string TargetDateFilter)
        {
            CswNbtNode ReturnVal = null;

            CswNbtObjClassGenerator GeneratorNode = (CswNbtObjClassGenerator)CswNbtNodeGenerator;

            if (String.IsNullOrEmpty(GeneratorNode.TargetType.SelectedNodeTypeIds.ToString()))
            {
                throw new CswDniException(CswEnumErrorType.Error, "Invalid generator configuration", "_getTargetNodeForGenerator got a null SelectedNodeTypeIds on nodeid " + GeneratorNode.NodeId);
            }
            else
            {
                Int32 NodeTypeId = CswConvert.ToInt32(GeneratorNode.TargetType.SelectedNodeTypeIds[0]);   // case 28612 - just check the first one
                if (Int32.MinValue != NodeTypeId)
                {
                    CswNbtMetaDataNodeType ThisCreatedNodeType = _CswNbtResources.MetaData.getNodeType(NodeTypeId);
                    if (null != ThisCreatedNodeType)
                    {
                        CswNbtMetaDataNodeType    CreatedNodeType            = ThisCreatedNodeType.getNodeTypeLatestVersion();
                        CswNbtMetaDataObjectClass CreatedMetaDataObjectClass = CreatedNodeType.getObjectClass();

                        CswNbtObjClass CreatedObjClass = CswNbtObjClassFactory.makeObjClass(_CswNbtResources, CreatedMetaDataObjectClass);
                        if (!(CreatedObjClass is CswNbtPropertySetGeneratorTarget))
                        {
                            throw new CswDniException("CswNbtActGenerateNodes got an invalid object class: " + CreatedObjClass.ObjectClass.ToString());
                        }
                        CswNbtPropertySetGeneratorTarget GeneratorTarget = (CswNbtPropertySetGeneratorTarget)CreatedObjClass;

                        // CreatedForNTP is the parent or owner of the new node. Inspections created for Inspection Targets, Tasks for Equipment, etc.
                        CswNbtMetaDataNodeTypeProp CreatedForNTP = CreatedNodeType.getNodeTypePropByObjectClassProp(GeneratorTarget.ParentPropertyName);
                        CswNbtMetaDataNodeTypeProp GeneratorNTP  = CreatedNodeType.getNodeTypePropByObjectClassProp(CswNbtPropertySetGeneratorTarget.PropertyName.Generator);
                        CswNbtMetaDataNodeTypeProp DueDateNTP    = CreatedNodeType.getNodeTypePropByObjectClassProp(CswNbtPropertySetGeneratorTarget.PropertyName.DueDate);

                        CswNbtView CswNbtView = new CswNbtView(_CswNbtResources);
                        CswNbtView.ViewName = "Nodes for Generator";

                        CswNbtViewRelationship RootRelationship     = CswNbtView.AddViewRelationship(CreatedNodeType, false);
                        CswNbtViewProperty     CreatedForParentProp = CswNbtView.AddViewProperty(RootRelationship, CreatedForNTP);
                        CswNbtView.AddViewPropertyFilter(CreatedForParentProp, CswNbtFieldTypeRuleRelationship.SubFieldName.NodeID, CswEnumNbtFilterMode.Equals, ParentPk.PrimaryKey.ToString(), false);
                        CswNbtViewProperty GeneratorProp = CswNbtView.AddViewProperty(RootRelationship, GeneratorNTP);
                        CswNbtView.AddViewPropertyFilter(GeneratorProp, CswNbtFieldTypeRuleRelationship.SubFieldName.NodeID, CswEnumNbtFilterMode.Equals, CswNbtNodeGenerator.NodeId.PrimaryKey.ToString(), false);
                        CswNbtViewProperty DueDateProp = CswNbtView.AddViewProperty(RootRelationship, DueDateNTP);
                        //Case 24572
                        CswNbtView.AddViewPropertyFilter(DueDateProp, CswNbtFieldTypeRuleDateTime.SubFieldName.Value, CswEnumNbtFilterMode.Equals, TargetDateFilter, false);

                        ICswNbtTree ExistingNodesTree = _CswNbtResources.Trees.getTreeFromView(_CswNbtResources.CurrentNbtUser, CswNbtView, true, false, false);

                        if (ExistingNodesTree.getChildNodeCount() > 0)
                        {
                            ExistingNodesTree.goToNthChild(0);
                            ReturnVal = ExistingNodesTree.getNodeForCurrentPosition();
                        }
                    }
                }
            }
            return(ReturnVal);
        }//_getTargetNodeForGenerator
Пример #2
0
        public CswNbtView getTreeViewOfFutureNodes(IEnumerable GeneratorNodes)
        {
            CswNbtView ReturnVal = new CswNbtView(_CswNbtResources);

            ReturnVal.ViewName = "All Future Nodes";
            CswNbtMetaDataObjectClass GeneratorObjectClass  = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.GeneratorClass);
            CswNbtViewRelationship    GeneratorRelationship = ReturnVal.AddViewRelationship(GeneratorObjectClass, false);

            ArrayList TargetNodeTypeIds = new ArrayList();

            foreach (CswNbtNode CurrentGeneratorNode in GeneratorNodes)
            {
                GeneratorRelationship.NodeIdsToFilterIn.Add(CurrentGeneratorNode.NodeId);
                CswNbtObjClassGenerator Generator = CurrentGeneratorNode;
                foreach (String nodeTypeId in Generator.TargetType.SelectedNodeTypeIds)
                {
                    Int32 CurrentTargetNodeTypeId = CswConvert.ToInt32(nodeTypeId);
                    if (!(TargetNodeTypeIds.Contains(CurrentTargetNodeTypeId)))
                    {
                        TargetNodeTypeIds.Add(CurrentTargetNodeTypeId);
                    }
                }
            }

            foreach (Int32 TargetNodeTypeId in TargetNodeTypeIds)
            {
                CswNbtMetaDataNodeType TargetNodeType = _CswNbtResources.MetaData.getNodeType(TargetNodeTypeId);
                if (TargetNodeType != null)
                {
                    CswNbtMetaDataObjectClass TargetObjectClass = TargetNodeType.getObjectClass();

                    CswNbtObjClass TargetObjClass = CswNbtObjClassFactory.makeObjClass(_CswNbtResources, TargetObjectClass);
                    if (!(TargetObjClass is CswNbtPropertySetGeneratorTarget))
                    {
                        throw new CswDniException("CswNbtActGenerateFutureNodes.getTreeViewOfFutureNodes() got an invalid object class: " + TargetObjectClass.ObjectClass);
                    }

                    CswNbtViewRelationship   TargetRelationship   = ReturnVal.AddViewRelationship(GeneratorRelationship, CswEnumNbtViewPropOwnerType.Second, TargetNodeType.getNodeTypePropByObjectClassProp(CswNbtPropertySetGeneratorTarget.PropertyName.Generator), false);
                    CswNbtViewProperty       IsFutureFlagProperty = ReturnVal.AddViewProperty(TargetRelationship, TargetNodeType.getNodeTypePropByObjectClassProp(CswNbtPropertySetGeneratorTarget.PropertyName.IsFuture));
                    CswNbtViewPropertyFilter IsFutureFilter       = ReturnVal.AddViewPropertyFilter(IsFutureFlagProperty, CswNbtFieldTypeRuleLogical.SubFieldName.Checked, CswEnumNbtFilterMode.Equals, CswEnumTristate.True, false);
                }
            }

            return(ReturnVal);
        }//getTreeViewOfFutureNodes()
Пример #3
0
        public JObject doObjectClassButtonClick(CswPropIdAttr PropId, string SelectedText, string TabIds, JObject PropsToSave, string NodeIds, string PropIds)
        {
            JObject RetObj = new JObject();

            if (null == PropId ||
                Int32.MinValue == PropId.NodeTypePropId ||
                null == PropId.NodeId ||
                Int32.MinValue == PropId.NodeId.PrimaryKey)
            {
                throw new CswDniException(CswEnumErrorType.Error, "Cannot execute a button click without valid parameters.", "Attempted to call DoObjectClassButtonClick with invalid NodeId and NodeTypePropId.");
            }

            CswNbtNode Node = _CswNbtResources.Nodes.GetNode(PropId.NodeId);

            if (null == Node)
            {
                throw new CswDniException(CswEnumErrorType.Error, "Cannot find a valid node with the provided parameters.", "No node exists for NodePk " + PropId.NodeId.ToString() + ".");
            }

            CswNbtMetaDataNodeTypeProp NodeTypeProp = _CswNbtResources.MetaData.getNodeTypeProp(PropId.NodeTypePropId);

            if (null == NodeTypeProp)
            {
                throw new CswDniException(CswEnumErrorType.Error, "Cannot find a valid property with the provided parameters.", "No property exists for NodeTypePropId " + PropId.NodeTypePropId.ToString() + ".");
            }

            CswNbtObjClass NbtObjClass = CswNbtObjClassFactory.makeObjClass(_CswNbtResources, Node.getObjectClassId(), Node);

            CswCommaDelimitedString TabIdsCDS = new CswCommaDelimitedString();

            TabIdsCDS.FromString(TabIds);
            CswNbtObjClass.NbtButtonData ButtonData = new CswNbtObjClass.NbtButtonData(NodeTypeProp)
            {
                SelectedText = SelectedText,
                PropsToSave  = PropsToSave,
                TabIds       = TabIdsCDS,
                NodeIds      = new CswCommaDelimitedString(),
                PropIds      = new CswCommaDelimitedString()
            };
            ButtonData.NodeIds.FromString(NodeIds);
            ButtonData.PropIds.FromString(PropIds);

            bool Success = NbtObjClass.triggerOnButtonClick(ButtonData);

            if (null == ButtonData.Action || ButtonData.Action == CswEnumNbtButtonAction.Unknown)
            {
                ButtonData.Action = CswEnumNbtButtonAction.nothing;
            }
            if (Node.NodeId == _CswNbtResources.CurrentNbtUser.UserId)
            {
                RetObj["updateDefaults"] = true;
            }
            RetObj["action"]     = ButtonData.Action.ToString();
            RetObj["actionData"] = ButtonData.Data;  //e.g. popup url
            RetObj["message"]    = ButtonData.Message;
            RetObj["tabids"]     = ButtonData.TabIds.ToString();
            RetObj["savedprops"] = ButtonData.PropsToReturn;
            RetObj["success"]    = Success.ToString().ToLower();

            return(RetObj);
        }
Пример #4
0
        private void _updateInspectionNode(CswNbtSdInspectionsDataModels.InspectionData.CswNbtInspection Inspection, CswNbtSdInspectionsDataModels.InspectionUpdateData UpdateCollection)
        {
            if (Int32.MinValue != Inspection.InspectionId)
            {
                CswPrimaryKey InspectionPk   = new CswPrimaryKey("nodes", Inspection.InspectionId);
                CswNbtNode    InspectionNode = _CswNbtResources.Nodes.GetNode(InspectionPk, Inspection.DesignId);
                if (null != InspectionNode)
                {
                    CswNbtObjClassInspectionDesign NodeAsDesign = (CswNbtObjClassInspectionDesign)InspectionNode;
                    if (NodeAsDesign.Status.Value == Completed || NodeAsDesign.Status.Value == CompletedLate)
                    {
                        UpdateCollection.Completed.Add(Inspection);
                    }
                    else if (NodeAsDesign.Status.Value == Cancelled)
                    {
                        UpdateCollection.Cancelled.Add(Inspection);
                    }
                    else if (NodeAsDesign.Status.Value == Missed)
                    {
                        UpdateCollection.Missed.Add(Inspection);
                    }
                    else
                    {
                        Inspection.Counts = new CswNbtSdInspectionsDataModels.InspectionData.CswNbtInspection.QuestionCounts();
                        /* We loop once to set the property values */
                        CswNbtMetaDataNodeType InspectionNt = InspectionNode.getNodeType();
                        if (null != InspectionNt)
                        {
                            //Can edit the nodetype
                            if (_CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Edit, InspectionNt))
                            {
                                foreach (CswNbtSdInspectionsDataModels.InspectionData.CswNbtInspection.QuestionAnswer Question in Inspection.Questions)
                                {
                                    CswNbtMetaDataNodeTypeProp Ntp = InspectionNt.getNodeTypeProp(Question.QuestionId);
                                    if (null != Ntp && null != Ntp.FirstEditLayout)
                                    {
                                        CswNbtMetaDataNodeTypeTab Tab = InspectionNt.getNodeTypeTab(Ntp.FirstEditLayout.TabId);
                                        if (null != Tab)
                                        {
                                            bool CanEdit = (
                                                _CswNbtResources.Permit.canTab(CswEnumNbtNodeTypePermission.Edit, InspectionNt, Tab) ||
                                                _CswNbtResources.Permit.isPropWritable(CswEnumNbtNodeTypePermission.Edit, Ntp, Tab)
                                                );

                                            CswNbtNodePropQuestion PropAsQuestion = InspectionNode.Properties[Ntp];
                                            if (CanEdit)
                                            {
                                                PropAsQuestion.Answer           = Question.Answer;
                                                PropAsQuestion.CorrectiveAction = Question.CorrectiveAction;
                                                DateTime DateAnswered = CswConvert.ToDateTime(Question.DateAnswered);
                                                if (DateTime.MinValue != DateAnswered)
                                                {
                                                    PropAsQuestion.DateAnswered = DateAnswered;
                                                }
                                                DateTime DateCorrected = CswConvert.ToDateTime(Question.DateCorrected);
                                                if (DateTime.MinValue != DateCorrected)
                                                {
                                                    PropAsQuestion.DateCorrected = DateCorrected;
                                                }
                                                PropAsQuestion.Comments = Question.Comments;
                                            }
                                            if (false == string.IsNullOrEmpty(Question.Answer))
                                            {
                                                Inspection.Counts.Answered += 1;
                                            }
                                            else
                                            {
                                                Inspection.Counts.UnAnswered += 1;
                                            }
                                            if (false == PropAsQuestion.IsCompliant)
                                            {
                                                Inspection.Counts.Ooc += 1;
                                            }
                                            Inspection.Counts.Total += 1;
                                        }
                                    }
                                }
                                InspectionNode.postChanges(true);
                                if (false == string.IsNullOrEmpty(Inspection.Action) && (Inspection.Action.ToLower() == "finish" || Inspection.Action.ToLower() == "cancel"))
                                {
                                    CswNbtMetaDataNodeTypeProp ButtonNtp = null;
                                    if (Inspection.Action.ToLower() == "finish")
                                    {
                                        ButtonNtp = InspectionNode.getNodeType().getNodeTypeProp(CswNbtObjClassInspectionDesign.PropertyName.Finish);
                                    }
                                    else if (Inspection.Action.ToLower() == "cancel")
                                    {
                                        ButtonNtp = InspectionNode.getNodeType().getNodeTypeProp(CswNbtObjClassInspectionDesign.PropertyName.Cancel);
                                    }

                                    if (null != ButtonNtp && null != ButtonNtp.FirstEditLayout)
                                    {
                                        CswNbtMetaDataNodeTypeTab ButtonTab = _CswNbtResources.MetaData.getNodeTypeTab(ButtonNtp.FirstEditLayout.TabId);
                                        if (null != ButtonTab &&
                                            (
                                                _CswNbtResources.Permit.canTab(CswEnumNbtNodeTypePermission.Edit, InspectionNt, NodeTypeTab: ButtonTab) ||
                                                _CswNbtResources.Permit.isPropWritable(CswEnumNbtNodeTypePermission.Edit, ButtonNtp, ButtonTab)
                                            )
                                            )
                                        {
                                            _InspectionDesignOc = _InspectionDesignOc ?? _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.InspectionDesignClass);
                                            CswNbtObjClass NbtObjClass = CswNbtObjClassFactory.makeObjClass(_CswNbtResources, _InspectionDesignOc, InspectionNode);
                                            CswNbtObjClass.NbtButtonData ButtonData = new CswNbtObjClass.NbtButtonData(ButtonNtp);
                                            NbtObjClass.triggerOnButtonClick(ButtonData);
                                        }
                                    }
                                }
                            }
                        }
                        /* Reinit since state has changed. */
                        NodeAsDesign = InspectionNode;

                        if (NodeAsDesign.Status.Value == Completed || NodeAsDesign.Status.Value == CompletedLate)
                        {
                            /* Nothing to do */
                        }
                        else if (NodeAsDesign.Status.Value == ActionRequired)
                        {
                            Inspection.Status = NodeAsDesign.Status.Value;
                            /* We loop again to modify the return with the status of the Inspection per QuestionAnswer */
                            foreach (CswNbtSdInspectionsDataModels.InspectionData.CswNbtInspection.QuestionAnswer Question in Inspection.Questions)
                            {
                                Question.Status = NodeAsDesign.Status.Value;
                            }
                            /* In case the Inspection has been modified by someone else */
                            Inspection.DueDateAsDate       = NodeAsDesign.InspectionDate.DateTimeValue;
                            Inspection.InspectionPointName = NodeAsDesign.Target.CachedNodeName;
                            Inspection.LocationPath        = NodeAsDesign.Location.CachedValue;
                            UpdateCollection.ActionRequired.Add(Inspection);
                        }
                        else
                        {
                            UpdateCollection.InComplete.Add(Inspection);
                        }
                    }
                }
            }
        }