コード例 #1
0
ファイル: CswNbtSdC3.cs プロジェクト: crfroehlich/legacy
        public static C3CreateMaterialResponse importC3Product(ICswResources CswResources, CswNbtC3Import.Request Request)
        {
            C3CreateMaterialResponse ret = new C3CreateMaterialResponse();

            CswNbtResources _CswNbtResources = (CswNbtResources)CswResources;

            CswC3SearchParams CswC3SearchParams = new CswC3SearchParams();
            CswC3Product      C3ProductDetails  = new CswC3Product();

            if (Int32.MinValue != Request.Cdbregno && Int32.MinValue != Request.C3ProductId)
            {
                CswC3SearchParams.ACDSearchParams           = new ACDSearchParams();
                CswC3SearchParams.ACDSearchParams.ProductId = Request.C3ProductId;
                CswC3SearchParams.ACDSearchParams.Cdbregno  = Request.Cdbregno;
            }
            else if (Int32.MinValue != Request.C3ProductId)
            {
                CswC3SearchParams.C3SearchParams           = new C3SearchParams();
                CswC3SearchParams.C3SearchParams.ProductId = Request.C3ProductId;
            }
            else
            {
                throw new CswDniException(CswEnumErrorType.Error, "Cannot run import, missing parameters.", "Cannot import C3 or ACD data without a Product Id or CdbRegNo.");
            }

            CswNbtC3ClientManager CswNbtC3ClientManager = new CswNbtC3ClientManager(_CswNbtResources, CswC3SearchParams);
            SearchClient          C3SearchClient        = CswNbtC3ClientManager.initializeC3Client();

            if (null != C3SearchClient)
            {
                // Perform C3 search to get the product details
                CswRetObjSearchResults SearchResults = C3SearchClient.getProductDetails(CswC3SearchParams);
                if (SearchResults.CswC3SearchResults.Length > 0)
                {
                    C3ProductDetails = SearchResults.CswC3SearchResults[0];

                    string NodeTypeName = Request.NodeTypeName;
                    if (false == string.IsNullOrEmpty(NodeTypeName))
                    {
                        CswNbtMetaDataNodeType NodeTypeToBeImported = _CswNbtResources.MetaData.getNodeType(NodeTypeName);
                        if (null != NodeTypeToBeImported)
                        {
                            // Instance the ImportManger
                            ImportManager C3Import = new ImportManager(_CswNbtResources, C3ProductDetails);

                            // Create the temporary material node
                            CswNbtPropertySetMaterial C3ProductTempNode = _CswNbtResources.Nodes.makeNodeFromNodeTypeId(NodeTypeToBeImported.NodeTypeId, IsTemp : true, OnAfterMakeNode : delegate(CswNbtNode NewNode)
                            {
                                //Set the c3productid property
                                ((CswNbtPropertySetMaterial)NewNode).C3ProductId.Text = C3ProductDetails.ProductId.ToString();
                                // Add props to the tempnode
                                C3Import.addNodeTypeProps(NewNode);

                                // Sync Hazard Classes and PCID data if C3ProductTempNode is of type Chemical
                                if (NewNode.getObjectClass().ObjectClass == CswEnumNbtObjectClass.ChemicalClass)
                                {
                                    CswNbtObjClassChemical ChemicalNode = NewNode;
                                    ChemicalNode.syncFireDbData();
                                    ChemicalNode.syncPCIDData();
                                }
                                //C3ProductTempNode.postChanges( false );
                            });

                            // Get or create a vendor node
                            C3CreateMaterialResponse.State.Supplier Supplier = C3Import.constructVendorObject(C3ProductDetails.SupplierName);

                            // Create size node(s)
                            Collection <C3CreateMaterialResponse.State.SizeRecord> ProductSizes = C3Import.constructSizeObjects();

                            // Create synonyms node(s)
                            C3Import.createMaterialSynonyms(C3ProductTempNode);

                            // Create a document node if C3ProductTempNode is of type Chemical
                            CswPrimaryKey SDSDocumentNodeId = new CswPrimaryKey();
                            if (C3ProductTempNode.ObjectClass.ObjectClass == CswEnumNbtObjectClass.ChemicalClass)
                            {
                                SDSDocumentNodeId = C3Import.createMaterialDocument(C3ProductTempNode);
                            }

                            #region Return Object

                            ret.success    = true;
                            ret.actionname = "create material";

                            C3CreateMaterialResponse.State.MaterialType MaterialType = new C3CreateMaterialResponse.State.MaterialType();
                            MaterialType.name = Request.NodeTypeName;
                            MaterialType.val  = Request.NodeTypeId;

                            C3CreateMaterialResponse.State State = new C3CreateMaterialResponse.State();
                            State.materialId = C3ProductTempNode.NodeId.ToString();
                            State.tradeName  = C3ProductTempNode.TradeName.Text;
                            State.partNo     = C3ProductTempNode.PartNumber.Text;
                            ret.state        = State;

                            //State.useExistingTempNode = true;
                            State.supplier = Supplier;
                            if (string.IsNullOrEmpty(State.supplier.val))
                            {
                                State.addNewC3Supplier = true;
                            }
                            State.materialType = MaterialType;
                            State.sizes        = ProductSizes;
                            if (null != SDSDocumentNodeId)
                            {
                                State.sds.sdsDocId = SDSDocumentNodeId.ToString();
                            }

                            #endregion Return Object
                        } //if (null != NodeTypeToBeImported)
                    }     //if( false == string.IsNullOrEmpty( NodeTypeName ) )
                }         //if( SearchResults.CswC3SearchResults.Length > 0 )
            }             //if( null != C3SearchClient )

            return(ret);
        }//importC3Product()