private bool LoadMiscellaneousFormat(string filePath) { try { FormatHandler fHandler = FFormatManager.GetFormatHandlerFromFilePath(filePath); if (null == fHandler) { return(false); } pb4ImageFiles.Visible = true; pb4ImageFiles.ImageLocation = fHandler.ThumbnailFile; if (textBoxName.Text.Length == 0) { textBoxName.Text = Path.GetFileNameWithoutExtension(filePath); } if (textBoxDescription.Text.Length == 0) { textBoxDescription.Text = Path.GetFileNameWithoutExtension(filePath); } } catch (Exception ex) { _log.Error(ex.ToString()); } return(true); }
private void OnBnOkClicked(object sender, EventArgs e) { try { string filePath = fileSelectCtrl.FileName; string fileExt = Path.GetExtension(filePath).ToLower(); fileExt = fileExt.Substring(1); if (!File.Exists(filePath)) { return; } // get tree node for document insertion PPDataContext db = new PPDataContext(); if (null == _nodeTag || _nodeTag.IsDocument) { throw new Exception("Invalid TreeNode tag"); } TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, _nodeTag.TreeNode); if (string.Equals("dll", fileExt, StringComparison.CurrentCultureIgnoreCase)) { // make sure "Parametric Component" document type exist if (null == DocumentType.GetByName(db, "Parametric component")) { DocumentType.CreateNew(db, "Parametric component", "Parametric component", "PicParam"); } // create new document Component component = treeNode.InsertComponent( db , filePath , componentLoaderControl.ComponentGuid , DocumentName , DocumentDescription , ThumbnailPath); // create associated majorations if any if (componentLoaderControl.HasMajorations) { component.InsertNewMajorationSet(db, componentLoaderControl.Profile, componentLoaderControl.Majorations); } // create associated default param values if (chkDefaultParameters.Checked) { component.InsertNewParamDefaultValues(db, componentLoaderControl.ParamDefaultValues); } // save document ID to be used later // -> to retrieve document tree node DocumentID = component.DocumentID; OpenInsertedDocument = true; } else { // get a format handler FormatHandler fHandler = FFormatManager.GetFormatHandlerFromFileExt(fileExt); if (null == fHandler) { throw new ExceptionDAL(string.Format("No valid format handler from file extension: {0}", fileExt)); } // get document type DocumentType docType = DocumentType.GetByName(db, fHandler.Name); if (null == docType) { docType = DocumentType.CreateNew(db, fHandler.Name, fHandler.Description, fHandler.Application); } // insert document in database Document document = treeNode.InsertDocument( db , filePath , DocumentName , DocumentDescription , docType.Name , ThumbnailPath); // save document ID DocumentID = document.ID; OpenInsertedDocument = fHandler.OpenInPLMPackLib; } } catch (ExceptionDAL ex) { MessageBox.Show( ex.Message , Application.ProductName , MessageBoxButtons.OK , MessageBoxIcon.Error); _log.Error(ex.ToString()); } catch (Exception ex) { _log.Error(ex.ToString()); } }