public static void Write(this ReportProperties reportProperties, CSideWriter writer)
        {
            writer.BeginSection("PROPERTIES");

            var relevantProperties = reportProperties.Where(p => p.HasValue);

            foreach (Property property in relevantProperties)
            {
                // The object text format for reports in NAV 2013 does not seem to
                // differentiate between the last property, and the ones preceding it.
                // I like the simplicity, but dislike the inconsistency... ;)
                var isLastProperty = false; // (property == relevantProperties.Last());
                property.Write(isLastProperty, PropertiesStyle.Field, writer);
            }

            writer.EndSection();
        }
Exemple #2
0
 public void setProperty(Property p)
 {
     ReportProperties.set(p);
 }
Exemple #3
0
        /// <summary>
        /// Creates a flow document of the report data
        /// </summary>
        /// <returns></returns>
        /// <exception cref="ArgumentException">Flow document must have a specified page height</exception>
        /// <exception cref="ArgumentException">Flow document must have a specified page width</exception>
        /// <exception cref="ArgumentException">"Flow document must have only one ReportProperties section, but it has {0}"</exception>
        public FlowDocument CreateFlowDocument()
        {
            MemoryStream mem = new MemoryStream();

            byte[] buf = Encoding.UTF8.GetBytes(_xamlData);
            mem.Write(buf, 0, buf.Length);
            mem.Position = 0;
            FlowDocument res = XamlReader.Load(mem) as FlowDocument;

            if (res.PageHeight == double.NaN)
            {
                throw new ArgumentException("Flow document must have a specified page height");
            }
            if (res.PageWidth == double.NaN)
            {
                throw new ArgumentException("Flow document must have a specified page width");
            }

            // remember original values
            _pageHeight = res.PageHeight;
            _pageWidth  = res.PageWidth;

            // search report properties
            DocumentWalker             walker     = new DocumentWalker();
            List <SectionReportHeader> headers    = walker.Walk <SectionReportHeader>(res);
            List <SectionReportFooter> footers    = walker.Walk <SectionReportFooter>(res);
            List <ReportProperties>    properties = walker.Walk <ReportProperties>(res);

            if (properties.Count > 0)
            {
                if (properties.Count > 1)
                {
                    throw new ArgumentException(String.Format("Flow document must have only one ReportProperties section, but it has {0}", properties.Count));
                }
                ReportProperties prop = properties[0];
                if (prop.ReportName != null)
                {
                    ReportName = prop.ReportName;
                }
                if (prop.ReportTitle != null)
                {
                    ReportTitle = prop.ReportTitle;
                }
                if (headers.Count > 0)
                {
                    PageHeaderHeight = headers[0].PageHeaderHeight;
                }
                if (footers.Count > 0)
                {
                    PageFooterHeight = footers[0].PageFooterHeight;
                }

                // remove properties section from FlowDocument
                DependencyObject parent = prop.Parent;
                if (parent is FlowDocument)
                {
                    ((FlowDocument)parent).Blocks.Remove(prop); parent = null;
                }
                if (parent is Section)
                {
                    ((Section)parent).Blocks.Remove(prop); parent = null;
                }
            }

            // make height smaller to have enough space for page header and page footer
            res.PageHeight = _pageHeight - _pageHeight * (PageHeaderHeight + PageFooterHeight) / 100d;

            // search image objects
            List <Image> images = new List <Image>();

            walker.Tag            = images;
            walker.VisualVisited += new DocumentVisitedEventHandler(walker_VisualVisited);
            walker.Walk(res);

            // load all images
            foreach (Image image in images)
            {
                if (ImageProcessing != null)
                {
                    ImageProcessing(this, new ImageEventArgs(this, image));
                }
                try
                {
                    if (image.Tag is string)
                    {
                        image.Source = new BitmapImage(new Uri("file:///" + Path.Combine(_xamlImagePath, image.Tag.ToString())));
                    }
                }
                catch (Exception ex)
                {
                    // fire event on exception and check for Handled = true after each invoke
                    if (ImageError != null)
                    {
                        bool handled = false;
                        lock (ImageError)
                        {
                            ImageErrorEventArgs eventArgs = new ImageErrorEventArgs(ex, this, image);
                            foreach (var ed in ImageError.GetInvocationList())
                            {
                                ed.DynamicInvoke(this, eventArgs);
                                if (eventArgs.Handled)
                                {
                                    handled = true; break;
                                }
                            }
                        }
                        if (!handled)
                        {
                            throw;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
                if (ImageProcessed != null)
                {
                    ImageProcessed(this, new ImageEventArgs(this, image));
                }
                // TODO: find a better way to specify file names
            }

            return(res);
        }
    /// <summary>
    ///
    /// </summary>
    private void PrintReport()
    {
        //if space is required, then it can be passed by - char
        //the - will remove by space

        string username    = "******";
        string titel       = "null";
        string showfilter  = "null";
        string curdate     = "null";
        string paperformat = string.Empty;
        string papersize   = string.Empty;
        string table       = string.Empty;
        string fields      = string.Empty;
        string whereclause = string.Empty;
        string groupby     = "NONE";
        string orderby     = string.Empty;
        string reporttype  = string.Empty;

        string securityKey = string.Empty;

        string selectSql          = string.Empty;
        string countSql           = string.Empty;
        string gbselectexpression = string.Empty;
        string reportCode         = string.Empty;

        EPageSize    EpageSize;
        EPaperFormat EpaperFormat;

        DBUtil.CONN_STRING = ConfigurationManager.ConnectionStrings["obcore_connectionstring"].ConnectionString;
        try
        {
            string   QueryStringUrl = Server.UrlDecode(Request.Url.Query.Substring(Request.Url.Query.IndexOf('?') + 1));
            string[] KeyValues      = QueryStringUrl.Split('&');

            for (int i = 0; i < KeyValues.Length; i++)
            {
                string[] KeyValuePair = KeyValues[i].Split('=');
                string   key          = KeyValuePair.Length > 0 ? KeyValuePair[0].Trim() : string.Empty;
                string   value        = KeyValues[i].Substring(KeyValues[i].IndexOf('=') + 1).Trim();

                switch (key)
                {
                case "username":
                    username = value;
                    break;

                case "securityKey":
                    securityKey = value;
                    break;

                case "titel":
                    titel = value;
                    break;

                case "showfilter":
                    showfilter = value;
                    break;

                case "curdate":
                    curdate = value;
                    break;

                case "paperformat":
                    paperformat = value;
                    break;

                case "papersize":
                    papersize = value;
                    break;

                case "reporttype":
                    reporttype = value;
                    break;

                case "reportcode":
                    reportCode = value;
                    break;

                case "table":
                    table = value.Replace("@@@", "\"");
                    break;

                case "fields":
                    fields = value;
                    break;

                case "whereclause":
                    whereclause = value;
                    break;

                case "groupby":
                    groupby = value;
                    break;

                case "orderby":
                    orderby = value;
                    break;

                case "gbselectexpression":
                    gbselectexpression = value;
                    break;
                }
            }


            if (!string.IsNullOrEmpty(fields) && !string.IsNullOrEmpty(table))
            {
                selectSql = " select " + fields + " from " + table;

                if (!string.IsNullOrEmpty(whereclause))
                {
                    selectSql += " where " + whereclause + " ";
                }

                if (!groupby.Equals("NONE") && !string.IsNullOrEmpty(groupby))
                {
                    if (reporttype == "Regular")
                    {
                        countSql = " select count(*)," + groupby + " from " + table;
                    }
                    else
                    {
                        countSql = " select " + gbselectexpression + "," + groupby + " from " + table;
                    }

                    if (!string.IsNullOrEmpty(whereclause))
                    {
                        countSql += " where " + whereclause + " ";
                    }

                    countSql += " group by " + groupby;

                    selectSql += " order by " + groupby;
                }

                if (!string.IsNullOrEmpty(orderby))
                {
                    selectSql += selectSql.Contains("order by") == true ? " , " + orderby : " order by " + orderby;
                    if (countSql != string.Empty)
                    {
                        countSql += " order by " + orderby;
                    }
                }
            }

            Dictionary <string, string> dicParams = new Dictionary <string, string>();

            username = username != "null" && securityKey != string.Empty ? "Static Name" : "null";

            dicParams.Add("username", username);
            dicParams.Add("titel", titel);

            showfilter = showfilter != "null" ? whereclause == string.Empty ? "De data wordt niet gefiltered"
                : whereclause
                : showfilter;
            dicParams.Add("showfilter", showfilter);
            dicParams.Add("curdate", curdate.Equals("null") == true ? "null" : DateTime.Now.ToString("dd/MM/yyyy"));

            switch (papersize)
            {
            case "a3":
                EpageSize = EPageSize.A3;
                break;

            case "a4":
                EpageSize = EPageSize.A4;
                break;

            default:
                EpageSize = EPageSize.A4;
                break;
            }

            switch (paperformat)
            {
            case "landscape":
                EpaperFormat = EPaperFormat.LandScape;
                break;

            case "portrait":
                EpaperFormat = EPaperFormat.Portrait;
                break;

            default:
                EpaperFormat = EPaperFormat.Portrait;
                break;
            }

            ReportUtil oReportUtil = new ReportUtil();

            ReportProperties data = oReportUtil.GetReportProperties(selectSql, reportCode, dicParams, EpageSize, EpaperFormat, Server.MapPath(FileNameManager.PdfFileName));

            DataTable recordCountTableForEachGroup = oReportUtil.GetRecordCountForEachGroup(countSql, reportCode);

            switch (reporttype)
            {
            case "Regular":
                oReportUtil.GenerateRegularReport(data, recordCountTableForEachGroup, Response);
                break;

            case "Piechart":
            case "Histogram":
                Dictionary <string, string> groupColors =
                    new ColorUtil().GetGroupColors(reportCode, recordCountTableForEachGroup, table, groupby);
                List <Group> oListGroup = new List <Group>();
                for (int i = 0; i < recordCountTableForEachGroup.Rows.Count; i++)
                {
                    Group oGroup = new Group();
                    oGroup.GroupValue  = double.Parse(recordCountTableForEachGroup.Rows[i][0].ToString());
                    oGroup.GroupName   = recordCountTableForEachGroup.Rows[i][groupby].ToString();
                    oGroup.GroupColour = XColor.FromArgb(System.Drawing.ColorTranslator.FromHtml("#" + groupColors[oGroup.GroupName]));
                    oListGroup.Add(oGroup);
                }

                if (reporttype == "Piechart")
                {
                    oReportUtil.GeneratePieChart(data, Response, oListGroup);
                }
                else if (reporttype == "Histogram")
                {
                    oReportUtil.GenerateColumnChart(data, Response, oListGroup, groupby);
                }
                break;

            default:
                oReportUtil.GenerateRegularReport(data, recordCountTableForEachGroup, Response);
                break;
            }
        }
        catch (Exception oEx)
        {
            Response.Write("Following server error occurs...<br/>");
            Response.Write("Select sql:" + selectSql + "<br/>");
            Response.Write("Count sql:" + countSql + "<br/>");
            Response.Write(oEx.Message + "<br/>");
            Response.Write(oEx.StackTrace);
        }
    }
Exemple #5
0
        static void Main(string[] args)
        {
            ReportProperties rp = new ReportProperties();

            rp.table.AddColumns(new ColumnAttribute("Title", 20), new ColumnAttribute("Item", 90));
            rp.table.AddData(new string[2] {
                "1", "2"
            }, new string[2] {
                "Test Data For Long Cell That Its OverFlown Letters Should Be Hidden 593958 341", "2123"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            },
                             new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            }, new string[2] {
                "1", "2"
            });

            ReportProperties.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape;

            PdfReport pdf = new PdfReport(rp);
        }
    private void PrintReportForList()
    {
        string username    = "******";
        string titel       = "null";
        string showfilter  = "null";
        string curdate     = "null";
        string paperformat = string.Empty;
        string papersize   = string.Empty;
        string table       = string.Empty;
        string whereclause = string.Empty;
        string reporttype  = string.Empty;
        string fieldswidth = string.Empty;
        string groupby     = "NONE";

        string securityKey = string.Empty;

        string       selectSql          = string.Empty;
        string       countSql           = string.Empty;
        string       gbselectexpression = string.Empty;
        string       reportCode         = string.Empty;
        EPageSize    EpageSize;
        EPaperFormat EpaperFormat;

        string artCode = string.Empty;

        reportCode = Request.QueryString["reportcode"];
        artCode    = Request.QueryString["artCode"];
        string listName = Request.QueryString["listName"];

        artCode = artCode.Split(':')[1].Trim();
        string docName = artCode + "_" + listName;

        table       = Request.QueryString["table"];
        whereclause = Request.QueryString["whereClause"];
        selectSql   = WrappingManager.GetListQueryByListName(table, whereclause, reportCode, listName);

        DBUtil.CONN_STRING = ConfigurationManager.ConnectionStrings["obcore_connectionstring"].ConnectionString;

        try
        {
            string   QueryStringUrl = Server.UrlDecode(Request.Url.Query.Substring(Request.Url.Query.IndexOf('?') + 1));
            string[] KeyValues      = QueryStringUrl.Split('&');

            for (int i = 0; i < KeyValues.Length; i++)
            {
                string[] KeyValuePair = KeyValues[i].Split('=');
                string   key          = KeyValuePair.Length > 0 ? KeyValuePair[0].Trim() : string.Empty;
                string   value        = KeyValues[i].Substring(KeyValues[i].IndexOf('=') + 1).Trim();

                switch (key)
                {
                case "username":
                    username = value;
                    break;

                case "securityKey":
                    securityKey = value;
                    break;

                case "titel":
                    titel = value;
                    break;

                case "showfilter":
                    showfilter = value;
                    break;

                case "curdate":
                    curdate = value;
                    break;

                case "paperformat":
                    paperformat = value;
                    break;

                case "papersize":
                    papersize = value;
                    break;

                case "reporttype":
                    reporttype = value.ToLower();
                    break;

                case "reportcode":
                    reportCode = value;
                    break;

                case "table":
                    table = value.Replace("@@@", "\"");
                    break;
                }
            }



            Dictionary <string, string> dicParams = new Dictionary <string, string>();

            username = username != "null" && securityKey != string.Empty ? "Static Name" : "null";

            dicParams.Add("username", username);
            dicParams.Add("titel", titel);

            showfilter = showfilter != "null" ? whereclause == string.Empty ? "De data wordt niet gefiltered"
                : whereclause
                : showfilter;
            dicParams.Add("showfilter", showfilter);
            dicParams.Add("curdate", curdate.Equals("null") == true ? "null" : DateTime.Now.ToString("dd/MM/yyyy"));

            switch (papersize)
            {
            case "a3":
                EpageSize = EPageSize.A3;
                break;

            case "a4":
                EpageSize = EPageSize.A4;
                break;

            default:
                EpageSize = EPageSize.A4;
                break;
            }

            switch (paperformat)
            {
            case "landscape":
                EpaperFormat = EPaperFormat.LandScape;
                break;

            case "portrait":
                EpaperFormat = EPaperFormat.Portrait;
                break;

            default:
                EpaperFormat = EPaperFormat.Portrait;
                break;
            }

            ReportUtil oReportUtil = new ReportUtil();

            ReportProperties data = oReportUtil.GetReportProperties(selectSql, fieldswidth, reportCode, dicParams, EpageSize, EpaperFormat, Server.MapPath(FileNameManager.PdfFileName));

            DataTable recordCountTableForEachGroup = oReportUtil.GetRecordCountForEachGroup(countSql, reportCode);

            switch (reporttype)
            {
            case "regular":
                oReportUtil.GenerateRegularReport(data, recordCountTableForEachGroup, Response);
                break;

            case "piechart":
            case "histogram":
                Dictionary <string, string> groupColors =
                    new ColorUtil().GetGroupColors(reportCode, recordCountTableForEachGroup, table, groupby);
                List <Group> oListGroup = new List <Group>();
                for (int i = 0; i < recordCountTableForEachGroup.Rows.Count; i++)
                {
                    Group oGroup = new Group();
                    oGroup.GroupValue  = double.Parse(recordCountTableForEachGroup.Rows[i][0].ToString());
                    oGroup.GroupName   = recordCountTableForEachGroup.Rows[i][groupby].ToString();
                    oGroup.GroupColour = XColor.FromArgb(System.Drawing.ColorTranslator.FromHtml("#" + groupColors[oGroup.GroupName]));
                    oListGroup.Add(oGroup);
                }

                if (reporttype.ToLower() == "piechart")
                {
                    oReportUtil.GeneratePieChart(data, Response, oListGroup);
                }
                else if (reporttype.ToLower() == "histogram")
                {
                    oReportUtil.GenerateColumnChart(data, Response, oListGroup, groupby);
                }
                break;

            default:
                oReportUtil.GenerateRegularReport(data, recordCountTableForEachGroup, Response);
                break;
            }
        }
        catch (Exception oEx)
        {
            Response.Write("Following server error occurs...<br/>");
            Response.Write("Select sql:" + selectSql + "<br/>");
            Response.Write("Count sql:" + countSql + "<br/>");
            Response.Write(oEx.Message + "<br/>");
            Response.Write(oEx.StackTrace);
        }
    }