Exemple #1
0
        private void AddClick(object sender, RoutedEventArgs e)
        {
            string resultPath = string.Empty;

            using (var dialog = new FolderBrowserDialog())
            {
                DialogResult result = dialog.ShowDialog();

                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    resultPath = dialog.SelectedPath;
                }
                else
                {
                    return;
                }
            }

            if (ListOfDirectories.FirstOrDefault(dir => dir.Path == resultPath) != null)
            {
                return;
            }

            int count = Directory.CreateDirectory(resultPath).GetFiles().Length;

            ListOfDirectories.Add(new DirectoryObject(Rules.FirstOrDefault(rule => rule.AccessID == 0), resultPath, count));
        }
Exemple #2
0
        private void CopyClick(object sender, RoutedEventArgs e)
        {
            if (MainDataGrid.SelectedIndex < 0)
            {
                System.Windows.MessageBox.Show("Выберите исходную папку");
                return;
            }

            DirectoryObject currentDir = MainDataGrid.SelectedItem as DirectoryObject;

            if (string.IsNullOrEmpty(CopyToIdTB.Text))
            {
                System.Windows.MessageBox.Show("Введите идентификатор целевой папки");
                return;
            }

            DirectoryObject toDir = ListOfDirectories.FirstOrDefault(dir => dir.Id == int.Parse(CopyToIdTB.Text));

            if (toDir == null || toDir.Id == currentDir.Id)
            {
                System.Windows.MessageBox.Show("Введите корректное значение идентификатора папки");
                return;
            }

            if (toDir.AccessRule.AccessID < currentDir.AccessRule.AccessID)
            {
                System.Windows.MessageBox.Show("Исходная папка имеет более высокий уровень секретности. Копирование невозможно");
                return;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string dirName = System.IO.Path.GetDirectoryName(openFileDialog.FileName);

                if (!dirName.Contains(currentDir.Path))
                {
                    System.Windows.MessageBox.Show("Вы выбрали файл, который находится за пределами исходной папки. Выберете другой файл");
                    return;
                }

                try
                {
                    string name = System.IO.Path.GetFileName(openFileDialog.FileName);

                    string newPath = System.IO.Path.Combine(toDir.Path, name);

                    File.WriteAllBytes(newPath, File.ReadAllBytes(openFileDialog.FileName));
                }
                catch (Exception)
                {
                    System.Windows.MessageBox.Show("Ошибка");
                    return;
                }

                System.Windows.MessageBox.Show("Файл был успешно скопирован");
            }
        }