Ejemplo n.º 1
0
        /// <summary>
        /// Open a CSV file with serial numbers and MAC address, read it and create new entries in the database.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        void mainWindow_SendToDatabase(object sender, RoutedEventArgs e)
        {
            const string tag = ClassName + ".LoadTrackersFromFile:";

            string filename = ViewModel.FileSelectionViewModel.FileSelectionModel.Filename;

            Trace.TraceInformation(tag + string.Format("filename={0}", filename));

            string message = string.Format(
                Local.Resources.LoadToDatabaseConfirmation,
                filename);

            MessageBoxResult confirmation = MessageBox.Show(
                message,
                Local.Resources.LoadToDatabaseConfirmationCaption,
                MessageBoxButton.OKCancel,
                MessageBoxImage.Question);

            if (confirmation == MessageBoxResult.Cancel)
            {
                Trace.TraceInformation(tag + "Cancelled by the user.");
                return;
            }

            try
            {
                var      reader        = new StreamReader(filename);
                DateTime batchDateTime = File.GetCreationTime(filename);
                Gateway.GatewayEntities gatewayEntities = GetGatewayEntities();

                TrackerLoader.LoadTrackers(reader, gatewayEntities, batchDateTime);
                reader.Close();
            }
            catch (FileNotFoundException)
            {
                Trace.TraceError(tag + "File not found.");
            }
            catch (ArgumentException)
            {
                Trace.TraceError(tag + "Empty filename.");
            }

            Trace.TraceInformation(tag + ExitText);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load a file, adding entries to the job list for possible printing later.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        void mainWindow_LoadFile(object sender, RoutedEventArgs e)
        {
            string filename = ViewModel.FileSelectionViewModel.FileSelectionModel.Filename;

            List <Job> jobList = TrackerLoader.LoadTrackersFromFileToList(filename);

            if (jobList != null)
            {
                if (jobList.Count < 1)
                {
                    MessageBox.Show(
                        Local.Resources.NoRecordsFoundInFile, Local.Resources.ImportError,
                        MessageBoxButton.OK,
                        MessageBoxImage.Exclamation);
                }
                else
                {
                    foreach (Job j in jobList)
                    {
                        ViewModel.JobListViewModel.JobList.Add(j);
                    }
                }
            }
        }