コード例 #1
0
        //Try to load the images from the DB file.
        Boolean LoadImagesFromDB(Template template)
        {
            if (this.dbData.CreateDB(template))
            {
                // When we are loading from an existing data file, ensure that the template in the template db matches  stored in the data db
                List<string> errors = CheckCodesVsImageData();
                if (errors.Count > 0)
                {
                    DlgTemplatesDontMatch dlg = new DlgTemplatesDontMatch(errors);
                    dlg.Owner = this;
                    bool? result = dlg.ShowDialog();
                    if (result == true)
                    {
                        this.state.immediateExit = true;
                        Application.Current.Shutdown();
                        return true;
                    }
                    else
                    {
                        this.dbData.templateTable =  dbData.CreateDataTableFromDatabaseTable(Constants.TABLETEMPLATE);
                    }
                }

                // We generate the data user interface controls from the template description after the database has been created from the template
                myControls.GenerateControls(dbData);
                MenuItemControlsInSeparateWindow_Click(this.MenuItemControlsInSeparateWindow, null);  //this.ControlsInMainWindow();
                this.dbData.CreateLookupTables();
                this.dbData.GetImagesAll();
                return true;
            }
            return false;
        }
コード例 #2
0
        // Load the code template and then the images from either the database (if it exists) or the actual images (if it doesn't exist)
        private void loadImagesFromSources()
        {
            // First, select a template file which should reside with  the image set, otherwise abort loading (which means the user can try again later)
            // Also pass it the last image folder / template file viewed, which will be shown in the file dialog
            string tpath = persist.ReadLastImageFolderPath();       // the last path opened by the user is stored in the registry
            string filename = persist.ReadLastImageTemplateName();  // the template filname opened by the user is stored in the registry

            tpath = Utilities.GetTemplateFileFromUser(tpath, filename);  // Returns the path and the file name
            if (tpath == null) return;
            // Parse the returned file path to get just the filename and the path to the folder.
            filename = System.IO.Path.GetFileName(tpath);
            if (filename.Equals ("")) filename = Constants.DBTEMPLATEFILENAME;
            persist.WriteLastImageTemplateName(filename);  // We should really do this on exit as well, but I didn't feel like storing it

            tpath = System.IO.Path.GetDirectoryName(tpath);

            if ("" == tpath || null == tpath) return;

            this.FolderPath = tpath;        // We keep the path in two places for convenience of referencing them
            this.dbData.FolderPath = tpath;

            // Create the template to the Timelapse Template database
            this.template = new Template();

            if (!template.Open(this.FolderPath, filename)) return;

            // We now have the template file. Load the TemplateTable from that file, which makes it data accessible through its table
            template.LoadTemplateTable();

            // Find the .ddb file in the image set folder. If a single .ddb file is found, use that one
            // If there are multiple .ddb files, ask the use to choose one and use that
            // However, if the user cancels that choice, just abort.
            // If there are no .ddb files, then just create the standard one.
            switch (this.dbData.FindFile())
            {
                case 0: // An existing .ddb file is available
                    if (this.LoadImagesFromDB(template) == true)
                    {
                        if (state.immediateExit) return;
                        LoadComplete(false);
                    }
                    break;
                case 1: // User cancelled the process of choosing between .ddb files
                    if (state.immediateExit) return;
                    break;
                case 2: // There are no existing .ddb files
                default:
                    if (LoadDByScanningImageFolder() == false)
                    {
                        DlgMessageBox dlgMB = new DlgMessageBox();

                        dlgMB.MessageTitle = "No Images Found in the Image Set Folder";
                        dlgMB.MessageProblem = "There doesn't seem to be any JPG images in your chosen image folder:";
                        dlgMB.MessageProblem += Environment.NewLine + "\u2022 " + this.FolderPath + Environment.NewLine;
                        dlgMB.MessageReason = "\u2022 The folder has no JPG files in it (image files ending in '.jpg'), or" + Environment.NewLine;
                        dlgMB.MessageReason += "\u2022 You may has selected the wrong folder, i.e., a folder other than the one containing the images.";
                        dlgMB.MessageSolution = "\u2022 Check that the chosen folder actually contains JPG images (i.e., a 'jpg' suffix), or" + Environment.NewLine;
                        dlgMB.MessageSolution += "\u2022 Choose another folder.";
                        dlgMB.IconType = MessageBoxImage.Error;
                        dlgMB.ButtonType = MessageBoxButton.OK;
                        dlgMB.ShowDialog();
                        return;
                    }
                    break;
            }
            state.isContentChanged = false; // We've altered some content

            // For persistance: set a flag if We've opened the same image folder we worked with in the last session.
            // If its different, saved the new folder path
            this.ImageFolderReopened = (tpath == this.FolderPath) ? true : false;
        }
コード例 #3
0
ファイル: DBData.cs プロジェクト: saulgreenberg/Timelapse
 /// <summary>
 /// Create a database file (if needed) and connect to it. Also keeps a local copy of the template
 /// </summary>
 /// <returns></returns>
 public bool CreateDB(Template template)
 {
     // Create the DB
     try
     {
         this.DB = new SQLiteWrapper(this.FilePath);
         this.templateTable = template.templateTable;
         return true;
     }
     catch
     {
         return false;
     }
 }