Exemple #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>();
            }
        }
Exemple #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);
        }
Exemple #3
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            int maxSubmissions = AllServices.Count;
            List <ServiceSheetViewModel> updatedSubmissions = new List <ServiceSheetViewModel>();
            string downloadUrl;

            string customerSignatureUrl;
            string image1Url;
            string image2Url;
            string image3Url;
            string image4Url;
            string image5Url;

            foreach (ServiceSheetViewModel currentSubmission in AllServices.ToList())
            {
                downloadUrl = currentSubmission.MttEngSignatureUrl;
                ImageSource imgEngSignature = CanvasDataReader.downloadImage(downloadUrl, CanvasUser, FullUrl);

                //If there has been an error with the image download, then return an empty collection
                if (imgEngSignature == null)
                {
                    updatedSubmissions = null;
                    return;
                }

                currentSubmission.MttEngineerSignature = imgEngSignature;
                currentSubmission.MttEngineerSignature.Freeze();


                //Download the customer signature
                customerSignatureUrl = currentSubmission.CustomerSignatureUrl;
                if (!customerSignatureUrl.Equals(""))
                {
                    ImageSource imgCustSignature = CanvasDataReader.downloadImage(customerSignatureUrl, CanvasUser, FullUrl);

                    //If there has been an error with the image download, then return an empty collection
                    if (imgCustSignature == null)
                    {
                        updatedSubmissions = null;
                        return;
                    }

                    currentSubmission.CustomerSignature = imgCustSignature;
                    currentSubmission.CustomerSignature.Freeze();
                }

                //Download all the images, if they exist
                image1Url = currentSubmission.Image1Url;
                if (!image1Url.Equals(""))
                {
                    ImageSource img1 = CanvasDataReader.downloadImage(image1Url, CanvasUser, FullUrl);

                    //If there has been an error with the image download, then return an empty collection
                    if (img1 == null)
                    {
                        updatedSubmissions = null;
                        return;
                    }

                    currentSubmission.Image1 = img1;
                    currentSubmission.Image1.Freeze();
                }

                image2Url = currentSubmission.Image2Url;
                if (!image2Url.Equals(""))
                {
                    ImageSource img2 = CanvasDataReader.downloadImage(image2Url, CanvasUser, FullUrl);

                    //If there has been an error with the image download, then return an empty collection
                    if (img2 == null)
                    {
                        updatedSubmissions = null;
                        return;
                    }

                    currentSubmission.Image2 = img2;
                    currentSubmission.Image2.Freeze();
                }

                image3Url = currentSubmission.Image3Url;
                if (!image3Url.Equals(""))
                {
                    ImageSource img3 = CanvasDataReader.downloadImage(image3Url, CanvasUser, FullUrl);

                    //If there has been an error with the image download, then return an empty collection
                    if (img3 == null)
                    {
                        updatedSubmissions = null;
                        return;
                    }

                    currentSubmission.Image3 = img3;
                    currentSubmission.Image3.Freeze();
                }

                image4Url = currentSubmission.Image4Url;
                if (!image4Url.Equals(""))
                {
                    ImageSource img4 = CanvasDataReader.downloadImage(image4Url, CanvasUser, FullUrl);

                    //If there has been an error with the image download, then return an empty collection
                    if (img4 == null)
                    {
                        updatedSubmissions = null;
                        return;
                    }

                    currentSubmission.Image4 = img4;
                    currentSubmission.Image4.Freeze();
                }

                image5Url = currentSubmission.Image5Url;
                if (!image5Url.Equals(""))
                {
                    ImageSource img5 = CanvasDataReader.downloadImage(image5Url, CanvasUser, FullUrl);

                    //If there has been an error with the image download, then return an empty collection
                    if (img5 == null)
                    {
                        updatedSubmissions = null;
                        return;
                    }

                    currentSubmission.Image5 = img5;
                    currentSubmission.Image5.Freeze();
                }

                updatedSubmissions.Add(currentSubmission);
                CurrentStatus = CurrentStatus + 1;
                (sender as BackgroundWorker).ReportProgress(CurrentStatus);
            }

            //Return the list of submissions with the images
            e.Result = updatedSubmissions;
        }