Example #1
0
        private void downloadDataFromDatabase()
        {
            //RT 27/2/17 - This now downloads for given service sheet numbers
            bool validEntries = validateEntries();

            if (!validEntries)
            {
                return;
            }

            int  startNumber;
            bool startNumberParsed = int.TryParse(SubmissionStartNumber, out startNumber);
            int  endNumber;
            bool endNumberParsed = int.TryParse(SubmissionEndNumber, out endNumber);


            List <ServiceSheetViewModel> serviceSheetsDownloaded = DbServiceSheet.downloadServiceSheetsForSubmissions(startNumber, endNumber);

            if (serviceSheetsDownloaded == null)
            {
                return;
            }
            AllServiceSheets = new ObservableCollection <ServiceSheetViewModel>(serviceSheetsDownloaded);

            //Now we need to download the images from Canvas
            //RT 7/2/17 - Moving to caching
            //UserViewModel canvasUserVM = new UserViewModel(UserViewModel.MODE_CANVAS);
            //UserView userView = new UserView();
            //userView.DataContext = canvasUserVM;
            //bool? userResult = userView.ShowDialog();

            ////RT 3/12/16 - The box may have been cancelled
            //if (userResult != true)
            //{
            //    MessageBox.Show("Unable to download images. Exiting.");
            //    AllServiceSheets = null;
            //    return;
            //}

            UserViewModel userResult = CanvasDataReader.getCanvasUser();

            //RT 3/12/16 - The box may have been cancelled
            if (userResult == null)
            {
                MessageBox.Show("Unable to download images. Exiting.");
                AllServiceSheets = null;
                return;
            }

            CanvasImageDownloadViewModel imageVM           = new CanvasImageDownloadViewModel(AllServiceSheets.ToList(), userResult, true);
            CanvasImageDownloadView      imageDownloadView = new CanvasImageDownloadView();

            imageDownloadView.DataContext = imageVM;
            bool?result = imageDownloadView.ShowDialog();

            //Set the servicesheets back to the result from the dialog

            if (result == true)
            {
                AllServiceSheets = new ObservableCollection <ServiceSheetViewModel>(imageVM.AllServices);
            }
            else
            {
                AllServiceSheets = new ObservableCollection <ServiceSheetViewModel>();
            }
        }
Example #2
0
        private void downloadCanvasData(object canvasPasswordBox)
        {
            //RT 7/2/17 - Moving the canvas user to the cache
            //CanvasUserVM = new UserViewModel(UserViewModel.MODE_CANVAS);
            //UserView userView = new UserView();
            //userView.DataContext = CanvasUserVM;
            //bool? userResult = userView.ShowDialog();

            UserViewModel userResultVM = CanvasDataReader.getCanvasUser();

            //RT 3/12/16 - The box may have been cancelled
            if (userResultVM == null)
            {
                return;
            }

            //RT 25/2/17 - Get the latest submission date from the database
            DateTime?lastSubmissionDateFound = DbServiceSheet.getLastSubmissionDate();

            if (lastSubmissionDateFound == null)
            {
                return;
            }

            DateTime lastSubmissionDate = lastSubmissionDateFound.Value;

            lastSubmissionDate = lastSubmissionDate.AddDays(-1);

            //CanvasUserVM.CanvasPasswordBox = (PasswordBox)canvasPasswordBox;
            //RT 26/11/16 - Changing the password to use a PasswordBox for security
            //AllServiceSheets = CanvasDataReader.downloadXml(CanvasUser.Username, CanvasUser.Password, DtStartSubmissionsDownload, DtEndSubmissionsDownload);
            AllServiceSheets = CanvasDataReader.downloadXml(userResultVM, lastSubmissionDate, DateTime.Now);

            //If no submissions have been returned, then exit.  None available, or error has occured.  Error will have been shown already
            if (AllServiceSheets == null)
            {
                return;
            }

            //Now we need to download the images from Canvas, using a progress bar
            CanvasImageDownloadView      imageDownloadView = new CanvasImageDownloadView();
            List <ServiceSheetViewModel> serviceSheetList  = new List <ServiceSheetViewModel>(AllServiceSheets);
            CanvasImageDownloadViewModel imageVM           = new CanvasImageDownloadViewModel(serviceSheetList, userResultVM, false);

            imageDownloadView.DataContext = imageVM;
            bool?result = imageDownloadView.ShowDialog();

            //Set the servicesheets back to the result from the dialog

            if (result == true)
            {
                AllServiceSheets = new ObservableCollection <ServiceSheetViewModel>(imageVM.AllServices);
            }
            else
            {
                AllServiceSheets = new ObservableCollection <ServiceSheetViewModel>();
            }

            //RT23/1/17 - Check if the sheets have already been imported to the database
            List <int> dbSubmissionNumbers = DbServiceSheet.getAllSubmissionNumbers();

            removeServiceSheetsAlreadyProcessed(dbSubmissionNumbers);
        }
        private void downloadCanvasData(object canvasPasswordBox)
        {
            CanvasUserVM = new CanvasUserViewModel();
            CanvasUserView userView = new CanvasUserView();
            userView.DataContext = CanvasUserVM;
            bool? userResult = userView.ShowDialog();

            //RT 3/12/16 - The box may have been cancelled
            if (userResult != true)
            {
                return;
            }
            
            //CanvasUserVM.CanvasPasswordBox = (PasswordBox)canvasPasswordBox;
            //RT 26/11/16 - Changing the password to use a PasswordBox for security
            //AllServiceSheets = CanvasDataReader.downloadXml(CanvasUser.Username, CanvasUser.Password, DtStartSubmissionsDownload, DtEndSubmissionsDownload);
            AllServiceSheets = CanvasDataReader.downloadXml(CanvasUserVM, DtStartSubmissionsDownload, DtEndSubmissionsDownload);

            //If no submissions have been returned, then exit.  None available, or error has occured.  Error will have been shown already
            if (AllServiceSheets == null)
            {
                return;
            }

            //Now we need to download the images from Canvas, using a progress bar
            CanvasImageDownloadView imageDownloadView = new CanvasImageDownloadView();
            List<ServiceSheetViewModel> serviceSheetList = new List<ServiceSheetViewModel>(AllServiceSheets);
            CanvasImageDownloadViewModel imageVM = new CanvasImageDownloadViewModel(serviceSheetList, CanvasUserVM);
            imageDownloadView.DataContext = imageVM;
            bool? result = imageDownloadView.ShowDialog();
            //Set the servicesheets back to the result from the dialog

            if (result == true)
            {
                AllServiceSheets = new ObservableCollection<ServiceSheetViewModel>(imageVM.AllServices);
            }
            else
            {
                AllServiceSheets = new ObservableCollection<ServiceSheetViewModel>();
            }
            
        }