Ejemplo n.º 1
0
        /// <summary>
        /// Export the containers List in Excel file
        /// </summary>
        /// <param name="page"></param>
        public static void ExportContainers(Page page)
        {
            using (CollectionView cv = new CollectionView(HyperCatalog.Business.Container.GetAll()))
            {
                cv.Sort("GroupId");

                using (CollectionView cvCG = new CollectionView(ContainerGroup.GetAll()))
                {
                    using (CollectionView cvCT = new CollectionView(ContainerType.GetAll()))
                    {
                        using (CollectionView cvDT = new CollectionView(DataType.GetAll()))
                        {
                            using (CollectionView cvU = new CollectionView(User.GetAll()))
                            {
                                using (CollectionView cvLG = new CollectionView(LookupGroup.GetAll()))
                                {
                                    using (CollectionView cvIM = new CollectionView(InheritanceMethod.GetAll()))
                                    {
                                        // string contains html code to export
                                        System.Text.StringBuilder sb = new System.Text.StringBuilder(string.Empty);

                                        sb.Append("<html><body>");
                                        sb.Append("<table border='1'>");
                                        /******** Writing the User info and Current date ***********/
                                        int ColCount = 28;
                                        sb.Append("<tr style='border: none' valign='top'><td style='font-weight:bold;font-size: 14;border: none; font-family:Arial Unicode MS' colspan=" + ColCount + ">" + "Container Report" + "</td></tr>");
                                        sb.Append("<tr style='border: none' valign='top'><td style='font-weight:bold;border: none; font-size: 14; font-family:Arial Unicode MS'>Generated By: </td><td style='border: none; font-size: 14; font-family:Arial Unicode MS' colspan=" + (ColCount - 1).ToString() + ">" + SessionState.User.FullName + "</td></tr>");
                                        sb.Append("<tr style='border: none' valign='top'><td style='font-weight:bold;border: none; font-size: 14;font-family:Arial Unicode MS'>Exported On: </td><td style='border: none ;font-size: 14; font-family:Arial Unicode MS' colspan=" + (ColCount - 1).ToString() + ">" + SessionState.User.FormatUtcDate(DateTime.UtcNow, true, "MM/dd/yyyy:HH:mm:ss") + "</td></tr>");



                                        #region "Header"

                                        sb.Append("<tr style='font-size: 14; font-weight: bold;font-family:Arial Unicode MS background-color: lightgrey' wordwrap='true'>");
                                        sb.Append("<td>Id</td>");
                                        sb.Append("<td>Container group</td>");
                                        sb.Append("<td>xmlname</td>");
                                        sb.Append("<td>Name</td>");
                                        sb.Append("<td>Label</td>");
                                        sb.Append("<td>Definition</td>");
                                        sb.Append("<td>Entry rule</td>");
                                        sb.Append("<td>Sample</td>");
                                        sb.Append("<td>Data type</td>");
                                        sb.Append("<td>Container type</td>");
                                        sb.Append("<td>Lookup</td>");
                                        sb.Append("<td>Input mask</td>");
                                        sb.Append("<td>Max length</td>");
                                        sb.Append("<td>Translatable</td>");
                                        sb.Append("<td>Regionalizable</td>");
                                        sb.Append("<td>Localizable</td>");
                                        sb.Append("<td>Publishable</td>");
                                        sb.Append("<td>Readonly</td>");
                                        sb.Append("<td>Keep if obsolete</td>");
                                        sb.Append("<td>Inheritance method</td>");
                                        sb.Append("<td>Sort</td>");
                                        sb.Append("<td>Segment</td>");
                                        sb.Append("<td>ValidationMask</td>");
                                        sb.Append("<td>WWXPath</td>");
                                        sb.Append("<td>Creator</td>");
                                        sb.Append("<td>Create date</td>");
                                        sb.Append("<td>Modifier</td>");
                                        sb.Append("<td>Modifier date</td>");
                                        sb.Append("</tr>");
                                        #endregion

                                        string cellColor = "#D0D0D0", defaultCellColor = "#D0D0D0";
                                        for (int i = 0; i < cv.Count; i++)
                                        {
                                            Container curContainer = ((Container)cv[i]);
                                            sb.Append("<tr valign='top' style='font-size: 14; font-family:Arial Unicode MS;background-color: " + cellColor + ";text-color: black;'>");
                                            sb.Append("<td>" + curContainer.Id + "</td>");
                                            //********************************************************************************************
                                            //GADSC Code Change for displaying the Goup/Subgroup path of the container group in the report
                                            //Ezilla Bug N0:68758
                                            //Modified By:Kanthi.J
                                            //********************************************************************************************
                                            cvCG.ApplyFilter("Id", curContainer.GroupId, HyperCatalog.Business.CollectionView.FilterOperand.Equals);
                                            sb.Append("<td>" + ((ContainerGroup)cvCG[0]).Path + ((ContainerGroup)cvCG[0]).Name + "</td>");
                                            sb.Append("<td>" + curContainer.Tag + "</td>");
                                            sb.Append("<td>" + curContainer.Name + "</td>");
                                            sb.Append("<td>" + curContainer.Label + "</td>");
                                            sb.Append("<td>" + curContainer.Definition + "</td>");
                                            sb.Append("<td>" + curContainer.EntryRule + "</td>");
                                            sb.Append("<td>" + curContainer.Sample + "</td>");
                                            cvDT.ApplyFilter("Code", curContainer.DataTypeCode, HyperCatalog.Business.CollectionView.FilterOperand.Equals);
                                            sb.Append("<td>" + ((DataType)cvDT[0]).Name + "</td>");
                                            cvCT.ApplyFilter("Code", curContainer.ContainerTypeCode, HyperCatalog.Business.CollectionView.FilterOperand.Equals);
                                            sb.Append("<td>" + ((ContainerType)cvCT[0]).Name + "</td>");
                                            if (curContainer.LookupId == -1)
                                            {
                                                sb.Append("<td></td>");
                                            }
                                            else
                                            {
                                                cvLG.ApplyFilter("Id", curContainer.LookupId, HyperCatalog.Business.CollectionView.FilterOperand.Equals);
                                                sb.Append("<td>" + ((LookupGroup)cvLG[0]).Name + "</td>");
                                            }
                                            sb.Append("<td>" + curContainer.InputMask + "</td>");
                                            sb.Append("<td>" + curContainer.MaxLength + "</td>");
                                            sb.Append("<td>" + curContainer.Translatable + "</td>");
                                            sb.Append("<td>" + curContainer.Regionalizable + "</td>");
                                            sb.Append("<td>" + curContainer.Localizable + "</td>");
                                            sb.Append("<td>" + curContainer.Publishable + "</td>");
                                            sb.Append("<td>" + curContainer.ReadOnly + "</td>");
                                            sb.Append("<td>" + curContainer.KeepIfObsolete + "</td>");
                                            cvIM.ApplyFilter("Id", curContainer.InheritanceMethodId, HyperCatalog.Business.CollectionView.FilterOperand.Equals);
                                            sb.Append("<td>" + ((InheritanceMethod)cvIM[0]).Name + "</td>");
                                            sb.Append("<td>" + curContainer.Sort + "</td>");
                                            sb.Append("<td>" + curContainer.SegmentId + "</td>");
                                            sb.Append("<td>" + curContainer.ValidationMask + "</td>");
                                            sb.Append("<td>" + curContainer.WWXPath + "</td>");
                                            cvU.ApplyFilter("Id", curContainer.CreatorId, HyperCatalog.Business.CollectionView.FilterOperand.Equals);
                                            sb.Append("<td>" + ((User)cvU[0]).FullName + "</td>");
                                            sb.Append("<td>" + curContainer.CreateDate + "</td>");
                                            if (curContainer.ModifierId == -1)
                                            {
                                                sb.Append("<td></td>");
                                            }
                                            else
                                            {
                                                cvU.ApplyFilter("Id", curContainer.ModifierId, HyperCatalog.Business.CollectionView.FilterOperand.Equals);
                                            }
                                            sb.Append("<td>" + ((User)cvU[0]).FullName + "</td>");
                                            sb.Append("<td>" + curContainer.ModifyDate + "</td>");

                                            sb.Append("</tr>");
                                            if (cellColor == defaultCellColor)
                                            {
                                                cellColor = "white";
                                            }
                                            else
                                            {
                                                cellColor = defaultCellColor;
                                            }
                                        }

                                        sb.Append("</table>");
                                        sb.Append("</body></html>");

                                        string fileName = string.Empty;
                                        fileName += "Containers.xls";

                                        string exportContent = sb.ToString();
                                        page.Response.Clear();
                                        page.Response.ClearContent();
                                        page.Response.ClearHeaders();
                                        page.Response.Charset = string.Empty;
                                        page.Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
                                        page.Response.ContentType = "application/vnd.ms-excel;";
                                        //Fix for CR 5109 - Prabhu R S
                                        page.Response.ContentEncoding = System.Text.Encoding.UTF8;
                                        page.EnableViewState          = false;
                                        page.Response.Write(exportContent);
                                        page.Response.End();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Export the lookups List with values in Excel file
        /// </summary>
        /// <param name="page"></param>
        public static void ExportLookups(Page page)
        {
            using (LookupGroupList lList = LookupGroup.GetAll())
            {
                // string contains html code to export
                System.Text.StringBuilder sb = new System.Text.StringBuilder(string.Empty);

                sb.Append("<html><body>");
                sb.Append("<table border='1'>");

                #region "Header"
                sb.Append("<tr align='center' style='font-size: 14; font-weight: bold; background-color: lightgrey' wordwrap='true'>");
                sb.Append("<td>Id</td>");
                sb.Append("<td>Name</td>");
                sb.Append("<td>Comment</td>");
                sb.Append("<td>Multi choice</td>");
                sb.Append("<td>Sep</td>");
                sb.Append("<td>Value</td>");
                sb.Append("<td>Comment</td>");
                sb.Append("<td>Sort</td>");
                sb.Append("</tr>");
                #endregion

                string cellColor = "#D0D0D0", defaultCellColor = "#D0D0D0";
                for (int i = 0; i < lList.Count; i++)
                {
                    LookupGroup     curLookupGroup = lList[i];
                    LookupValueList lvList         = LookupGroup.GetByKey(curLookupGroup.Id).Values;
                    for (int j = 0; j < lvList.Count; j++)
                    {
                        LookupValue curLookupValue = lvList[j];

                        sb.Append("<tr valign='top' style='background-color: " + cellColor + "; text-color: black;'>");
                        sb.Append("<td>" + curLookupGroup.Id + "</td>");
                        sb.Append("<td>" + curLookupGroup.Name + "</td>");
                        sb.Append("<td>" + curLookupGroup.Comment + "</td>");
                        sb.Append("<td>" + curLookupGroup.MultiChoice + "</td>");
                        sb.Append("<td>" + curLookupValue.Text + "</td>");
                        sb.Append("<td>" + curLookupValue.Comment + "</td>");
                        sb.Append("<td>" + curLookupValue.Sort + "</td>");
                        sb.Append("</tr>");
                        if (cellColor == defaultCellColor)
                        {
                            cellColor = "white";
                        }
                        else
                        {
                            cellColor = defaultCellColor;
                        }
                    }
                }

                sb.Append("</table>");
                sb.Append("</body></html>");

                string fileName = string.Empty;
                fileName += "Lookups.xls";

                string exportContent = sb.ToString();
                page.Response.Clear();
                page.Response.ClearContent();
                page.Response.ClearHeaders();
                page.Response.Charset = string.Empty;
                page.Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
                page.Response.ContentType = "application/vnd.ms-excel;";
                //Fix for CR 5109 - Prabhu R S
                page.Response.ContentEncoding = System.Text.Encoding.UTF8;
                page.EnableViewState          = false;
                page.Response.Write(exportContent);
                page.Response.End();
            }
        }