private void OnTSMenuItemNewDocument(object sender, EventArgs e) { try { // get data context Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); // get current branch node Pic.DAL.SQLite.TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, CurrentNodeTag.TreeNode); // force creation of a profile if no profile exist Pic.DAL.SQLite.CardboardProfile[] cardboardProfiles = Pic.DAL.SQLite.CardboardProfile.GetAll(db); if (cardboardProfiles.Length == 0) { FormEditProfiles dlgProfile = new FormEditProfiles(); dlgProfile.ShowDialog(); } cardboardProfiles = Pic.DAL.SQLite.CardboardProfile.GetAll(db); if (cardboardProfiles.Length == 0) { return; // no profile -> exit } // show document creation dialog FormCreateDocument dlg = new FormCreateDocument { TreeNode = new NodeTag(NodeTag.NType.NTBranch, CurrentNodeTag.TreeNode) }; if (DialogResult.OK == dlg.ShowDialog()) { // redraw current branch ShowBranch(CurrentNodeTag); // get current document Id int documentId = dlg.DocumentID; // get TreeNode from documentID List <Pic.DAL.SQLite.TreeNode> listTreeNodeNew = Pic.DAL.SQLite.TreeNode.GetByDocumentId(db, dlg.DocumentID); if (listTreeNodeNew.Count == 0) { _log.Error(string.Format("Failed to retrieve treeNode from document ID : {0}", dlg.DocumentID)); return; // -> failed to retrieve node } TreeNodeCreated?.Invoke(this, new NodeEventArgs(listTreeNodeNew[0].ID, NodeTag.NType.NTBranch)); } } catch (Exception ex) { _log.Error(ex.ToString()); } }
private void OnTSMenuItemNewBranch(object sender, EventArgs e) { try { // show dialog FormCreateBranch dlg = new FormCreateBranch(); if (DialogResult.OK == dlg.ShowDialog()) { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); // get parent node Pic.DAL.SQLite.TreeNode parentNode = Pic.DAL.SQLite.TreeNode.GetById(db, CurrentNodeTag.TreeNode); // create new branch Pic.DAL.SQLite.TreeNode nodeNew = parentNode.CreateChild(db, dlg.BranchName, dlg.BranchDescription, dlg.BranchImage); // redraw branch ShowBranch(CurrentNodeTag); // event TreeNodeCreated?.Invoke(this, new NodeEventArgs(nodeNew.ID, NodeTag.NType.NTBranch)); } } catch (Exception ex) { _log.Error(ex.ToString()); } }