/// Copyright (c) 2021 Iiro Iivanainen, Harri Linna, Jere Pakkanen, Riikka Vilavaara /// /// Permission is hereby granted, free of charge, to any person obtaining /// a copy of this software and associated documentation files (the /// "Software"), to deal in the Software without restriction, including /// without limitation the rights to use, copy, modify, merge, publish, /// distribute, sublicense, and/or sell copies of the Software, and to /// permit persons to whom the Software is furnished to do so, subject to /// the following conditions: /// /// The above copyright notice and this permission notice shall be included /// in all copies or substantial portions of the Software. /// /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, /// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF /// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. /// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY /// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, /// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE /// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /// using System.Collections.Generic; using System.Windows; using Microsoft.Win32; using System.Windows.Controls; using System.IO; namespace GroundhogApp.Dialogs { /// /// Interaction logic for ConnectorDialog.xaml /// public partial class ConnectorDialog : Window { public ConnectorDialog(List> InitialCoordinates, string CopyFolder) { InitializeComponent(); DataContext = this; Coordinates = new List>(); FilePath = ""; ConnectorName = ""; DataDescription = ""; if (CopyFolder != null) CopyToFolderCheckBox.IsEnabled = true; else CopyToFolderCheckBox.IsEnabled = false; foreach (var coordinate in InitialCoordinates) { Coordinates.Add(new List { coordinate[0], coordinate[1], coordinate[2] }); // TODO: Accept multiple coordinates at once. } } public List> Coordinates { get; set; } public string FilePath { get ; set; } public string ConnectorName { get; set; } public string DataDescription { get; set; } static public bool CopyToFolder { get; set; } /// /// Opens a dialog for choosing the file. /// /// /// private void OpenBtn_Click(object sender, RoutedEventArgs e) { DataContext = this; var openFileDialog = new OpenFileDialog(); openFileDialog.Title = "Opening attachment"; if (openFileDialog.ShowDialog() == true) { FilePathBox.Text = openFileDialog.FileName; ConnectorNameBox.Text = System.IO.Path.GetFileNameWithoutExtension(openFileDialog.FileName); FileInfo fileInfo = new FileInfo(openFileDialog.FileName); FileSize.Text = Utilities.FormatBytes(fileInfo.Length); } } /// /// Checks if the file specified exists and closes the dialog for adding the data. /// /// /// private void AddButton_Click(object sender, RoutedEventArgs e) { FilePath = FilePathBox.Text; ConnectorName = ConnectorNameBox.Text; DataDescription = DescriptionBox.Text; if (!System.IO.File.Exists(FilePath)) { MessageBox.Show("File does not exists in the specified location " + FilePath, "Alert", MessageBoxButton.OK, MessageBoxImage.Information); return; } DialogResult = true; } /// /// Closes the dialog cancelling the addition of data. /// /// /// private void CancelButton_Click(object sender, RoutedEventArgs e) { DialogResult = false; } /// /// Simple validation allowing only integers above 0. /// /// /// private void NumberValidationTextBox(object sender, TextChangedEventArgs e) { TextBox tb = sender as TextBox; int result; int.TryParse(tb.Text, out result); if (result < 1) { tb.Text = 1.ToString(); tb.Select(tb.Text.Length, 0); // Move the cursor at the end of the textbox. } else tb.Text = result.ToString(); } } }