Example #1
0
        /// <summary>
        /// This button will pop a new user info dialog.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ProjectEditButton_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            //Update settings with new selected project
            if (_projectCollection != null && _selectedProjectIndex != -1 && _projectCollection.Count > 0)
            {
                //Get selected project
                FieldBooks selectedProject = _projectCollection[_selectedProjectIndex];

                //Build connection file
                SQLiteConnection selectedProjectConnection = new SQLiteConnection(new SQLitePlatformWinRT(), selectedProject.ProjectDBPath);

                //Get metadata
                List <object> inMeta = accessData.ReadTableFromDBConnection(metadataModel.GetType(), null, selectedProjectConnection);

                if (inMeta != null && inMeta.Count > 0)
                {
                    //Show UserInfoPart window as a modal dialog
                    WindowWrapper.Current().Dispatcher.Dispatch(() =>
                    {
                        selectedProject.metadataForProject = inMeta[0] as Metadata;

                        var modal                   = Window.Current.Content as ModalDialog;
                        var view                    = modal.ModalContent as Views.FieldBookDialog;
                        modal.ModalContent          = view = new Views.FieldBookDialog(selectedProject);
                        view.ViewModel.projectEdit += ViewModel_projectEdit;
                        modal.IsModal               = true;
                    });
                }
            }
        }
Example #2
0
        /// <summary>
        /// Will init UI with default values coming from database
        /// </summary>
        /// <param name="incomingData"></param>
        /// <param name="isWaypoint"></param>
        public void AutoFillDialog(FieldBooks incomingData)
        {
            //Set detail
            existingUserDetail = incomingData;

            //Disable some vital information controls
            _enability = false;

            //Set UI values
            _projectName         = existingUserDetail.metadataForProject.ProjectName;
            _selectedProjectType = existingUserDetail.metadataForProject.FieldworkType;
            _startStationNumber  = existingUserDetail.metadataForProject.StationStartNumber;
            _geologistCode       = existingUserDetail.metadataForProject.UserCode;

            _projectLeaderFN = existingUserDetail.metadataForProject.ProjectLeader_FN;
            _projectLeaderMN = existingUserDetail.metadataForProject.ProjectLeader_MN;
            _projectLeaderLN = existingUserDetail.metadataForProject.ProjectLeader_LN;
            _geologistFN     = existingUserDetail.metadataForProject.ProjectUser_FN;
            _geologistMN     = existingUserDetail.metadataForProject.ProjectUser_MN;
            _geologistLN     = existingUserDetail.metadataForProject.ProjectUser_LN;

            //Refresh UI
            RaisePropertyChanged("ProjectName");
            RaisePropertyChanged("GeologistCode");
            RaisePropertyChanged("Enability");

            RaisePropertyChanged("ProjectLeaderFN");
            RaisePropertyChanged("ProjectLeaderMN");
            RaisePropertyChanged("ProjectLeaderLN");
            RaisePropertyChanged("GeologistFN");
            RaisePropertyChanged("GeologistMN");
            RaisePropertyChanged("GeologistLN");
        }
Example #3
0
        /// <summary>
        /// Will delete an entire field book and start fresh
        /// </summary>
        public async void DeleteFieldBook()
        {
            //Clear map page of any layers before deleting them, else they won't be.
            EventHandler deleteLayerRequest = deleteAllLayers;

            if (deleteLayerRequest != null)
            {
                deleteLayerRequest(this, null);
            }

            //In case user is deleting the only project
            if (_projectCollection.Count > 1)
            {
                //Update application to be set as the first project in the list
                int newIndex = 0;
                while (newIndex == _selectedProjectIndex)
                {
                    newIndex++;
                }

                FieldBooks resetProject = _projectCollection[newIndex];
                localSetting.SetSettingValue(ApplicationLiterals.KeywordFieldProject, _projectCollection[newIndex].ProjectPath);
                localSetting.SetSettingValue(DatabaseLiterals.FieldUserInfoFWorkType, _projectCollection[newIndex].metadataForProject.FieldworkType);
                localSetting.SetSettingValue(DatabaseLiterals.FieldUserInfoUCode, _projectCollection[newIndex].metadataForProject.UserCode);
                localSetting.SetSettingValue(DatabaseLiterals.FieldUserInfoID, _projectCollection[newIndex].metadataForProject.MetaID);

                ApplicationData.Current.SignalDataChanged();
                DataAccess.DbPath = _projectCollection[newIndex].ProjectDBPath;
            }



            //Delete
            if (_projectCollection[_selectedProjectIndex].ProjectPath != null && _projectCollection[_selectedProjectIndex].ProjectPath != string.Empty)
            {
                StorageFolder folderToDelete = await StorageFolder.GetFolderFromPathAsync(_projectCollection[_selectedProjectIndex].ProjectPath);

                try
                {
                    await folderToDelete.DeleteAsync();
                }
                catch (Exception)
                {
                }
            }



            //If user is trying to delete the only loaded field book
            if (_projectCollection.Count == 1)
            {
                AddNewProject();
            }

            //Refresh page
            FillProjectCollectionAsync();
        }
Example #4
0
        /// <summary>
        /// From a given field book, will open a user info dialog
        /// </summary>
        /// <param name="stationReport"></param>
        public void PopUserInfo(FieldBooks projectDetails)
        {
            var modal = Window.Current.Content as ModalDialog;
            var view  = modal.ModalContent as Views.FieldBookDialog;

            view = new Views.FieldBookDialog(projectDetails);
            //view.Tag = ReportDetailedStation;
            modal.ModalContent = view;
            modal.IsModal      = true;
        }
Example #5
0
        /// <summary>
        /// Will delete the selected field book from local state
        /// </summary>
        /// <param name="sender"></param>
        public async void ValidateDeleteProject(object sender)
        {
            //Get selected book
            FieldBooks selectedProject = _projectCollection[_selectedProjectIndex];

            //Ask user for backup
            var           loadLocalization = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
            ContentDialog backupDialog     = new ContentDialog()
            {
                Title               = loadLocalization.GetString("ProjectBackupTitle"),
                Content             = loadLocalization.GetString("ProjectBackupContent"),
                PrimaryButtonText   = loadLocalization.GetString("Generic_ButtonYes/Content"),
                SecondaryButtonText = loadLocalization.GetString("Generic_ButtonNo/Content")
            };

            backupDialog.Closed += BackupDialog_Closed;
            await backupDialog.ShowAsync();
        }
        public FieldBookDialog(FieldBooks inProject, bool init = false)
        {
            if (inProject != null)
            {
                incomingProject = inProject;
            }

            if (init)
            {
                isForInit = true;
            }
            this.InitializeComponent();

            this.ViewModel = new FieldBookDialogViewModel();

            this.Loading += UserInfoPart_Loading;
            this.userInfoSaveButton.GotFocus -= userInfoSaveButton_GotFocusAsync;
            this.userInfoSaveButton.GotFocus += userInfoSaveButton_GotFocusAsync; //bug 306
        }
Example #7
0
        /// <summary>
        /// This button will delete the selected project/field book from the local state folder.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public async void ProjectDeleteButton_TappedAsync(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            //Make sure something is selected and that user is not trying to delete the only project left
            if (_projectCollection != null && _selectedProjectIndex != -1)
            {
                FieldBooks selectedBook = _projectCollection[_selectedProjectIndex];

                var           loadLocalization = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
                ContentDialog deleteBookDialog = new ContentDialog()
                {
                    Title               = loadLocalization.GetString("ProjectDeleteDialogTitle"),
                    Content             = loadLocalization.GetString("ProjectDeleteDialogContent") + " (" + selectedBook.metadataForProject.Geologist + ", " + selectedBook.metadataForProject.ProjectName + ").",
                    PrimaryButtonText   = loadLocalization.GetString("Generic_ButtonYes/Content"),
                    SecondaryButtonText = loadLocalization.GetString("Generic_ButtonNo/Content")
                };
                deleteBookDialog.Style = (Style)Application.Current.Resources["DeleteDialog"];
                ContentDialogResult cdr = await deleteBookDialog.ShowAsync();

                if (cdr == ContentDialogResult.Primary)
                {
                    ValidateDeleteProject(this);
                }
            }
        }
Example #8
0
        /// <summary>
        /// Will start a backup process for field books.
        /// </summary>
        /// <returns></returns>
        public async Task BackupFieldBook()
        {
            //Set progress ring
            _progressRingActive     = true;
            _progressRingVisibility = true;
            RaisePropertyChanged("ProgressRingActive");
            RaisePropertyChanged("ProgressRingVisibility");

            //Variables
            List <StorageFile> FilesToBackup = new List <StorageFile>();
            FileServices       fs            = new FileServices();

            //Iterate through field book folder files
            //Make sure something is selected and that user is not trying to delete the only project left
            if (_projectCollection != null && _selectedProjectIndex != -1)
            {
                FieldBooks    selectedBook = _projectCollection[_selectedProjectIndex];
                StorageFolder fieldBook    = await StorageFolder.GetFolderFromPathAsync(selectedBook.ProjectPath);

                //Get a list of files from field book
                IReadOnlyList <StorageFile> fieldBookPhotosRO = await fieldBook.GetFilesAsync();

                //calculate new name for output database in the archive
                string       uCode            = currentLocalSettings.Containers[ApplicationLiterals.LocalSettingMainContainer].Values[Dictionaries.DatabaseLiterals.FieldUserInfoUCode].ToString();
                FileServices fService         = new FileServices();
                string       newName          = fService.CalculateDBCopyName(uCode) + ".sqlite";
                StorageFile  databaseToRename = null;

                //Build list of files to add to archive
                foreach (StorageFile files in fieldBookPhotosRO)
                {
                    //Get databases
                    if (files.Name.ToLower().Contains(".sqlite") && files.Name.Contains(Dictionaries.DatabaseLiterals.DBName))
                    {
                        databaseToRename = files;
                    }
                    else if (!files.Name.Contains("zip"))
                    {
                        FilesToBackup.Add(files);
                    }
                }

                //Copy and rename database
                if (databaseToRename != null)
                {
                    StorageFile newFile = await databaseToRename.CopyAsync(fieldBook, newName);

                    FilesToBackup.Add(newFile);

                    //Zip and Copy
                    var loadLocalization = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
                    await fs.SaveArchiveCopy(FilesToBackup, selectedBook.ProjectPath, selectedBook.metadataForProject.UserCode, selectedBook.metadataForProject.ProjectName + "_");

                    await newFile.DeleteAsync();
                }
            }

            //Unset progress ring
            _progressRingActive     = false;
            _progressRingVisibility = false;
            RaisePropertyChanged("ProgressRingActive");
            RaisePropertyChanged("ProgressRingVisibility");

            return;
        }
Example #9
0
        /// <summary>
        /// Will fill the project collection with information related to it
        /// </summary>
        private async void FillProjectCollectionAsync()
        {
            _projectCollection.Clear();

            List <string> invalidFieldBookToDelete = new List <string>();

            //Iterate through local state folder
            IReadOnlyList <StorageFolder> localStateFolders = await ApplicationData.Current.LocalFolder.GetFoldersAsync();

            IEnumerable <StorageFolder> reverseStateList = localStateFolders.Reverse();

            foreach (StorageFolder sf in reverseStateList)
            {
                //Get files
                IReadOnlyList <StorageFile> localFiles = await sf.GetFilesAsync();

                foreach (StorageFile sfi in localFiles)
                {
                    //Get the database
                    if (sfi.FileType.Contains("sql") && sfi.DisplayName == DatabaseLiterals.DBName)
                    {
                        FieldBooks currentDB = new FieldBooks();

                        using (SQLiteConnection currentConnection = accessData.GetConnectionFromPath(sfi.Path))
                        {
                            List <object> metadataTableRows = accessData.ReadTableFromDBConnectionWithoutClosingConnection(metadataModel.GetType(), string.Empty, currentConnection);
                            foreach (object m in metadataTableRows)
                            {
                                //For metadata
                                Metadata met = m as Metadata;
                                currentDB.CreateDate        = met.StartDate;
                                currentDB.GeologistGeolcode = met.Geologist + "[" + met.UserCode + "]";
                                //currentDB.metadataForProject.FieldworkType = met.FieldworkType;
                                //currentDB.metadataForProject.MetaID = met.MetaID;
                                currentDB.ProjectPath        = Path.GetDirectoryName(sfi.Path);
                                currentDB.ProjectDBPath      = sfi.Path;
                                currentDB.metadataForProject = m as Metadata;
                            }

                            //For stations
                            string        stationQuerySelect = "SELECT *";
                            string        stationQueryFrom   = " FROM " + DatabaseLiterals.TableStation;
                            string        stationQueryWhere  = " WHERE " + DatabaseLiterals.TableStation + "." + DatabaseLiterals.FieldStationAlias + " NOT LIKE '%" + DatabaseLiterals.KeywordStationWaypoint + "%'";
                            string        stationQueryFinal  = stationQuerySelect + stationQueryFrom + stationQueryWhere;
                            List <object> stationCountResult = accessData.ReadTableFromDBConnectionWithoutClosingConnection(stationModel.GetType(), stationQueryFinal, currentConnection);
                            if (stationCountResult != null && stationCountResult.Count > 0)
                            {
                                currentDB.StationNumber = stationCountResult.Count.ToString();
                            }
                            else if (stationCountResult != null && stationCountResult.Count == 0)
                            {
                                currentDB.StationNumber = "0";
                            }
                            else
                            {
                                currentDB.StationNumber = "?";
                            }
                            if (stationCountResult.Count != 0)
                            {
                                Station lastStation = (Station)stationCountResult[stationCountResult.Count - 1];
                                currentDB.StationLastEntered = lastStation.StationAlias;
                            }

                            //If field book is invalid keep parent folder path at least user will be able to delete it.
                            if (metadataTableRows.Count == 0 && stationCountResult.Count == 0)
                            {
                                StorageFolder parentFolder = await sfi.GetParentAsync();

                                currentDB.ProjectPath = parentFolder.Path;
                            }

                            _projectCollection.Add(currentDB);

                            currentConnection.Close();
                            GC.Collect();
                            GC.WaitForPendingFinalizers();

                            System.Runtime.InteropServices.Marshal.ReleaseComObject(sfi);

                            break; //Forget about other files
                        }
                    }
                }
            }

            //Refresh UI
            RaisePropertyChanged("ProjectCollection");

            //Select the current active project, so it's highlighted in the list view
            ResourceLoader loadLocal = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();

            if (_projectCollection.Count == 0)
            {
                //Show end message
                ContentDialog noFieldBookDialog = new ContentDialog()
                {
                    Title             = loadLocal.GetString("FieldBookPageNoBookTitle"),
                    Content           = loadLocal.GetString("FieldBookPageNoBookContent"),
                    PrimaryButtonText = loadLocal.GetString("GenericDialog_ButtonOK")
                };

                await noFieldBookDialog.ShowAsync();

                _noFieldBookWatermark = true;
                RaisePropertyChanged("NoFieldBookWatermark");

                //Send event about missing field books.
                fieldBooksUpdate?.Invoke(this, false);
            }
            else
            {
                SelectActiveProject();
                _noFieldBookWatermark = false;
                RaisePropertyChanged("NoFieldBookWatermark");

                //Send event about missing field books.
                fieldBooksUpdate?.Invoke(this, true);
            }
        }