Beispiel #1
0
        private void btnCompare_Click(object sender, RoutedEventArgs e)
        {
            List <ComparedObject> objectComparisonList = new List <ComparedObject>();

            for (int i = 0; i < documentationImportList.Count; i++)
            {
                DeviceIconGroup databaseItem = databaseImportList.Find(x => x.deviceName.Equals(documentationImportList[i].deviceName));
                ComparedObject  co           = new ComparedObject()
                {
                    DeviceDoc = documentationImportList[i].deviceName, DeviceDB = databaseItem.deviceName, Result = documentationImportList[i].IsEqualTo(databaseItem)
                };
                objectComparisonList.Add(co);
            }
            dgConnections.ItemsSource = objectComparisonList;
        }
Beispiel #2
0
 public bool IsEqualTo(DeviceIconGroup other)
 {
     if (deviceName.Equals(other.deviceName) && (iconNames.Count == other.iconNames.Count))
     {
         for (int i = 0; i < iconNames.Count; i++)
         {
             if (!iconNames[i].Equals(other.iconNames[i]))
             {
                 return(false);
             }
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #3
0
        private void ExportComparison(object title)
        {
            // Must have write permissions to the path folder
            FileInfo file = new FileInfo(titlePDF.ToString() + ".pdf");

            file.Delete();
            var fileStream = file.Create();

            fileStream.Close();
            PdfDocument pdfdoc      = new PdfDocument(new PdfWriter(file));
            PdfFont     font        = PdfFontFactory.CreateFont(StandardFonts.TIMES_BOLD);
            PdfFont     cellFont    = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
            PdfFont     OKFont      = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
            PdfFont     NOKFont     = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
            Style       headerStyle = new Style();

            headerStyle.SetFont(font).SetFontSize(11);
            headerStyle.SetBold();
            Style cellStyle = new Style();

            cellStyle.SetFont(cellFont).SetFontSize(10);
            Style OKStyle = new Style();

            OKStyle.SetFont(OKFont).SetFontSize(10);
            OKStyle.SetFontColor(ColorConstants.GREEN, 1);
            Style NOKStyle = new Style();

            NOKStyle.SetFont(NOKFont).SetFontSize(10);
            NOKStyle.SetFontColor(ColorConstants.RED, 1);

            pdfdoc.SetDefaultPageSize(PageSize.A2.Rotate());
            pdfdoc.SetTagged();
            using (Document document = new Document(pdfdoc))
            {
                iText.Layout.Element.Cell cell;
                Table table = CreateHeaders(document, headerStyle, title.ToString());
                for (int i = 0; i < documentationImportList.Count; i++)
                {
                    cell = new iText.Layout.Element.Cell(1, 1);
                    cell.Add(new Paragraph(documentationImportList[i].deviceName)).AddStyle(cellStyle);
                    table.AddCell(cell);
                    foreach (string iconName in documentationImportList[i].iconNames)
                    {
                        // documentationImportList[i].iconNames;
                        if (File.Exists(imagesDir + "icono" + iconName + ".png"))
                        {
                            ImageData imageData = ImageDataFactory.Create(imagesDir + "icono" + iconName + ".png");
                            iText.Layout.Element.Image pdfImg = new iText.Layout.Element.Image(imageData);
                            pdfImg.SetHeight(32);
                            pdfImg.SetWidth(32);
                            table.AddCell(pdfImg);
                        }
                        else
                        {
                            table.AddCell("X");
                        }
                    }

                    for (int j = documentationImportList[i].iconNames.Count; j < 17; j++)
                    {
                        table.AddCell("");
                    }

                    DeviceIconGroup databaseItem = databaseImportList.Find(x => x.deviceName.Equals(documentationImportList[i].deviceName));
                    cell = new iText.Layout.Element.Cell(1, 1);
                    cell.Add(new Paragraph(databaseItem.deviceName)).AddStyle(cellStyle);
                    table.AddCell(cell);//.AddStyle(cellStyle);


                    foreach (string iconName in databaseItem.iconNames)
                    {
                        if (File.Exists(imagesDir + "icono" + iconName + ".png"))
                        {
                            // documentationImportList[i].iconNames;
                            ImageData imageData = ImageDataFactory.Create(imagesDir + "icono" + iconName + ".png");
                            iText.Layout.Element.Image pdfImg = new iText.Layout.Element.Image(imageData);
                            pdfImg.SetHeight(32);
                            pdfImg.SetWidth(32);
                            table.AddCell(pdfImg);
                        }
                        else
                        {
                            table.AddCell("X");
                        }
                    }


                    for (int j = 19 + databaseItem.iconNames.Count; j < 36; j++)
                    {
                        table.AddCell("");
                    }

                    if (documentationImportList[i].IsEqualTo(databaseItem))
                    {
                        cell = new iText.Layout.Element.Cell(1, 1);
                        cell.Add(new Paragraph("OK")).AddStyle(OKStyle);
                        table.AddCell(cell);
                    }
                    else
                    {
                        cell = new iText.Layout.Element.Cell(1, 1);
                        cell.Add(new Paragraph("NOK")).AddStyle(NOKStyle);
                        table.AddCell(cell);
                    }

                    this.Dispatcher.Invoke(
                        new UpdatePgBar(this.updatePgBar),
                        new object[] { (double.Parse(i.ToString()) / double.Parse(documentationImportList.Count().ToString())) * 100 }
                        );
                }

                //Create table
                document.Add(table);


                this.Dispatcher.Invoke(
                    new FinishReading(EnableWindowOptions),
                    new object[] { }
                    );
            }
        }
Beispiel #4
0
        private void ReadExcelFileDocument(object excelObj)
        {
            documentationImportList.Clear();
            int x, y;

            x = 0;
            y = 0;

            string filename = ((ExcelObject)excelObj).path;
            string tab      = ((ExcelObject)excelObj).tab;

            using (SpreadsheetDocument doc = SpreadsheetDocument.Open(filename, false))
            {
                WorkbookPart          workbookPart = doc.WorkbookPart;
                SharedStringTablePart sstpart      = null;
                SharedStringTable     sst          = null;
                if (workbookPart.GetPartsOfType <SharedStringTablePart>().Count() > 0)
                {
                    sstpart = workbookPart.GetPartsOfType <SharedStringTablePart>().First();
                    sst     = sstpart.SharedStringTable;
                }
                List <Sheet>         sheets     = workbookPart.Workbook.Descendants <Sheet>().ToList();
                List <WorksheetPart> sheetParts = workbookPart.WorksheetParts.ToList();
                int           indexOfTab        = workbookPart.Workbook.Descendants <Sheet>().ToList().IndexOf(workbookPart.Workbook.Descendants <Sheet>().ToList().Find(obj => obj.Name.Equals(tab)));
                WorksheetPart worksheetPart     = GetWorksheetPart(workbookPart, tab);
                //  WorksheetPart worksheetPart = workbookPart.WorksheetParts.ToList()[indexOfTab];

                //workbookPart.WorksheetParts.ToList().Find(x=>x.Worksheet.XName)
                //string sheetName = workbookPart.Workbook.Descendants<Sheet>().ToList().IndexOf();


                //workbookPart.Workbook.Descendants<Sheet>().ElementAt(sheetIndex).Name

                Worksheet sheet = worksheetPart.Worksheet;

                var cells = sheet.Descendants <DocumentFormat.OpenXml.Spreadsheet.Cell>();
                var rows  = sheet.Descendants <Row>();

                Console.WriteLine("Row count = {0}", rows.LongCount());
                Console.WriteLine("Cell count = {0}", cells.LongCount());


                foreach (Row row in rows)
                {
                    if (x < 2)
                    {
                        x++;
                        continue;
                    }
                    DeviceIconGroup dig = new DeviceIconGroup();
                    foreach (DocumentFormat.OpenXml.Spreadsheet.Cell c in row.Elements <DocumentFormat.OpenXml.Spreadsheet.Cell>())
                    {
                        if (y == 1)
                        {
                            y++;
                            continue;
                        }

                        if ((c.DataType != null) && (c.DataType == CellValues.SharedString))
                        {
                            int    ssid = int.Parse(c.CellValue.Text);
                            string str  = sst.ChildElements[ssid].InnerText;
                            if (y == 0)
                            {
                                dig.deviceName = str;
                            }
                            else
                            {
                                dig.iconNames.Add(str);
                            }
                        }
                        else if (c.CellValue != null && c.DataType == CellValues.String)
                        {
                            if (y == 0)
                            {
                                dig.deviceName = c.CellValue.Text;
                            }
                            else
                            {
                                dig.iconNames.Add(c.CellValue.Text);
                            }
                        }
                        y++;
                    }
                    this.Dispatcher.Invoke(
                        new UpdatePgBar(this.updatePgBar),
                        new object[] { (double.Parse(x.ToString()) / double.Parse(rows.Count().ToString())) * 100 }
                        );
                    documentationImportList.Add(dig);

                    x++;
                    y = 0;
                }

                // Close the document.
                doc.Close();
            }

            this.Dispatcher.Invoke(
                new FinishReading(EnableWindowOptions),
                new object[] { }
                );
        }
Beispiel #5
0
        private void ReadExcelFileDatabase(object fileName)
        {
            databaseImportList.Clear();
            int x, y;

            x = 0;
            y = 0;


            using (SpreadsheetDocument doc = SpreadsheetDocument.Open(fileName.ToString(), false))
            {
                WorkbookPart          workbookPart = doc.WorkbookPart;
                SharedStringTablePart sstpart      = null;
                SharedStringTable     sst          = null;
                if (workbookPart.GetPartsOfType <SharedStringTablePart>().Count() > 0)
                {
                    sstpart = workbookPart.GetPartsOfType <SharedStringTablePart>().First();
                    sst     = sstpart.SharedStringTable;
                }
                WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();


                Worksheet sheet = worksheetPart.Worksheet;

                var cells = sheet.Descendants <DocumentFormat.OpenXml.Spreadsheet.Cell>();
                var rows  = sheet.Descendants <Row>();

                Console.WriteLine("Row count = {0}", rows.LongCount());
                Console.WriteLine("Cell count = {0}", cells.LongCount());


                foreach (Row row in rows)
                {
                    DeviceIconGroup dig = new DeviceIconGroup();
                    foreach (DocumentFormat.OpenXml.Spreadsheet.Cell c in row.Elements <DocumentFormat.OpenXml.Spreadsheet.Cell>())
                    {
                        if (y == 1)
                        {
                            y++;
                            continue;
                        }

                        if ((c.DataType != null) && (c.DataType == CellValues.SharedString))
                        {
                            int    ssid = int.Parse(c.CellValue.Text);
                            string str  = sst.ChildElements[ssid].InnerText;
                            if (y == 0)
                            {
                                dig.deviceName = str;
                            }
                            else
                            {
                                dig.iconNames.Add(str);
                            }
                        }
                        else if (c.CellValue != null && c.DataType == CellValues.String)
                        {
                            if (y == 0)
                            {
                                dig.deviceName = c.CellValue.Text;
                            }
                            else
                            {
                                dig.iconNames.Add(c.CellValue.Text);
                            }
                        }
                        y++;
                    }
                    this.Dispatcher.Invoke(
                        new UpdatePgBar(this.updatePgBar),
                        new object[] { (double.Parse(x.ToString()) / double.Parse(rows.Count().ToString())) * 100 }
                        );
                    databaseImportList.Add(dig);

                    x++;
                    y = 0;
                }

                // Close the document.
                doc.Close();
            }

            this.Dispatcher.Invoke(
                new FinishReading(EnableWindowOptions),
                new object[] { }
                );
        }