Пример #1
0
 public static void getQuota(ICswResources Resources, CswNbtQuotaResponse Response, QuotaRequest Request)
 {
     if (null != Resources)
     {
         CswNbtResources NbtResources  = (CswNbtResources)Resources;
         CswNbtActQuotas ActQuotas     = new CswNbtActQuotas(NbtResources);
         int             NodeTypeId    = Request.NodeTypeId;
         int             ObjectClassId = Request.ObjectClassId;
         if (NodeTypeId <= 0)
         {
             CswNbtNodeKey Key = wsNBT.getNodeKey(Request.NodeKey);
             if (null != Key)
             {
                 NodeTypeId    = Key.NodeTypeId;
                 ObjectClassId = Key.ObjectClassId;
             }
         }
         if (NodeTypeId <= 0)
         {
             CswNbtNode Node = NbtResources.Nodes[Request.NodeId];
             if (null != Node)
             {
                 NodeTypeId    = Node.NodeTypeId;
                 ObjectClassId = Node.getObjectClassId();
             }
         }
         Response.Data = ActQuotas.CheckQuota(NodeTypeId, ObjectClassId);
     }
 }
Пример #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);
        }
Пример #3
0
        public static void initializeCreateMaterial(ICswResources CswResources, MaterialResponse Response, string NodeId)
        {
            if (null != CswResources)
            {
                CswNbtResources         NbtResources         = (CswNbtResources)CswResources;
                CswNbtActCreateMaterial CreateMaterialAction = new CswNbtActCreateMaterial(NbtResources);

                // Get/Create a node
                CswPrimaryKey NodePk   = CreateMaterialAction.makeTemp(NodeId);
                CswNbtNode    TempNode = NbtResources.getNode(NodePk, null);
                Response.Data.TempNode           = new CswNbtNode.Node(TempNode);
                Response.Data.TempNodeObjClassId = CswConvert.ToString(TempNode.getObjectClassId());

                // Suppliers view
                CswNbtView SupplierView = CreateMaterialAction.getMaterialSuppliersView();
                if (null != SupplierView)
                {
                    Response.Data.SuppliersView.SessionViewId = SupplierView.SessionViewId;
                }

                // CIS-53353 - Allow adding suppliers if the user has Create on any Vendor nodetype
                Response.Data.AllowSupplierAdd = false;
                CswNbtMetaDataObjectClass VendorOC = NbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.VendorClass);
                foreach (CswNbtMetaDataNodeType VendorNT in VendorOC.getNodeTypes())
                {
                    if (NbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Create, VendorNT))
                    {
                        Response.Data.AllowSupplierAdd = true;
                    }
                }

                //Determine the steps
                int StepNo = 1;
                MaterialResponse.WizardStep TypeAndIdentity = new MaterialResponse.WizardStep()
                {
                    StepNo   = StepNo,
                    StepName = "Choose Type and Identity"
                };
                Response.Data.Steps.Add(TypeAndIdentity);
                StepNo++;

                MaterialResponse.WizardStep AdditionalProps = new MaterialResponse.WizardStep()
                {
                    StepNo   = StepNo,
                    StepName = "Additional Properties"
                };
                Response.Data.Steps.Add(AdditionalProps);
                StepNo++;

                #region Alert wizard to active modules

                bool ContainersEnabled = NbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.Containers);
                if (ContainersEnabled)
                {
                    bool CanSize = false;
                    CswNbtMetaDataObjectClass SizeOC = NbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.SizeClass);
                    foreach (CswNbtMetaDataNodeType SizeNT in SizeOC.getNodeTypes())
                    {
                        if (NbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Create, SizeNT))
                        {
                            CanSize = true;
                        }
                    }
                    if (CanSize)
                    {
                        MaterialResponse.WizardStep Sizes = new MaterialResponse.WizardStep()
                        {
                            StepNo   = StepNo,
                            StepName = "Size(s)"
                        };
                        Response.Data.Steps.Add(Sizes);
                        Response.Data.ContainerLimit = CswConvert.ToInt32(NbtResources.ConfigVbls.getConfigVariableValue(CswEnumNbtConfigurationVariables.container_receipt_limit.ToString()));
                        StepNo++;
                    }
                    else
                    {
                        ContainersEnabled = false;
                    }
                }
                Response.Data.ContainersModuleEnabled = ContainersEnabled;

                bool SDSEnabled = NbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.SDS);
                if (SDSEnabled)
                {
                    MaterialResponse.WizardStep AttachSDS = new MaterialResponse.WizardStep()
                    {
                        StepNo   = StepNo,
                        StepName = "Attach SDS"
                    };
                    Response.Data.Steps.Add(AttachSDS);

                    // Permission is a separate check now because we still want to show the Attach SDS step
                    // even if the User doesn't have permission. If they don't have permission, we display
                    // a message on the client.
                    CswNbtMetaDataNodeType SDSNT = NbtResources.MetaData.getNodeType("SDS Document");
                    Response.Data.addSDSPermission = null != SDSNT && NbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Create, SDSNT);
                }
                Response.Data.SDSModuleEnabled = SDSEnabled;

                #endregion Alert wizard to active modules

                // Get the ChemicalObjClassId
                CswNbtMetaDataObjectClass ChemicalOC = NbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.ChemicalClass);
                Response.Data.ChemicalObjClassId = CswConvert.ToString(ChemicalOC.ObjectClassId);

                // Determine Constituent NodeTypes
                CswCommaDelimitedString ConstituentNodeTypeIds = new CswCommaDelimitedString();
                foreach (CswNbtMetaDataNodeType ChemicalNT in ChemicalOC.getNodeTypes())
                {
                    CswNbtMetaDataNodeTypeProp IsConstituentNTP = ChemicalNT.getNodeTypePropByObjectClassProp(CswNbtObjClassChemical.PropertyName.IsConstituent);
                    // Yes this is a weird way to know whether a nodetype is a Constituent nodetype,
                    // but as long as this property remains servermanaged, this will work
                    if (IsConstituentNTP.HasDefaultValue() &&
                        CswEnumTristate.True == IsConstituentNTP.getDefaultValue(false).AsLogical.Checked)
                    {
                        ConstituentNodeTypeIds.Add(ChemicalNT.NodeTypeId.ToString());
                    }
                }
                Response.Data.ConstituentNodeTypeIds = ConstituentNodeTypeIds.ToString();
            }
        }
Пример #4
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);
        }
        private static void _recurseForRelatingNodes(CswNbtResources NbtResources, CswNbtExplorerReturn Return, CswNbtNode Node, int Level, string OwnerIdStr)
        {
            CswNbtMetaDataNodeType TargetNodeType = Node.getNodeType();

            foreach (CswNbtMetaDataNodeTypeProp RelNTP in TargetNodeType.getNodeTypeProps(CswEnumNbtFieldType.Relationship))    //TODO: Locations are just like relationships, we should be able to handle them
            {
                CswNbtNodePropRelationship RelProp = Node.Properties[RelNTP];
                string Icon = _getIconFromRelationshipProp(NbtResources, RelNTP);
                if (CswTools.IsPrimaryKey(RelProp.RelatedNodeId))
                {
                    CswNbtNode             TargetNode = NbtResources.Nodes[RelProp.RelatedNodeId];
                    CswNbtMetaDataNodeType TargetNT   = TargetNode.getNodeType();

                    if (FilterVal.Contains("NT_" + TargetNode.NodeTypeId) || FilterVal.Contains("OC_" + TargetNode.getObjectClassId()))
                    {
                        string targetIdStr = OwnerIdStr + "_" + RelProp.RelatedNodeId.ToString();
                        _addToGraph(Return, RelProp.PropName + ": " + RelProp.CachedNodeName, Node.NodeId.ToString(), RelProp.RelatedNodeId.ToString(), Icon, Level, "Instance", RelProp.RelatedNodeId.ToString(), TargetNT.NodeTypeName, RelNTP.PropId);

                        if (Level + 1 <= MAX_DEPTH)
                        {
                            _recurseForRelatedNTs(NbtResources, Return, TargetNode.NodeTypeId, 1, RelProp.RelatedNodeId.ToString());
                        }

                        if (Level + 1 <= MAX_DEPTH)
                        {
                            _recurseForRelatingNodes(NbtResources, Return, TargetNode, Level + 1, targetIdStr);
                        }
                    }
                }
            }
        }