public CalDataViewer(ref List <TaskData> inputData, CTTask task) { InitializeComponent(); taskDataList = inputData; currentTask = task; taskDataList.Sort((y, x) => x.CompleteDateString .CompareTo(y.CompleteDateString)); foreach (TaskData data in taskDataList) { TreeViewItem newItem = new(); newItem.Header = $"({data.DataId}) {data.CompleteDateString}"; TaskDataTree.Items.Add(newItem); } TaskDataTree.Items.Refresh(); foreach (string file in Directory.GetFiles(currentTask.TaskDirectory)) { TreeViewItem newItem = new(); newItem.Header = Path.GetFileName(file); TaskFilesTree.Items.Add(newItem); } TaskFilesTree.Items.Refresh(); }
private void MainWindow_Drop(object sender, DragEventArgs e) { if (!ItemIsSelected()) { MessageBox.Show("An item must be selected in the list to drop a file.", "No Item Selection", MessageBoxButton.OK, MessageBoxImage.Warning); return; } //Handle an Outlook attachment being dropped if (e.Data.GetDataPresent("FileGroupDescriptorW")) { OutlookDataObject outlookData = new(e.Data); string[] files = (string[])outlookData.GetData("FileGroupDescriptorW"); if (files.Length > 1) { MessageBox.Show("Only one item can be dropped into the window at a time.", "Multiple Items", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } string file = files[0]; //Move file from memory to receiving folder MemoryStream[] fileContents = (MemoryStream[])outlookData.GetData("FileContents"); FileStream fileStream = new($"{config.ListDir}\\receiving\\{file}", FileMode.Create); string filePath = $"{config.ListDir}\\receiving\\{file}"; fileContents[0].CopyTo(fileStream); fileStream.Close(); //Try to move the file to item folder string newFileName; string taskFolder = null; do { DropFileInfo info = new(); if (ItemIsSelected()) { info.SerialNumberBox.Text = SelectedSN(); } info.DateBox.Text = DateTime.UtcNow.ToString(database.dateFormat); info.TaskBox.ItemsSource = database.GetFromWhere <CTTask>(new() { { "serial_number", SelectedSN() } }); if (info.ShowDialog() == false) { if (File.Exists(filePath)) { File.Delete(filePath); } return; } else { if (Directory.Exists(filePath)) { File.Delete(filePath); MessageBox.Show("Drag and drop for folders is not currently supported.", "Drag and Drop", MessageBoxButton.OK, MessageBoxImage.Error); return; } newFileName = $"{info.DateBox.Text}_{info.SerialNumberBox.Text}{Path.GetExtension(file)}"; CTTask currentTask = (CTTask)info.TaskBox.SelectedItem; taskFolder = currentTask.GetTaskFolderIfExists(); if (taskFolder == null) { MessageBox.Show($"{info.SerialNumberBox.Text} Task: ({currentTask.TaskId}){currentTask.TaskTitle} does not have a valid folder.", "Invalid Directory", MessageBoxButton.OK, MessageBoxImage.Error); break; } } }while (!MoveToTaskFolder(filePath, taskFolder, newFileName)); } //Handle a file on disk being dropped else if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (files.Length > 1) { MessageBox.Show("Only one item can be dropped into the window at a time.", "Multiple Items", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } string file = files[0]; string newFileName; string taskFolder = null; do { if (Directory.Exists(file)) { MessageBox.Show("Drag and drop for folders is not currently supported.", "Drag and Drop", MessageBoxButton.OK, MessageBoxImage.Error); return; } DropFileInfo info = new(); if (ItemIsSelected()) { info.SerialNumberBox.Text = SelectedSN(); } info.TaskBox.ItemsSource = database.GetFromWhere <CTTask>(new() { { "serial_number", SelectedSN() } }); info.DateBox.Text = DateTime.UtcNow.ToString(database.dateFormat); if (info.ShowDialog() == false) { return; } else { newFileName = $"{info.DateBox.Text}_{info.SerialNumberBox.Text}{Path.GetExtension(file)}"; CTTask currentTask = (CTTask)info.TaskBox.SelectedItem; taskFolder = currentTask.GetTaskFolderIfExists(); if (taskFolder == null) { MessageBox.Show($"{info.SerialNumberBox.Text} Task: ({currentTask.TaskId}){currentTask.TaskTitle} does not have a valid folder.", "Invalid Directory", MessageBoxButton.OK, MessageBoxImage.Error); break; } } }while (!MoveToTaskFolder(file, taskFolder, newFileName)); } UpdateItemList(); }