Example #1
0
        /// <summary>
        /// Run the next iteration of this batch operation
        /// </summary>
        public void runBatchOp(CswNbtObjClassBatchOp BatchNode)
        {
            try
            {
                if (BatchNode != null && BatchNode.OpNameValue == CswEnumNbtBatchOpName.MultiButtonClick)
                {
                    BatchNode.start();

                    MultiButtonClickBatchData BatchData = new MultiButtonClickBatchData(BatchNode.BatchData.Text);
                    if (BatchData.MultiNodeIds.Count > 0)
                    {
                        String        NodeIdStr   = BatchData.MultiNodeIds.First.ToString();
                        CswPrimaryKey MultiNodePk = new CswPrimaryKey();
                        MultiNodePk.FromString(NodeIdStr);

                        CswNbtMetaDataNodeTypeProp NodeTypeProp = _CswNbtResources.MetaData.getNodeTypeProp(BatchData.NodeTypePropId);
                        if (Int32.MinValue != MultiNodePk.PrimaryKey && null != NodeTypeProp)
                        {
                            CswNbtObjClass.NbtButtonData ButtonData = new CswNbtObjClass.NbtButtonData(NodeTypeProp);
                            CswNbtNode MultiNode = _CswNbtResources.Nodes[MultiNodePk];
                            if (MultiNode != null)
                            {
                                MultiNode.ObjClass.triggerOnButtonClick(ButtonData);
                            }
                        }
                        // Setup for next iteration
                        BatchData.MultiNodeIds.RemoveAt(0);
                        BatchNode.BatchData.Text    = BatchData.ToString();
                        BatchNode.PercentDone.Value = getPercentDone(BatchNode);
                    }
                    else
                    {
                        BatchNode.finish();
                    }
                    BatchNode.postChanges(false);
                }
            }
            catch (Exception ex)
            {
                BatchNode.error(ex);
            }
        } // runBatchOp()
Example #2
0
        private bool _updateNodeProps(JObject NodeObj)
        {
            bool Ret = false;
            Collection <JProperty> Props = new Collection <JProperty>();


            if (null != NodeObj.Property("tabs"))
            {
                JObject Tabs = (JObject)NodeObj.Property("tabs").Value;
                foreach (JProperty Prop in from Tab
                         in Tabs.Properties()
                         where (null != Tab.Value)
                         select(JObject) Tab.Value
                         into TabProps
                         from Prop
                         in TabProps.Properties()
                         where (null != Prop.Value &&
                                Prop.Name != "nexttab" &&
                                Prop.Name != "currenttab")
                         let PropAtr = (JObject)Prop.Value
                                       where null != PropAtr["wasmodified"] &&
                                       CswConvert.ToBoolean(PropAtr["wasmodified"])
                                       select Prop)
                {
                    Props.Add(Prop);
                }
            }


            // post changes once per node, not once per prop
            Collection <CswNbtNode> NodesToPost = new Collection <CswNbtNode>();

            foreach (JProperty Prop in Props)
            {
                if (null != Prop.Name)
                {
                    string        NodePropId      = Prop.Name; // ~ "prop_4019_nodeid_nodes_24709"
                    string[]      SplitNodePropId = NodePropId.Split('_');
                    Int32         NodeTypePropId  = CswConvert.ToInt32(SplitNodePropId[1]);
                    CswPrimaryKey NodePk          = new CswPrimaryKey(SplitNodePropId[3], CswConvert.ToInt32(SplitNodePropId[4]));

                    CswNbtNode Node = _CswNbtResources.Nodes[NodePk];
                    CswNbtMetaDataNodeTypeProp MetaDataProp = _CswNbtResources.MetaData.getNodeTypeProp(NodeTypePropId);

                    JObject PropObj = (JObject)Prop.Value;

                    CswNbtMetaDataNodeTypeTab Tab = _CswNbtResources.MetaData.getNodeTypeTab(Node.NodeTypeId, CswConvert.ToString(PropObj["currenttab"]));
                    Node.Properties[MetaDataProp].ReadJSON(PropObj, null, null);

                    //Case 20964. Client needs to know whether the inspection is complete.
                    if (false == Ret && Node.getObjectClass().ObjectClass == CswNbtMetaDataObjectClass.NbtObjectClass.InspectionDesignClass)
                    {
                        CswNbtMetaDataObjectClassProp MetaDataOCP = MetaDataProp.getObjectClassProp();
                        if (MetaDataOCP != null)
                        {
                            CswNbtMetaDataObjectClassProp Finish = _CswNbtResources.MetaData.getObjectClassProp(Node.getObjectClassId(), CswNbtObjClassInspectionDesign.PropertyName.Finish);
                            CswNbtMetaDataObjectClassProp Cancel = _CswNbtResources.MetaData.getObjectClassProp(Node.getObjectClassId(), CswNbtObjClassInspectionDesign.PropertyName.Cancel);
                            if (MetaDataOCP == Finish ||
                                MetaDataOCP == Cancel)
                            {
                                //Ret = Ret || Node.Properties[MetaDataProp].AsButton.Checked == Tristate.True;
                                CswNbtObjClass.NbtButtonData ButtonData = new CswNbtObjClass.NbtButtonData(MetaDataProp);
                                ((CswNbtObjClassInspectionDesign)Node).onButtonClick(ButtonData);
                            }
                        }
                    }

                    if (false == NodesToPost.Contains(Node))
                    {
                        NodesToPost.Add(Node);
                    }
                }
            }

            foreach (CswNbtNode Node in NodesToPost)
            {
                Node.postChanges(false);
            }
            return(Ret);
        }
Example #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);
        }
Example #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);
                        }
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Instance a new EnterprisePart Request Item
        /// </summary>
        public CswNbtObjClassRequestItem makeEnterprisePartRequestItem(CswNbtObjClassEnterprisePart EnterprisePart, CswNbtObjClass.NbtButtonData ButtonData)
        {
            checkForCentralInventoryGroups(_CswNbtResources);
            CswNbtObjClassRequestItem RequestItem   = null;
            CswNbtMetaDataObjectClass RequestItemOC = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.RequestItemClass);
            CswNbtMetaDataNodeType    RequestItemNT = RequestItemOC.getNodeTypes().FirstOrDefault();
            CswNbtSdTabsAndProps      PropsAction   = new CswNbtSdTabsAndProps(_CswNbtResources);

            if (null != RequestItemNT)
            {
                RequestItem = PropsAction.getAddNodeAndPostChanges(RequestItemNT, delegate(CswNbtNode NewNode)
                {
                    CswNbtObjClassRequestItem RequestItemNode    = NewNode;
                    RequestItemNode.EnterprisePart.RelatedNodeId = EnterprisePart.NodeId;
                    RequestItemNode.Type.Value = CswNbtObjClassRequestItem.Types.EnterprisePart;
                    if (null != _ThisUser.DefaultLocationId)
                    {
                        CswNbtObjClassLocation DefaultAsLocation = _CswNbtResources.Nodes.GetNode(_ThisUser.DefaultLocationId);
                        if (null != DefaultAsLocation)
                        {
                            RequestItemNode.Location.SelectedNodeId = DefaultAsLocation.NodeId;
                            RequestItemNode.Location.CachedNodeName = DefaultAsLocation.Location.CachedNodeName;
                            RequestItemNode.Location.CachedPath     = DefaultAsLocation.Location.CachedPath;
                        }
                    }
                });
            }
            return(RequestItem);
        }
Example #6
0
        /// <summary>
        /// Instance a new Material Request Item based on the selected button option - the type will either be By Bulk or By Size.
        /// </summary>
        public CswNbtObjClassRequestItem makeMaterialRequestItem(CswNbtPropertySetMaterial Material, CswNbtObjClass.NbtButtonData ButtonData)
        {
            checkForCentralInventoryGroups(_CswNbtResources);
            CswNbtObjClassRequestItem RequestItem   = null;
            CswNbtMetaDataObjectClass RequestItemOC = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.RequestItemClass);
            CswNbtMetaDataNodeType    RequestItemNT = RequestItemOC.getNodeTypes().FirstOrDefault();
            CswNbtSdTabsAndProps      PropsAction   = new CswNbtSdTabsAndProps(_CswNbtResources);

            if (null != RequestItemNT)
            {
                RequestItem = PropsAction.getAddNodeAndPostChanges(RequestItemNT, delegate(CswNbtNode NewNode)
                {
                    CswNbtObjClassRequestItem RequestItemNode = NewNode;
                    RequestItemNode.Material.RelatedNodeId    = Material.NodeId;
                    if (null != _ThisUser.DefaultLocationId)
                    {
                        CswNbtObjClassLocation DefaultAsLocation = _CswNbtResources.Nodes.GetNode(_ThisUser.DefaultLocationId);
                        if (null != DefaultAsLocation)
                        {
                            RequestItemNode.Location.SelectedNodeId = DefaultAsLocation.NodeId;
                            RequestItemNode.Location.CachedNodeName = DefaultAsLocation.Location.CachedNodeName;
                            RequestItemNode.Location.CachedPath     = DefaultAsLocation.Location.CachedPath;
                        }
                    }
                    switch (ButtonData.SelectedText)
                    {
                    case CswNbtPropertySetMaterial.CswEnumRequestOption.Size:
                        RequestItemNode.Type.Value = CswNbtObjClassRequestItem.Types.MaterialSize;
                        break;

                    default:     //Request by Bulk
                        RequestItemNode.Type.Value = CswNbtObjClassRequestItem.Types.MaterialBulk;
                        break;
                    }
                });
            }
            return(RequestItem);
        }
Example #7
0
        /// <summary>
        /// Instance a new Container Request Item based on the selected button option - the type will either be Dispense, Move, or Dispose.
        /// </summary>
        public CswNbtObjClassRequestItem makeContainerRequestItem(CswNbtObjClassContainer Container, CswNbtObjClass.NbtButtonData ButtonData)
        {
            checkForCentralInventoryGroups(_CswNbtResources);
            CswNbtObjClassRequestItem RequestItem;
            CswNbtMetaDataObjectClass RequestItemOC = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.RequestItemClass);
            CswNbtMetaDataNodeType    RequestItemNT = RequestItemOC.getNodeTypes().FirstOrDefault();
            CswNbtSdTabsAndProps      PropsAction   = new CswNbtSdTabsAndProps(_CswNbtResources);

            RequestItem = PropsAction.getAddNodeAndPostChanges(RequestItemNT, delegate(CswNbtNode NewNode)
            {
                CswNbtObjClassRequestItem RequestItemNode = NewNode;
                if (null != getCurrentRequestNodeId() && null != Container)
                {
                    RequestItemNode.Container.RelatedNodeId = Container.NodeId;
                    RequestItemNode.Material.RelatedNodeId  = Container.Material.RelatedNodeId;
                    CswPrimaryKey SelectedLocationId        = CswTools.IsPrimaryKey(_ThisUser.DefaultLocationId) ?
                                                              _ThisUser.DefaultLocationId :
                                                              Container.Location.SelectedNodeId;
                    ButtonData.Action = CswEnumNbtButtonAction.request;
                    switch (ButtonData.SelectedText)
                    {
                    case CswEnumNbtContainerRequestMenu.Dispense:
                        RequestItemNode.Type.Value              = CswNbtObjClassRequestItem.Types.ContainerDispense;
                        RequestItemNode.Quantity.UnitId         = Container.Quantity.UnitId;
                        RequestItemNode.Size.RelatedNodeId      = Container.Size.RelatedNodeId;
                        RequestItemNode.Location.SelectedNodeId = SelectedLocationId;
                        //Scope available units of measure on Quantity based on the Container's Material
                        CswNbtNode MaterialNode = _CswNbtResources.Nodes[Container.Material.RelatedNodeId];
                        if (null != MaterialNode)
                        {
                            CswNbtUnitViewBuilder Vb = new CswNbtUnitViewBuilder(_CswNbtResources);
                            Vb.setQuantityUnitOfMeasureView(MaterialNode, RequestItemNode.Quantity);
                        }
                        break;

                    case CswEnumNbtContainerRequestMenu.Dispose:
                        RequestItemNode.Type.Value = CswNbtObjClassRequestItem.Types.ContainerDispose;
                        RequestItemNode.Location.SelectedNodeId = Container.Location.SelectedNodeId;
                        break;

                    case CswEnumNbtContainerRequestMenu.Move:
                        RequestItemNode.Type.Value = CswNbtObjClassRequestItem.Types.ContainerMove;
                        RequestItemNode.Location.SelectedNodeId = SelectedLocationId;
                        break;
                    }
                    RequestItemNode.Location.RefreshNodeName();
                }
            });
            if (null == RequestItem)
            {
                throw new CswDniException(CswEnumErrorType.Error, "Could not generate a new request item.", "Failed to create a new Request Item node.");
            }
            return(RequestItem);
        }