/// <summary> /// Set the filename for a file property /// </summary> /// <param name="FileName"></param> /// <param name="JctNodePropId"></param> public void SetFileName(string FileName, CswNbtNodePropBlob BlobProp) { CswTableUpdate ts = _CswNbtResources.makeCswTableUpdate("getFirstFileName", "blob_data"); DataTable dt = ts.getTable("where jctnodepropid = " + BlobProp.JctNodePropId); if (dt.Rows.Count > 0) { dt.Rows[0]["filename"] = FileName; } ts.update(dt); }
/// <summary> /// Get the filename for a file property /// </summary> /// <param name="JctNodePropId"></param> /// <returns></returns> public string GetFileName(CswNbtNodePropBlob BlobProp) { string ret = ""; CswTableSelect ts = _CswNbtResources.makeCswTableSelect("getFirstFileName", "blob_data"); DataTable dt = ts.getTable("where jctnodepropid = " + BlobProp.JctNodePropId); if (dt.Rows.Count > 0) { ret = dt.Rows[0]["filename"].ToString(); } return(ret); }
/// <summary> /// Gets the url for the active C of A Document attached to this ReceiptLot node. /// </summary> /// <param name="ButtonData">Data required for the client to open the file</param> public void getCofA(NbtButtonData ButtonData) { if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.ManufacturerLotInfo)) { if (ButtonData.SelectedText.Equals(PropertyName.ViewCofA)) { CswNbtObjClassCofADocument CofADoc = CswNbtObjClassCofADocument.getActiveCofADocument(_CswNbtResources, NodeId); if (null != CofADoc) { string url = ""; switch (CofADoc.FileType.Value) { case CswNbtPropertySetDocument.CswEnumDocumentFileTypes.File: url = CswNbtNodePropBlob.getLink(CofADoc.File.JctNodePropId, CofADoc.NodeId); break; case CswNbtPropertySetDocument.CswEnumDocumentFileTypes.Link: url = CswNbtNodePropLink.GetFullURL(CofADoc.Link.Prefix, CofADoc.Link.Href, CofADoc.Link.Suffix); break; } ButtonData.Data["url"] = url; ButtonData.Action = CswEnumNbtButtonAction.popup; } else { ButtonData.Message = "There are no active C of A assigned to this " + NodeType.NodeTypeName; ButtonData.Action = CswEnumNbtButtonAction.nothing; } } else { CswNbtView AssignedCofADocsView = CswNbtObjClassCofADocument.getAssignedCofADocumentsView(_CswNbtResources, NodeId); if (null != AssignedCofADocsView) { AssignedCofADocsView.SaveToCache(IncludeInQuickLaunch: false, UpdateCache: true); ButtonData.Data["viewid"] = AssignedCofADocsView.SessionViewId.ToString(); ButtonData.Data["title"] = AssignedCofADocsView.ViewName; ButtonData.Data["nodeid"] = NodeId.ToString(); ButtonData.Data["nodetypeid"] = NodeTypeId.ToString(); ButtonData.Action = CswEnumNbtButtonAction.griddialog; } else { ButtonData.Message = "Could not find the Assigned C of A prop"; ButtonData.Action = CswEnumNbtButtonAction.nothing; } } } }
public static string getAssignedSDSDocumentUrl( CswNbtResources _CswNbtResources, CswPrimaryKey MaterialId ) { string url = ""; if( _CswNbtResources.Modules.IsModuleEnabled( CswEnumNbtModuleName.SDS ) ) { CswNbtMetaDataObjectClass SDSDocOC = _CswNbtResources.MetaData.getObjectClass( CswEnumNbtObjectClass.SDSDocumentClass ); CswNbtMetaDataNodeType SDSDocumentNT = SDSDocOC.FirstNodeType; CswNbtView docView = getAssignedSDSDocumentsView( _CswNbtResources, MaterialId ); // We need to re-add these properties because they were removed from the 'Assigned SDS' view in Case 31223 CswNbtMetaDataNodeTypeProp LinkNTP = SDSDocumentNT.getNodeTypePropByObjectClassProp( CswNbtPropertySetDocument.PropertyName.Link ); docView.AddViewProperty( docView.Root.ChildRelationships[0].ChildRelationships[0], LinkNTP ); CswNbtMetaDataNodeTypeProp FileNTP = SDSDocumentNT.getNodeTypePropByObjectClassProp( CswNbtPropertySetDocument.PropertyName.File ); docView.AddViewProperty( docView.Root.ChildRelationships[0].ChildRelationships[0], FileNTP ); CswNbtMetaDataNodeTypeProp FileTypeNTP = SDSDocumentNT.getNodeTypePropByObjectClassProp( CswNbtPropertySetDocument.PropertyName.FileType ); docView.AddViewProperty( docView.Root.ChildRelationships[0].ChildRelationships[0], FileTypeNTP ); // If ChemWatch is enabled, we need to check for this type of file too if( _CswNbtResources.Modules.IsModuleEnabled( CswEnumNbtModuleName.ChemWatch ) ) { CswNbtMetaDataNodeTypeProp ChemWatchNTP = SDSDocumentNT.getNodeTypePropByObjectClassProp( PropertyName.ChemWatch ); docView.AddViewProperty( docView.Root.ChildRelationships[0].ChildRelationships[0], ChemWatchNTP ); } CswNbtObjClassUser currentUserNode = _CswNbtResources.Nodes[_CswNbtResources.CurrentNbtUser.UserId]; CswNbtObjClassJurisdiction userJurisdictionNode = _CswNbtResources.Nodes[currentUserNode.JurisdictionProperty.RelatedNodeId]; ICswNbtTree docsTree = _CswNbtResources.Trees.getTreeFromView( docView, false, false, false ); docsTree.goToNthChild( 0 ); //This is a property view, so the data is on the 2nd level int childCount = docsTree.getChildNodeCount(); int lvlMatched = Int32.MinValue; string matchedFileType = ""; CswNbtTreeNodeProp matchedFileProp = null; CswNbtTreeNodeProp matchedLinkProp = null; CswNbtTreeNodeProp matchedChemWatchProp = null; CswPrimaryKey matchedNodeId = null; if( childCount > 0 ) { for( int i = 0; i < childCount; i++ ) { docsTree.goToNthChild( i ); string format = ""; string language = ""; string fileType = ""; CswNbtTreeNodeProp fileProp = null; CswNbtTreeNodeProp linkProp = null; CswNbtTreeNodeProp chemWatchProp = null; CswPrimaryKey nodeId = docsTree.getNodeIdForCurrentPosition(); foreach( CswNbtTreeNodeProp prop in docsTree.getChildNodePropsOfNode() ) { CswNbtMetaDataNodeTypeProp docNTP = _CswNbtResources.MetaData.getNodeTypeProp( prop.NodeTypePropId ); switch( docNTP.getObjectClassPropName() ) { case PropertyName.Format: format = prop.Field1; break; case PropertyName.Language: language = prop.Field1; break; case PropertyName.FileType: fileType = prop.Field1; break; case PropertyName.File: fileProp = prop; break; case PropertyName.Link: linkProp = prop; break; case PropertyName.ChemWatch: chemWatchProp = prop; break; } } if( lvlMatched < 0 ) { matchedFileType = fileType; matchedFileProp = fileProp; matchedLinkProp = linkProp; matchedChemWatchProp = chemWatchProp; matchedNodeId = nodeId; lvlMatched = 0; } if( null != userJurisdictionNode ) { if( lvlMatched < 1 && format.Equals( userJurisdictionNode.Format.Value ) ) { matchedFileType = fileType; matchedFileProp = fileProp; matchedLinkProp = linkProp; matchedChemWatchProp = chemWatchProp; matchedNodeId = nodeId; lvlMatched = 1; } if( lvlMatched < 2 && language.Equals( currentUserNode.Language ) ) { matchedFileType = fileType; matchedFileProp = fileProp; matchedLinkProp = linkProp; matchedChemWatchProp = chemWatchProp; matchedNodeId = nodeId; lvlMatched = 2; } if( lvlMatched < 3 && format.Equals( userJurisdictionNode.Format.Value ) && language.Equals( currentUserNode.Language ) ) { matchedFileType = fileType; matchedFileProp = fileProp; matchedLinkProp = linkProp; matchedChemWatchProp = chemWatchProp; matchedNodeId = nodeId; lvlMatched = 3; } } docsTree.goToParentNode(); } switch( matchedFileType ) { case CswEnumDocumentFileTypes.File: int jctnodepropid = CswConvert.ToInt32( matchedFileProp.JctNodePropId ); url = CswNbtNodePropBlob.getLink( jctnodepropid, matchedNodeId ); break; case CswEnumDocumentFileTypes.Link: CswNbtMetaDataNodeTypeProp linkNTP = SDSDocumentNT.getNodeTypePropByObjectClassProp( PropertyName.Link ); //url = CswNbtNodePropLink.GetFullURL( linkNTP.Attribute1, matchedLinkProp.Field1_Big, linkNTP.Attribute2 ); url = CswNbtNodePropLink.GetFullURL( linkNTP.DesignNode.getAttributeValueByColumn( CswEnumNbtPropertyAttributeColumn.Attribute1 ), matchedLinkProp.Field1_Big, linkNTP.DesignNode.getAttributeValueByColumn( CswEnumNbtPropertyAttributeColumn.Attribute2 ) ); break; case CswEnumDocumentFileTypes.ChemWatch: url = "Services/ChemWatch/GetSDSDocument?filename=" + matchedChemWatchProp.Field1; break; } } } return url; }
public int saveFile(string PropIdAttr, byte[] BlobData, string ContentType, string FileName, out string Href, int BlobDataId = Int32.MinValue, bool PostChanges = true, CswNbtNode Node = null) { CswPropIdAttr PropId = new CswPropIdAttr(PropIdAttr); CswNbtMetaDataNodeTypeProp MetaDataProp = _CswNbtResources.MetaData.getNodeTypeProp(PropId.NodeTypePropId); if (null == Node) { Node = _CswNbtResources.Nodes[PropId.NodeId]; } CswNbtNodePropWrapper FileProp = Node.Properties[MetaDataProp]; if (_CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Edit, MetaDataProp.getNodeType(), _CswNbtResources.CurrentNbtUser) && _CswNbtResources.Permit.isPropWritable(CswEnumNbtNodeTypePermission.Edit, MetaDataProp, null, FileProp)) { if (Int32.MinValue == FileProp.JctNodePropId) { FileProp.makePropRow(); //if we don't have a jct_node_prop row for this prop, we do now if (PostChanges) { Node.postChanges(true); } } if (FileProp.getFieldType().FieldType == CswEnumNbtFieldType.Image) { //case 29692: support EXIF image rotation metadata to properly orient photos bool img_ok = false; MemoryStream ms = new MemoryStream(BlobData, 0, BlobData.Length); ms.Write(BlobData, 0, BlobData.Length); System.Drawing.Image img = null; try { img = Image.FromStream(ms, true); img_ok = true; } catch { } if (img_ok == true) { FixOrientation(ref img); ImageConverter converter = new ImageConverter(); BlobData = (byte[])converter.ConvertTo(img, typeof(byte[])); } } //Save the file to blob_data CswTableUpdate BlobUpdate = _CswNbtResources.makeCswTableUpdate("saveBlob", "blob_data"); string whereClause = "where jctnodepropid = " + FileProp.JctNodePropId; if (Int32.MinValue != BlobDataId) { whereClause += " and blobdataid = " + BlobDataId; } DataTable BlobTbl = BlobUpdate.getTable(whereClause); if (BlobTbl.Rows.Count > 0 && (Int32.MinValue != BlobDataId || FileProp.getFieldTypeValue() == CswEnumNbtFieldType.File || FileProp.getFieldTypeValue() == CswEnumNbtFieldType.MOL)) { BlobTbl.Rows[0]["blobdata"] = BlobData; BlobTbl.Rows[0]["contenttype"] = ContentType; BlobTbl.Rows[0]["filename"] = FileName; BlobTbl.Rows[0]["auditlevel"] = MetaDataProp.AuditLevel; BlobDataId = CswConvert.ToInt32(BlobTbl.Rows[0]["blobdataid"]); } else { DataRow NewRow = BlobTbl.NewRow(); NewRow["jctnodepropid"] = FileProp.JctNodePropId; NewRow["blobdata"] = BlobData; NewRow["contenttype"] = ContentType; NewRow["filename"] = FileName; NewRow["auditlevel"] = MetaDataProp.AuditLevel; BlobDataId = CswConvert.ToInt32(NewRow["blobdataid"]); BlobTbl.Rows.Add(NewRow); } BlobUpdate.update(BlobTbl); if (Node.getObjectClass().ObjectClass == CswEnumNbtObjectClass.ReportClass) { CswNbtObjClassReport Report = Node; CswFilePath FilePathTools = new CswFilePath(_CswNbtResources); string ReportPath = FilePathTools.getFullReportFilePath(Report.RPTFile.JctNodePropId.ToString()); _createReportFile(ReportPath, Report.RPTFile.JctNodePropId, BlobData); } if (CswEnumNbtFieldType.File == FileProp.getFieldTypeValue()) { SetLastModified(FileProp); } FileProp.SyncGestalt(); if (PostChanges) { Node.postChanges(false); } Href = CswNbtNodePropBlob.getLink(FileProp.JctNodePropId, PropId.NodeId, BlobDataId); } //canNodeType() && isPropWritable() else { Href = string.Empty; //To satifsy the "ref string Href" throw new CswDniException(CswEnumErrorType.Error, "You do not have sufficient priveledges to save files", "User " + _CswNbtResources.CurrentNbtUser.UserId + " attemped to save blobdata on JctNodeProp " + FileProp.JctNodePropId); } return(BlobDataId); }
} // TreeToJson() private void _TreeNodeToGrid(CswNbtView View, ICswNbtTree Tree, CswExtJsGrid grid, CswExtJsGridRow gridrow) { string gridUniquePrefix = _getUniquePrefix(View); Collection <CswNbtTreeNodeProp> ChildProps = Tree.getChildNodePropsOfNode(); foreach (CswNbtTreeNodeProp Prop in ChildProps) { // Potential bug here! // If the view defines the property by objectclass propname, but the nodetype propname differs, this might break CswExtJsGridDataIndex dataIndex = new CswExtJsGridDataIndex(gridUniquePrefix, Prop.PropName); bool IsHidden = Prop.Hidden; bool IsLocked = Tree.getNodeLockedForCurrentPosition(); string newValue = string.Empty; if (false == IsHidden) { CswPrimaryKey NodeId = Tree.getNodeIdForCurrentPosition(); CswNbtMetaDataNodeTypeProp MetaDataProp = _CswNbtResources.MetaData.getNodeTypeProp(Prop.NodeTypePropId); string oldValue = Prop.Gestalt; if (string.IsNullOrEmpty(oldValue)) { oldValue = null; } switch (Prop.FieldType) { case CswEnumNbtFieldType.Button: if (false == IsLocked) { CswNbtFieldTypeRuleButton buttonFTR = (CswNbtFieldTypeRuleButton)MetaDataProp.getFieldTypeRule(); grid.rowData.btns.Add(new CswExtJsGridButton { DataIndex = dataIndex.ToString(), RowNo = gridrow.RowNo, MenuOptions = Prop[buttonFTR.MenuOptionsSubField.Column], SelectedText = oldValue ?? Prop.PropName, PropAttr = new CswPropIdAttr(NodeId, Prop.NodeTypePropId).ToString(), Mode = String.IsNullOrEmpty(MetaDataProp.DesignNode.getAttributeValueByColumn(CswEnumNbtPropertyAttributeColumn.Extended)) ? "button" : MetaDataProp.DesignNode.getAttributeValueByColumn(CswEnumNbtPropertyAttributeColumn.Extended) }); } break; case CswEnumNbtFieldType.File: string LinkUrl = CswNbtNodePropBlob.getLink(Prop.JctNodePropId, NodeId); if (false == string.IsNullOrEmpty(LinkUrl) && false == string.IsNullOrEmpty(oldValue)) { newValue = "<a target=\"blank\" href=\"" + LinkUrl + "\">" + (oldValue) + "</a>"; } break; case CswEnumNbtFieldType.Image: string ImageUrl = CswNbtNodePropImage.getLink(Prop.JctNodePropId, NodeId); if (false == string.IsNullOrEmpty(ImageUrl)) { newValue = "<a target=\"blank\" href=\"" + ImageUrl + "\">" + (oldValue ?? "Image") + "</a>"; } break; case CswEnumNbtFieldType.Link: //string Href = CswNbtNodePropLink.GetFullURL( MetaDataProp.Attribute1, Prop.Field1_Big, MetaDataProp.Attribute2 ); string Href = CswNbtNodePropLink.GetFullURL(MetaDataProp.DesignNode.getAttributeValueByColumn(CswEnumNbtPropertyAttributeColumn.Attribute1), Prop.Field1_Big, MetaDataProp.DesignNode.getAttributeValueByColumn(CswEnumNbtPropertyAttributeColumn.Attribute2)); if (false == string.IsNullOrEmpty(Href)) { newValue = "<a target=\"blank\" href=\"" + Href + "\">" + (oldValue ?? "Link") + "</a>"; } break; case CswEnumNbtFieldType.Logical: newValue = CswConvert.ToDisplayString(CswConvert.ToTristate(oldValue)); break; case CswEnumNbtFieldType.MOL: string molUrl = CswNbtNodePropMol.getLink(Prop.JctNodePropId, NodeId); if (false == string.IsNullOrEmpty(molUrl)) { newValue = "<a target=\"blank\" href=\"" + molUrl + "\">" + "Structure.jpg" + "</a>"; } break; default: newValue = oldValue; break; } } gridrow.data[dataIndex] = newValue; } // foreach( JObject Prop in ChildProps ) // Recurse, but add properties of child nodes to the same gridrow for (Int32 c = 0; c < Tree.getChildNodeCount(); c++) { Tree.goToNthChild(c); _TreeNodeToGrid(View, Tree, grid, gridrow); Tree.goToParentNode(); } } // _TreeNodeToGrid()