Exemplo n.º 1
0
        private void CreateMasterForms(RasterImage Image, string masterformsdirectory, string masterformsname, string folderName)
        {
            try
            {
                IMasterFormsCategory parentCategory = null;
                string      _masterformsdirectory   = masterformsdirectory;
                string      _masterformsname        = masterformsname;
                RasterImage _masterformsimage       = Image;
                //nothing selected, add it to root category
                RasterCodecs rasterCodecs = StartUpRasterCodecs();
                DiskMasterFormsRepository workingRepository = new DiskMasterFormsRepository(rasterCodecs, _masterformsdirectory);
                //BuildMasterFormList(workingRepository.RootCategory, _tvMasterForms.Nodes, true);
                parentCategory = workingRepository.RootCategory;
                //parentCategoryNode = _tvMasterForms.Nodes[0];
                //Add master form to repository and tree view
                IMasterForm newForm = parentCategory.AddMasterForm(CreateMasterForm(_masterformsname), null, (RasterImage)null);

                if (_masterformsimage != null)
                {
                    AddMasterFormPages(_masterformsimage, newForm as DiskMasterForm, folderName);
                }
            }
            catch (Exception exp)
            {
                //Messager.ShowError(this, exp);
            }
        }
        public void DeleteChildCategory(IMasterFormsCategory category)
        {
            // Check
            if (category == null)
            {
                throw new ArgumentNullException("category");
            }

            if (!_childCategories.Contains(category))
            {
                throw new ArgumentException("Category not child of this category", "category");
            }

            DiskMasterFormsCategoryExample diskCategory = category as DiskMasterFormsCategoryExample;

            if (diskCategory == null)
            {
                throw new Exception("Invalid category type");                   // cast above failed
            }
            // Call clear to delete all children of this category
            category.Clear();

            // Remove it from the list
            _childCategories.Remove(category);
        }
Exemplo n.º 3
0
        private bool IsFormsNameValid()
        {
            IMasterFormsCategory parentCategory = null;

            DiskMasterFormsRepository workingRepository = new DiskMasterFormsRepository(new RasterCodecs(), _txtMasterFormsDirectory.Text);

            parentCategory = workingRepository.RootCategory;

            //Build array of current form names
            string[] existingForms = new string[parentCategory.MasterForms.Count];
            for (int i = 0; i < parentCategory.MasterForms.Count; i++)
            {
                existingForms[i] = parentCategory.MasterForms[i].Name;
            }

            foreach (string existingForm in existingForms)
            {
                if (existingForm.ToUpper() == _txtMasterFormsName.Text.Trim().ToUpper())
                {
                    MessageBox.Show("That Master Forms already exist", "Error");
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 4
0
 internal DiskMasterFormExample(IMasterFormsRepository repository, string name, string path, IMasterFormsCategory parent)
 {
     _repository       = repository;
     _processingEngine = new FormProcessingEngine();
     _attributes       = null;
     _name             = name;
     _parent           = parent;
     _path             = path;
 }
 internal DiskMasterFormsCategoryExample(IMasterFormsRepository repository, string name, string path, IMasterFormsCategory parent)
 {
     _repository        = repository;
     _name              = name;
     _parent            = parent;
     _path              = path;
     _recognitionEngine = new FormRecognitionEngine();
     _childCategories   = new MasterFormsCategoryCollection();
     _masterForms       = new MasterFormCollection();
 }
 private int GetMasterFormCount(IMasterFormsCategory rootCategory)
 {
     try
     {
         int count = rootCategory.MasterFormsCount;
         foreach (IMasterFormsCategory childCategory in rootCategory.ChildCategories)
         {
             count = count + GetMasterFormCount(childCategory);
         }
         return(count);
     }
     catch
     {
         return(0);
     }
 }
        public void Clear()
        {
            // Delete the child categories first
            while (_childCategories.Count > 0)
            {
                IMasterFormsCategory childCategory = _childCategories[0];

                // Delete it, this will remove itself from the list
                DeleteChildCategory(childCategory);
            }

            // Delete all the master forms in this category
            while (_masterForms.Count > 0)
            {
                IMasterForm masterForm = _masterForms[0];

                // Delete it, this will remove itself from the list
                DeleteMasterForm(masterForm);
            }

            // At this point, we can safely remove the directory
            Directory.Delete(Path);
        }
Exemplo n.º 8
0
        private void UpdateData()
        {
            var recognitionEngineVersion = FormRecognitionEngine.Version;

#if FOR_DOTNET4
            var originalFullTextSearchManager = recognitionEngine.FullTextSearchManager;
#endif

            try
            {
                if (!Directory.Exists(_txtSrcFolder.Text))
                {
                    Invoke((MethodInvoker) delegate { Messager.Show(this, "Please select valid folder", MessageBoxIcon.Error, MessageBoxButtons.OK); });
                    return;
                }

                // Set the data version to latest, we want to update the data to use the latest
                FormRecognitionEngine.Version = FormRecognitionEngine.LatestVersion;

                // Set the full text search engine
                DiskMasterFormsRepository workingRepository = new DiskMasterFormsRepository(_codecs, _txtSrcFolder.Text);

#if FOR_DOTNET4
                if (_cbUseFullTextSearch.Checked)
                {
                    DiskFullTextSearchManager fullTextSearchManager = new DiskFullTextSearchManager();
                    fullTextSearchManager.IndexDirectory    = Path.Combine(workingRepository.Path, "index");
                    recognitionEngine.FullTextSearchManager = fullTextSearchManager;
                }
#endif
                IMasterFormsCategory parentCategory = workingRepository.RootCategory;
                Invoke((MethodInvoker) delegate { _prgbar.Maximum = parentCategory.MasterForms.Count; });

                for (int i = 0; i < _prgbar.Maximum; i++)
                {
                    if (!_isRunning)
                    {
                        return;
                    }

                    Invoke((MethodInvoker) delegate { _prgbar.Value++; });

                    //Get the Original Attributes
                    DiskMasterForm            originalMasterForm = parentCategory.MasterForms[i] as DiskMasterForm;
                    FormRecognitionAttributes originalAttributes = originalMasterForm.ReadAttributes();
                    recognitionEngine.OpenMasterForm(originalAttributes);
                    recognitionEngine.CloseMasterForm(originalAttributes);

                    FormRecognitionOptions    options    = new FormRecognitionOptions();
                    FormRecognitionAttributes attributes = recognitionEngine.CreateMasterForm(parentCategory.MasterForms[i].Name, new Guid(), options);
                    recognitionEngine.CloseMasterForm(attributes);

                    IMasterForm newForm = parentCategory.AddMasterForm(attributes, null, (RasterImage)null);

                    DiskMasterForm currentMasterForm = parentCategory.MasterForms[i] as DiskMasterForm;
                    attributes = currentMasterForm.ReadAttributes();
                    FormPages   formPages = currentMasterForm.ReadFields();
                    RasterImage formImage = currentMasterForm.ReadForm();

                    for (int j = 0; j < formImage.PageCount; j++)
                    {
                        //Get the Page Recognition Options for the original Attributes
                        PageRecognitionOptions pageOptions = GetPageOptions(j, originalAttributes);

                        //Add each new page to the masterform by creating attributes for each page
                        formImage.Page = j + 1;
                        recognitionEngine.OpenMasterForm(attributes);
                        recognitionEngine.DeleteMasterFormPage(attributes, j + 1);
                        recognitionEngine.InsertMasterFormPage(j + 1, attributes, formImage.Clone(), pageOptions, null);
#if FOR_DOTNET4
                        if (_cbUseFullTextSearch.Checked)
                        {
                            recognitionEngine.UpsertMasterFormToFullTextSearch(attributes, "index", null, null, null, null);
                        }
#endif

                        recognitionEngine.CloseMasterForm(attributes);
                    }

                    FormProcessingEngine tempProcessingEngine = new FormProcessingEngine();
                    tempProcessingEngine.OcrEngine     = ocrEngine;
                    tempProcessingEngine.BarcodeEngine = barcodeEngine;

                    for (int j = 0; j < recognitionEngine.GetFormProperties(attributes).Pages; j++)
                    {
                        tempProcessingEngine.Pages.Add(new FormPage(j + 1, formImage.XResolution, formImage.YResolution));
                    }

                    formPages = tempProcessingEngine.Pages;
                    currentMasterForm.WriteAttributes(attributes);

                    currentMasterForm.WriteFields(parentCategory.MasterForms[i].ReadFields());
                }
#if FOR_DOTNET4
                if (recognitionEngine.FullTextSearchManager != null)
                {
                    recognitionEngine.FullTextSearchManager.Index();
                }
#endif
                System.Diagnostics.Process.Start(_txtSrcFolder.Text);
            }
            catch (Exception ex)
            {
                Invoke((MethodInvoker) delegate { Messager.Show(this, ex, MessageBoxIcon.Error); });
            }
            finally
            {
                // Restore the original version
                FormRecognitionEngine.Version = recognitionEngineVersion;
#if FOR_DOTNET4
                recognitionEngine.FullTextSearchManager = originalFullTextSearchManager;
#endif
                _isRunning = false;
                Invoke((MethodInvoker) delegate
                {
                    _prgbar.Value = 0;
                    UpdateControls();
                });
            }
        }