예제 #1
0
        internal CswNbtNode createVendorNode(bool IsTemp = false)
        {
            CswNbtObjClassVendor VendorNode = _CswNbtResources.Nodes.makeNodeFromNodeTypeId(_getNodeTypeId("Vendor"), delegate(CswNbtNode NewNode)
            {
                CswNbtMetaDataNodeTypeProp NameNTP      = _CswNbtResources.MetaData.getNodeTypeProp(NewNode.NodeTypeId, CswNbtObjClassVendor.PropertyName.VendorName);
                NewNode.Properties[NameNTP].AsText.Text = "TempVendor";
            }, IsTemp);

            _finalize();

            return(VendorNode.Node);
        }
예제 #2
0
        public JObject initNewTempMaterialNode(Int32 NodeTypeId, string SupplierId, string Suppliername, string Tradename, string PartNo, string NodeId, bool IsConstituent, bool CorporateSupplier)
        {
            JObject Ret = new JObject();

            //Check if the vendor needs to be created
            if (false == CswTools.IsPrimaryKey(CswConvert.ToPrimaryKey(SupplierId)) && false == IsConstituent)
            {
                CswNbtMetaDataObjectClass VendorOC = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.VendorClass);
                if (null != VendorOC)
                {
                    CswNbtMetaDataNodeType VendorNT = VendorOC.FirstNodeType;
                    if (null != VendorNT)
                    {
                        CswNbtObjClassVendor NewVendorNode = _CswNbtResources.Nodes.makeNodeFromNodeTypeId(VendorNT.NodeTypeId, IsTemp : true, OnAfterMakeNode : delegate(CswNbtNode NewNode)
                        {
                            CswNbtObjClassVendor NodeAsVendor = (CswNbtObjClassVendor)NewNode;
                            NodeAsVendor.VendorName.Text      = Suppliername;
                            NodeAsVendor.VendorName.SyncGestalt();
                            if (CorporateSupplier)
                            {
                                NodeAsVendor.VendorType.Value = CswNbtObjClassVendor.VendorTypes.Corporate;
                            }
                        });
                        //Set the supplierId to the new vendor node
                        SupplierId = NewVendorNode.NodeId.ToString();
                    }
                }
            }

            CswPrimaryKey CurrentTempNodePk = CswConvert.ToPrimaryKey(NodeId);

            if (CswTools.IsPrimaryKey(CurrentTempNodePk))
            {
                CswNbtPropertySetMaterial CurrentTempNode = _CswNbtResources.Nodes.GetNode(CurrentTempNodePk);
                if (null != CurrentTempNode)
                {
                    Int32 CurrentNodeTypeId = CurrentTempNode.NodeTypeId;
                    if (NodeTypeId != CurrentNodeTypeId)
                    {
                        // Then we want to just forget about the first temp node created and create a new one with the new nodetype
                        Ret = _tryCreateTempMaterial(NodeTypeId, CswConvert.ToPrimaryKey(SupplierId), Tradename, PartNo, null, IsConstituent);
                    }
                    else
                    {
                        // If the nodetype isn't different then we want to get the props and check if it exsits
                        Ret = _tryCreateTempMaterial(NodeTypeId, CswConvert.ToPrimaryKey(SupplierId), Tradename, PartNo, CurrentTempNodePk.ToString(), IsConstituent);
                    }
                }
            }
            return(Ret);
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="VendorName"></param>
        /// <returns></returns>
        public C3CreateMaterialResponse.State.Supplier constructVendorObject(string VendorName)
        {
            C3CreateMaterialResponse.State.Supplier Supplier = new C3CreateMaterialResponse.State.Supplier();

            CswNbtView VendorView = new CswNbtView(_CswNbtResources);

            VendorView.ViewName = "VendorWithNameEquals";

            CswNbtMetaDataObjectClass VendorOC           = _CswNbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.VendorClass);
            CswNbtViewRelationship    ParentRelationship = VendorView.AddViewRelationship(VendorOC, true);

            CswNbtMetaDataObjectClassProp VendorNameOCP = VendorOC.getObjectClassProp(CswNbtObjClassVendor.PropertyName.VendorName);

            VendorView.AddViewPropertyAndFilter(ParentRelationship, VendorNameOCP, VendorName, CswEnumNbtSubFieldName.Text);

            // If MLM is enabled, we only want to match on corporate vendors
            if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.MLM))
            {
                CswNbtMetaDataObjectClassProp VendorTypeOCP = VendorOC.getObjectClassProp(CswNbtObjClassVendor.PropertyName.VendorTypeName);
                VendorView.AddViewPropertyAndFilter(ParentRelationship, VendorTypeOCP, CswNbtObjClassVendor.VendorTypes.Corporate, CswEnumNbtSubFieldName.Text);
            }

            ICswNbtTree VendorsTree = _CswNbtResources.Trees.getTreeFromView(VendorView, false, true, true);
            bool        NewVendor   = true;

            if (VendorsTree.getChildNodeCount() > 0)
            {
                NewVendor = false;

                VendorsTree.goToNthChild(0);
                CswNbtObjClassVendor VendorNode = VendorsTree.getNodeForCurrentPosition();
                Supplier.name     = CswConvert.ToString(VendorNode.VendorName.Text);
                Supplier.val      = CswConvert.ToString(VendorNode.NodeId);
                Supplier.nodelink = CswConvert.ToString(VendorNode.Node.NodeLink);
            }

            if (NewVendor)
            {
                // Don't create a new node just return an empty value in the return object - Case 28687
                Supplier.name     = VendorName;
                Supplier.val      = string.Empty;
                Supplier.nodelink = string.Empty;
            }

            Supplier.corporate = _CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.MLM);

            return(Supplier);
        }//createVendorNode()
        /// <summary>
        /// Update logic
        /// </summary>
        public override void update()
        {

            CswNbtMetaDataNodeType vendorNT = _CswNbtSchemaModTrnsctn.MetaData.getNodeType( "Vendor" );
            bool makeSigma = true;
            bool makeAlfa = true;
            bool makeVWR = true;

            foreach( CswNbtObjClassVendor vendorNode in vendorNT.getNodes( false, false ) )
            {
                if( vendorNode.VendorName.Text.Equals( "Sigma-Aldrich" ) ) makeSigma = false;
                if( vendorNode.VendorName.Text.Equals( "VWR Scientific" ) ) makeVWR = false;
                if( vendorNode.VendorName.Text.Equals( "Alfa-Aesar" ) ) makeAlfa = false;
            }

            if( null != vendorNT )
            {
                if( makeSigma )
                {
                    CswNbtObjClassVendor sigmaNode = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( vendorNT.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode );
                    sigmaNode.VendorName.Text = "Sigma-Aldrich";
                    sigmaNode.postChanges( false );
                }

                if( makeVWR )
                {
                    CswNbtObjClassVendor vwrNode = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( vendorNT.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode );
                    vwrNode.VendorName.Text = "VWR Scientific";
                    vwrNode.postChanges( false );
                }

                if( makeAlfa )
                {
                    CswNbtObjClassVendor alfaNode = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( vendorNT.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode );
                    alfaNode.VendorName.Text = "Alfa-Aesar";
                    alfaNode.postChanges( false );
                }
            }

        }
예제 #5
0
        public override void update()
        {
            CswNbtMetaDataObjectClass InventoryGroupOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswNbtMetaDataObjectClass.NbtObjectClass.InventoryGroupClass );

            CswNbtObjClassInventoryGroup DefaultNodeAsInventoryGroup = null;
            foreach( CswNbtNode Group in InventoryGroupOc.getNodes( true, false ) )
            {
                CswNbtObjClassInventoryGroup NodeAsInventoryGroup = Group;
                if( null != NodeAsInventoryGroup )
                {
                    if( NodeAsInventoryGroup.Name.Text.ToLower() == "cispro" )
                    {
                        DefaultNodeAsInventoryGroup = NodeAsInventoryGroup;
                        DefaultNodeAsInventoryGroup.Name.Text = "Default Inventory Group";
                        DefaultNodeAsInventoryGroup.IsDemo = true;
                        DefaultNodeAsInventoryGroup.postChanges( ForceUpdate: false );
                    }
                }
            }
            if( null == DefaultNodeAsInventoryGroup )
            {
                CswNbtMetaDataNodeType InventoryGroupNt = InventoryGroupOc.getLatestVersionNodeTypes().FirstOrDefault();
                if( null != InventoryGroupNt )
                {
                    DefaultNodeAsInventoryGroup = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( InventoryGroupNt.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode, OverrideUniqueValidation: false );
                    DefaultNodeAsInventoryGroup.Name.Text = "Default Inventory Group";
                    DefaultNodeAsInventoryGroup.postChanges( ForceUpdate: false );
                }
            }
            CswNbtMetaDataObjectClass LocationOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswNbtMetaDataObjectClass.NbtObjectClass.LocationClass );
            CswNbtObjClassLocation DefaultLocation = null;
            if( null != DefaultNodeAsInventoryGroup )
            {
                foreach( CswNbtObjClassLocation Location in LocationOc.getNodes( true, false ) )
                {
                    if( null != Location )
                    {
                        if( Location.Name.Text.ToLower() == "center hall" )
                        {
                            DefaultLocation = Location;
                        }
                        if( null == Location.InventoryGroup.RelatedNodeId || Int32.MinValue == Location.InventoryGroup.RelatedNodeId.PrimaryKey )
                        {
                            Location.InventoryGroup.RelatedNodeId = DefaultNodeAsInventoryGroup.NodeId;
                            Location.postChanges( ForceUpdate: false );
                        }
                    }
                }
            }

            CswNbtMetaDataObjectClass WorkUnitOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswNbtMetaDataObjectClass.NbtObjectClass.WorkUnitClass );
            CswNbtMetaDataNodeType WorkUnitNt = WorkUnitOc.getLatestVersionNodeTypes().FirstOrDefault();
            if( null != WorkUnitNt )
            {
                WorkUnitNt.NameTemplateValue = "";
                WorkUnitNt.addNameTemplateText( CswNbtObjClassWorkUnit.NamePropertyName );
                CswNbtObjClassWorkUnit DefaultWorkUnit = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( WorkUnitNt.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode, OverrideUniqueValidation: false );
                DefaultWorkUnit.Name.Text = "Default Work Unit";
                DefaultWorkUnit.IsDemo = true;
                DefaultWorkUnit.postChanges( ForceUpdate: false );

                CswNbtMetaDataObjectClass UserOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswNbtMetaDataObjectClass.NbtObjectClass.UserClass );
                Collection<Int32> RoleIdsWithUsers = new Collection<Int32>();
                CswNbtMetaDataNodeType UserNt = null;
                foreach( CswNbtObjClassUser User in UserOc.getNodes( true, false ) )
                {
                    if( null != User )
                    {
                        UserNt = UserNt ?? User.NodeType;
                        RoleIdsWithUsers.Add( User.RoleId.PrimaryKey );
                        if( null == User.WorkUnitProperty.RelatedNodeId || Int32.MinValue == User.WorkUnitProperty.RelatedNodeId.PrimaryKey )
                        {
                            User.WorkUnitProperty.RelatedNodeId = DefaultWorkUnit.NodeId;
                        }
                        if( null != DefaultLocation && ( null == User.DefaultLocationProperty.SelectedNodeId || Int32.MinValue == User.DefaultLocationProperty.SelectedNodeId.PrimaryKey ) )
                        {
                            User.DefaultLocationProperty.SelectedNodeId = DefaultLocation.NodeId;
                        }
                        User.postChanges( ForceUpdate: false );
                    }
                }

                CswNbtMetaDataObjectClass RoleOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswNbtMetaDataObjectClass.NbtObjectClass.RoleClass );
                if( null == UserNt )
                {
                    UserNt = UserOc.getLatestVersionNodeTypes().FirstOrDefault();
                }
                if( null != UserNt )
                {
                    foreach( CswNbtObjClassRole Role in RoleOc.getNodes( true, false ) )
                    {
                        if( null != Role && false == RoleIdsWithUsers.Contains( Role.NodeId.PrimaryKey ) )
                        {
                            string ValidUserName = CswNbtObjClassUser.getValidUserName( Role.Name.Text.ToLower() );
                            if( ValidUserName != CswNbtObjClassUser.ChemSWAdminUsername )
                            {
                                if( CswNbtObjClassUser.IsUserNameUnique( _CswNbtSchemaModTrnsctn.MetaData._CswNbtMetaDataResources.CswNbtResources, ValidUserName ) )
                                {
                                    CswNbtObjClassUser NewUser = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( UserNt.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode, OverrideUniqueValidation: false );
                                    NewUser.IsDemo = false;
                                    NewUser.Role.RelatedNodeId = Role.NodeId;
                                    NewUser.UsernameProperty.Text = ValidUserName;
                                    NewUser.WorkUnitProperty.RelatedNodeId = DefaultWorkUnit.NodeId;
                                    if( null != DefaultLocation )
                                    {
                                        NewUser.DefaultLocationProperty.SelectedNodeId = DefaultLocation.NodeId;
                                    }
                                    NewUser.PasswordProperty.Password = Role.Name.Text.ToLower();
                                    NewUser.postChanges( ForceUpdate: false );
                                }
                            }
                        }
                    }
                }
                CswNbtMetaDataObjectClass IgPermissionOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswNbtMetaDataObjectClass.NbtObjectClass.InventoryGroupPermissionClass );
                foreach( CswNbtObjClassInventoryGroupPermission Permission in IgPermissionOc.getNodes( true, false ) )
                {
                    if( null != Permission )
                    {
                        if( null != DefaultNodeAsInventoryGroup && ( null == Permission.InventoryGroup.RelatedNodeId || Int32.MinValue == Permission.InventoryGroup.RelatedNodeId.PrimaryKey ) )
                        {
                            Permission.InventoryGroup.RelatedNodeId = DefaultNodeAsInventoryGroup.NodeId;
                        }
                        if( null == Permission.WorkUnit.RelatedNodeId || Int32.MinValue == Permission.WorkUnit.RelatedNodeId.PrimaryKey )
                        {
                            Permission.WorkUnit.RelatedNodeId = DefaultWorkUnit.NodeId;
                        }
                        Permission.postChanges( ForceUpdate: false );
                    }
                }
            }

            CswNbtMetaDataObjectClass MaterialOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswNbtMetaDataObjectClass.NbtObjectClass.MaterialClass );
            CswNbtMetaDataObjectClass SynonymOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswNbtMetaDataObjectClass.NbtObjectClass.MaterialSynonymClass );
            CswNbtMetaDataObjectClass SizeOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswNbtMetaDataObjectClass.NbtObjectClass.SizeClass );
            CswNbtMetaDataObjectClass VendorOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswNbtMetaDataObjectClass.NbtObjectClass.VendorClass );
            CswNbtMetaDataObjectClass UnitOc = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswNbtMetaDataObjectClass.NbtObjectClass.UnitOfMeasureClass );

            CswNbtObjClassVendor DefaultVendor = null;
            CswNbtMetaDataNodeType VendorNt = VendorOc.getLatestVersionNodeTypes().FirstOrDefault();
            if( null != VendorNt )
            {
                DefaultVendor = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( VendorNt.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode, OverrideUniqueValidation: false );
                DefaultVendor.VendorName.Text = "Default Vendor";
                DefaultVendor.IsDemo = true;
                DefaultVendor.postChanges( ForceUpdate: false );
            }
            CswNbtMetaDataNodeType SizeNt = SizeOc.getLatestVersionNodeTypes().FirstOrDefault();
            CswNbtMetaDataNodeType SynonymNt = SynonymOc.getLatestVersionNodeTypes().FirstOrDefault();
            CswNbtObjClassUnitOfMeasure DefaultSizeUnit = null;
            CswNbtObjClassUnitOfMeasure DefaultTimeUnit = null;
            foreach( CswNbtObjClassUnitOfMeasure Unit in UnitOc.getNodes( true, false ) )
            {
                if( null != Unit )
                {
                    if( Unit.Name.Text.ToLower() == "g" )
                    {
                        DefaultSizeUnit = Unit;
                    }
                    else if( Unit.Name.Text.ToLower() == "years" )
                    {
                        DefaultTimeUnit = Unit;
                    }
                }
            }

            foreach( CswNbtMetaDataNodeType MaterialNt in MaterialOc.getLatestVersionNodeTypes() )
            {
                CswNbtObjClassMaterial Material = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( MaterialNt.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode, OverrideUniqueValidation: false );
                Material.IsDemo = true;
                Material.TradeName.Text = "Default " + MaterialNt.NodeTypeName;
                if( null != DefaultVendor )
                {
                    Material.Supplier.RelatedNodeId = DefaultVendor.NodeId;
                }
                Material.PartNumber.Text = "658-35AB";
                Material.PhysicalState.Value = CswNbtObjClassMaterial.PhysicalStates.Solid;
                Material.ExpirationInterval.Quantity = 1;
                if( null != DefaultTimeUnit )
                {
                    Material.ExpirationInterval.UnitId = DefaultTimeUnit.NodeId;
                }
                Material.postChanges( ForceUpdate: false );

                if( null != SizeNt )
                {
                    CswNbtObjClassSize Size = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( SizeNt.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode, OverrideUniqueValidation: false );
                    Size.IsDemo = true;
                    Size.Material.RelatedNodeId = Material.NodeId;
                    Size.CatalogNo.Text = "NE-H5/3";
                    Size.InitialQuantity.Quantity = 1;
                    if( null != DefaultSizeUnit )
                    {
                        Size.InitialQuantity.UnitId = DefaultSizeUnit.NodeId;
                    }
                    Size.postChanges( ForceUpdate: false );
                }

                if( null != SynonymNt )
                {
                    CswNbtObjClassMaterialSynonym Synonym = _CswNbtSchemaModTrnsctn.Nodes.makeNodeFromNodeTypeId( SynonymNt.NodeTypeId, CswNbtNodeCollection.MakeNodeOperation.WriteNode, OverrideUniqueValidation: false );
                    Synonym.IsDemo = true;
                    Synonym.Material.RelatedNodeId = Material.NodeId;
                    Synonym.Name.Text = Material.TradeName.Text + " Synonym";
                    Synonym.postChanges( ForceUpdate: false );
                }
            }


        }//Update()
예제 #6
0
        private CswNbtNode _commitMaterialNode(JObject MaterialObj)
        {
            CswNbtNode Ret = null;

            Int32 MaterialNodeTypeId = CswConvert.ToInt32(MaterialObj["materialnodetypeid"]);

            if (Int32.MinValue != MaterialNodeTypeId)
            {
                CswNbtMetaDataNodeType MaterialNt = _CswNbtResources.MetaData.getNodeType(MaterialNodeTypeId);
                if (null != MaterialNt)
                {
                    Ret = _CswNbtResources.Nodes[CswConvert.ToString(MaterialObj["materialId"])];
                    if (null != Ret)
                    {
                        // Set the Vendor node property isTemp = false if necessary
                        bool          IsConstituent = CswConvert.ToBoolean(MaterialObj["isConstituent"]);
                        CswPrimaryKey VendorNodePk  = CswConvert.ToPrimaryKey(CswConvert.ToString(MaterialObj["supplierid"]));
                        if (CswTools.IsPrimaryKey(VendorNodePk) && false == IsConstituent)
                        {
                            CswNbtObjClassVendor VendorNode = _CswNbtResources.Nodes.GetNode(VendorNodePk);
                            if (null != VendorNode && VendorNode.IsTemp)
                            {
                                VendorNode.PromoteTempToReal();
                            }
                        }

                        //Ret.IsTemp = false;
                        JObject MaterialProperties          = (JObject)MaterialObj["properties"];
                        CswNbtSdTabsAndProps SdTabsAndProps = new CswNbtSdTabsAndProps(_CswNbtResources);
                        SdTabsAndProps.saveProps(Ret.NodeId, Int32.MinValue, MaterialProperties, Ret.NodeTypeId, null, IsIdentityTab: false, setIsTempToFalse: false);

                        NewMaterial FinalMaterial = new NewMaterial(_CswNbtResources, Ret);
                        FinalMaterial.TradeName = CswConvert.ToString(MaterialObj["tradename"]);
                        if (false == IsConstituent)
                        {
                            FinalMaterial.SupplierId = CswConvert.ToPrimaryKey(CswConvert.ToString(MaterialObj["supplierid"]));
                            FinalMaterial.PartNo     = CswConvert.ToString(MaterialObj["partno"]);
                        }

                        CswNbtPropertySetMaterial NodeAsMaterial = FinalMaterial.commit();
                        NodeAsMaterial.Save.setHidden(value: false, SaveToDb: true);

                        JObject RequestObj = CswConvert.ToJObject(MaterialObj["request"]);
                        if (RequestObj.HasValues)
                        {
                            _processRequest(CswConvert.ToString(RequestObj["requestitemid"]), NodeAsMaterial);
                        }
                        CswNbtActReceiving Receiving = new CswNbtActReceiving(_CswNbtResources);

                        CswPrimaryKey SDSNodeId = new CswPrimaryKey();
                        if (null != MaterialObj["sdsDocId"])
                        {
                            SDSNodeId.FromString(MaterialObj["sdsDocId"].ToString());
                            JObject SDSProps = CswConvert.ToJObject(MaterialObj["sdsDocProperties"]);
                            Receiving.commitSDSDocNode(NodeAsMaterial.NodeId, SDSNodeId, SDSProps);
                        }
                        Ret.PromoteTempToReal();
                    }
                }

                if (null == Ret)
                {
                    throw new CswDniException(CswEnumErrorType.Error,
                                              "Failed to create new material.",
                                              "Attempted to call _commitMaterialNode failed.");
                }
            }
            return(Ret);
        }