public void TestGeneralParametersProcessing() { TParameterList parameters = new TParameterList(); TVariant value = new TVariant(); value.ApplyFormatString("Currency"); Assert.AreEqual("0", value.ToFormattedString(), "null value for currency should be 0"); value = new TVariant(value.ToFormattedString()); parameters.Add("amountdue", value, -1, 2, null, null, ReportingConsts.CALCULATIONPARAMETERS); parameters.Save("testDebug.csv", true); Assert.AreEqual(true, parameters.Exists("amountdue", -1, 1, eParameterFit.eBestFitEvenLowerLevel), "can find added parameter"); Assert.AreEqual("0", parameters.Get("amountdue", -1, 2, eParameterFit.eBestFit).ToFormattedString(), "currency parameter is stored not correctly"); //Assert.AreEqual("0", parameters.Get("amountdue", -1, 1, eParameterFit.eBestFit).ToFormattedString(), "currency parameter is stored not correctly"); Assert.AreEqual("0", parameters.Get("amountdue", -1, 1, eParameterFit.eBestFitEvenLowerLevel).ToFormattedString(), "currency parameter cannot be accessed from level up"); parameters.Add("IntegerList", "300,400"); parameters.Save("test.csv", false); parameters.Load(Path.GetFullPath("test.csv")); Assert.AreEqual("eString:300,400", parameters.Get( "IntegerList").EncodeToString(), "integers separated by comma should be treated as string"); parameters.Save("test2.csv", true); }
/// <summary> /// Load stored options and parameters from a file; /// this will automatically make this setting the most recent /// if the setting does not exist, it is removed from the list of recent settings, and ASettingsName is cleared /// /// </summary> /// <returns>void</returns> public StringCollection LoadSettings(ref String ASettingsName, ref TParameterList AParameters) { StringCollection ReturnValue; String path; // need to switch back to the application directory, because the path names might be relative to the application Environment.CurrentDirectory = FApplicationDirectory; path = FSettingsDirectory + FReportName + System.IO.Path.DirectorySeparatorChar + ASettingsName + ".xml"; if (!System.IO.File.Exists(path)) { path = FUserSettingsDirectory + FReportName + System.IO.Path.DirectorySeparatorChar + ASettingsName + ".xml"; } if (System.IO.File.Exists(path)) { AParameters.Load(path); // nobody needs to see this variable AParameters.RemoveVariable("systemsettings"); ReturnValue = UpdateRecentlyUsedSettings(ASettingsName); } else { // setting does not exist anymore, and should disappear from the menu ReturnValue = UpdateRecentlyUsedSettings(ASettingsName); ReturnValue.Remove(ASettingsName); ASettingsName = ""; } return ReturnValue; }
/// <summary> /// calculate the report and save the result and returned parameters to file /// </summary> public static void CalculateReport(string AReportParameterXmlFile, TParameterList ASpecificParameters, int ALedgerNumber = -1) { // important: otherwise month names are in different language, etc Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB", false); TReportGeneratorUIConnector ReportGenerator = new TReportGeneratorUIConnector(); TParameterList Parameters = new TParameterList(); string resultFile = AReportParameterXmlFile.Replace(".xml", ".Results.xml"); string parameterFile = AReportParameterXmlFile.Replace(".xml", ".Parameters.xml"); Parameters.Load(AReportParameterXmlFile); if (ALedgerNumber != -1) { Parameters.Add("param_ledger_number_i", ALedgerNumber); } Parameters.Add(ASpecificParameters); ReportGenerator.Start(Parameters.ToDataTable()); while (!ReportGenerator.Progress.JobFinished) { Thread.Sleep(500); } Assert.IsTrue(ReportGenerator.GetSuccess(), "Report did not run successfully"); TResultList Results = new TResultList(); Results.LoadFromDataTable(ReportGenerator.GetResult()); Parameters.LoadFromDataTable(ReportGenerator.GetParameter()); if (!Parameters.Exists("ControlSource", ReportingConsts.HEADERPAGELEFT1, -1, eParameterFit.eBestFit)) { Parameters.Add("ControlSource", new TVariant("Left1"), ReportingConsts.HEADERPAGELEFT1); } if (!Parameters.Exists("ControlSource", ReportingConsts.HEADERPAGELEFT2, -1, eParameterFit.eBestFit)) { Parameters.Add("ControlSource", new TVariant("Left2"), ReportingConsts.HEADERPAGELEFT2); } Parameters.Save(parameterFile, false); Results.WriteCSV(Parameters, resultFile, ",", false, false); }
/// <summary> /// This will check, if the set of settings with the given name is already existing /// and if it is a system settings; ie. it is provided by the organisation/OpenPetra.org and should not be overwritten. /// all settings in the user directory are non system settings, all in the {app}/reports30/Settings are system settings /// </summary> /// <returns>void</returns> public bool IsSystemSettings(String ASettingsName) { bool ReturnValue = false; // need to switch back to the application directory, because the path names might be relative to the application Environment.CurrentDirectory = FApplicationDirectory; String Filename = FSettingsDirectory + FReportName + System.IO.Path.DirectorySeparatorChar + ASettingsName + ".xml"; if (System.IO.File.Exists(Filename)) { TParameterList Parameters = new TParameterList(); try { Parameters.Load(Filename); if (Parameters.Get("systemsettings").ToBool()) { ReturnValue = true; } } finally { } } return ReturnValue; }
/// <summary> /// todoComment /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void MenuItemClick(System.Object sender, System.EventArgs e) { Int32 columnCounter; String detailReportCSV; String action; String query; String LineCode; DataRowView[] TheDataRowViewArray; TResult SelectedResult; String paramName; String paramValue; String SettingsDirectory; MenuItem ClickedMenuItem = (MenuItem)sender; TheDataRowViewArray = FGridView.SelectedDataRowsAsDataRowView; if (TheDataRowViewArray.Length <= 0) { // no row is selected return; } LineCode = TheDataRowViewArray[0][0].ToString(); SelectedResult = null; foreach (TResult r in results.GetResults()) { if (r.code == LineCode) { SelectedResult = r; } } detailReportCSV = (String)ClickedMenuItem.Tag; StringHelper.GetNextCSV(ref detailReportCSV, ","); // get rid of the name action = StringHelper.GetNextCSV(ref detailReportCSV, ","); if (action == "PartnerEditScreen") { #if TODO // get the partner key Int64 PartnerKey = Convert.ToInt64(SelectedResult.column[Convert.ToInt32(detailReportCSV)].ToString()); // TODO: open Partner Edit screen with the given partner key #endif } else if (action.IndexOf(".xml") != -1) { query = StringHelper.GetNextCSV(ref detailReportCSV, ","); FDetailParameters = new TParameterList(FOrigParameters); FDetailParameters.Add("param_whereSQL", query); // get the parameter names and values while (detailReportCSV.Length > 0) { paramName = StringHelper.GetNextCSV(ref detailReportCSV, ","); paramValue = StringHelper.GetNextCSV(ref detailReportCSV, ","); FDetailParameters.Add(paramName, new TVariant(paramValue)); } // add the values of the selected column (in this example the first one) for (columnCounter = 0; columnCounter <= FDetailParameters.Get("MaxDisplayColumns").ToInt() - 1; columnCounter += 1) { FDetailParameters.Add("param_" + FDetailParameters.Get("param_calculation", columnCounter).ToString(), SelectedResult.column[columnCounter]); } // action is a link to a settings file; it contains e.g. xmlfiles, currentReport, and column settings // TParameterList.Load adds the new parameters to the existing parameters SettingsDirectory = TClientSettings.ReportingPathReportSettings; FDetailParameters.Load(SettingsDirectory + '/' + action); GenerateReportInThread(); } }