/// <summary> /// This procedure will remove the currently selected column, /// and after that no column is selected /// /// </summary> /// <returns>void</returns> protected bool RemoveColumn(System.Int32 ASelectedColumn, bool AAskBeforeRemove) { bool ReturnValue; System.Int32 NewMaxColumn; ReturnValue = false; if ((!AAskBeforeRemove) || (MessageBox.Show("Do you really want to delete this column?", "Really delete?", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)) { NewMaxColumn = TUC_ColumnHelper.RemoveColumn(ref FColumnParameters, ASelectedColumn); /* need to move the following columns to the left */ FPetraUtilsObject.FMaxDisplayColumns = NewMaxColumn; FillColumnGrid(); FSelectedColumn = -1; SelectColumn(-1); ReturnValue = true; } return(ReturnValue); }
/// <summary> /// This procedure will switch the two columns /// and after that the column in the new position is selected /// /// </summary> /// <returns>void</returns> protected virtual void MoveColumn(System.Int32 ASelectedColumn, System.Int32 ANewColumnPosition) { if ((ANewColumnPosition > -1) && (ANewColumnPosition < FColumnParameters.Get("MaxDisplayColumns").ToInt())) { if (SelectColumn(-1)) { TUC_ColumnHelper.SwitchColumn(ref FColumnParameters, ASelectedColumn, ANewColumnPosition); FillColumnGrid(); SelectColumn(ANewColumnPosition); } } }
/// <summary> /// Sets the selected values in the controls, using the parameters loaded from a file /// /// </summary> /// <param name="AParameters"></param> /// <returns>void</returns> public void SetControls(TParameterList AParameters) { System.Int32 MaxDisplayColumns; MaxDisplayColumns = TUC_ColumnHelper.SetControls(ref FColumnParameters, ref AParameters); /* copy values for columns to the current set of parameters */ FPetraUtilsObject.FMaxDisplayColumns = MaxDisplayColumns; chkYTD.Checked = AParameters.Get("param_ytd").ToBool(); FillColumnGrid(); }
/// <summary> /// Reads the selected values from the controls, /// and stores them into the parameter system of FCalculator /// /// </summary> /// <param name="ACalculator"></param> /// <param name="AReportAction"></param> /// <returns>void</returns> public void ReadControls(TRptCalculator ACalculator, TReportActionEnum AReportAction) { System.Int32 MaxDisplayColumns; MaxDisplayColumns = TUC_ColumnHelper.ReadControls(ref FColumnParameters, ref ACalculator); FPetraUtilsObject.FMaxDisplayColumns = MaxDisplayColumns; for (int Counter = 0; Counter <= FColumnParameters.Get("MaxDisplayColumns").ToInt() - 1; Counter += 1) { String SelectedLedgers = FColumnParameters.Get("param_selected_ledgers", Counter).ToString(false); if (SelectedLedgers.Length != 0) { ACalculator.AddColumnFunctionLedgers(Counter, "add", StringHelper.StrSplit(SelectedLedgers, ","), FColumnParameters.Get("param_calculation", Counter).ToString(), FColumnParameters.Get("param_ytd", Counter).ToBool()); } } // set the global param_ytd; that is needed for formatting the header of some reports String ytdMixed = ""; for (int Counter = 0; Counter <= FColumnParameters.Get("MaxDisplayColumns").ToInt() - 1; ++Counter) { TVariant ParamYtd = FColumnParameters.Get("param_ytd", Counter); if (!ParamYtd.IsZeroOrNull()) { if (ytdMixed.Length == 0) { ytdMixed = ParamYtd.ToString(); } if (ParamYtd.ToString() != ytdMixed) { ytdMixed = "mixed"; } } } if (ytdMixed.Length != 0) { ACalculator.AddParameter("param_ytd", ytdMixed); } }
/// <summary> /// This procedure will add a new column; /// it will check if the currently selected column can be unselected; /// the new column is selected /// </summary> /// <param name="ASelectedColumn">the new column should be inserted after this column /// if it is -1, the column will be added at the right</param> /// <returns>true if a new column was added /// </returns> protected bool AddColumn(System.Int32 ASelectedColumn) { bool ReturnValue; System.Int32 NewColumn; ReturnValue = false; if (SelectColumn(-1)) { NewColumn = TUC_ColumnHelper.AddColumn(ref FColumnParameters, ASelectedColumn); FillColumnGrid(); SelectColumn(NewColumn); ApplyColumn(NewColumn, false); ReturnValue = true; } return(ReturnValue); }
/// <summary> /// Fills the column choice datagrid with the current values, /// that are stored in the local column parameters /// /// </summary> /// <returns>void</returns> public void FillColumnGrid() { DataTable ColumnTab; DataRow RowContent; DataRow RowAppliesTo; DataRow RowYTD; String AppliesTo; System.Int32 Column1; System.Int32 Column2; bool ShowAppliesTo; System.Int32 RowCounter; TVariant Ytd; ColumnTab = new System.Data.DataTable(); /* create columns */ for (int Counter = 0; Counter <= FColumnParameters.Get("MaxDisplayColumns").ToInt() - 1; Counter += 1) { ColumnTab.Columns.Add("Column " + Convert.ToString(Counter + 1)); } /* first row: name of calculation */ RowContent = ColumnTab.NewRow(); /* second row: if necessary with number of involved columns */ RowAppliesTo = ColumnTab.NewRow(); /* third row: Ytd */ RowYTD = ColumnTab.NewRow(); ShowAppliesTo = false; for (int Counter = 0; Counter <= FColumnParameters.Get("MaxDisplayColumns").ToInt() - 1; Counter += 1) { String Calculation = FColumnParameters.GetOrDefault("param_calculation", Counter, new TVariant(cmbColumnRelation.GetSelectedString())).ToString(); AppliesTo = ""; if (cmbColumnRelation.FindString(Calculation) != -1) { Column1 = FColumnParameters.Get("FirstColumn", Counter).ToInt(); Column2 = FColumnParameters.Get("SecondColumn", Counter).ToInt(); AppliesTo = AppliesTo + " (Column " + Convert.ToString(Column1 + 1); if (Column2 != -1) { AppliesTo = AppliesTo + " and " + Convert.ToString(Column2 + 1); } AppliesTo = AppliesTo + ")"; ShowAppliesTo = true; } else if (FColumnParameters.Exists("param_selected_ledgers", Counter)) { AppliesTo = AppliesTo + FColumnParameters.Get("param_selected_ledgers", Counter).ToString(); ShowAppliesTo = true; } RowAppliesTo[Counter] = AppliesTo; RowContent[Counter] = Calculation; /* YTD */ Ytd = FColumnParameters.Get("param_ytd", Counter); if (Ytd.IsZeroOrNull()) { RowYTD[Counter] = ""; } else { if (Ytd.ToBool()) { RowYTD[Counter] = "YTD"; } else { RowYTD[Counter] = "non-YTD"; } } } RowCounter = 0; ColumnTab.Rows.InsertAt(RowContent, RowCounter); if (ShowAppliesTo) { RowCounter = RowCounter + 1; ColumnTab.Rows.InsertAt(RowAppliesTo, RowCounter); } RowCounter = RowCounter + 1; ColumnTab.Rows.InsertAt(RowYTD, RowCounter); grdColumns.Columns.Clear(); for (int Counter = 0; Counter <= FColumnParameters.Get("MaxDisplayColumns").ToInt() - 1; Counter += 1) { grdColumns.AddTextColumn("Column " + Convert.ToString(Counter + 1), ColumnTab.Columns[Counter]); } grdColumns.DataSource = new DevAge.ComponentModel.BoundDataView(new DataView(ColumnTab)); grdColumns.DataSource.AllowEdit = false; grdColumns.DataSource.AllowNew = false; grdColumns.DataSource.AllowDelete = false; grdColumns.AutoSizeCells(); TUC_ColumnHelper.LoadDataToGrid(ref grdColumns, ref ColumnTab); }
/// <summary> /// This procedure will apply the current settings of the column, /// and then will unselect the column /// /// </summary> /// <returns>void</returns> protected bool ApplyColumn(System.Int32 ASelectedColumn, bool ACheckForDoubleEntries) { bool ReturnValue; String Calculation; System.Int32 Column1; System.Int32 Column2; TColumnFunction Func; ReturnValue = false; if (rbtFromGL.Checked) { Calculation = cmbYearSelection.GetSelectedString(0); } else { Calculation = cmbColumnRelation.GetSelectedString(0); } if (!ACheckForDoubleEntries || TUC_ColumnHelper.CheckAddDoubleEntry(ref FColumnParameters, Calculation, ASelectedColumn)) { if (rbtFromGL.Checked) { FColumnParameters.Add("param_calculation", new TVariant(cmbYearSelection.GetSelectedString(0)), ASelectedColumn); if (chkYTD.Visible) { FColumnParameters.Add("param_ytd", new TVariant(chkYTD.Checked), ASelectedColumn); } /* only add selected ledgers, if the list box is visible (multiledger screen) */ if (clbLedger.Visible) { FColumnParameters.Add("param_selected_ledgers", new TVariant(clbLedger.GetCheckedStringList()), ASelectedColumn); } } else { Calculation = cmbColumnRelation.GetSelectedString(); Column1 = cmbColumnSelection1.GetSelectedInt32(); Column2 = cmbColumnSelection2.GetSelectedInt32(); Func = GetFunction(Calculation); FColumnParameters.Add("param_calculation", new TVariant(Calculation), ASelectedColumn); if (Func != null) { if (Func.FNumberColumns > 0) { FColumnParameters.Add("FirstColumn", new TVariant(Column1), ASelectedColumn); } if (Func.FNumberColumns > 1) { FColumnParameters.Add("SecondColumn", new TVariant(Column2), ASelectedColumn); } } FColumnParameters.Add("param_ytd", new TVariant(), ASelectedColumn); FColumnParameters.RemoveVariable("param_selected_ledgers", ASelectedColumn); } ReturnValue = true; } return(ReturnValue); }
/// <summary> /// get the function object of the given calculation string /// </summary> /// <returns>nil if the function cannot be found /// </returns> protected TColumnFunction GetFunction(String calculation, TParameterList AParameterList, int AColumnNumber) { return(TUC_ColumnHelper.GetFunction(ref FAvailableFunctions, calculation, AParameterList, AColumnNumber)); }
/// <summary> /// get the function object of the given calculation string /// </summary> /// <returns>nil if the function cannot be found /// </returns> protected TColumnFunction GetFunction(String calculation) { return(TUC_ColumnHelper.GetFunction(ref FAvailableFunctions, calculation)); }