コード例 #1
0
        private void downloadDatabaseEntries()
        {
            DateTime monthEndDay = MonthFirstDay.AddMonths(1);

            monthEndDay = monthEndDay.AddDays(-1);

            List <ServiceSheetViewModel> downloadedServiceSheets = DbServiceSheet.downloadServiceSheets(MonthFirstDay, monthEndDay);

            if (downloadedServiceSheets == null)
            {
                return;
            }

            //Create the list of possible days for each engineer
            Dictionary <DateTime, List <DbEmployee> > missingDays = createPossibleEngineerDaysCalendar();

            Dictionary <DateTime, List <DbEmployee> > actualDays = new Dictionary <DateTime, List <DbEmployee> >();

            if (missingDays == null)
            {
                return;
            }

            //Copy the possible days to the missing.
            //Dictionary<DateTime, List<DbEmployee>> missingDays = new Dictionary<DateTime, List<DbEmployee>>(possibleDays);

            //Create actual days list and update missing list
            updateActualandMissingCalendars(actualDays, missingDays, downloadedServiceSheets);

            //Set the actual and missing calendar days on the calendar rows
            updateCalendarActualAndMissingDates(actualDays, missingDays);
        }
コード例 #2
0
        private void saveActivity()
        {
            bool valid = validateEntry();

            if (!valid)
            {
                return;
            }

            //Need to create the service sheet / day entities and save
            ServiceSheetViewModel serviceSheetCreated = new ServiceSheetViewModel(SelectedUser, SelectedActivity, StartDate, EndDate);

            //Now save
            serviceSheetCreated.SaveToModel();
            bool saveSuccessful = DbServiceSheet.saveSheetsAndDays(serviceSheetCreated);

            if (!saveSuccessful)
            {
                MessageBox.Show("Error saving to database.  Need to show error message!");
                return;
            }
            else
            {
                MessageBox.Show("Activity added to database");
            }
        }
コード例 #3
0
        private void loadHolidayAbsences()
        {
            List <ServiceSheetViewModel> loadedSheets = DbServiceSheet.loadHolidayAbsenceSheets();

            if (loadedSheets == null)
            {
                return;
            }
            AllAbsenceHolidays = new ObservableCollection <ServiceSheetViewModel>(loadedSheets);
        }
コード例 #4
0
        private bool validateEntry()
        {
            if (SelectedUser == null)
            {
                MessageBox.Show("You must select an engineer.");
                return(false);
            }
            else if (SelectedActivity == null)
            {
                MessageBox.Show("You must select an activity.");
                return(false);
            }
            else if (StartDate == new DateTime())
            {
                MessageBox.Show("You must select a start date");
                return(false);
            }
            else if (EndDate == new DateTime())
            {
                MessageBox.Show("You must select an end date");
                return(false);
            }
            else if (StartDate > EndDate)
            {
                MessageBox.Show("Start date must be before end date");
                return(false);
            }

            //Check that a service sheet doesn't exist for the absence dates
            bool?clashingDate = DbServiceSheet.checkForClashingDates(StartDate, EndDate, SelectedUser.Username);

            if (clashingDate == null)
            {
                MessageBox.Show("Error checking duplicates in database. Not saved.  Need to show error message!");
                return(false);
            }
            else if (clashingDate == true)
            {
                MessageBox.Show("A sheet already exists for these dates.");
                return(false);
            }

            return(true);
        }
コード例 #5
0
        private void saveToDatabase()
        {
            //Export to csv
            bool csvExportSuccessful = exportCsvData();

            if (!csvExportSuccessful)
            {
                MessageBox.Show("Error exporting to csv.  Database save not completed");
                return;
            }

            bool saveSuccessful = DbServiceSheet.saveSheetsAndDays(AllServiceSheets);

            if (!saveSuccessful)
            {
                MessageBox.Show("Error saving to database.  Need to show error message!");
                return;
            }
        }
コード例 #6
0
        private void setupUsernameCombobox()
        {
            #if DEBUG
            if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                return;
            }
            #endif

            //Loads the usernames from the Service Sheet table
            List <DbEmployee> usernames = DbServiceSheet.getAllUsers();
            if (usernames == null)
            {
                MessageBox.Show("Error loading usernames");
                Employees = null;
                return;
            }
            Employees = new ObservableCollection <DbEmployee>(usernames);
        }
コード例 #7
0
        private Dictionary <DateTime, List <DbEmployee> > createPossibleEngineerDaysCalendar()
        {
            Dictionary <DateTime, List <DbEmployee> > possibleDays = new Dictionary <DateTime, List <DbEmployee> >();

            //Download all the engineers names

            m_engineers = DbServiceSheet.getAllUsers();
            if (m_engineers == null)
            {
                return(null);
            }

            DateTime calendarStart = MonthFirstDay.Date;
            //Use the entre calendar month
            DateTime calendarEnd = calendarStart.AddMonths(1);

            for (DateTime currentDate = calendarStart; currentDate.Date < calendarEnd.Date; currentDate = currentDate.AddDays(1))
            {
                possibleDays.Add(currentDate, new List <DbEmployee>(m_engineers));
            }

            return(possibleDays);
        }
コード例 #8
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);
        }
コード例 #9
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>();
            }
        }