Exemple #1
0
        private void _populateUnitViewRelationships(CswNbtView UnitView, string PhysicalState, bool ExcludeEach)
        {
            CswNbtMetaDataObjectClass UnitOfMeasureOC = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.UnitOfMeasureClass);
            CswNbtMetaDataNodeType    EachNT          = null;

            foreach (CswNbtMetaDataNodeType UnitOfMeasureNodeType in UnitOfMeasureOC.getNodeTypes())
            {
                CswNbtMetaDataNodeTypeProp UnitTypeProp = UnitOfMeasureNodeType.getNodeTypePropByObjectClassProp(CswNbtObjClassUnitOfMeasure.PropertyName.UnitType);
                if (UnitTypeProp.HasDefaultValue())
                {
                    CswEnumNbtUnitTypes UnitType = (CswEnumNbtUnitTypes)UnitTypeProp.getDefaultValue(false).AsList.Value;
                    if (_physicalStateMatchesUnitType(PhysicalState, UnitType, ExcludeEach))
                    {
                        if (UnitType == CswEnumNbtUnitTypes.Each)
                        {
                            EachNT = UnitOfMeasureNodeType;
                        }
                        else
                        {
                            UnitView.AddViewRelationship(UnitOfMeasureNodeType, true);
                        }
                    }
                }
            }
            if (null != EachNT) //Case 29933 - Each units always go at the end of the list
            {
                UnitView.AddViewRelationship(EachNT, true);
            }
        }
Exemple #2
0
        public static JObject getImportBtnItems(CswNbtResources CswNbtResources)
        {
            JObject ImportableNodeTypes = new JObject();

            Collection <CswEnumNbtObjectClass> MaterialPropSetMembers = CswNbtPropertySetMaterial.Members();

            foreach (CswEnumNbtObjectClass ObjectClassName in MaterialPropSetMembers)
            {
                CswNbtMetaDataObjectClass ObjectClass = CswNbtResources.MetaData.getObjectClass(ObjectClassName);
                foreach (CswNbtMetaDataNodeType CurrentNT in ObjectClass.getNodeTypes())
                {
                    CswNbtMetaDataNodeTypeProp IsConstituentNTP = CurrentNT.getNodeTypePropByObjectClassProp(CswNbtPropertySetMaterial.PropertyName.IsConstituent);
                    if (IsConstituentNTP.HasDefaultValue() &&
                        CswEnumTristate.False == IsConstituentNTP.getDefaultValue(false).AsLogical.Checked)
                    {
                        JObject NodeType = new JObject();
                        ImportableNodeTypes[CurrentNT.NodeTypeName] = NodeType;
                        NodeType["nodetypename"] = CurrentNT.NodeTypeName;
                        NodeType["nodetypeid"]   = CurrentNT.NodeTypeId.ToString();
                        NodeType["iconfilename"] = CswNbtMetaDataObjectClass.IconPrefix16 + CurrentNT.IconFileName;
                        NodeType["objclass"]     = ObjectClassName.ToString();
                    }
                }
            }

            return(ImportableNodeTypes);
        }//getImportBtnItems()
        } // getDefaultValue()

        public bool HasDefaultValue()
        {
            bool ret = false;

            if (null != _NodeTypeProp)
            {
                ret = _NodeTypeProp.HasDefaultValue();
            }
            return(ret);
        } // HasDefaultValue()
Exemple #4
0
 /// <summary>
 /// Whether a default value of the property is defined
 /// </summary>
 public bool HasDefaultValue()
 {
     return(_CswNbtMetaDataNodeTypeProp.HasDefaultValue());
 }
Exemple #5
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();
            }
        }
        public override void update()
        {
            CswNbtMetaDataObjectClass InventoryGroupOc           = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass(CswEnumNbtObjectClass.InventoryGroupClass);
            CswNbtMetaDataObjectClass InventoryGroupPermissionOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass(CswEnumNbtObjectClass.InventoryGroupPermissionClass);
            CswNbtMetaDataNodeType    InvGrpNT     = InventoryGroupOc.FirstNodeType;
            CswNbtMetaDataNodeType    InvGrpPermNT = InventoryGroupPermissionOc.FirstNodeType;

            //1: Get Default Inventory Group
            CswNbtObjClassInventoryGroup DefaultInventoryGroup = null;
            CswNbtObjClassInventoryGroup CISProInventoryGroup  = null;

            foreach (CswNbtObjClassInventoryGroup InventoryGroup in InventoryGroupOc.getNodes(true, false, false, true))
            {
                if (InventoryGroup.Name.Text == "Default Inventory Group")
                {
                    DefaultInventoryGroup = InventoryGroup;
                }
                else if (InventoryGroup.Name.Text == "CISPro")
                {
                    CISProInventoryGroup = InventoryGroup;
                }
            }
            if (null == DefaultInventoryGroup)
            {
                DefaultInventoryGroup = InventoryGroupOc.getNodes(true, false, false, true).FirstOrDefault();
            }
            if (null == DefaultInventoryGroup)
            {
                if (null != InvGrpNT)
                {
                    DefaultInventoryGroup = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId(InvGrpNT.NodeTypeId, delegate(CswNbtNode NewNode)
                    {
                        CswNbtObjClassInventoryGroup DefInvGrp = NewNode;
                        DefInvGrp.Name.Text = "Default Inventory Group";
                    });
                }
            }

            if (null != DefaultInventoryGroup) //At this point DefaultInventoryGroup should never be null
            {
                //2: Set Default Value to Default Inventory Group, if no DefaultValue is present
                CswNbtMetaDataObjectClass LocationOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass(CswEnumNbtObjectClass.LocationClass);
                foreach (CswNbtMetaDataNodeType LocationNt in LocationOc.getNodeTypes())
                {
                    CswNbtMetaDataNodeTypeProp InventoryGroupNtp = LocationNt.getNodeTypePropByObjectClassProp(CswNbtObjClassLocation.PropertyName.InventoryGroup);
                    if (false == InventoryGroupNtp.HasDefaultValue())
                    {
                        InventoryGroupNtp.DefaultValue.AsRelationship.RelatedNodeId = DefaultInventoryGroup.NodeId;
                    }
                }

                //3: Update any null Inventory Group values with Default
                foreach (CswNbtObjClassLocation Location in LocationOc.getNodes(true, false, false, true))
                {
                    if (false == CswTools.IsPrimaryKey(Location.InventoryGroup.RelatedNodeId))
                    {
                        Location.InventoryGroup.RelatedNodeId = DefaultInventoryGroup.NodeId;
                        Location.postChanges(ForceUpdate: false);
                    }
                }

                //4: Ensure at least one Inventory Group Permission exists
                CswNbtMetaDataNodeType IgPermNt = InventoryGroupPermissionOc.getLatestVersionNodeTypes().FirstOrDefault();
                if (null != IgPermNt)
                {
                    try
                    {
                        CswNbtObjClassInventoryGroupPermission DefaultPermission = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId(IgPermNt.NodeTypeId, delegate(CswNbtNode NewNode)
                        {
                            CswNbtObjClassInventoryGroupPermission WildCardPerm = NewNode;
                            WildCardPerm.PermissionGroup.RelatedNodeId          = DefaultInventoryGroup.NodeId;
                            WildCardPerm.ApplyToAllRoles.Checked     = CswEnumTristate.True;
                            WildCardPerm.ApplyToAllWorkUnits.Checked = CswEnumTristate.True;
                            WildCardPerm.Dispense.Checked            = CswEnumTristate.True;
                            WildCardPerm.Dispose.Checked             = CswEnumTristate.True;
                            WildCardPerm.Edit.Checked      = CswEnumTristate.True;
                            WildCardPerm.Request.Checked   = CswEnumTristate.True;
                            WildCardPerm.Undispose.Checked = CswEnumTristate.True;
                        });
                    }
                    catch (CswDniException ex) //If we're here, it's because this wildcard already exists
                    {
                        if (ex.ErrorType != CswEnumErrorType.Warning)
                        {
                            throw;
                        }
                    }
                }

                //5: Get rid of deprecated CISPro Inventory Group and move their permissions over to Default Inventory Group
                if (null != CISProInventoryGroup)
                {
                    CswNbtMetaDataObjectClass WorkUnitOc      = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass(CswEnumNbtObjectClass.WorkUnitClass);
                    CswNbtObjClassWorkUnit    DefaultWorkUnit = null;
                    foreach (CswNbtObjClassWorkUnit WorkUnit in WorkUnitOc.getNodes(true, false, false, true))
                    {
                        if (WorkUnit.Name.Text == "Default Work Unit")
                        {
                            DefaultWorkUnit = WorkUnit;
                        }
                    }
                    if (null != DefaultWorkUnit)
                    {
                        foreach (CswNbtObjClassInventoryGroupPermission InventoryGroupPerm in InventoryGroupPermissionOc.getNodes(true, false, false, true))
                        {
                            if (InventoryGroupPerm.PermissionGroup.RelatedNodeId == CISProInventoryGroup.NodeId)
                            {
                                try
                                {
                                    InventoryGroupPerm.PermissionGroup.RelatedNodeId = DefaultInventoryGroup.NodeId;
                                    InventoryGroupPerm.PermissionGroup.SyncGestalt();
                                    InventoryGroupPerm.WorkUnit.RelatedNodeId = DefaultWorkUnit.NodeId;
                                    InventoryGroupPerm.WorkUnit.SyncGestalt();
                                    InventoryGroupPerm.postChanges(false);
                                }
                                catch (CswDniException) //If we're here, it's because the Permission already exists on Default Inventory Group
                                {
                                    InventoryGroupPerm.Node.delete(true, true);
                                }
                            }
                        }
                    }
                    CISProInventoryGroup.Node.delete(true, true);
                }
            }
            //6: Fix Inventory Group Permissions grid prop
            if (null != InvGrpNT && null != InvGrpPermNT)
            {
                CswNbtMetaDataNodeTypeProp PermissionsNTP = InvGrpNT.getNodeTypePropByObjectClassProp(CswNbtObjClassInventoryGroup.PropertyName.Permissions);

                CswNbtView InvGrpPermView = _CswNbtSchemaModTrnsctn.restoreView(PermissionsNTP.ViewId);
                if (null == InvGrpPermView)
                {
                    InvGrpPermView          = _CswNbtSchemaModTrnsctn.makeSafeView("Permissions", CswEnumNbtViewVisibility.Property);
                    InvGrpPermView.ViewMode = CswEnumNbtViewRenderingMode.Grid;
                }
                InvGrpPermView.Root.ChildRelationships.Clear();

                CswNbtMetaDataNodeTypeProp PermissionGroupNTP = InvGrpPermNT.getNodeTypePropByObjectClassProp(CswNbtObjClassInventoryGroupPermission.PropertyName.PermissionGroup);
                CswNbtMetaDataNodeTypeProp RoleNTP            = InvGrpPermNT.getNodeTypePropByObjectClassProp(CswNbtObjClassInventoryGroupPermission.PropertyName.Role);
                CswNbtMetaDataNodeTypeProp WorkUnitNTP        = InvGrpPermNT.getNodeTypePropByObjectClassProp(CswNbtObjClassInventoryGroupPermission.PropertyName.WorkUnit);
                CswNbtMetaDataNodeTypeProp ViewNTP            = InvGrpPermNT.getNodeTypePropByObjectClassProp(CswNbtObjClassInventoryGroupPermission.PropertyName.View);
                CswNbtMetaDataNodeTypeProp EditNTP            = InvGrpPermNT.getNodeTypePropByObjectClassProp(CswNbtObjClassInventoryGroupPermission.PropertyName.Edit);
                CswNbtMetaDataNodeTypeProp DispenseNTP        = InvGrpPermNT.getNodeTypePropByObjectClassProp(CswNbtObjClassInventoryGroupPermission.PropertyName.Dispense);
                CswNbtMetaDataNodeTypeProp RequestNTP         = InvGrpPermNT.getNodeTypePropByObjectClassProp(CswNbtObjClassInventoryGroupPermission.PropertyName.Request);

                CswNbtViewRelationship RootRel = InvGrpPermView.AddViewRelationship(InvGrpNT, false);
                CswNbtViewRelationship PermRel = InvGrpPermView.AddViewRelationship(RootRel, CswEnumNbtViewPropOwnerType.Second, PermissionGroupNTP, true);
                InvGrpPermView.AddViewProperty(PermRel, PermissionGroupNTP, 1);
                InvGrpPermView.AddViewProperty(PermRel, RoleNTP, 2);
                InvGrpPermView.AddViewProperty(PermRel, WorkUnitNTP, 3);
                InvGrpPermView.AddViewProperty(PermRel, ViewNTP, 4);
                InvGrpPermView.AddViewProperty(PermRel, EditNTP, 5);
                InvGrpPermView.AddViewProperty(PermRel, DispenseNTP, 6);
                InvGrpPermView.AddViewProperty(PermRel, RequestNTP, 7);
                InvGrpPermView.save();

                PermissionsNTP.ViewId = InvGrpPermView.ViewId;
            }
        }