Example #1
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);
        }
Example #2
0
        /// <summary>
        /// Performs inputed operation
        /// </summary>
        public (string calculationInput, string calculationHistory) Calculate(string calculationInput, string calculationHistory, string operation)
        {
            calculationInput = calculationInput.Replace('.', ',');

            double temp = double.Parse(calculationInput);

            if (firstArgument == null)
            {
                if (operation == _buttonValues.COS)
                {
                    calculationInput   = Math.Cos(temp).ToString("G5");
                    calculationHistory = $"cos ({temp})";
                }
                else if (operation == _buttonValues.INVERSE)
                {
                    calculationInput   = (1d / temp).ToString("G5");
                    calculationHistory = "1 / " + temp;
                }
                else if (operation == _buttonValues.SQRT)
                {
                    calculationInput   = Math.Sqrt(temp).ToString("G5");
                    calculationHistory = operation + temp;
                }
                else if (operation == _buttonValues.PLUS ||
                         operation == _buttonValues.MINUS ||
                         operation == _buttonValues.MULTIPY ||
                         operation == _buttonValues.DIVIDE)
                {
                    calculationHistory = temp + operation;
                    firstArgument      = temp;
                }
            }
            else if (operation != _buttonValues.EQUALS)
            {
                if (operation == _buttonValues.COS ||
                    operation == _buttonValues.SQRT ||
                    operation == _buttonValues.INVERSE)
                {
                    return(calculationInput, calculationHistory);
                }

                calculationHistory = firstArgument + operation;
            }


            if (operation == _buttonValues.EQUALS && (calculationHistory.ToString().Length > 0))
            {
                calculationHistory += calculationInput;

                operation = calculationHistory.ToString()[calculationHistory.ToString().Length - calculationInput.Length - 1].ToString();
                if (operation == _buttonValues.PLUS)
                {
                    calculationInput = (firstArgument + double.Parse(calculationInput)).ToString();
                }
                else if (operation == _buttonValues.MINUS)
                {
                    calculationInput = (firstArgument - double.Parse(calculationInput)).ToString();
                }
                else if (operation == _buttonValues.MULTIPY)
                {
                    double.TryParse((firstArgument * double.Parse(calculationInput)).ToString(), out double FormattedResult);
                    calculationInput = FormattedResult.ToString("G5");
                }
                else if (operation == _buttonValues.DIVIDE)
                {
                    double.TryParse((firstArgument / double.Parse(calculationInput)).ToString(), out double FormattedResult);
                    calculationInput = FormattedResult.ToString("G5");
                }
                else
                {
                    calculationHistory = calculationInput.Replace(calculationInput, string.Empty);
                }

                firstArgument = null;
            }

            calculationInput = calculationInput.Replace(',', '.');

            return(calculationInput, calculationHistory);
        }