private void toolStripMenuItemNewBranch(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, _treeNodeId); // create new branch Pic.DAL.SQLite.TreeNode nodeNew = parentNode.CreateChild(db, dlg.BranchName, dlg.BranchDescription, dlg.BranchImage); // redraw branch ShowBranch(_treeNodeId); // event if (null != TreeNodeCreated) { TreeNodeCreated(this, new NodeEventArgs(nodeNew.ID, NodeTag.NodeType.NT_TREENODE)); } } } catch (System.Exception ex) { _log.Error(ex.ToString()); } }
private void SaveParameters() { // data context Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); // get component by guid Pic.DAL.SQLite.Component comp = Pic.DAL.SQLite.Component.GetByGuid(db, _guid); if (null == comp) return; // get user entered values comp.UpdateDefaultParamValueSet(db, _pluginViewCtrl.ParamValues); }
public override CardboardFormat[] LoadCardboardFormats() { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.CardboardFormat[] _cardboardFormats = Pic.DAL.SQLite.CardboardFormat.GetAll(db); List<CardboardFormat> listFormat = new List<CardboardFormat>(); foreach (Pic.DAL.SQLite.CardboardFormat format in _cardboardFormats) listFormat.Add(new CardboardFormat(format.ID, format.Name, format.Description, format.Length, format.Width)); return listFormat.ToArray(); }
private void DisplayParameters() { // build list of controls starting with lb_ and nud_ List <Control> listControl = new List <Control>(); foreach (Control ctrl in Controls) { if (ctrl.Name.StartsWith("nud_") || ctrl.Name.StartsWith("lb_")) { listControl.Add(ctrl); } } // remove these controls foreach (Control ctrl in listControl) { Controls.Remove(ctrl); } listControl.Clear(); // get selected combo item CompComboItem item = cbComponent.SelectedItem as CompComboItem; if (null == item) { return; } // get selected component parameters Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Dictionary <string, double> dict = Pic.DAL.SQLite.Component.GetParamDefaultValues(db, item.Guid); // create controls const int lblX = 10, nudX = 160, incY = 26; Size sizelb = new Size(150, 18), sizenud = new Size(70, 12); int posY = 10; int tabIndex = 0; foreach (KeyValuePair <string, double> param in dict) { Label lb = new Label(); lb.Name = "lb_" + param.Key; lb.Text = param.Key; lb.Size = sizelb; lb.Location = new System.Drawing.Point(lblX, posY); lb.TabIndex = ++tabIndex; Controls.Add(lb); NumericUpDown nud = new NumericUpDown(); nud.Name = "nud_" + param.Key; nud.Value = (decimal)param.Value; nud.Size = sizenud; nud.Location = new System.Drawing.Point(nudX, posY); nud.TabIndex = ++tabIndex; Controls.Add(nud); // increment Y posY += incY; } }
private void UpdateParameters() { // get selected component Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.Component comp = Pic.DAL.SQLite.Component.GetByGuid(db, _guid); // set description lbDescription.Text = comp.Document.Description; // initialize plugin viewer _pluginViewCtrl.PluginPath = comp.Document.File.Path(db); _pluginViewCtrl.ParamValues = Pic.DAL.SQLite.Component.GetParamDefaultValues(db, _guid); }
public string GetFilePathFromGuid(Guid guid) { // get db constext Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); // retrieve component Pic.DAL.SQLite.Component comp = Pic.DAL.SQLite.Component.GetByGuid(db, guid); if (null == comp) throw new PluginException(string.Format("Failed to load Component with Guid = {0}", guid.ToString())); // return path return comp.Document.File.Path(db); }
private void SaveParameters() { // data context Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); // get component by guid Pic.DAL.SQLite.Component comp = Pic.DAL.SQLite.Component.GetByGuid(db, _guid); if (null == comp) { return; } // get user entered values comp.UpdateDefaultParamValueSet(db, _pluginViewCtrl.ParamValues); }
public override CardboardFormat[] LoadCardboardFormats() { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.CardboardFormat[] _cardboardFormats = Pic.DAL.SQLite.CardboardFormat.GetAll(db); List <CardboardFormat> listFormat = new List <CardboardFormat>(); foreach (Pic.DAL.SQLite.CardboardFormat format in _cardboardFormats) { listFormat.Add(new CardboardFormat(format.ID, format.Name, format.Description, format.Length, format.Width)); } return(listFormat.ToArray()); }
public string GetFilePathFromGuid(Guid guid) { // get db constext Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); // retrieve component Pic.DAL.SQLite.Component comp = Pic.DAL.SQLite.Component.GetByGuid(db, guid); if (null == comp) { throw new PluginException(string.Format("Failed to load Component with Guid = {0}", guid.ToString())); } // return path return(comp.Document.File.Path(db)); }
public double GetDoubleParameterDefaultValue(Guid guid, string name) { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.Component comp = Pic.DAL.SQLite.Component.GetByGuid(db, guid); if (null == comp) throw new PluginException(string.Format("Failed to load Component with Guid = {0}", guid.ToString())); try { return comp.GetParamDefaultValueDouble(db, name); } catch (Exception ex) { _log.Error(ex.Message); // rethrow exception throw ex; } }
private void toolStripMenuItemNewDocument(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, _treeNodeId); // 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(); // initialize dialog dlg.TreeNode = new NodeTag(NodeTag.NodeType.NT_TREENODE, _treeNodeId); if (DialogResult.OK == dlg.ShowDialog()) { // redraw current branch ShowBranch(_treeNodeId); // 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 } if (null != TreeNodeCreated) { TreeNodeCreated(this, new NodeEventArgs(listTreeNodeNew[0].ID, NodeTag.NodeType.NT_TREENODE)); } } } catch (System.Exception ex) { _log.Error(ex.ToString()); } }
public double GetDoubleParameterDefaultValue(Guid guid, string name) { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.Component comp = Pic.DAL.SQLite.Component.GetByGuid(db, guid); if (null == comp) { throw new PluginException(string.Format("Failed to load Component with Guid = {0}", guid.ToString())); } try { return(comp.GetParamDefaultValueDouble(db, name)); } catch (Exception ex) { _log.Error(ex.Message); // rethrow exception throw ex; } }
public FormEditDefaultParamValues(List<Guid> dependanciesGUID) { InitializeComponent(); _pluginViewCtrl.Localizer = LocalizerImpl.Instance; // fill combo Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); // load component from Guids foreach (Guid guid in dependanciesGUID) { Pic.DAL.SQLite.Component cp = Pic.DAL.SQLite.Component.GetByGuid(db, guid); cbComponent.Items.Add(new CompComboItem(cp.Document.Name, cp.Guid)); } // initialize _pluginViewCtrl _pluginViewCtrl.SearchMethod = new ComponentSearchMethodDB(); _pluginViewCtrl.ShowSummary = false; // initialize combo if (cbComponent.Items.Count > 0) cbComponent.SelectedIndex = 0; }
public FormEditDefaultParamValues(List <Guid> dependanciesGUID) { InitializeComponent(); _pluginViewCtrl.Localizer = LocalizerImpl.Instance; // fill combo Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); // load component from Guids foreach (Guid guid in dependanciesGUID) { Pic.DAL.SQLite.Component cp = Pic.DAL.SQLite.Component.GetByGuid(db, guid); cbComponent.Items.Add(new CompComboItem(cp.Document.Name, cp.Guid)); } // initialize _pluginViewCtrl _pluginViewCtrl.SearchMethod = new ComponentSearchMethodDB(); _pluginViewCtrl.ShowSummary = false; // initialize combo if (cbComponent.Items.Count > 0) { cbComponent.SelectedIndex = 0; } }
private void UpdateParameters() { // get selected component Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.Component comp = Pic.DAL.SQLite.Component.GetByGuid(db, _guid); // set description lbDescription.Text = comp.Document.Description; // initialize plugin viewer _pluginViewCtrl.PluginPath = comp.Document.File.Path(db); Dictionary <string, Pic.Plugin.Parameter> dictParameters = new Dictionary <string, Pic.Plugin.Parameter>(); foreach (var kvp in Pic.DAL.SQLite.Component.GetParamDefaultValues(db, _guid)) { dictParameters.Add(kvp.Key, new Pic.Plugin.ParameterDouble(kvp.Key, kvp.Key, false, 0.0, false, 0.0, kvp.Value) { Value = kvp.Value }); } _pluginViewCtrl.ParamValues = dictParameters; }
public void ShowBranch(NodeTag nodeTag) { // save current branch ID CurrentNodeTag = nodeTag; // clear existing buttons Controls.Clear(); tooltip.RemoveAll(); _listTreeNodes = new List <NodeTag>(); try { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.TreeNode branch = Pic.DAL.SQLite.TreeNode.GetById(db, nodeTag.TreeNode); foreach (Pic.DAL.SQLite.TreeNode tn in branch.Childrens(db)) { // annotate image Image thumbnailImage = tn.Thumbnail.GetImage(); Pic.DAL.SQLite.Thumbnail.Annotate(thumbnailImage, tn.Name); // insert node _listTreeNodes.Add( new NodeTag( tn.IsDocument ? NodeTag.NType.NTDocument : NodeTag.NType.NTBranch , tn.ID , tn.Name , tn.Description , thumbnailImage) ); } } catch (Exception /*ex*/) { } i = x = y = 0; timer.Start(); }
public void ShowBranch(int treeNodeId) { // save current branch ID _treeNodeId = treeNodeId; // clear existing buttons Controls.Clear(); tooltip.RemoveAll(); _listTreeNodes = new List<NodeTag>(); try { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.TreeNode branch = Pic.DAL.SQLite.TreeNode.GetById(db, treeNodeId); foreach (Pic.DAL.SQLite.TreeNode tn in branch.Childrens(db)) { // annotate image Image thumbnailImage = tn.Thumbnail.GetImage(); Pic.DAL.SQLite.Thumbnail.Annotate(thumbnailImage, tn.Name); // insert node _listTreeNodes.Add( new NodeTag( tn.IsDocument ? NodeTag.NodeType.NT_DOCUMENT : NodeTag.NodeType.NT_TREENODE , tn.ID , tn.Name , tn.Description , thumbnailImage) ); } } catch (Exception /*ex*/) { } i = x = y = 0; timer.Start(); }
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()); } }
private void SaveParameters() { // data context Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); // get component by guid Pic.DAL.SQLite.Component comp = Pic.DAL.SQLite.Component.GetByGuid(db, _guid); if (null == comp) { return; } Dictionary <string, double> dictNameValue = new Dictionary <string, double>(); foreach (var v in _pluginViewCtrl.ParamValues) { if (v.Value is Pic.Plugin.ParameterDouble p) { dictNameValue[p.Name] = p.Value; } } // get user entered values comp.UpdateDefaultParamValueSet(db, dictNameValue); }
void setNewComponentGuid(object sender, EventArgs e) { try { // get node NodeTag tag = GetCurrentTag(); // retrieve database node Pic.DAL.SQLite.PPDataContext db0 = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.TreeNode tn = Pic.DAL.SQLite.TreeNode.GetById(db0, tag.TreeNode); int parentNodeID = tn.ParentNodeID.Value; // if not a component -> exit if (!tn.IsComponent) return; // get document Pic.DAL.SQLite.Document doc = tn.Documents(db0)[0]; // get component Pic.DAL.SQLite.Component comp = Pic.DAL.SQLite.Component.GetByDocumentID(db0, doc.ID); // initial Guid Guid initialGuid = comp.Guid; string name = doc.Name; string description = doc.Description; // store majoration sets Dictionary<string, Dictionary<string, double>> majoSets = comp.GetAllMajorationSets(db0); // store parameter default values Dictionary<string, double> paramDefaultValues = comp.GetParamDefaultValues(); // copy thumbnail string originalThumbnailPath = tn.Thumbnail.File.Path(db0); string newThumbnailPath = System.IO.Path.ChangeExtension(System.IO.Path.GetTempFileName(), "jpg"); System.IO.File.Copy(originalThumbnailPath, newThumbnailPath); // show dialog and ask for new Guid FormDefineComponentGUID form = new FormDefineComponentGUID(); form.Guid = comp.Guid; if (DialogResult.OK != form.ShowDialog() || form.Guid == initialGuid) return; // ### 0 ### regenerate component with new guid string outputPath = System.IO.Path.ChangeExtension(System.IO.Path.GetTempFileName(), "dll"); if (!Pic.Plugin.PluginGenerator.Regenerate(doc.File.Path(db0), outputPath, form.Guid, string.Empty, string.Empty)) { // on failure -> exit _log.Error(string.Format("Failed to regenerate component {0} ({1})", doc.Name, outputPath)); return; } // ### 1 ### try and delete existing component -------------------------------------------------- try { using (Pic.DAL.SQLite.PPDataContext db1 = new Pic.DAL.SQLite.PPDataContext()) { Pic.DAL.SQLite.Component compToDelete = Pic.DAL.SQLite.Component.GetByGuid(db1, initialGuid); compToDelete.Delete(db1, true); } } catch (Exception /*ex*/) { } // ### 2 ### insert new component --------------------------------------------------------------- using (Pic.DAL.SQLite.PPDataContext db2 = new Pic.DAL.SQLite.PPDataContext()) { Pic.DAL.SQLite.TreeNode parentTNode = Pic.DAL.SQLite.TreeNode.GetById(db2, parentNodeID); Pic.DAL.SQLite.Component comp2 = parentTNode.InsertComponent(db2, outputPath, form.Guid, name, description, newThumbnailPath); } // ### 3 ### recreate majorations if any using (Pic.DAL.SQLite.PPDataContext db3 = new Pic.DAL.SQLite.PPDataContext()) { Pic.DAL.SQLite.Component comp3 = Pic.DAL.SQLite.Component.GetByGuid(db3, form.Guid); comp3.InsertMajorationSets(db3, majoSets); } // ### 4 ### recreate default values if any using (Pic.DAL.SQLite.PPDataContext db4 = new Pic.DAL.SQLite.PPDataContext()) { Pic.DAL.SQLite.Component comp4 = Pic.DAL.SQLite.Component.GetByGuid(db4, form.Guid); comp4.InsertNewParamDefaultValues(db4, paramDefaultValues); } } catch (Exception ex) { _log.Error(ex.ToString()); } }
private string GetSelectedNodePath() { // retrieve database node Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); NodeTag tag = GetCurrentTag(); Pic.DAL.SQLite.TreeNode tn = Pic.DAL.SQLite.TreeNode.GetById(db, tag.TreeNode); if (!tn.IsDocument) return string.Empty; // get document Pic.DAL.SQLite.Document doc = tn.Documents(db)[0]; return doc.File.Path(db); }
protected int GetImageIndex(Pic.DAL.SQLite.TreeNode tn) { if (tn.IsDocument) { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.Document doc = tn.Documents(db)[0]; string docTypeName = doc.DocumentType.Name.ToLower(); Dictionary<string, int> format2iconDictionnary = new Dictionary<string, int>() { {"parametric component" , 2}, {"treedim des" , 3}, {"autodesk dxf" , 4}, {"adobe acrobat" , 5}, {"adobe illustrator" , 8}, {"raster image" , 9}, {"ms word" , 10}, {"ms excel" , 11}, {"ms powerpoint" , 12}, {"open office write" , 13}, {"open office calc" , 14}, {"artioscad" , 15}, {"treedim des3" , 17} }; if (format2iconDictionnary.ContainsKey(docTypeName)) return format2iconDictionnary[docTypeName]; else return 0; } else { if (string.Equals(tn.Name, "Root", StringComparison.CurrentCultureIgnoreCase)) return 16; // Root else return 0; } }
// finish public virtual void Finalize(Pic.DAL.SQLite.PPDataContext db) { }
private void toolStripMenuItemNewDocument(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, _treeNodeId); // 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(); // initialize dialog dlg.TreeNode = new NodeTag(NodeTag.NodeType.NT_TREENODE, _treeNodeId); if (DialogResult.OK == dlg.ShowDialog()) { // redraw current branch ShowBranch(_treeNodeId); // 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 } if (null != TreeNodeCreated) TreeNodeCreated(this, new NodeEventArgs(listTreeNodeNew[0].ID, NodeTag.NodeType.NT_TREENODE)); } } catch (System.Exception ex) { _log.Error(ex.ToString()); } }
private void renameNode(object sender, EventArgs e) { try { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); NodeTag tag = GetCurrentTag(); Pic.DAL.SQLite.TreeNode tn = Pic.DAL.SQLite.TreeNode.GetById(db, tag.TreeNode); FormRenameNode form = new FormRenameNode(); form.NodeName = tn.Name; form.NodeDescription = tn.Description; form.Image = tn.Thumbnail.GetImage(); if (DialogResult.OK == form.ShowDialog()) { tn.Name = form.NodeName; tn.Description = form.NodeDescription; db.SubmitChanges(); if (form.HasValidThumbnailPath) Pic.DAL.SQLite.TreeNode.ReplaceThumbnail(tag.TreeNode, form.ThumbnailPath); TreeNode treeNode = FindNode(null, tag); treeNode.Text = form.NodeName; treeNode.ToolTipText = form.NodeDescription; } } catch (System.Exception ex) { Debug.Fail(ex.ToString()); _log.Debug(ex.ToString()); } }
private void backupNode(object sender, EventArgs e) { try { // get node Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); NodeTag tag = GetCurrentTag(); Pic.DAL.SQLite.TreeNode tn = Pic.DAL.SQLite.TreeNode.GetById(db, tag.TreeNode); // get backup file name SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "Backup file (*.zip)|*.zip|" + "All files (*.*)|*.*"; dlg.FilterIndex = 0; dlg.Title = string.Format(PicParam.Properties.Resources.ID_TREEMENUBACKUP, tn.Name); dlg.FileName = string.Format("{0}.zip", tn.Name); if (DialogResult.OK == dlg.ShowDialog()) { List<string> treeNodePath = tn.GetTreeNodePath(db); // backup branch FormWorkerThreadTask.Execute(new TPTBackupBranch(treeNodePath, dlg.FileName)); } } catch (Exception ex) { Debug.Fail(ex.ToString()); _log.Debug(ex.ToString()); } }
/// <summary> /// Thumbnail /// </summary> public Image GetThumbnail() { if (null == _thumbnail) { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.TreeNode node = Pic.DAL.SQLite.TreeNode.GetById(db, _id); Image tempImage = node.Thumbnail.GetImage(); Pic.DAL.SQLite.Thumbnail.Annotate(tempImage, node.Name); _thumbnail = tempImage; } return _thumbnail; }
private void insertNewBranchLabel_Click(object sender, EventArgs e) { try { // get current tree node NodeTag tag = GetCurrentTag(); if (null == tag || tag.IsDocument) throw new Exception("Invalid branch tag"); // 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, tag.TreeNode); // create new branch Pic.DAL.SQLite.TreeNode nodeNew = parentNode.CreateChild(db, dlg.BranchName, dlg.BranchDescription, dlg.BranchImage); // insert branch node InsertTreeNode(SelectedNode, nodeNew); // select current node SelectedNode = FindNode(null, tag); } } catch (System.Exception ex) { Debug.Fail(ex.ToString()); _log.Debug(ex.ToString()); } }
private void insertNewDocumentLabel_Click(object sender, EventArgs e) { try { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); NodeTag tag = GetCurrentTag(); if (null == tag || tag.IsDocument) throw new Exception("Invalid TreeNode tag"); Pic.DAL.SQLite.TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, tag.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; // show dialog FormCreateDocument dlg = new FormCreateDocument(); dlg.TreeNode = tag; if (DialogResult.OK == dlg.ShowDialog()) { // insert document in treeview List<Pic.DAL.SQLite.TreeNode> tnodes = Pic.DAL.SQLite.TreeNode.GetByDocumentId(db, dlg.DocumentID); // (re)populate parent node PopulateChildren(SelectedNode); if (dlg.OpenInsertedDocument) { // select current node NodeTag newDocTag = new NodeTag(NodeTag.NodeType.NT_DOCUMENT, tnodes[0].ID); SelectedNode = FindNode(null, newDocTag); // <- for some reasons, this does not work // however, we can force document opening with the following line SelectionChanged(this, new NodeEventArgs(newDocTag.TreeNode, newDocTag.Type), newDocTag.Name); } } } catch (System.Exception ex) { Debug.Fail(ex.ToString()); _log.Error(ex.ToString()); } }
private void DisplayParameters() { // build list of controls starting with lb_ and nud_ List<Control> listControl = new List<Control>(); foreach (Control ctrl in Controls) if (ctrl.Name.StartsWith("nud_") || ctrl.Name.StartsWith("lb_")) listControl.Add(ctrl); // remove these controls foreach (Control ctrl in listControl) Controls.Remove(ctrl); listControl.Clear(); // get selected combo item CompComboItem item = cbComponent.SelectedItem as CompComboItem; if (null == item) return; // get selected component parameters Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Dictionary<string, double> dict = Pic.DAL.SQLite.Component.GetParamDefaultValues(db, item.Guid); // create controls const int lblX = 10, nudX = 160, incY = 26; Size sizelb = new Size(150, 18), sizenud = new Size(70, 12); int posY = 10; int tabIndex = 0; foreach (KeyValuePair<string, double> param in dict) { Label lb = new Label(); lb.Name = "lb_" + param.Key; lb.Text = param.Key; lb.Size = sizelb; lb.Location = new System.Drawing.Point(lblX, posY); lb.TabIndex = ++tabIndex; Controls.Add(lb); NumericUpDown nud = new NumericUpDown(); nud.Name = "nud_" + param.Key; nud.Value = (decimal)param.Value; nud.Size = sizenud; nud.Location = new System.Drawing.Point(nudX, posY); nud.TabIndex = ++tabIndex; Controls.Add(nud); // increment Y posY += incY; } }
void duplicateLabel_Click(object sender, EventArgs e) { try { // ### 1 ### Build new document name // get node NodeTag tag = GetCurrentTag(); // retrieve database tree node Pic.DAL.SQLite.PPDataContext db0 = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.TreeNode tn = Pic.DAL.SQLite.TreeNode.GetById(db0, tag.TreeNode); Pic.DAL.SQLite.TreeNode tnParent = tn.GetParent(db0); if (!tn.IsDocument) return; // document name Pic.DAL.SQLite.Document doc = tn.Documents(db0)[0]; int i = 1; string docNameCopy = string.Format("{0} ({1})", doc.Name, i++); while (!tnParent.AllowChildCreation(db0, docNameCopy)) docNameCopy = string.Format("{0} ({1})", doc.Name, i++); // ### 2 ### retrieve document file path string docFilePath = tn.Documents(db0)[0].File.Path(db0); string newDocFilePath = System.IO.Path.ChangeExtension(System.IO.Path.GetTempFileName(), System.IO.Path.GetExtension(docFilePath)); // copy thumbnail string originalThumbnailPath = tn.Thumbnail.File.Path(db0); string newThumbnailPath = System.IO.Path.ChangeExtension(System.IO.Path.GetTempFileName(), "jpg"); System.IO.File.Copy(originalThumbnailPath, newThumbnailPath); if (tn.IsComponent) { // *** COMPONENT // get component Pic.DAL.SQLite.Component comp = Pic.DAL.SQLite.Component.GetByDocumentID(db0, doc.ID); // store parameter default values Dictionary<string, double> paramDefaultValues = comp.GetParamDefaultValues(); // store majoration sets Dictionary<string, Dictionary<string, double>> majoSets = comp.GetAllMajorationSets(db0); // regenerate plugin file rather than just make a copy Guid guid = Guid.NewGuid(); if (!Pic.Plugin.PluginGenerator.Regenerate(doc.File.Path(db0), newDocFilePath, guid, string.Empty, string.Empty)) { // on failure -> exit _log.Error(string.Format("Failed to regenerate component {0} ({1})", doc.Name, docFilePath)); return; } tnParent.InsertComponent(db0, newDocFilePath, guid, docNameCopy, doc.Description, newThumbnailPath); // insert default values using (Pic.DAL.SQLite.PPDataContext db1 = new Pic.DAL.SQLite.PPDataContext()) { Pic.DAL.SQLite.Component comp1 = Pic.DAL.SQLite.Component.GetByGuid(db1, guid); comp1.InsertNewParamDefaultValues(db1, paramDefaultValues); } // insert majorations using (Pic.DAL.SQLite.PPDataContext db2 = new Pic.DAL.SQLite.PPDataContext()) { Pic.DAL.SQLite.Component comp2 = Pic.DAL.SQLite.Component.GetByGuid(db2, guid); comp2.InsertMajorationSets(db2, majoSets); } // *** COMPONENT } else { // *** OTHER DOCUMENT // copy document itself System.IO.File.Copy(docFilePath, newDocFilePath); // insert new document tnParent.InsertDocument(db0, newDocFilePath, docNameCopy, doc.Description, doc.DocumentType.Name, newThumbnailPath); // *** OTHER DOCUMENT } try { // delete copied document + thumbnail System.IO.File.Delete(newDocFilePath); System.IO.File.Delete(newThumbnailPath); } catch (Exception /*ex*/) { } } catch (Exception ex) { _log.Error(ex.ToString()); } CollapseRoot(); }
private void deleteNode(object sender, EventArgs e) { try { // retrieve database node Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); NodeTag tag = GetCurrentTag(); Pic.DAL.SQLite.TreeNode tn = Pic.DAL.SQLite.TreeNode.GetById(db, tag.TreeNode); // prepare warning message string message = string.Empty; if (tn.IsDocument) message = string.Format(PicParam.Properties.Resources.ID_TREEWARNING_DELETEDOCUMENT, tn.Name); else message = string.Format(PicParam.Properties.Resources.ID_TREEWARNING_DELETEBRANCH, tn.Name); // show warning message and proceed with node deletion if necessary if (DialogResult.Yes == MessageBox.Show(message, Application.ProductName, MessageBoxButtons.YesNo)) { // delete from data base tn.Delete(db, true, null); // delete from tree control TreeNode treeNode = FindNode(null, tag); treeNode.Remove(); } } catch (System.Exception ex) { Debug.Fail(ex.ToString()); _log.Debug(ex.ToString()); } }
void DocumentTreeView_NodeDropped(object sender, NodeDroppedArgs args) { try { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); // get data treenodes NodeTag tagFrom = args._treeNodeFrom.Tag as NodeTag; Pic.DAL.SQLite.TreeNode nodeFrom = Pic.DAL.SQLite.TreeNode.GetById(db, tagFrom.TreeNode); NodeTag tagTo = args._treeNodeTo.Tag as NodeTag; Pic.DAL.SQLite.TreeNode nodeTo = Pic.DAL.SQLite.TreeNode.GetById(db, tagTo.TreeNode); // check that nodeTo is not a descendant of nodeFrom if (nodeTo.IsDescendantOf(db, nodeFrom)) { MessageBox.Show(string.Format(PicParam.Properties.Resources.ID_TREEWARNING_CANNOTMOVENODE, nodeFrom.Name, nodeTo.Name) , Application.ProductName , MessageBoxButtons.OK , MessageBoxIcon.Error); return; } // confirm ? if (DialogResult.Yes == MessageBox.Show( string.Format(PicParam.Properties.Resources.ID_TREEWARNING_MOVENODE, nodeFrom.Name, nodeTo.Name) , Application.ProductName , MessageBoxButtons.YesNo , MessageBoxIcon.Warning)) { // move node in the database nodeFrom.Move(db, nodeTo); // rebuild tree Pic.DAL.SQLite.TreeBuilder builder = new Pic.DAL.SQLite.TreeBuilder(); builder.BuildTree(this); } } catch (Pic.DAL.SQLite.ExceptionDAL ex) { MessageBox.Show(ex.ToString()); _log.Error(string.Format("Exception caught : {0}", ex.ToString())); } catch (Exception ex) { MessageBox.Show(ex.ToString()); _log.Error(string.Format("Exception caught : {0}", ex.ToString())); } }
void DocumentTreeView_DragDrop(object sender, DragEventArgs e) { if (null == _draggedNode) return; // retrieve the client coordinates of the drop location. Point targetPoint = PointToClient(new Point(e.X, e.Y)); // retrieve the node at the drop location. TreeNode dropTargetNode = GetNodeAt(targetPoint); if (null != dropTargetNode) { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); NodeTag tagTo = dropTargetNode.Tag as NodeTag; Pic.DAL.SQLite.TreeNode nodeTo = Pic.DAL.SQLite.TreeNode.GetById(db, tagTo.TreeNode); if (!nodeTo.IsDocument) NodeDropped(this, new NodeDroppedArgs(_draggedNode, dropTargetNode)); } }
public void AskRootNode() { FormCreateBranch form = new FormCreateBranch(); if (DialogResult.OK == form.ShowDialog()) { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.TreeNode.CreateNew(db, form.BranchName, form.BranchDescription, form.BranchImage); } }
private void toolStripMenuItemNewBranch(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, _treeNodeId); // create new branch Pic.DAL.SQLite.TreeNode nodeNew = parentNode.CreateChild(db, dlg.BranchName, dlg.BranchDescription, dlg.BranchImage); // redraw branch ShowBranch(_treeNodeId); // event if (null != TreeNodeCreated) TreeNodeCreated(this, new NodeEventArgs(nodeNew.ID, NodeTag.NodeType.NT_TREENODE)); } } catch (System.Exception ex) { _log.Error(ex.ToString()); } }
public void OnTreeNodeCreated(object sender, NodeEventArgs e) { Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.TreeNode nodeNew = Pic.DAL.SQLite.TreeNode.GetById(db, e.Node); TreeNode parentNode = FindNode(null, new NodeTag(NodeTag.NodeType.NT_TREENODE, nodeNew.ParentNodeID.Value)); // clear parentNode.Nodes.Clear(); // insert dummy node parentNode.Nodes.Add("_DUMMY_"); // collapse parentNode.Collapse(); // reload parentNode.Expand(); }
public void PopulateAndSelectNode(NodeTag tag) { TreeNode nodeSelected = FindNode(null, tag); BeginUpdate(); // this disables redrawing of tree if (null == nodeSelected) { _log.Error(string.Format("Failed to retrieve valid node from NodeTag {0}", tag.ToString())); // retrieve db node Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext(); Pic.DAL.SQLite.TreeNode tn = Pic.DAL.SQLite.TreeNode.GetById(db, tag.TreeNode); // insert all needed parents and node nodeSelected = InsertNodeAndParents(tn, db); if (null == nodeSelected) { _log.Error(string.Format("Failed to retrieve valid node from NodeTag {0}", tag.ToString())); return; // -> complete failure } } if (null != nodeSelected) { _preventEventTriggering = true; // ################## --> needed to update tree nodeSelected.Expand(); // ################## --> needed to update tree SelectedNode = nodeSelected; EndUpdate(); // enables the redrawing of the treeview _preventEventTriggering = false; SelectedNode = nodeSelected; } else EndUpdate(); // enables the redrawing of the treeview }
// process methods to be implemented public abstract bool Process(Pic.DAL.SQLite.PPDataContext db, TreeNode tn);