private void _acceptButton_Click(object sender, EventArgs e) { if (_nameTextBox.Text.Length == 0) { TaskDialogEx.Show(this, "Please enter a name", Text, TaskDialogCommonButtons.OK, TaskDialogIcon.Error); } else if (File.Exists(Path)) { var result = TaskDialogEx.Show( this, "File name already exists, would you like to overwrite it?", Text, TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No | TaskDialogCommonButtons.Cancel, TaskDialogIcon.Warning, 2); if (result == DialogResult.Yes) { DialogResult = DialogResult.OK; } else if (result == DialogResult.No) { DialogResult = DialogResult.Cancel; } } else if (Directory.Exists(Path)) { TaskDialogEx.Show(this, "Directory already exists", Text, TaskDialogCommonButtons.OK, TaskDialogIcon.Error); } else { DialogResult = DialogResult.OK; } }
public void DoDelete() { if (!CanDelete) { return; } string message = _listView.SelectedItems.Count == 1 ? "Are you sure you want to delete this file?" : $"Are you sure you want to delete {_listView.SelectedItems.Count} files?"; var result = TaskDialogEx.Show(this, message, FindForm().Text, TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No, TaskDialogIcon.Warning); if (result != DialogResult.Yes) { return; } foreach (string fileName in SelectedFiles) { try { File.Delete(fileName); } catch { // Ignore. } } }
private void _exportToExcel_Click(object sender, EventArgs e) { string fileName = "Wastedge Export.xlsx"; if (_fileName != null) { fileName = Path.GetFileNameWithoutExtension(_fileName) + ".xlsx"; } using (var form = new SaveFileDialog()) { form.Filter = "Excel (*.xlsx)|*.xlsx|All Files (*.*)|*.*"; form.RestoreDirectory = true; form.FileName = fileName; if (form.ShowDialog(this) != DialogResult.OK) { return; } fileName = form.FileName; } try { var results = GetAllResults(); using (var stream = File.Create(fileName)) { new ExportExcelExporter().Export(stream, results, BuildExport()); } } catch (Exception ex) { if (ex is TargetInvocationException) { ex = ((TargetInvocationException)ex).InnerException; } TaskDialogEx.Show(this, "An unexpected error occured" + Environment.NewLine + Environment.NewLine + ex.Message, Text, TaskDialogCommonButtons.OK, TaskDialogIcon.Error); return; } try { Process.Start(fileName); } catch { // Ignore exceptions. } }
private void _add_Click(object sender, EventArgs e) { var member = _filter.SelectedItem as FilterField; if (member == null) { TaskDialogEx.Show(this, "Unknown field", Text, TaskDialogCommonButtons.OK, TaskDialogIcon.Error); return; } AddFilter(member.Field); _filter.Text = null; }
private void AddFile(string fileName) { string target = Path.Combine(_fileBrowser.Directory, Path.GetFileName(fileName)); if (File.Exists(target)) { var result = TaskDialogEx.Show(this, "A file with the same name already exists. Do you want to overwrite the existing file?", Text, TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No, TaskDialogIcon.Warning); if (result == DialogResult.No) { return; } File.Delete(target); } File.Copy(fileName, target); }
private void DoRunReport(string path) { ReportDefinition report; try { report = ReportDefinition.Load(_api, path); } catch { TaskDialogEx.Show(this, "Unable to load report", Text, TaskDialogCommonButtons.OK, TaskDialogIcon.Error); return; } using (var form = new ReportForm(_api, Path.GetDirectoryName(path), Path.GetFileName(path), report)) { form.ShowDialog(this); } }
public void DoDelete() { if (!CanDelete) { return; } var result = TaskDialogEx.Show(this, "Are you sure you want to delete this folder and its entire contents?", FindForm().Text, TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No, TaskDialogIcon.Warning); if (result == DialogResult.Yes) { try { IODirectory.Delete(Directory, true); Reload(); } catch { TaskDialogEx.Show(this, "An error occured while deleting the directory", FindForm().Text, TaskDialogCommonButtons.OK, TaskDialogIcon.Error); } } }
private void _dragDropManager_DragDrop(object sender, FilesDragEventArgs e) { EndDragDrop(); var node = _treeView.GetNodeAt(_treeView.PointToClient(new Point(e.X, e.Y))); if (node == null) { return; } string targetPath = (string)node.Tag; var matches = BuildMatches(targetPath, e); if (matches == null) { return; } try { foreach (var match in matches) { string target = Path.Combine(targetPath, Path.GetFileName(match.Path)); if (match.Kind.IsFile() && File.Exists(target)) { var result = TaskDialogEx.Show( this, "The destination already has a file with this name. Do you want to overwrite the existing file?", FindForm().Text, TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No | TaskDialogCommonButtons.Cancel, TaskDialogIcon.Warning ); if (result == DialogResult.No) { continue; } if (result == DialogResult.Cancel) { return; } File.Delete(target); } switch (match.Kind) { case DropMatchKind.DirectoryMove: IODirectory.Move(match.Path, target); break; case DropMatchKind.DirectoryCopy: PathUtil.CopyDirectory(match.Path, target); break; case DropMatchKind.FileMove: File.Move(match.Path, target); break; case DropMatchKind.FileCopy: File.Copy(match.Path, target); break; case DropMatchKind.FileVirtual: File.WriteAllBytes(target, e.DropData.GetFileData(match.Index)); break; } } } catch { TaskDialogEx.Show(this, "Could not complete the operation", FindForm().Text, TaskDialogCommonButtons.OK, TaskDialogIcon.Error); } }
private void _editInExcel_Click(object sender, EventArgs e) { GetAllResults(); using (var form = new EditInExcelInstructionsForm()) { if (form.ShowDialog(this) != DialogResult.OK) { return; } } ApiRowErrorsCollection errors = null; var original = new RecordSet(); var editing = original; foreach (var resultSet in _resultSets) { original.AddResultSet(resultSet); } while (true) { string fileName; for (int i = 0; ; i++) { fileName = "Wastedge Export"; if (i > 0) { fileName += $" ({i})"; } fileName += ".xlsx"; fileName = Path.Combine(Path.GetTempPath(), fileName); if (!File.Exists(fileName)) { break; } } try { using (var stream = File.Create(fileName)) { new ExcelExporter().Export(stream, _entity, editing, errors); } try { Process.Start(fileName); } catch { // Ignore exceptions. } using (var form = new EditInExcelWaitForm()) { if (form.ShowDialog(this) != DialogResult.OK) { return; } } RecordSetChanges changes; RecordSet modified; while (true) { try { using (var stream = File.OpenRead(fileName)) { modified = new ExcelImporter().Import(stream, _entity); } changes = RecordSetChanges.Create(original, modified); break; } catch (IOException) { var result = TaskDialogEx.Show( this, "The Excel file cannot be opened. Please close the Excel file before uploading your changes", Text, TaskDialogCommonButtons.OK | TaskDialogCommonButtons.Cancel, TaskDialogIcon.Error ); if (result == DialogResult.Cancel) { return; } } } using (var form = new EditInExcelUploadForm(_api, _entity, changes)) { form.ShowDialog(this); errors = form.Errors; } if (errors != null) { using (var form = new ValidationErrorsForm(errors)) { if (form.ShowDialog(this) != DialogResult.OK) { return; } editing = modified; } } else { ReloadResults(); return; } } finally { try { File.Delete(fileName); } catch { // Ignore. } } } }