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(); }); } }
private void AddMasterFormPages(RasterImage imagesToAdd, DiskMasterForm currentform, string folderName) { try { DiskMasterForm currentMasterForm = currentform; FormRecognitionAttributes attributes = currentMasterForm.ReadAttributes(); FormPages formPages = currentMasterForm.ReadFields(); RasterImage formImage = currentMasterForm.ReadForm(); for (int i = 0; i < imagesToAdd.PageCount; i++) { //Add each new page to the masterform by creating attributes for each page imagesToAdd.Page = i + 1; AddPageToMasterForm(imagesToAdd.Clone(), attributes, -1, null); } //Add image if (formImage != null) { formImage.AddPages(imagesToAdd.CloneAll(), 1, imagesToAdd.PageCount); } else { formImage = imagesToAdd.CloneAll(); } //Only add processing pages for the new pages if (formPages != null) { for (int i = 0; i < imagesToAdd.PageCount; i++) { formPages.Add(new FormPage(formPages.Count + 1, imagesToAdd.XResolution, imagesToAdd.YResolution)); } } else { //No processing pages exist so we must create them FormRecognitionEngine recognitionEngine = SetupRecognitionEngine(); FormProcessingEngine tempProcessingEngine = new FormProcessingEngine(); tempProcessingEngine.OcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false); //tempProcessingEngine.BarcodeEngine = barcodeEngine; for (int i = 0; i < recognitionEngine.GetFormProperties(attributes).Pages; i++) { tempProcessingEngine.Pages.Add(new FormPage(i + 1, imagesToAdd.XResolution, imagesToAdd.YResolution)); } formPages = tempProcessingEngine.Pages; } //FormField newField = null; //AnnHiliteObject newObject = new AnnHiliteObject(); //newField = new TextFormField(); //newField.Name = "test"; //newField.Bounds = new LogicalRectangle(50, 50, 50, 50, LogicalUnit.Pixel); //FormField newField1 = null; //AnnHiliteObject newObject1 = new AnnHiliteObject(); //newField1 = new OmrFormField(); //newField1.Name = "test1"; //newField1.Bounds = new LogicalRectangle(50, 50, 50, 50, LogicalUnit.Pixel); //newObject.Tag = newField; //newObject1.Tag = newField1; //FormField currentField = newObject.Tag as FormField; //FormField currentField1 = newObject1.Tag as FormField; //formPages[0].Add(currentField); //formPages[0].Add(currentField1); currentMasterForm.WriteForm(formImage); currentMasterForm.WriteAttributes(attributes); currentMasterForm.WriteFields(formPages); DBHelper.UpdateTifPageCount(formImage.PageCount.ToString(), folderName); } catch (Exception ex) { throw; } }
private bool AddField(DiskMasterForm currentform, List <XmlModel> model) { try { DiskMasterForm currentMasterForm = currentform; FormRecognitionAttributes attributes = currentMasterForm.ReadAttributes(); FormPages formPages = currentMasterForm.ReadFields(); RasterImage formImage = currentMasterForm.ReadForm(); foreach (XmlModel xmlModel in model) { int i = formPages[xmlModel.PageNumber - 1].Count; formPages[xmlModel.PageNumber - 1].RemoveRange(0, i); foreach (XmlDetail xmlDetail in xmlModel.Detail) { FormField newField = null; if (xmlDetail.FieldInfo.ObjectId == -51) // For textfield => -51 //for OmrField => -50 { newField = new TextFormField(); (newField as TextFormField).EnableIcr = xmlDetail.FieldInfo.OcrFieldInfo.EnableICR; (newField as TextFormField).EnableOcr = xmlDetail.FieldInfo.OcrFieldInfo.EnableOCR; (newField as TextFormField).Type = (xmlDetail.FieldInfo.OcrFieldInfo.Character == true ? TextFieldType.Character : (xmlDetail.FieldInfo.OcrFieldInfo.Numeric == true ? TextFieldType.Numerical : TextFieldType.Data)); if (xmlDetail.FieldInfo.OcrFieldInfo.CellBoarders) { newField.Dropout |= DropoutFlag.CellsDropout; } else { newField.Dropout &= ~DropoutFlag.CellsDropout; } if (xmlDetail.FieldInfo.OcrFieldInfo.Words) { newField.Dropout |= DropoutFlag.WordsDropout; } else { newField.Dropout &= ~DropoutFlag.WordsDropout; } } else { newField = new OmrFormField(); if (xmlDetail.FieldInfo.OmrFieldInfo.WithFrame) { (newField as OmrFormField).FrameMethod = OcrOmrFrameDetectionMethod.WithFrame; } else if (xmlDetail.FieldInfo.OmrFieldInfo.WithoutFrame) { (newField as OmrFormField).FrameMethod = OcrOmrFrameDetectionMethod.WithoutFrame; } else if (xmlDetail.FieldInfo.OmrFieldInfo.Auto) { (newField as OmrFormField).FrameMethod = OcrOmrFrameDetectionMethod.Auto; } if (xmlDetail.FieldInfo.OmrFieldInfo.Lowest) { (newField as OmrFormField).Sensitivity = OcrOmrSensitivity.Lowest; } else if (xmlDetail.FieldInfo.OmrFieldInfo.Low) { (newField as OmrFormField).Sensitivity = OcrOmrSensitivity.Low; } else if (xmlDetail.FieldInfo.OmrFieldInfo.High) { (newField as OmrFormField).Sensitivity = OcrOmrSensitivity.High; } else if (xmlDetail.FieldInfo.OmrFieldInfo.Highest) { (newField as OmrFormField).Sensitivity = OcrOmrSensitivity.Highest; } } newField.Name = xmlDetail.FieldInfo.Name; newField.Bounds = new LeadRect(Convert.ToInt32(Annotations.Engine.AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.X, Leadtools.Annotations.Engine.AnnUnit.Unit, 96)), Convert.ToInt32(Annotations.Engine.AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.Y, Annotations.Engine.AnnUnit.Unit, 96)), Convert.ToInt32(Annotations.Engine.AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.Width, Annotations.Engine.AnnUnit.Unit, 96)), Convert.ToInt32(Annotations.Engine.AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.Height, Annotations.Engine.AnnUnit.Unit, 96))); // newField.Bounds= new LogicalRectangle(AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.X, AnnUnit.Unit, 96), AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.Y, AnnUnit.Unit, 96), AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.Width, AnnUnit.Unit, 96), AnnUnitConverter.ConvertToPixels(xmlDetail.Cordinates.Height, AnnUnit.Unit, 96), LogicalUnit.Pixel); Annotations.Engine.AnnHiliteObject newObject = new Annotations.Engine.AnnHiliteObject(); newObject.Tag = newField; FormField currentField = newObject.Tag as FormField; formPages[xmlModel.PageNumber - 1].Add(currentField); } } currentMasterForm.WriteForm(formImage); currentMasterForm.WriteAttributes(attributes); currentMasterForm.WriteFields(formPages); return(true); } catch (Exception ex) { return(false); throw; } }