示例#1
0
        public void RemoveMemoTest()
        {
            // Test Parameters
            int linkMemoId = 1;

            FileLink fl = LinkManager.GetLink(linkMemoId);

            // Get memo value
            string initialMemo = fl.LinkMemo;

            // Remove memo
            fl.RemoveMemo();
            Assert.AreEqual("", fl.LinkMemo);

            // Restore initial memo value
            fl.UpdateMemo(initialMemo);
            Assert.AreEqual(initialMemo, fl.LinkMemo);
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (myLinks == null || myLinks.Count == 0)
            {
                return;
            }

            // Handle changing and removing link memo
            string prompt     = "Select a link / group to update its memo.";
            bool   isSelected = ForceSingleSelection(prompt);

            if (!isSelected)
            {
                return;
            }

            try {
                // Get selected item / row
                var selected = FileLinkslistView.SelectedItems;
                if (selected.Count != 1)
                {
                    return;
                }
                ListViewItem row = selected[0];

                // Retrieve FileLink for selected row
                int      linkID = (int)row.Tag;
                FileLink link   = LinkManager.GetLink(linkID);
                if (link == null)
                {
                    return;
                }

                // Compare memo field with existing memo
                string newMemo      = txtMemo.Text.Trim();
                string originalMemo = link.LinkMemo ?? "";
                bool   isSameMemo   = (newMemo == originalMemo);
                if (isSameMemo)
                {
                    return;
                }

                // Remove memo if new is empty. Update otherwise.
                bool wantsRemoved = (string.IsNullOrEmpty(newMemo));
                if (wantsRemoved)
                {
                    bool wasRemoved = link.RemoveMemo();
                    if (wasRemoved)
                    {
                        LogMemoRemoval(link.LinkMemoID, originalMemo);
                        string removedPrompt = $"Memo removed for link number {link.LinkMemoID}";
                        Messenger.Show(removedPrompt, caption);
                    }
                }
                else
                {
                    bool wasUpdated = link.UpdateMemo(newMemo);
                    if (wasUpdated)
                    {
                        LogMemoChanged(link.LinkMemoID, originalMemo, newMemo);
                        string updatedPrompt = $"Memo updated for link number {link.LinkMemoID}";
                        Messenger.Show(updatedPrompt, caption);
                    }
                }
                FillListView(); // Refresh GUI
                txtMemo.Text = "";
            }
            catch (SqlException) {
                Messenger.ShowDbMsg();
            }
        }