private void butSaveTemplate_Click(object sender, EventArgs e) { this.selectedGroupTemplate = ucSingleTemplateEditor1.GetDocumentGroupTemplateWithChangedGeneralProperties(); var groupTemplateWithChangedFields = ucSingleTemplateEditor1.GetDocumentGroupTemplateWithChangedFields(); this.selectedGroupTemplate.DataFields = groupTemplateWithChangedFields.DataFields; this.selectedGroupTemplate.CalculationFields = groupTemplateWithChangedFields.CalculationFields; this.selectedGroupTemplate.ConditionalFields = groupTemplateWithChangedFields.ConditionalFields; var templateProcessor = new TemplateProcessor(Directories.AppRootPath); if (Directories.AllowSaveTemplatesToFiles) { this.selectedGroupTemplate.TemplateGroupName = System.Text.RegularExpressions.Regex.Replace(this.selectedGroupTemplate.TemplateGroupName, @"[^0-9a-zA-Z]", string.Empty); var saved = templateProcessor.SaveTemplateToFile(this.selectedGroupTemplate); if (saved == true) { GroupTemplateSavedInGroupTemplateEditor?.Invoke(this.selectedGroupTemplate); } } else { this.selectedGroupTemplate.TemplateGroupName = System.Text.RegularExpressions.Regex.Replace(this.selectedGroupTemplate.TemplateGroupName, @"[^0-9a-zA-Z]", string.Empty); GroupTemplateSavedInGroupTemplateEditor?.Invoke(this.selectedGroupTemplate); } ucTemplateSelector1.UpdateSelectedTemplateName(selectedGroupTemplate.TemplateGroupName); }
/// <summary> /// Shows the general properties of a group template /// </summary> public void ShowGeneralProperties(DocumentGroupTemplate groupTemplate) { lblClassName.Visible = false; txtClassName.Visible = false; this.groupTemplate = groupTemplate; if (this.groupTemplate != null) { txtGroupName.Text = this.groupTemplate.TemplateGroupName; txtIban.Text = string.Empty; if (this.groupTemplate.PreSelectionCondition.IBANs != null) { foreach (var item in this.groupTemplate.PreSelectionCondition.IBANs) { txtIban.Text = txtIban.Text + item + Environment.NewLine; } } txtKeyWords.Text = string.Empty; if (this.groupTemplate.KeyWords != null) { foreach (var item in this.groupTemplate.KeyWords) { txtKeyWords.Text = txtKeyWords.Text + item + Environment.NewLine; } } } }
/// <summary> /// Checks if a group template has datafields that are still missing in the class template. If a data field is missing, it will be added to the class template (including eg. automatic regexExpressionFinder magic). /// Added datafields are also returned to indicate which fields were added. /// </summary> /// <param name="groupTemplate"></param> /// <param name="classTemplate"></param> /// <param name="inputText"></param> /// <returns></returns> public List <FieldTemplateBase> UpdateFieldsFromGroupTemplate(DocumentGroupTemplate groupTemplate, DocumentClassTemplate classTemplate, string inputText) { var retVal = new List <FieldTemplateBase>(); var fieldSet = classTemplate.DataFields.Select(x => x.Name).ToHashSet(); foreach (var item in groupTemplate.DataFields.ToList()) { if (fieldSet.Contains(item.Name) == false) { var newDataField = AutoCreateDataFieldClassTemplateFromDataFieldGroupTemplate(item, inputText); classTemplate.DataFields.Add(newDataField); retVal.Add(newDataField); } } fieldSet = classTemplate.ConditionalFields.Select(x => x.Name).ToHashSet(); foreach (var item in groupTemplate.ConditionalFields.ToList()) { if (item.OnlyStoreInGroupTemplate == false && fieldSet.Contains(item.Name) == false) { classTemplate.ConditionalFields.Add(item); retVal.Add(item); } } return(retVal); }
private void UcTemplateSelector1_SelectionChanged(string templateName) { if (this.selectedGroupTemplate.TemplateGroupName != templateName) { this.selectedGroupTemplate = this.groupTemplates.Where(x => x.TemplateGroupName == templateName).FirstOrDefault(); ucSingleTemplateEditor1.ShowPropertiesAndDataFields(this.selectedGroupTemplate); } }
private void butNewTemplate_Click(object sender, EventArgs e) { var newTemplate = new DocumentGroupTemplate(); newTemplate.TemplateGroupName = Translation.LanguageStrings.NewGroupTemplateDefaultGroupName; groupTemplates.Add(newTemplate); ucTemplateSelector1.TemplateNames.Add(new StringValue(newTemplate.TemplateGroupName)); }
private void TemplateEditor_GroupTemplateSavedInGroupTemplateEditor(DocumentGroupTemplate savedGroupTemplate) { var template = this.groupTemplates.Where(x => x.TemplateGroupName == savedGroupTemplate.TemplateGroupName).FirstOrDefault(); if (template != null) { template = savedGroupTemplate; } MessageBox.Show(Translation.LanguageStrings.MsgGroupTemplateSaved + ": " + savedGroupTemplate.TemplateGroupName, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary> /// Shows the data fields of a group template /// </summary> public void ShowDataFields(DocumentGroupTemplate groupTemplate) { this.groupTemplate = groupTemplate; var controlList = new List <Control>(); foreach (Control control in flowLayoutPanel1.Controls) { controlList.Add(control); } foreach (Control control in controlList) { flowLayoutPanel1.Controls.Remove(control); control.Dispose(); } if (this.groupTemplate != null && this.groupTemplate.DataFields != null) { foreach (var item in this.groupTemplate.DataFields) { var newDataField = (ucDataFieldGroupTemplate)Activator.CreateInstance(UserControlSelector.DataFieldGroupTemplateUserControl, item); newDataField.Tag = Guid.NewGuid(); newDataField.DataFieldEraser += DeleteDataFieldGroupTemplate; flowLayoutPanel1.Controls.Add(newDataField); } } if (this.groupTemplate != null && this.groupTemplate.CalculationFields != null) { foreach (var item in this.groupTemplate.CalculationFields) { var newCalculationField = (ucCalculationFieldGroupTemplate)Activator.CreateInstance(UserControlSelector.CalculationFieldGroupTemplateUserControl, item); newCalculationField.Tag = Guid.NewGuid(); newCalculationField.CalculationFieldEraser += DeleteCalculationField; flowLayoutPanel1.Controls.Add(newCalculationField); } } if (this.groupTemplate != null && this.groupTemplate.ConditionalFields != null) { foreach (var item in this.groupTemplate.ConditionalFields) { var newConditionalField = (ucConditionalFieldTemplate)Activator.CreateInstance(UserControlSelector.ConditionalFieldTemplateUserControl, item); newConditionalField.Tag = Guid.NewGuid(); newConditionalField.ConditionalFieldEraser += DeleteConditionalField; flowLayoutPanel1.Controls.Add(newConditionalField); } } }
/// <summary> /// Saves group template to the specified directory. /// </summary> /// <param name="template">Group template</param> /// <param name="templateDirectory">Template directory</param> public bool SaveTemplateToFile(DocumentGroupTemplate template, string templateDirectory) { var retVal = false; if (string.IsNullOrWhiteSpace(template.TemplateGroupName) == false) { var templateJson = JsonConvert.SerializeObject(template, Formatting.Indented); var filePath = Path.Combine(templateDirectory, template.TemplateGroupName + ".json.txt"); File.WriteAllText(filePath, templateJson); retVal = true; } return(retVal); }
private void OnButOkClick() { var selectedRows = dataGridView1.SelectedRows; if (selectedRows != null) { if (selectedRows.Count > 0) { foreach (DataGridViewRow row in selectedRows) { this.SelectedGrouptTemplate = row.DataBoundItem as DocumentGroupTemplate; break; } } } this.Close(); }
/// <summary> /// Deletes group template from directory /// </summary> /// <param name="template"></param> /// <returns></returns> public bool DeleteTemplateFile(DocumentGroupTemplate template) { var filePath = Path.Combine(TemplateGroupDirectory, template.TemplateGroupName + ".json.txt"); try { if (File.Exists(filePath)) { File.Delete(filePath); return(true); } else { return(true); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } }
/// <summary> /// Shows a class template (general properties and data fields) within ucSingleTemplateEditor /// </summary> /// <param name="classTemplate">Class template</param> public void ShowPropertiesAndDataFields(DocumentClassTemplate classTemplate, DocumentGroupTemplate groupTemplate) { ucSingleTemplateEditor1.ShowPropertiesAndDataFields(classTemplate); ucExtractedData1.ShowExtractedData(new FieldExtractionResult(), classTemplate, groupTemplate); ucSingleTemplateEditor1.ActivateRegexAndPositionHelper(); }
/// <summary> /// Creates a class template for the input text with the given template name. Datafields will be generated based on the group template. Working regex expression for the data fields will be generated based on their text anchors (if possible). /// </summary> /// <param name="templateName"></param> /// <param name="inputText"></param> /// <param name="baseGroupTemplate"></param> /// <returns></returns> public DocumentClassTemplate AutoCreateClassTemplate(string templateName, string inputText, DocumentGroupTemplate baseGroupTemplate) { // var genericRechnung = JsonConvert.DeserializeObject<DocumentGroupTemplate>(File.ReadAllText(Path.Combine(appRootPath, "GenericTemplates", "GenericTemplateRechnungen.json.txt"))); //var genericRechnung = GetDocumentGroupTemplateByName("Rechnung", baseGroupTemplate); var retVal = new DocumentClassTemplate(); if (baseGroupTemplate != null) { retVal.TemplateClassName = templateName; retVal.TemplateGroupName = baseGroupTemplate.TemplateGroupName; RegexExpressionFinderResult regexResult; if (TryFindRegexMatchExpress(inputText, string.Empty, string.Empty, DataFieldType.AnchorLessIBAN, false, out regexResult)) { // retVal.PreSelectionCondition.IBANs = regexResult.MatchingValue.Replace(" ", string.Empty).ToUpper(); foreach (var item in regexResult.AllMatchingValues) { var cleaned = item.Replace(" ", string.Empty).ToUpper(); retVal.PreSelectionCondition.IBANs.Add(cleaned); } } foreach (var item in baseGroupTemplate.DataFields.ToList()) { var newDataField = AutoCreateDataFieldClassTemplateFromDataFieldGroupTemplate(item, inputText); retVal.DataFields.Add(newDataField); } //It's important to create a clone of the List<ConditionalFieldTemplate> to make the reference to the baseGroupTemplate.ConditionalFields disappear var baseConditionalFields = baseGroupTemplate.ConditionalFields.Where(x => x.OnlyStoreInGroupTemplate == false).ToList(); var objectClone = HelperExtensions.JsonDeepClone(baseConditionalFields); retVal.ConditionalFields.AddRange(objectClone); } return(retVal); }
/// <summary> /// Saves group template to the TemplateGroupDirectory. /// </summary> /// <param name="template">Group template</param> public bool SaveTemplateToFile(DocumentGroupTemplate template) { return(SaveTemplateToFile(template, TemplateGroupDirectory)); }
/// <summary> /// Shows general properties and data fields of a group template /// </summary> /// <param name="groupTemplate">Group template</param> public void ShowPropertiesAndDataFields(DocumentGroupTemplate groupTemplate) { ShowGeneralProperties(groupTemplate); ShowDataFields(groupTemplate); }
/// <summary> /// Shows the content of the extraction result /// </summary> /// <param name="extractionResult">Extraction result of type FieldExtractionResult</param> public void ShowExtractedData(FieldExtractionResult extractionResult, DocumentClassTemplate classTemplate, DocumentGroupTemplate groupTemplate) { txtClassName.Text = extractionResult.TemplateClassName; txtGroupName.Text = extractionResult.TemplateGroupName; ucExtractedDataFields1.ShowExtractedDataFields(extractionResult.DataFields); ucExtractedCalculationFields1.ShowExtractedCalculationFields(extractionResult.CalculationFields); var conditionalFields = classTemplate.ConditionalFields; foreach (var item in groupTemplate.ConditionalFields) { if (item.OnlyStoreInGroupTemplate) { conditionalFields.Add(item); } } ucExtractedConditionalFields1.ShowExtractedConditionalFields(extractionResult.ConditionalFields, conditionalFields); }
/// <summary> /// Shows the data fields of a group template /// </summary> /// <param name="groupTemplate">Group template</param> private void ShowDataFields(DocumentGroupTemplate groupTemplate) { ucDataFieldEditor1.ShowDataFields(groupTemplate); }
/// <summary> /// Shows the general properties of a group template /// </summary> private void ShowGeneralProperties(DocumentGroupTemplate groupTemplate) { ucGeneralPropertyEditor1.ShowGeneralProperties(groupTemplate); }
private void TemplateEditor_GroupTemplateDeletedInGroupTemplateEditor(DocumentGroupTemplate deletedGroupTemplate) { this.groupTemplates.Remove(deletedGroupTemplate); MessageBox.Show(Translation.LanguageStrings.MsgGroupTemplateDeleted + ": " + deletedGroupTemplate.TemplateGroupName, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void UcGroupTemplateEditor1_GroupTemplateSavedInGroupTemplateEditor(DocumentGroupTemplate savedGroupTemplate) { GroupTemplateSavedInGroupTemplateEditor?.Invoke(savedGroupTemplate); }
private void UcGroupTemplateEditor1_GroupTemplateDeletedInGroupTemplateEditor(DocumentGroupTemplate deletedGroupTemplate) { GroupTemplateDeletedInGroupTemplateEditor?.Invoke(deletedGroupTemplate); }