Exemplo n.º 1
0
        /// <summary>
        /// Replaces the field name with NULL if it is not needed in order to improve the performance of certain reports.
        /// </summary>
        /// <param name="AParameters"></param>
        /// <param name="AColumnDBNamesAndAliases">Dictionary of the column names. Key: full DB Name, Value: Alias.</param>
        /// <returns></returns>
        public static string ReplaceColumnWithNullWhenUnused(Dictionary <String, TVariant> AParameters,
                                                             Dictionary <String, String> AColumnDBNamesAndAliases)
        {
            List <string> Columns = new List <string>();

            TColumnSettingCollection tcsc = new TColumnSettingCollection();

            tcsc.DeserialiseCollection(AParameters["param_columns"].ToString());

            foreach (KeyValuePair <string, string> entry in AColumnDBNamesAndAliases)
            {
                if (tcsc.HasSettingForColumn(entry.Value))
                {
                    Columns.Add(entry.Key + " AS " + entry.Value);
                }
                else
                {
                    Columns.Add("NULL AS " + entry.Value);
                }
            }

            return(String.Join(",", Columns));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Helper function to load the Report Data in the standard case where no client-side processing is required.
        /// </summary>
        /// <param name="AUseProgressBar">Use a ProgressBar?</param>
        /// <param name="AReportName">The Name of the Report</param>
        /// <param name="AUseDataSet">True, if a ReportSet is used</param>
        /// <param name="ATableNames">The Names of the Tables</param>
        /// <param name="ACalc">ACalc object</param>
        /// <param name="AWindow">"Parent" Window</param>
        /// <param name="AUseColumnTab">"Parent" Window</param>
        /// <param name="AAddLedger">"Adds the Ledger Name to the Parameters"</param>
        /// <param name="ALedgerNumber">"The Ledger Number if used"</param>
        /// <param name="AMainTableName">Indicating Table (name) whether a report would be blank. Only if DataSet is used and Main Table isn't the first in the DataSet. </param>
        /// <param name="ASortBy">"Sort By..."</param>
        /// <returns></returns>
        public bool LoadReportData(
            bool AUseProgressBar,
            string AReportName,
            bool AUseDataSet,
            string[] ATableNames,
            TRptCalculator ACalc,
            Form AWindow,
            bool AUseColumnTab,
            bool AAddLedger       = false,
            Int32 ALedgerNumber   = -1,
            string AMainTableName = "",
            string ASortBy        = ""
            )
        {
            if (AUseColumnTab)
            {
                TColumnSettingCollection tcsc = new TColumnSettingCollection();

                for (int counter = 0; counter <= ACalc.GetParameters().Get("MaxDisplayColumns").ToInt() - 1; counter += 1)
                {
                    TColumnSetting tcs = new TColumnSetting(ACalc.GetParameters().Get("param_calculation", counter).ToString().Replace(" ",
                                                                                                                                       "").Replace("/", ""),
                                                            float.Parse(ACalc.GetParameters().Get("ColumnWidth", counter).ToString()), counter + 1);
                    tcsc.SetSettingForColumn(tcs);
                }

                ACalc.AddParameter("param_columns", tcsc.SerialiseCollection());
            }

            //paramsDictionary also contains the selected columns as serialised string
            Dictionary <String, TVariant> paramsDictionary = ParamsToDictionary(ACalc);

            DataTable ReportTable = null;
            DataSet   ReportSet   = null;


            Thread t;
            bool   ThreadFinished = false;

            if (AUseDataSet)
            {
                t = new Thread(() => ReportSet = GetReportDataSet(AReportName, paramsDictionary, ref ThreadFinished));
            }
            else
            {
                t = new Thread(() => ReportTable = GetReportDataTable(AReportName, paramsDictionary, ref ThreadFinished));
            }

            if (AUseProgressBar)
            {
                using (TProgressDialog dialog = new TProgressDialog(t))
                {
                    dialog.SetRefreshInterval(200);
                    dialog.ShowDialog();
                }

                // wait here until Thread is really finished
                while (!ThreadFinished)
                {
                    Thread.Sleep(50);
                }
            }
            else
            {
                t.Start();
                t.Join();
            }

            if ((AWindow == null) || AWindow.IsDisposed)
            {
                return(false);
            }

            if ((ReportTable == null) && (ReportSet == null))
            {
                FPetraUtilsObject.WriteToStatusBar("Report Cancelled.");
                return(false);
            }

            //Message if Report would be blank
            string Message = Catalog.GetString("No data has been found for the current selection.");

            if (AUseDataSet)
            {
                bool error = false;

                if (AMainTableName == String.Empty)
                {
                    if (ReportSet.Tables[0].Rows.Count == 0)
                    {
                        error = true;
                    }
                }
                else
                {
                    if (ReportSet.Tables[AMainTableName].Rows.Count == 0)
                    {
                        error = true;
                    }
                }

                if (error)
                {
                    MessageBox.Show(Message, "Error");
                    FPetraUtilsObject.WriteToStatusBar(Catalog.GetString("No data found for current selection."));
                    return(false);
                }
            }
            else if (ReportTable.Rows.Count == 0)
            {
                MessageBox.Show(Message, "Error");
                FPetraUtilsObject.WriteToStatusBar(Catalog.GetString("No data found for current selection."));
                return(false);
            }

            if (AAddLedger)
            {
                DataTable LedgerNameTable = TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.LedgerNameList);
                DataView  LedgerView      = new DataView(LedgerNameTable);
                LedgerView.RowFilter = "LedgerNumber=" + ALedgerNumber;
                String LedgerName = "";

                if (LedgerView.Count > 0)
                {
                    LedgerName = LedgerView[0].Row["LedgerName"].ToString();
                }

                ACalc.AddStringParameter("param_ledger_name", LedgerName);
            }

            if (!AUseDataSet && (ASortBy != ""))
            {
                DataView dv = ReportTable.DefaultView;
                dv.Sort     = ASortBy;
                ReportTable = dv.ToTable();
            }

            if (AUseDataSet)
            {
                foreach (string TableName in ATableNames)
                {
                    RegisterData(ReportSet.Tables[TableName], TableName);
                }
            }
            else
            {
                RegisterData(ReportTable, ATableNames[0]);
            }

            return(true);
        }