Exemplo n.º 1
0
        private void DeleteItem()
        {
            MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                for (int i = listView.SelectedItems.Count - 1; i >= 0; i--)
                {
                    ImageData item = (ImageData)listView.SelectedItems[i];
                    if (item.ImageSource.Contains("Folder"))
                    {
                        string path = treeViewMachinesAndTasksHandler.GetNodePath() + "\\" + item.Name;
                        if (Directory.Exists(path))
                        {
                            Directory.Delete(path, true);
                        }
                        treeViewMachinesAndTasksHandler.RemoveItem(item.Name);
                    }
                    else
                    {
                        string path = treeViewMachinesAndTasksHandler.GetNodePath() + "\\" + item.Name + ".my";
                        if (File.Exists(path))
                        {
                            File.Delete(path);
                        }
                    }
                }
                listViewBrowseImagesHandler.Refresh();
            }
        }
Exemplo n.º 2
0
        private void DeleteItem()
        {
            MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                if (listViewMachineGroups.Visibility == Visibility.Visible)
                {
                    for (int i = listViewMachineGroups.SelectedItems.Count - 1; i >= 0; i--)
                    {
                        ComputerDetailsData item = (ComputerDetailsData)listViewMachineGroups.SelectedItems[i];
                        if (item.ImageSource.Contains("Folder"))
                        {
                            string path = treeViewMachinesAndTasksHandler.GetNodePath() + "\\" + item.Name;
                            if (path != LockPath && path != DefaultPath)
                            {
                                var computersInfoFiles = Directory.GetFiles(treeViewMachinesAndTasksHandler.GetNodePath(), "*.my", SearchOption.AllDirectories);
                                foreach (string computerFile in computersInfoFiles)
                                {
                                    var computerData = FileHandler.Load <ComputerDetailsData>(computerFile);
                                    for (int j = listViewMachinesAndTasksHandler.clients.Count - 1; j >= 0; j--)
                                    {
                                        ClientHandler client = listViewMachinesAndTasksHandler.clients[j];
                                        if (client.CheckMacsInREC(client.macAddresses, computerData.macAddresses))
                                        {
                                            client.SendMessage(new Packet(DataIdentifier.CLOSE));
                                            client.deleting = true;
                                            break;
                                        }
                                    }
                                }
                                if (Directory.Exists(path))
                                {
                                    Directory.Delete(path, true);
                                }
                                treeViewMachinesAndTasksHandler.RemoveItem(item.Name);
                            }
                            else
                            {
                                MessageBox.Show("Cannot delete this folder", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                                return;
                            }
                        }
                        else
                        {
                            string path = treeViewMachinesAndTasksHandler.GetNodePath() + "\\" + item.Name + ".my";
                            for (int j = listViewMachinesAndTasksHandler.clients.Count - 1; j >= 0; j--)
                            {
                                ClientHandler client = listViewMachinesAndTasksHandler.clients[j];
                                if (client.CheckMacsInREC(client.macAddresses, item.macAddresses))
                                {
                                    client.SendMessage(new Packet(DataIdentifier.CLOSE));
                                    client.deleting = true;
                                    break;
                                }
                            }
                            if (File.Exists(path))
                            {
                                File.Delete(path);
                            }
                            if (File.Exists(path.Replace(".my", ".cfg")))
                            {
                                File.Delete(path.Replace(".my", ".cfg"));
                            }
                        }
                    }
                }
                else
                {
                    for (int i = listViewTasks.SelectedItems.Count - 1; i >= 0; i--)
                    {
                        TaskData item = (TaskData)listViewTasks.SelectedItems[i];
                        if (item.ImageSource.Contains("Folder"))
                        {
                            string path = treeViewMachinesAndTasksHandler.GetNodePath() + "\\" + item.Name;
                            if (Directory.Exists(path))
                            {
                                Directory.Delete(path, true);
                            }
                            treeViewMachinesAndTasksHandler.RemoveItem(item.Name);
                        }
                        else
                        {
                            string path = treeViewMachinesAndTasksHandler.GetNodePath() + "\\" + item.Name + ".my";
                            if (File.Exists(path))
                            {
                                File.Delete(path);
                            }
                        }
                    }
                }
                listViewMachinesAndTasksHandler.Refresh();
            }
        }