DFT Phone Data Collector

DFT Phone Data Collector

An appliation for extracting statistics from reports

Background

This was created to eventually be merged into Case Creator. Its initial purpose was to enable the bulk parsing, to deal with existing data, of thousands of word documents to extract data for relevant phone info in order to track trends, and will track information as it goes along once it’s incorporated into Case Creator. This project’s initial form was to quickly do a bulk parse of all of our previous examinations in order to figure out what mobile devices we saw the most often. It initially created a list of all the .doc files with a certain name in a specified folder, and then extracted specific word formfields from each document and saved them to a csv file.

I then took the base code from that tool and used it to start this one, with the intent for this tool to be used after every device is examined and for the data to be stored in a spreadsheet on our server.

A look around the application

Screenshots of the tabs

Usage

In order to allow for future changes to our template or the data we wish to collect, the settings tab stores which fields the user wishes to extract. It also allows the user to show all the fields found in the template in a grid, and allows them to be added by double clicking each required row. Once you’ve filled in what fields you wish to copy, you can specify a file in the Main tab. It will then parse the document and pull out the results for all of the fields specified in the settings tab and add them to a new row in the specified spreadsheet file. Any errors will be shown in the list in the Main tab. The end goal of this application would be to incorporate it into my Case Creator application, and use it to automatically parse the data for all phones in the submission upon completion.

A look around the application

Using the application

Code snippet #1

// Parses the fields from the template file
private void GrabTemplateFields()
{
    Word.Application wordApp = new Word.Application();
    Word.Document WordDoc = wordApp.Documents.Open(TemplateLocTB.Text, System.Reflection.Missing.Value, false);
    List<Fields> AllFieldsList = new List<Fields>();
    foreach (Word.FormField EachField in WordDoc.FormFields)
    {
        AllFieldsList.Add(new Fields() { FieldName = EachField.Name, Result = EachField.Result });                
    }
    AllFieldsGrid.ItemsSource = AllFieldsList;
    WordDoc.Close();
}

Code snippet #2

// Parses the specified fields from the specified document, and then adds them to spreadsheet specified in the settings tab
private void ProcessData()
{
    Word.Application wordApp = new Word.Application();
    Word.Document WordDoc = wordApp.Documents.Open(DocName, System.Reflection.Missing.Value, false);
    ItemsToAddToSS = new List<string>();
    foreach (string EachField in FieldsToCopy)
    {
        ItemsToAddToSS.Add(GetDocData(EachField, WordDoc));                
    }

    Excel.Application excelApp = new Excel.Application();
    Excel._Workbook ExcelBook = excelApp.Workbooks.Open(SSLocTB.Text, System.Reflection.Missing.Value, false);
    Excel._Worksheet ExcelSheet = ExcelBook.ActiveSheet;
    Excel.Range LastRow = ExcelSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
    int column = 1;
    foreach (string EachResult in ItemsToAddToSS)
    {        
        ExcelSheet.Cells[LastRow.Row + 1, column] = EachResult;                
        UpdateLogList(string.Format("{0}: {1} added to spreadsheet on row {2}.",FieldsToCopy[column-1], EachResult, LastRow.Row + 1));
        column++;
    }
    ExcelBook.Save();
    ExcelBook.Close();
    WordDoc.Close();
}