Exemplo n.º 1
0
            public CswNbtPropertySetMaterial commit()
            {
                CswNbtPropertySetMaterial Ret;

                if (null == Node)  //Don't commit twice
                {
                    if (existsInDb())
                    {
                        throw new CswDniException(CswEnumErrorType.Warning, "A material with the same Type, Tradename, Supplier and PartNo already exists.", "A material with this configuration already exists. Name: " + _ExistingNode.NodeName + " , ID: " + _ExistingNode.NodeId + ".");
                    }
                    if (false == existsInDb() && Int32.MinValue != NodeTypeId)
                    {
                        Ret  = _NbtResources.Nodes.makeNodeFromNodeTypeId(NodeTypeId, IsTemp: true);
                        Node = Ret.Node;
                    }
                    else
                    {
                        throw new CswDniException(CswEnumErrorType.Warning, "Cannot create a new Material object without a valid Supplier.", "Provided SupplierId was invalid.");
                    }
                }
                else
                {
                    Ret = Node;
                }

                Ret.TradeName.Text = TradeName;
                if (CswEnumTristate.False == Ret.IsConstituent.Checked)
                {
                    Ret.PartNumber.Text        = PartNo;
                    Ret.Supplier.RelatedNodeId = SupplierId;
                }

                //Case 29409 - if a User has Material Approval, set the created Material to Approved for Receiving = true, otherwise set it to default value (which should be "?")
                bool HasMaterialApproval = _NbtResources.Permit.can(CswEnumNbtActionName.Material_Approval);

                if (HasMaterialApproval)
                {
                    Ret.ApprovedForReceiving.Checked = CswEnumTristate.True;
                }

                //Ret.IsTemp = ( false == RemoveTempStatus );
                Ret.postChanges(ForceUpdate: false);

                return(Ret);
            }