Esempio n. 1
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="AResult"></param>
 /// <param name="AParameters"></param>
 /// <param name="APrinter"></param>
 public TReportPrinterCommon(TResultList AResult, TParameterList AParameters, TPrinter APrinter)
 {
     // go through all results and parameters and replace the unformatted and encoded date
     // the whole point is to format the dates differently, depending on the output (printer vs. CSV)
     FParameters  = AParameters.ConvertToFormattedStrings("Localized");
     FResultList  = AResult.ConvertToFormattedStrings(FParameters, "Localized");
     FResults     = FResultList.GetResults();
     FLowestLevel = FParameters.Get("lowestLevel").ToInt();
     FTimePrinted = DateTime.Now;
     FPrinter     = APrinter;
 }
Esempio n. 2
0
 /// <summary>
 /// constructor
 /// </summary>
 public TGridPreview(Form APreviewForm,
     TFrmPetraUtils APetraUtilsObject,
     TPreviewDelegate APreviewDelegate,
     TResultList AResultList,
     TParameterList AParameters)
 {
     results = AResultList.ConvertToFormattedStrings(AParameters);
     FOrigParameters = AParameters;
     parameters = AParameters.ConvertToFormattedStrings();
     FPreviewForm = APreviewForm;
     FPetraUtilsObject = APetraUtilsObject;
     FPreviewDelegate = APreviewDelegate;
     FGenerateReportThread = null;
 }
Esempio n. 3
0
        /// <summary>
        /// This returns the resultlist as lines for a CSV file
        /// </summary>
        /// <param name="AParameters"></param>
        /// <param name="separator">if this has the value FIND_BEST_SEPARATOR,
        /// then first the parameters will be checked for CSV_separator, and if that parameter does not exist,
        /// then the CurrentCulture is checked, for the local language settings</param>
        /// <param name="ADebugging">if true, thent the currency and date values are written encoded, not localized</param>
        /// <param name="AExportOnlyLowestLevel">if true, only the lowest level of AParameters are exported (level with higest depth)
        /// otherwise all levels in AParameter are exported</param>
        /// <returns>the lines to be written to the CSV file</returns>
        public List <string> WriteCSVInternal(TParameterList AParameters,
                                              string separator               = "FIND_BEST_SEPARATOR",
                                              Boolean ADebugging             = false,
                                              Boolean AExportOnlyLowestLevel = false)
        {
            List <string>  lines = new List <string>();
            int            i;
            string         strLine;
            ArrayList      sortedList;
            bool           display;
            bool           useIndented;
            TParameterList FormattedParameters;
            TResultList    FormattedResult;

            // myEncoding: Encoding;
            // bytes: array of byte;
            if (separator == "FIND_BEST_SEPARATOR")
            {
                if (AParameters.Exists("CSV_separator"))
                {
                    separator = AParameters.Get("CSV_separator").ToString();

                    if (separator.ToUpper() == "TAB")
                    {
                        separator = new String((char)9, 1);
                    }
                    else if (separator.ToUpper() == "SPACE")
                    {
                        separator = " ";
                    }
                }
                else
                {
                    separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator;
                }
            }

            if (ADebugging == false)
            {
                FormattedParameters = AParameters.ConvertToFormattedStrings("CSV");
                FormattedResult     = ConvertToFormattedStrings(FormattedParameters, "CSV");
            }
            else
            {
                FormattedParameters = AParameters;
                FormattedResult     = this;
            }

            // write headings
            strLine = "";

            // for debugging:
            // strLine = StringHelper.AddCSV(strLine, "masterRow", separator);
            // strLine = StringHelper.AddCSV(strLine, "childRow", separator);
            // strLine = StringHelper.AddCSV(strLine, "depth", separator);

            strLine = StringHelper.AddCSV(strLine, "id", separator);

            if (FormattedParameters.Exists("ControlSource", ReportingConsts.HEADERPAGELEFT1,
                                           -1, eParameterFit.eBestFit))
            {
                strLine = StringHelper.AddCSV(strLine, FormattedParameters.Get("ControlSource",
                                                                               ReportingConsts.HEADERPAGELEFT1,
                                                                               -1, eParameterFit.eBestFit).ToString(), separator);
            }

            if (FormattedParameters.Exists("ControlSource", ReportingConsts.HEADERPAGELEFT2,
                                           -1, eParameterFit.eBestFit))
            {
                strLine = StringHelper.AddCSV(strLine, FormattedParameters.Get("ControlSource",
                                                                               ReportingConsts.HEADERPAGELEFT2,
                                                                               -1, eParameterFit.eBestFit).ToString(), separator);
            }

            if (FormattedParameters.Exists("ControlSource", ReportingConsts.HEADERCOLUMN,
                                           -1, eParameterFit.eBestFit))
            {
                strLine = StringHelper.AddCSV(strLine, "header 1", separator);
                strLine = StringHelper.AddCSV(strLine, "header 0", separator);
            }

            useIndented = false;

            for (i = 0; i <= FormattedParameters.Get("lowestLevel").ToInt(); i++)
            {
                if (FormattedParameters.Exists("indented", ReportingConsts.ALLCOLUMNS, i, eParameterFit.eBestFit))
                {
                    useIndented = true;
                }
            }

            MaxDisplayColumns = AParameters.Get("MaxDisplayColumns").ToInt32();

            for (i = 0; i < MaxDisplayColumns; i++)
            {
                if ((!FormattedParameters.Get("ColumnCaption", i, -1, eParameterFit.eBestFit).IsNil()))
                {
                    strLine =
                        StringHelper.AddCSV(strLine,
                                            (FormattedParameters.Get("ColumnCaption",
                                                                     i, -1, eParameterFit.eBestFit).ToString() + ' ' +
                                             FormattedParameters.Get("ColumnCaption2",
                                                                     i, -1,
                                                                     eParameterFit.eBestFit).ToString(false) + ' ' +
                                             FormattedParameters.Get("ColumnCaption3", i, -1, eParameterFit.eBestFit).ToString(
                                                 false)).Trim(), separator);

                    if (useIndented)
                    {
                        strLine = StringHelper.AddCSV(strLine, "", separator);
                    }
                }
            }

            lines.Add(strLine);
            FormattedResult.SortChildren();
            sortedList = new ArrayList();
            FormattedResult.CreateSortedListByMaster(sortedList, 0);

            int LowestLevel = -1;

            if (AExportOnlyLowestLevel)
            {
                // find the highest level
                foreach (TResult element in sortedList)
                {
                    if (element.depth > LowestLevel)
                    {
                        LowestLevel = element.depth;
                    }
                }
            }

            // write each row to CSV file
            foreach (TResult element in sortedList)
            {
                if (AExportOnlyLowestLevel &&
                    (element.depth < LowestLevel))
                {
                    continue;
                }

                if (element.display)
                {
                    strLine = "";

                    // for debugging
                    // strLine = StringHelper.AddCSV(strLine, element.masterRow.ToString(), separator);
                    // strLine = StringHelper.AddCSV(strLine, element.childRow.ToString(), separator);
                    // strLine = StringHelper.AddCSV(strLine, element.depth.ToString(), separator);

                    strLine = StringHelper.AddCSV(strLine, element.code, separator);

                    if (FormattedParameters.Exists("ControlSource", ReportingConsts.HEADERPAGELEFT1, -1, eParameterFit.eBestFit))
                    {
                        if (ADebugging)
                        {
                            strLine = StringHelper.AddCSV(strLine, element.descr[0].EncodeToString(), separator);
                        }
                        else
                        {
                            strLine = StringHelper.AddCSV(strLine, element.descr[0].ToString(), separator);
                        }
                    }

                    if (FormattedParameters.Exists("ControlSource", ReportingConsts.HEADERPAGELEFT2, -1, eParameterFit.eBestFit))
                    {
                        if (ADebugging)
                        {
                            strLine = StringHelper.AddCSV(strLine, element.descr[1].EncodeToString(), separator);
                        }
                        else
                        {
                            strLine = StringHelper.AddCSV(strLine, element.descr[1].ToString(), separator);
                        }
                    }

                    if (FormattedParameters.Exists("ControlSource", ReportingConsts.HEADERCOLUMN, -1, eParameterFit.eBestFit))
                    {
                        if (ADebugging)
                        {
                            strLine = StringHelper.AddCSV(strLine, element.header[1].EncodeToString(), separator);
                            strLine = StringHelper.AddCSV(strLine, element.header[0].EncodeToString(), separator);
                        }
                        else
                        {
                            strLine = StringHelper.AddCSV(strLine, element.header[1].ToString(), separator);
                            strLine = StringHelper.AddCSV(strLine, element.header[0].ToString(), separator);
                        }
                    }

                    /* TODO: try to export in the right codepage, to print umlaut and other special characters correctly
                     * if element.childRow = 7 then
                     * begin
                     * myEncoding := System.Text.Encoding.get_ASCII;
                     * TLogging.Log(Encoding.Default.EncodingName);
                     * TLogging.Log(element.column[0].ToString());
                     * SetLength(bytes, Encoding.Default.GetByteCount(element.column[0].ToString()));
                     * bytes := Encoding.Default.GetBytes(element.column[0].ToString());
                     * TLogging.Log(myEncoding.GetChars(bytes));
                     * // this will still not help with Excel
                     * end;
                     */
                    display = false;

                    for (i = 0; i <= MaxDisplayColumns - 1; i += 1)
                    {
                        if (FormattedParameters.Get("indented", i, element.depth, eParameterFit.eAllColumnFit).ToBool() == true)
                        {
                            strLine = StringHelper.AddCSV(strLine, "", separator);
                        }

                        if (((element.column[i] != null) && (!element.column[i].IsNil())) || (ADebugging))
                        {
                            display = true;

                            if (ADebugging)
                            {
                                strLine = StringHelper.AddCSV(strLine, element.column[i].EncodeToString(), separator);
                            }
                            else
                            {
                                strLine = StringHelper.AddCSV(strLine, element.column[i].ToString().Trim(), separator);
                            }
                        }
                        else
                        {
                            strLine = StringHelper.AddCSV(strLine, "", separator);
                        }

                        if ((FormattedParameters.Get("indented", i, element.depth, eParameterFit.eAllColumnFit).ToBool() != true) && useIndented)
                        {
                            strLine = StringHelper.AddCSV(strLine, "", separator);
                        }
                    }

                    if (display)
                    {
                        lines.Add(strLine);
                    }
                }
            }

            sortedList = null;
            return(lines);
        }
Esempio n. 4
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="AResult"></param>
 /// <param name="AParameters"></param>
 /// <param name="APrinter"></param>
 public TReportPrinterCommon(TResultList AResult, TParameterList AParameters, TPrinter APrinter)
 {
     // go through all results and parameters and replace the unformatted and encoded date
     // the whole point is to format the dates differently, depending on the output (printer vs. CSV)
     FParameters = AParameters.ConvertToFormattedStrings("Localized");
     FResultList = AResult.ConvertToFormattedStrings(FParameters, "Localized");
     FResults = FResultList.GetResults();
     FLowestLevel = FParameters.Get("lowestLevel").ToInt();
     FTimePrinted = DateTime.Now;
     FPrinter = APrinter;
 }
Esempio n. 5
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="AResultList"></param>
 /// <param name="AParameters"></param>
 public TReportExcel(TResultList AResultList, TParameterList AParameters)
 {
     results = AResultList.ConvertToFormattedStrings(AParameters, "CSV");
     parameters = AParameters.ConvertToFormattedStrings("CSV");
 }
Esempio n. 6
0
        /// <summary>
        /// This returns the resultlist as lines for a CSV file
        /// </summary>
        /// <param name="AParameters"></param>
        /// <param name="separator">if this has the value FIND_BEST_SEPARATOR,
        /// then first the parameters will be checked for CSV_separator, and if that parameter does not exist,
        /// then the CurrentCulture is checked, for the local language settings</param>
        /// <param name="ADebugging">if true, thent the currency and date values are written encoded, not localized</param>
        /// <param name="AExportOnlyLowestLevel">if true, only the lowest level of AParameters are exported (level with higest depth)
        /// otherwise all levels in AParameter are exported</param>
        /// <returns>the lines to be written to the CSV file</returns>
        public List <string>WriteCSVInternal(TParameterList AParameters,
            string separator = "FIND_BEST_SEPARATOR",
            Boolean ADebugging = false,
            Boolean AExportOnlyLowestLevel = false)
        {
            List <string>lines = new List <string>();
            int i;
            string strLine;
            ArrayList sortedList;
            bool display;
            bool useIndented;
            TParameterList FormattedParameters;
            TResultList FormattedResult;

            // myEncoding: Encoding;
            // bytes: array of byte;
            if (separator == "FIND_BEST_SEPARATOR")
            {
                if (AParameters.Exists("CSV_separator"))
                {
                    separator = AParameters.Get("CSV_separator").ToString();

                    if (separator.ToUpper() == "TAB")
                    {
                        separator = new String((char)9, 1);
                    }
                    else if (separator.ToUpper() == "SPACE")
                    {
                        separator = " ";
                    }
                }
                else
                {
                    separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator;
                }
            }

            if (ADebugging == false)
            {
                FormattedParameters = AParameters.ConvertToFormattedStrings("CSV");
                FormattedResult = ConvertToFormattedStrings(FormattedParameters, "CSV");
            }
            else
            {
                FormattedParameters = AParameters;
                FormattedResult = this;
            }

            // write headings
            strLine = "";

            // for debugging:
            // strLine = StringHelper.AddCSV(strLine, "masterRow", separator);
            // strLine = StringHelper.AddCSV(strLine, "childRow", separator);
            // strLine = StringHelper.AddCSV(strLine, "depth", separator);

            strLine = StringHelper.AddCSV(strLine, "id", separator);

            if (FormattedParameters.Exists("ControlSource", ReportingConsts.HEADERPAGELEFT1,
                    -1, eParameterFit.eBestFit))
            {
                strLine = StringHelper.AddCSV(strLine, FormattedParameters.Get("ControlSource",
                        ReportingConsts.HEADERPAGELEFT1,
                        -1, eParameterFit.eBestFit).ToString(), separator);
            }

            if (FormattedParameters.Exists("ControlSource", ReportingConsts.HEADERPAGELEFT2,
                    -1, eParameterFit.eBestFit))
            {
                strLine = StringHelper.AddCSV(strLine, FormattedParameters.Get("ControlSource",
                        ReportingConsts.HEADERPAGELEFT2,
                        -1, eParameterFit.eBestFit).ToString(), separator);
            }

            if (FormattedParameters.Exists("ControlSource", ReportingConsts.HEADERCOLUMN,
                    -1, eParameterFit.eBestFit))
            {
                strLine = StringHelper.AddCSV(strLine, "header 1", separator);
                strLine = StringHelper.AddCSV(strLine, "header 0", separator);
            }

            useIndented = false;

            for (i = 0; i <= FormattedParameters.Get("lowestLevel").ToInt(); i++)
            {
                if (FormattedParameters.Exists("indented", ReportingConsts.ALLCOLUMNS, i, eParameterFit.eBestFit))
                {
                    useIndented = true;
                }
            }

            MaxDisplayColumns = AParameters.Get("MaxDisplayColumns").ToInt32();

            for (i = 0; i < MaxDisplayColumns; i++)
            {
                if ((!FormattedParameters.Get("ColumnCaption", i, -1, eParameterFit.eBestFit).IsNil()))
                {
                    strLine =
                        StringHelper.AddCSV(strLine,
                            (FormattedParameters.Get("ColumnCaption",
                                 i, -1, eParameterFit.eBestFit).ToString() + ' ' +
                             FormattedParameters.Get("ColumnCaption2",
                                 i, -1,
                                 eParameterFit.eBestFit).ToString(false) + ' ' +
                             FormattedParameters.Get("ColumnCaption3", i, -1, eParameterFit.eBestFit).ToString(
                                 false)).Trim(), separator);

                    if (useIndented)
                    {
                        strLine = StringHelper.AddCSV(strLine, "", separator);
                    }
                }
            }

            lines.Add(strLine);
            FormattedResult.SortChildren();
            sortedList = new ArrayList();
            FormattedResult.CreateSortedListByMaster(sortedList, 0);

            int LowestLevel = -1;

            if (AExportOnlyLowestLevel)
            {
                // find the highest level
                foreach (TResult element in sortedList)
                {
                    if (element.depth > LowestLevel)
                    {
                        LowestLevel = element.depth;
                    }
                }
            }

            // write each row to CSV file
            foreach (TResult element in sortedList)
            {
                if (AExportOnlyLowestLevel
                    && (element.depth < LowestLevel))
                {
                    continue;
                }

                if (element.display)
                {
                    strLine = "";

                    // for debugging
                    // strLine = StringHelper.AddCSV(strLine, element.masterRow.ToString(), separator);
                    // strLine = StringHelper.AddCSV(strLine, element.childRow.ToString(), separator);
                    // strLine = StringHelper.AddCSV(strLine, element.depth.ToString(), separator);

                    strLine = StringHelper.AddCSV(strLine, element.code, separator);

                    if (FormattedParameters.Exists("ControlSource", ReportingConsts.HEADERPAGELEFT1, -1, eParameterFit.eBestFit))
                    {
                        if (ADebugging)
                        {
                            strLine = StringHelper.AddCSV(strLine, element.descr[0].EncodeToString(), separator);
                        }
                        else
                        {
                            strLine = StringHelper.AddCSV(strLine, element.descr[0].ToString(), separator);
                        }
                    }

                    if (FormattedParameters.Exists("ControlSource", ReportingConsts.HEADERPAGELEFT2, -1, eParameterFit.eBestFit))
                    {
                        if (ADebugging)
                        {
                            strLine = StringHelper.AddCSV(strLine, element.descr[1].EncodeToString(), separator);
                        }
                        else
                        {
                            strLine = StringHelper.AddCSV(strLine, element.descr[1].ToString(), separator);
                        }
                    }

                    if (FormattedParameters.Exists("ControlSource", ReportingConsts.HEADERCOLUMN, -1, eParameterFit.eBestFit))
                    {
                        if (ADebugging)
                        {
                            strLine = StringHelper.AddCSV(strLine, element.header[1].EncodeToString(), separator);
                            strLine = StringHelper.AddCSV(strLine, element.header[0].EncodeToString(), separator);
                        }
                        else
                        {
                            strLine = StringHelper.AddCSV(strLine, element.header[1].ToString(), separator);
                            strLine = StringHelper.AddCSV(strLine, element.header[0].ToString(), separator);
                        }
                    }

                    /* TODO: try to export in the right codepage, to print umlaut and other special characters correctly
                     * if element.childRow = 7 then
                     * begin
                     * myEncoding := System.Text.Encoding.get_ASCII;
                     * TLogging.Log(Encoding.Default.EncodingName);
                     * TLogging.Log(element.column[0].ToString());
                     * SetLength(bytes, Encoding.Default.GetByteCount(element.column[0].ToString()));
                     * bytes := Encoding.Default.GetBytes(element.column[0].ToString());
                     * TLogging.Log(myEncoding.GetChars(bytes));
                     * // this will still not help with Excel
                     * end;
                     */
                    display = false;

                    for (i = 0; i <= MaxDisplayColumns - 1; i += 1)
                    {
                        if (FormattedParameters.Get("indented", i, element.depth, eParameterFit.eAllColumnFit).ToBool() == true)
                        {
                            strLine = StringHelper.AddCSV(strLine, "", separator);
                        }

                        if (((element.column[i] != null) && (!element.column[i].IsNil())) || (ADebugging))
                        {
                            display = true;

                            if (ADebugging)
                            {
                                strLine = StringHelper.AddCSV(strLine, element.column[i].EncodeToString(), separator);
                            }
                            else
                            {
                                strLine = StringHelper.AddCSV(strLine, element.column[i].ToString().Trim(), separator);
                            }
                        }
                        else
                        {
                            strLine = StringHelper.AddCSV(strLine, "", separator);
                        }

                        if ((FormattedParameters.Get("indented", i, element.depth, eParameterFit.eAllColumnFit).ToBool() != true) && useIndented)
                        {
                            strLine = StringHelper.AddCSV(strLine, "", separator);
                        }
                    }

                    if (display)
                    {
                        lines.Add(strLine);
                    }
                }
            }

            sortedList = null;
            return lines;
        }