Accusoft.FSInvoices1.Net - Updated
Add a Row to a Line Item Table

For your application to be able to add or delete a row in a Line Item Table, it will need all of the following:

  1. FormResult generated by processing images of a document with Accusoft.FSInvoices.Processor.Anayze().
  2. Provide a GUI with the following features:
    1. A viewing window where the image files that were processed by Accusoft.FSInvoices.Processor.Anayze() can be loaded and edited.
    2. Ability to coordinate the information in FormResult with the loaded image.
  3. A template indicating what information in FormResult is relevant to the document processed by Accusoft.FSInvoices.Processor.Anayze() .

The FormResult returned by Accusoft.FSInvoices.Processor.Anayze() will contain the tables defined in FormDefinition. If a defined table is not found in the document, FormResult will report that table as an empty table (i.e. zero rows). As a result, the created GUI (item 2 above) needs to have the ability to present all tables, even empty ones, to the user for editing. For brevity, from this point on, this ability will be referred to as a Table Editor. In order for the Table Editor to add or delete rows, it needs to interact with a FormResult which contains all the information FormSuite for Invoices has collected for that table. All the methods relating to the Table Editor are found in the FormTable class.

The application acquires all the tables in FormResult with the following call:

 ReadOnlyCollection<FormTable> tables = FormResult .Tables();

The application would then use the user’s feedback from the GUI to determine which table the application needs to modify. The information needed from the GUI is the "area" on the image where the row to be added or deleted. This GUI defined "area" has to physically fit inside the area defined by FormTable.GetArea(). It is up to the application to verify this condition is met.

The methods in FormTable that you need to become familiar with are:

List<DocumentArea> FormTable.GetArea() Returns a list of DocumentArea classes. Each DocumentArea contains a rectangle and a page index. The rectangle defines the area of a table on a page identified by the page index. If the given form table spans several pages, the list will contain several DocumentArea classes.
FormTable.InsertRow(int32 DocumentPageIndex, int32 RowTop,  int32 RowBottom)

This method will insert the data extracted from the image file identified by DocumentPageIndex into the table, physically relative to the other rows in the table.  RowTop and RowBottom are absolute pixel Y-coordinates relative to the Top of the page. 'Physically relative' means that if a table already has a row 4 between page pixel Y-coordinates 100 and 110 and a row 5 between page pixel Y-coordinates 150 and 160 and RowTop  = 120 and RowBottom = 130, then the existing row 5 will become row 6 and the new row will be inserted as row 5.

Any data extracted from the image file between the RowTop and RowBottom that aligns with a column of the table will be added to the table as the column data for that column in the row added. Any data in the image file between the same two limits that does not align with a column will not be added to the table.

Example - how to use FormTable.InsertRow() by selecting an area within the image file page using the mouse capture controls
Copy Code
private void FormModelLineItemTableImage_MouseUp(object sender, MouseEventArgs e)
{
    . . .
    try
    {
        . . .
        Rectangle rubberBand = rubberRect;
        int pageIndex = InvoiceFormModel.Document.IndexOf(currentPage);

        if ((rubberBand.Width > 1 && rubberBand.Height > 1 ) &&
            (InvoiceFormModel.Tables.Count > 0))
        {
            if ((btnLineItemColumnSelect.BackColor == SystemColors.Highlight) &&
                (dgvFormLineItemTable.SelectedCells != null) &&
                (dgvFormLineItemTable.SelectedCells.Count > 0))
            { 
                . . .
           
                InvoiceFormModel.Tables[0].SetColumnHeader(dgvFormLineItemTable.Selected
                                      Cells[0].ColumnIndex, pageIndex, rubberBand);
             }
             
             else if (btnLineItemCellRubberBand.BackColor == SystemColors.Highlight)
             {
                 rubberBand = EditCurrentCellWithSelectedArea(rubberBand);
             }

     
             else if (btnLineItemRowInsert.BackColor == SystemColors.Highlight)
             {
                InvoiceFormModel.Tables[0].InsertRow(pageIndex, rubberBand.Top,
                                                     rubberBand.Bottom);
             }
           
             InitializeFormLineItemTableView();
        }
    }
}
FormTable.RemoveRow(int RowIndex) This method will allow the application to remove a row of data from a table, regardless of what image file page the data is on