コード例 #1
0
		private void Documents_Attach(Document entity)
		{
			this.SendPropertyChanging();
			entity.File = this;
		}
コード例 #2
0
		private void Documents_Detach(Document entity)
		{
			this.SendPropertyChanging();
			entity.File = null;
		}
コード例 #3
0
        private void bnOk_Click(object sender, EventArgs e)
        {
            try
            {
                string filePath = fileSelectCtrl.FileName;
                string fileExt  = System.IO.Path.GetExtension(filePath).ToLower();
                fileExt = fileExt.Substring(1);
                if (!System.IO.File.Exists(filePath))
                {
                    return;
                }

                // get tree node for document insertion
                Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext();
                if (null == _nodeTag || _nodeTag.IsDocument)
                {
                    throw new Exception("Invalid TreeNode tag");
                }
                Pic.DAL.SQLite.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 == Pic.DAL.SQLite.DocumentType.GetByName(db, "Parametric component"))
                    {
                        Pic.DAL.SQLite.DocumentType.CreateNew(db, "Parametric component", "Parametric component", "PicParam");
                    }

                    // create new document
                    Pic.DAL.SQLite.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 Pic.DAL.SQLite.ExceptionDAL(string.Format("No valid format handler from file extension: {0}", fileExt));
                    }
                    // get document type
                    Pic.DAL.SQLite.DocumentType docType = Pic.DAL.SQLite.DocumentType.GetByName(db, fHandler.Name);
                    if (null == docType)
                    {
                        docType = Pic.DAL.SQLite.DocumentType.CreateNew(db, fHandler.Name, fHandler.Description, fHandler.Application);
                    }
                    // insert document in database
                    Pic.DAL.SQLite.Document document = treeNode.InsertDocument(
                        db
                        , filePath
                        , DocumentName
                        , DocumentDescription
                        , docType.Name
                        , ThumbnailPath);
                    // save document ID
                    _documentId           = document.ID;
                    _openInsertedDocument = fHandler.OpenInPLMPackLib;
                }
            }
            catch (Pic.DAL.SQLite.ExceptionDAL ex)
            {
                MessageBox.Show(
                    ex.Message
                    , Application.ProductName
                    , MessageBoxButtons.OK
                    , MessageBoxIcon.Error);
                _log.Error(ex.ToString());
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }