Пример #1
0
        // Create HTML table based on IEntityCollection
        public static string HtmlExportEntityCollection(IEntityCollection collection)
        {
            List <string> columnNames = new List <string>();
            bool          bFirstItem  = true;
            string        sBody       = "";

            // get column properties
            IEnumerable <IEntityProperty> columnProperties = collection.OfType <IEntityObject>().First().Details.Properties.All();

            // iterate the collection and extract values by column name
            foreach (IEntityObject entityObj in collection)
            {
                if (bFirstItem)
                {
                    // opening an html tag and creating a table
                    //sBody = "<html>"
                    //sBody = sBody + "</br></br>"
                    //sBody = sBody + "<body style=""font-family: Arial, Helvetica, sans-serif;"" >"
                    sBody = "<table border=\"1\">";

                    // add columns names to the list
                    // row begins
                    sBody = sBody + "<tr>";
                    foreach (IEntityProperty entityProperty in columnProperties)
                    {
                        columnNames.Add(entityProperty.Name);
                        sBody = sBody + "<td>";
                        sBody = sBody + " " + entityProperty.DisplayName;
                        sBody = sBody + "</td>";
                    }
                    // row ends
                    sBody      = sBody + "</tr>";
                    bFirstItem = false;
                }

                sBody = sBody + "<tr>";
                for (int i = 0; i <= columnNames.Count - 1; i++)
                {
                    sBody = sBody + "<td>";
                    sBody = sBody + LightSwitchHelper.GetValue(entityObj, columnNames[i]);
                    sBody = sBody + "</td>";
                }
                sBody = sBody + "</tr>";
            }

            // Add closing tags if there was at least one item
            // bFirstItem = True by default
            // It is set to False when the first item is encountered
            if (!bFirstItem)
            {
                // closing the tags
                sBody = sBody + "</table>";
                //sBody = sBody + "</body>"
                //sBody = sBody + "</html>"
            }
            return(sBody);
        }
Пример #2
0
        // Create HTML table based on IEntityCollection
        public static string HtmlExportEntityCollection(IEntityCollection Collection, List <string> ColumnNames)
        {
            bool   bFirstItem = true;
            string sBody      = "";

            // iterate the collection and extract values by column name
            foreach (IEntityObject entityObj in Collection)
            {
                if (bFirstItem)
                {
                    // opening an html tag and creating a table
                    //sBody = "<html>"
                    //sBody = sBody + "</br></br>"
                    //sBody = sBody + "<body style=""font-family: Arial, Helvetica, sans-serif;"" >"
                    sBody = "<table border=\"1\">";

                    // add columns names to the list
                    // row begins
                    string sColumnName = null;
                    sBody = sBody + "<tr>";
                    foreach (string sColumnName_loopVariable in ColumnNames)
                    {
                        sColumnName = sColumnName_loopVariable;
                        sBody       = sBody + "<td>";
                        sBody       = sBody + " " + sColumnName;
                        sBody       = sBody + "</td>";
                    }
                    // row ends
                    sBody      = sBody + "</tr>";
                    bFirstItem = false;
                }

                sBody = sBody + "<tr>";
                for (int i = 0; i <= ColumnNames.Count - 1; i++)
                {
                    sBody = sBody + "<td>";
                    sBody = sBody + LightSwitchHelper.GetValue(entityObj, ColumnNames[i]);
                    sBody = sBody + "</td>";
                }
                sBody = sBody + "</tr>";
            }

            // Add closing tags if there was at least one item
            // bFirstItem = True by default
            // It is set to False when the first item is encountered
            if (!bFirstItem)
            {
                // closing the tags
                sBody = sBody + "</table>";
                //sBody = sBody + "</body>"
                //sBody = sBody + "</html>"
            }
            return(sBody);
        }
Пример #3
0
        // Create HTML table based on IVisualCollection
        public static string HtmlExport(IVisualCollection collection)
        {
            List <string> columnNames = new List <string>();

            string sBody = "";

            if (collection.Count > 0)
            {
                // opening an html tag and creating a table
                //Body = "<html>"
                //sBody = sBody + "</br></br>"
                //sBody = sBody + "<body style=""font-family: Arial, Helvetica, sans-serif;"" >"
                sBody = "<table border=\"1\">";

                // get column properties
                IEnumerable <IEntityProperty> columnProperties = collection.OfType <IEntityObject>().First().Details.Properties.All();

                // add columns names to the list
                // row begins
                sBody = sBody + "<tr>";
                foreach (IEntityProperty entityProperty in columnProperties)
                {
                    columnNames.Add(entityProperty.Name);
                    sBody = sBody + "<td>";
                    sBody = sBody + " " + entityProperty.DisplayName;
                    sBody = sBody + "</td>";
                }
                // row ends
                sBody = sBody + "</tr>";

                // iterate the collection and extract values by column name
                foreach (IEntityObject entityObj in collection)
                {
                    sBody = sBody + "<tr>";
                    for (int i = 0; i <= columnNames.Count - 1; i++)
                    {
                        sBody = sBody + "<td>";
                        sBody = sBody + LightSwitchHelper.GetValue(entityObj, columnNames[i]);
                        sBody = sBody + "</td>";
                    }
                    sBody = sBody + "</tr>";
                }

                // closing the tags
                sBody = sBody + "</table>";
                //sBody = sBody + "</body>"
                //sBody = sBody + "</html>"
            }
            return(sBody);
        }
Пример #4
0
        // Create HTML table based on IVisualCollection
        public static string HtmlExport(IVisualCollection Collection, List <string> ColumnNames)
        {
            string sBody = "";

            if (Collection.Count > 0)
            {
                // opening an html tag and creating a table
                //sBody = "<html>"
                //sBody = sBody + "</br></br>"
                //sBody = sBody + "<body style=""font-family: Arial, Helvetica, sans-serif;"" >"
                sBody = "<table border=\"1\">";

                string sColumnName = null;

                // add columns names to the list
                // row begins
                sBody = sBody + "<tr>";
                foreach (string sColumnName_loopVariable in ColumnNames)
                {
                    sColumnName = sColumnName_loopVariable;
                    sBody       = sBody + "<td>";
                    sBody       = sBody + " " + sColumnName;
                    sBody       = sBody + "</td>";
                }
                // row ends
                sBody = sBody + "</tr>";

                // iterate the collection and extract values by column name
                foreach (IEntityObject entityObj in Collection)
                {
                    sBody = sBody + "<tr>";
                    for (int i = 0; i <= ColumnNames.Count - 1; i++)
                    {
                        sBody = sBody + "<td>";
                        sBody = sBody + LightSwitchHelper.GetValue(entityObj, ColumnNames[i]);
                        sBody = sBody + "</td>";
                    }
                    sBody = sBody + "</tr>";
                }

                // closing the tags
                sBody = sBody + "</table>";
                //sBody = sBody + "</body>"
                //sBody = sBody + "</html>"
            }
            return(sBody);
        }
Пример #5
0
        // Exports an IEntityCollection to a table in given Document. BookmarkName is the name of the bookmark associated
        // with the table.
        public static dynamic ExportEntityCollection(dynamic Document, string BookmarkName, int StartRow, bool BuildColumnHeadings, IEntityCollection collection, List <ColumnMapping> ColumnNames)
        {
            // get column properties
            int columnCounter = 1;
            int rowCounter    = StartRow;

            // validate that the Document argument is expected type of Word.Document
            if (!IsWordDocumentObject(Document))
            {
                throw new System.ArgumentException("'Document' is not the expected type of dynamic. Expected dynamic should be a Word.Document dynamic.", "Document");
            }

            // validate the BookmarkName argument
            if (!IsValidBookmark(Document, BookmarkName))
            {
                throw new System.ArgumentException("'BookmarkName' was not found in 'Document'", "BookmarkName");
            }

            // validate that the bookmark is part of a table
            if (Document.Bookmarks(BookmarkName).Range.Tables.Count == 0)
            {
                throw new System.ArgumentException("No table was found at the bookmark", "BookmarkName");
            }

            // add table
            dynamic oTable = null;

            oTable = Document.Bookmarks(BookmarkName).Range.Tables(1);

            // validate the StartRow argument
            if (StartRow > oTable.Rows.Count)
            {
                throw new System.ArgumentException("'StartRow' is greater then the number of rows in the table", "StartRow");
            }

            // add columns names to the list
            foreach (ColumnMapping map in ColumnNames)
            {
                if (columnCounter > oTable.Columns.Count)
                {
                    oTable.Columns.Add();
                }
                if (BuildColumnHeadings)
                {
                    if (map.TableField.DisplayName.Length > 0)
                    {
                        oTable.Cell(rowCounter, columnCounter).Range.Text = map.TableField.DisplayName;
                    }
                    else
                    {
                        oTable.Cell(rowCounter, columnCounter).Range.Text = map.TableField.Name;
                    }
                }
                columnCounter += 1;
            }

            // add values on the row following the headers
            if (BuildColumnHeadings)
            {
                rowCounter += 1;
            }

            // iterate the collection and extract values by column name
            foreach (IEntityObject entityObj in collection)
            {
                for (int i = 0; i <= ColumnNames.Count - 1; i++)
                {
                    if (rowCounter > oTable.Rows.Count)
                    {
                        oTable.Rows.Add();
                    }
                    try
                    {
                        oTable.Cell(rowCounter, i + 1).Range.Text = LightSwitchHelper.GetValue(entityObj, ColumnNames[i].TableField.Name);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                rowCounter += 1;
            }

            return(Document);
        }
Пример #6
0
        // Exports an IVisualCollection to a table in either the active (UseActiveDocument = True) or a new document (UseActiveDocument = False)
        public static dynamic Export(IVisualCollection collection, bool UseActiveDocument)
        {
            dynamic    doc                = null;
            WordHelper wordProxy          = new WordHelper();
            bool       bUseActiveDocument = false;
            dynamic    rg = null;

            // if Word is active then use it
            if (wordProxy.GetWord())
            {
                // obtain a reference to the selection range
                if (UseActiveDocument)
                {
                    rg = wordProxy.Word.Selection.Range;
                    bUseActiveDocument = true;
                }
                else
                {
                    wordProxy.CreateDocument();
                }
            }
            else
            {
                wordProxy.CreateWord();
                wordProxy.CreateDocument();
            }

            List <string> columnNames = new List <string>();

            if (collection.Count > 0)
            {
                // get column properties
                IEnumerable <IEntityProperty> columnProperties = collection.OfType <IEntityObject>().First().Details.Properties.All();
                int columnCounter = 1;
                int rowCounter    = 1;

                // add table
                dynamic oTable = null;
                if (bUseActiveDocument)
                {
                    oTable = wordProxy.AddTable(collection.Count + 1, columnProperties.Count(), rg);
                }
                else
                {
                    oTable = wordProxy.AddTable(collection.Count + 1, columnProperties.Count());
                }


                // add columns names to the list
                foreach (IEntityProperty entityProperty in columnProperties)
                {
                    columnNames.Add(entityProperty.Name);

                    // add column headers to table
                    wordProxy.SetTableCell(oTable, 1, columnCounter, entityProperty.DisplayName);
                    columnCounter += 1;
                }

                // add values on the row following the headers
                rowCounter = 2;

                // iterate the collection and extract values by column name
                foreach (IEntityObject entityObj in collection)
                {
                    for (int i = 0; i <= columnNames.Count - 1; i++)
                    {
                        wordProxy.SetTableCell(oTable, rowCounter, i + 1, LightSwitchHelper.GetValue(entityObj, columnNames[i]));
                    }
                    rowCounter += 1;
                }
            }

            doc = wordProxy.Document;
            wordProxy.ShowDocument();

            return(doc);
        }
Пример #7
0
        // Exports a collection to a table in given Document. BookmarkName is the name of the bookmark associated
        // with the table.
        public static dynamic Export(dynamic Document, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection)
        {
            List <string> columnNames = new List <string>();


            if (collection.Count > 0)
            {
                // get column properties
                IEnumerable <IEntityProperty> columnProperties = collection.OfType <IEntityObject>().First().Details.Properties.All();
                int columnCounter = 1;
                int rowCounter    = StartRow;

                // validate that the Documnet argument is expected type of Word.Document
                if (!IsWordDocumentObject(Document))
                {
                    throw new System.ArgumentException("'Document' is not the expected type of dynamic. Expected dynamic should be a Word.Document dynamic.", "Document");
                }

                // validate the BookmarkName argument
                if (!IsValidBookmark(Document, BookmarkName))
                {
                    throw new System.ArgumentException("'BookmarkName' was not found in 'Document'", "BookmarkName");
                }

                // validate that the bookmark is part of a table
                if (Document.Bookmarks(BookmarkName).Range.Tables.Count == 0)
                {
                    throw new System.ArgumentException("No table was found at the bookmark", "BookmarkName");
                }

                // add table
                dynamic oTable = null;
                oTable = Document.Bookmarks(BookmarkName).Range.Tables(1);

                // validate the StartRow argument
                if (StartRow > oTable.Rows.Count)
                {
                    throw new System.ArgumentException("'StartRow' is greater then the number of rows in the table", "StartRow");
                }

                // add columns names to the list
                foreach (IEntityProperty entityProperty in columnProperties)
                {
                    columnNames.Add(entityProperty.Name);
                    if (columnCounter > oTable.Columns.Count)
                    {
                        oTable.Columns.Add();
                    }
                    if (BuildColumnHeadings)
                    {
                        oTable.Cell(rowCounter, columnCounter).Range.Text = entityProperty.DisplayName;
                    }
                    columnCounter += 1;
                }

                // add values on the row following the headers
                if (BuildColumnHeadings)
                {
                    rowCounter += 1;
                }

                // iterate the collection and extract values by column name
                foreach (IEntityObject entityObj in collection)
                {
                    for (int i = 0; i <= columnNames.Count - 1; i++)
                    {
                        if (rowCounter > oTable.Rows.Count)
                        {
                            oTable.Rows.Add();
                        }
                        oTable.Cell(rowCounter, i + 1).Range.Text = LightSwitchHelper.GetValue(entityObj, columnNames[i]);
                    }
                    rowCounter += 1;
                }
            }
            else
            {
                // No items in the collection
            }

            return(Document);
        }