Esempio n. 1
0
 private void butImport_Click(object sender, EventArgs e)
 {
     try {
         using (OpenFileDialog openDialog = ImportDialogSetup()) {
             if (openDialog.ShowDialog() != DialogResult.OK)
             {
                 return;                         //User cancelled out of OpenFileDialog
             }
             string fileContents          = File.ReadAllText(openDialog.FileName);
             TransferableAutoNotes import = JsonConvert.DeserializeObject <TransferableAutoNotes>(fileContents);
             AutoNoteControls.RemoveDuplicatesFromList(import.AutoNoteControls, import.AutoNotes);
             AutoNoteControls.InsertBatch(import.AutoNoteControls);
             AutoNotes.InsertBatch(import.AutoNotes);
             DataValid.SetInvalid(InvalidType.AutoNotes);
             AutoNoteL.FillListTree(treeNotes, _userOdCurPref);
             SecurityLogs.MakeLogEntry(Permissions.AutoNoteQuickNoteEdit, 0,
                                       $"Auto Note Import. {import.AutoNotes.Count} new Auto Notes, {import.AutoNoteControls.Count} new Prompts");
             MsgBox.Show(Lans.g(this, "Auto Notes successfully imported!") + "\r\n" + import.AutoNotes.Count + " " + Lans.g(this, "new Auto Notes")
                         + "\r\n" + import.AutoNoteControls.Count + " " + Lans.g(this, "new Prompts"));
         }
     }
     catch (Exception err) {
         FriendlyException.Show(Lans.g(this, "Auto Note(s) failed to import."), err);
     }
 }
Esempio n. 2
0
 private void FormAutoNotes_Load(object sender, System.EventArgs e)
 {
     if (IsSelectionMode)
     {
         butAdd.Visible         = false;
         labelSelection.Visible = true;
     }
     _userOdCurPref = UserOdPrefs.GetByUserAndFkeyType(Security.CurUser.UserNum, UserOdFkeyType.AutoNoteExpandedCats).FirstOrDefault();
     AutoNoteL.FillListTree(treeNotes, _userOdCurPref);
 }
Esempio n. 3
0
        private void butAdd_Click(object sender, System.EventArgs e)
        {
            if (!Security.IsAuthorized(Permissions.AutoNoteQuickNoteEdit))
            {
                return;
            }
            long selectedDefNum = 0;

            if (treeNotes.SelectedNode?.Tag is Def)
            {
                selectedDefNum = ((Def)treeNotes.SelectedNode.Tag).DefNum;
            }
            else if (treeNotes.SelectedNode?.Tag is AutoNote)
            {
                selectedDefNum = ((AutoNote)treeNotes.SelectedNode.Tag).Category;
            }
            FormAutoNoteEdit FormA = new FormAutoNoteEdit();

            FormA.IsNew       = true;
            FormA.AutoNoteCur = new AutoNote()
            {
                Category = selectedDefNum
            };
            FormA.ShowDialog();
            if (FormA.DialogResult != DialogResult.OK)
            {
                return;
            }
            treeNotes.SelectedNode?.Expand();              //expanding an AutoNote has no effect, and if nothing selected nothing to expand
            AutoNoteL.FillListTree(treeNotes, _userOdCurPref);
            if ((FormA.AutoNoteCur?.AutoNoteNum ?? 0) > 0) //select the newly added note in the tree
            {
                treeNotes.SelectedNode = treeNotes.Nodes.OfType <TreeNode>().SelectMany(x => AutoNoteL.GetNodeAndChildren(x)).Where(x => x.Tag is AutoNote)
                                         .FirstOrDefault(x => ((AutoNote)x.Tag).AutoNoteNum == FormA.AutoNoteCur.AutoNoteNum);
                treeNotes.SelectedNode?.EnsureVisible();
                treeNotes.Focus();
            }
        }
Esempio n. 4
0
        private void FormAutoNotes_FormClosing(object sender, FormClosingEventArgs e)
        {
            //store the current node expanded state for this user
            List <long> listExpandedDefNums = treeNotes.Nodes.OfType <TreeNode>()
                                              .SelectMany(x => AutoNoteL.GetNodeAndChildren(x, true))
                                              .Where(x => x.IsExpanded)
                                              .Select(x => ((Def)x.Tag).DefNum)
                                              .Where(x => x > 0).ToList();

            if (_userOdCurPref == null)
            {
                UserOdPrefs.Insert(new UserOdPref()
                {
                    UserNum     = Security.CurUser.UserNum,
                    FkeyType    = UserOdFkeyType.AutoNoteExpandedCats,
                    ValueString = string.Join(",", listExpandedDefNums)
                });
            }
            else
            {
                _userOdCurPref.ValueString = string.Join(",", listExpandedDefNums);
                UserOdPrefs.Update(_userOdCurPref);
            }
        }
Esempio n. 5
0
        private void treeNotes_MouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node == null || !(e.Node.Tag is AutoNote))
            {
                return;
            }
            AutoNote noteCur = ((AutoNote)e.Node.Tag).Copy();

            if (IsSelectionMode)
            {
                AutoNoteCur  = noteCur;
                DialogResult = DialogResult.OK;
                return;
            }
            FormAutoNoteEdit FormA = new FormAutoNoteEdit();

            FormA.IsNew       = false;
            FormA.AutoNoteCur = noteCur;
            FormA.ShowDialog();
            if (FormA.DialogResult == DialogResult.OK)
            {
                AutoNoteL.FillListTree(treeNotes, _userOdCurPref);
            }
        }
Esempio n. 6
0
 private void checkCollapse_CheckedChanged(object sender, System.EventArgs e)
 {
     AutoNoteL.SetCollapsed(treeNotes, checkCollapse.Checked);
 }
Esempio n. 7
0
        private void treeNotes_DragDrop(object sender, DragEventArgs e)
        {
            if (_grayNode != null)
            {
                _grayNode.BackColor = Color.White;
            }
            if (!e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
            {
                return;
            }
            TreeNode sourceNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");

            if (sourceNode == null || !(sourceNode.Tag is Def || sourceNode.Tag is AutoNote))
            {
                return;
            }
            TreeNode topNodeCur = treeNotes.TopNode;

            if (treeNotes.TopNode == sourceNode && sourceNode.PrevVisibleNode != null)
            {
                //if moving the topNode to another category, make the previous visible node the topNode once the move is successful
                topNodeCur = sourceNode.PrevVisibleNode;
            }
            Point    pt       = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
            TreeNode destNode = ((TreeView)sender).GetNodeAt(pt);

            if (destNode == null || !(destNode.Tag is Def || destNode.Tag is AutoNote)) //moving to root node (category 0)
            {
                if (sourceNode.Parent == null)                                          //already at the root node, nothing to do
                {
                    return;
                }
                if (!MsgBox.Show(this, MsgBoxButtons.YesNo, "Move the selected " + (sourceNode.Tag is AutoNote?"Auto Note":"category") + " to the root level?"))
                {
                    return;
                }
                if (sourceNode.Tag is Def)
                {
                    ((Def)sourceNode.Tag).ItemValue = "";
                }
                else                  //must be an AutoNote
                {
                    ((AutoNote)sourceNode.Tag).Category = 0;
                }
            }
            else              //moving to another folder (category)
            {
                if (destNode.Tag is AutoNote)
                {
                    destNode = destNode.Parent;                  //if destination is AutoNote, set destination to the parent, which is the category def node for the note
                }
                if (!IsValidDestination(sourceNode, destNode, sourceNode.Tag is Def))
                {
                    return;
                }
                if (!MsgBox.Show(this, MsgBoxButtons.YesNo,
                                 "Move the selected " + (sourceNode.Tag is AutoNote?"Auto Note":"category") + (destNode == null?" to the root level":"") + "?"))
                {
                    return;
                }
                //destNode will be null if a root AutoNote was selected as the destination
                long destDefNum = (destNode == null?0:((Def)destNode.Tag).DefNum);
                if (sourceNode.Tag is Def)
                {
                    ((Def)sourceNode.Tag).ItemValue = (destDefNum == 0?"":destDefNum.ToString()); //make a DefNum of 0 be a blank string in the db, not a "0" string
                }
                else                                                                              //must be an AutoNote
                {
                    ((AutoNote)sourceNode.Tag).Category = destDefNum;
                }
            }
            if (sourceNode.Tag is Def)
            {
                Defs.Update((Def)sourceNode.Tag);
                DataValid.SetInvalid(InvalidType.Defs);
            }
            else              //must be an AutoNote
            {
                AutoNotes.Update((AutoNote)sourceNode.Tag);
                DataValid.SetInvalid(InvalidType.AutoNotes);
            }
            treeNotes.TopNode = topNodeCur;          //if sourceNode was the TopNode and was moved, make the TopNode the previous visible node
            AutoNoteL.FillListTree(treeNotes, _userOdCurPref);
        }
Esempio n. 8
0
 private void FormAutoNoteExport_Load(object sender, System.EventArgs e)
 {
     _userPrefExpandedDefNums = UserOdPrefs.GetByUserAndFkeyType(Security.CurUser.UserNum, UserOdFkeyType.AutoNoteExpandedCats).FirstOrDefault();
     AutoNoteL.FillListTree(treeNotes, _userPrefExpandedDefNums);
 }