Exemple #1
0
        private void btnRemoveFile_Click(object sender, EventArgs e)
        {
            if (filesInLink == null || filesInLink.Count == 0)
            {
                return;
            }
            string prompt     = "Select a file to remove from group.";
            bool   isSelected = ForceSingleSelection(prompt);

            if (!isSelected)
            {
                return;
            }

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

                // Retrieve tracked file for selected row
                int         fileID = (int)row.Tag;
                TrackedFile tf     = FileManager.GetFile(fileID);
                if (tf == null)
                {
                    return;
                }

                // Confirm user wants to remove file
                string removePrompt = $"Remove {tf.Filename}.{tf.FileExtension} from group?";
                bool   wantsRemoved = (Messenger.ShowYesNo(removePrompt, caption) == DialogResult.Yes);
                if (!wantsRemoved)
                {
                    return;
                }

                // remove file from group
                bool wasRemoved = myLink.RemoveFiles(new List <int> {
                    tf.FileID
                });
                if (wasRemoved)
                {
                    LogFileRemoval(myLink, tf);
                    FillListView(); // Refresh GUI
                }
                else
                {
                    Messenger.Show("Unable to remove file from group.", caption);
                }
            }
            catch (SqlException) {
                Messenger.ShowDbMsg();
            }
        }
        public void JoinTest()
        {
            // Get file link for link memo id = 1
            int      linkMemoId = 1;
            FileLink fl         = LinkManager.GetLink(linkMemoId);

            // Get the files for file link
            List <TrackedFile> linkedFiles = fl.GetFiles();

            // Verify at least one file is returned
            Assert.IsNotNull(linkedFiles);

            // Get all files
            List <TrackedFile> allFiles = FileManagerDAL.GetFiles();

            // Find a file not in the MemoId = 1 list
            TrackedFile joinFile = null;

            // Get a list of the file IDs of the linked files
            List <int> linkedFileIDs = new List <int>();

            foreach (var file in linkedFiles)
            {
                linkedFileIDs.Add(file.FileID);
            }

            //
            foreach (var file in allFiles)
            {
                if (!linkedFileIDs.Contains(file.FileID))
                {
                    joinFile = file;
                    break;
                }
            }

            // Join file if we have found one
            if (joinFile != null)
            {
                // Join file
                fl.Join(joinFile.FileID);

                // Reteieve file list
                linkedFiles = fl.GetFiles();

                // Fill linedFileIDs with new file ID list
                linkedFileIDs.Clear();
                foreach (var file in linkedFiles)
                {
                    linkedFileIDs.Add(file.FileID);
                }

                // Verify joined file exists in the list
                Assert.IsTrue(linkedFileIDs.Contains(joinFile.FileID));

                // Remove joined file
                fl.RemoveFiles(new List <int> {
                    joinFile.FileID
                });
            }
        }