/// <summary> /// Performs actions that need to happen once the user changes the value of the 'Charge Option' ComboBox. /// </summary> /// <param name="AAChargeOptionComboBox">'Charge Option' ComboBox Control</param> /// <param name="ADetailChargeAmountLabel">'Charge Amount' Label Control</param> /// <param name="ADetailChargeAmountTextBox">'Charge Amount' TextBox Control</param> /// <param name="ADetailChargePercentageTextBox">'Charge Percentage' TextBox Control</param> public static void ChargeOptionComboChanged(TCmbAutoComplete AAChargeOptionComboBox, Label ADetailChargeAmountLabel, TTxtNumericTextBox ADetailChargeAmountTextBox, TTxtNumericTextBox ADetailChargePercentageTextBox) { ADetailChargeAmountLabel.Text = AAChargeOptionComboBox.GetSelectedString() + Catalog.GetString(" Amount:"); ADetailChargeAmountTextBox.Enabled = true; ADetailChargePercentageTextBox.Enabled = true; switch (AAChargeOptionComboBox.SelectedIndex) { case 2: ADetailChargePercentageTextBox.Enabled = false; ADetailChargePercentageTextBox.NumberValueDecimal = (decimal)0.0; break; case 3: ADetailChargeAmountLabel.Text = Catalog.GetString("Amount:"); // overwrite what was assigned earlier on ADetailChargeAmountTextBox.Enabled = false; // overwrite what was assigned earlier on ADetailChargeAmountTextBox.NumberValueDecimal = (decimal)0.0; break; } }
/// <summary> /// Sets up the value cell(s) for a specific data label /// /// </summary> /// <returns>void</returns> private void SetupGridValueCell(Int32 ARowIndex, PDataLabelRow ADataLabelRow) { Control cellControl; System.Windows.Forms.TextBox TextBoxEditor; TtxtPetraDate DateEditor; System.Windows.Forms.CheckBox CheckBoxEditor; TTxtNumericTextBox TextBoxNumericEditor; TTxtCurrencyTextBox TextBoxCurrencyEditor; TCmbAutoPopulated LookupValueEditor; TtxtAutoPopulatedButtonLabel PartnerKeyEditor; SourceGrid.Cells.Views.Cell ValueModel; SourceGrid.Cells.Views.Cell SuffixModel; PDataLabelValuePartnerRow DataLabelValuePartnerRow; PDataLabelValueApplicationRow DataLabelValueApplicationRow; // prepare model for the value cells ValueModel = new SourceGrid.Cells.Views.Cell(); ValueModel.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft; ValueModel.Font = new Font(FLocalDataLabelValuesGrid.Font.FontFamily.Name, FLocalDataLabelValuesGrid.Font.Size, FontStyle.Bold); // prepare model for suffix cells (e.g. for currency) SuffixModel = new SourceGrid.Cells.Views.Cell(); SuffixModel.BackColor = FLocalDataLabelValuesGrid.BackColor; SuffixModel.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft; // In this case the data value rows will only be created once a value is entered GetOrCreateDataLabelValueRow(false, ADataLabelRow, out DataLabelValuePartnerRow, out DataLabelValueApplicationRow); // initialize cell control cellControl = null; // Create field, according to specified data type // Create character field if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_CHAR) { TextBoxEditor = new System.Windows.Forms.TextBox(); cellControl = TextBoxEditor; if (DataLabelValuePartnerRow != null) { TextBoxEditor.Text = DataLabelValuePartnerRow.ValueChar; } else if (DataLabelValueApplicationRow != null) { TextBoxEditor.Text = DataLabelValueApplicationRow.ValueChar; } else { // Default value if no Label data exists for the Partner TextBoxEditor.Text = ""; } // enable save button in editor when cell contents have changed TextBoxEditor.TextChanged += new EventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)TextBoxEditor, new Position(ARowIndex, 1))); FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = TextBoxEditor; } // Create float field else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_FLOAT) { TextBoxNumericEditor = new TTxtNumericTextBox(); if (ADataLabelRow.NumDecimalPlaces == 0) { TextBoxNumericEditor.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.LongInteger; TextBoxNumericEditor.MaxLength = 14; } else { TextBoxNumericEditor.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.Decimal; TextBoxNumericEditor.DecimalPlaces = ADataLabelRow.NumDecimalPlaces; // limit text length. 14 for number of digits, 5 for decimal and thousands separators TextBoxNumericEditor.MaxLength = 14 + 5 + ADataLabelRow.NumDecimalPlaces; } TextBoxNumericEditor.NullValueAllowed = true; cellControl = TextBoxNumericEditor; if (ADataLabelRow.NumDecimalPlaces == 0) { if (DataLabelValuePartnerRow != null) { TextBoxNumericEditor.NumberValueLongInt = (long)DataLabelValuePartnerRow.ValueNum; } else if (DataLabelValueApplicationRow != null) { TextBoxNumericEditor.NumberValueLongInt = (long)DataLabelValueApplicationRow.ValueNum; } else { // Default value if no Label data exists for the Partner TextBoxNumericEditor.NumberValueLongInt = null; } } else { if (DataLabelValuePartnerRow != null) { TextBoxNumericEditor.NumberValueDecimal = DataLabelValuePartnerRow.ValueNum; } else if (DataLabelValueApplicationRow != null) { TextBoxNumericEditor.NumberValueDecimal = DataLabelValueApplicationRow.ValueNum; } else { // Default value if no Label data exists for the Partner TextBoxNumericEditor.NumberValueDecimal = null; } } // enable save button in editor when cell contents have changed TextBoxNumericEditor.TextChanged += new EventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)TextBoxNumericEditor, new Position(ARowIndex, 1))); FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = TextBoxNumericEditor; } // Create data field else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_DATE) { DateEditor = new TtxtPetraDate(); DateEditor.Date = null; cellControl = DateEditor; if (DataLabelValuePartnerRow != null) { if (!DataLabelValuePartnerRow.IsValueDateNull()) { DateEditor.Date = DataLabelValuePartnerRow.ValueDate; } } else if (DataLabelValueApplicationRow != null) { if (!DataLabelValueApplicationRow.IsValueDateNull()) { DateEditor.Date = DataLabelValueApplicationRow.ValueDate; } } // enable save button in editor when cell contents have changed DateEditor.DateChanged += new TPetraDateChangedEventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)DateEditor, new Position(ARowIndex, 1))); FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = DateEditor; } // Create integer field else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_INTEGER) { TextBoxNumericEditor = new TTxtNumericTextBox(); TextBoxNumericEditor.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.Integer; TextBoxNumericEditor.NullValueAllowed = true; cellControl = TextBoxNumericEditor; if (DataLabelValuePartnerRow != null) { TextBoxNumericEditor.NumberValueInt = DataLabelValuePartnerRow.ValueInt; } else if (DataLabelValueApplicationRow != null) { TextBoxNumericEditor.NumberValueInt = DataLabelValueApplicationRow.ValueInt; } else { // Default value if no Label data exists for the Partner TextBoxNumericEditor.NumberValueInt = null; } // enable save button in editor when cell contents have changed TextBoxNumericEditor.TextChanged += new EventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)TextBoxNumericEditor, new Position(ARowIndex, 1))); FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = TextBoxNumericEditor; } // Create currency field else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_CURRENCY) { TextBoxCurrencyEditor = new TTxtCurrencyTextBox(); TextBoxCurrencyEditor.DecimalPlaces = 2; TextBoxCurrencyEditor.CurrencyCode = ADataLabelRow.CurrencyCode; TextBoxCurrencyEditor.NullValueAllowed = true; cellControl = TextBoxCurrencyEditor; if (DataLabelValuePartnerRow != null) { TextBoxCurrencyEditor.NumberValueDecimal = DataLabelValuePartnerRow.ValueCurrency; } else if (DataLabelValueApplicationRow != null) { TextBoxCurrencyEditor.NumberValueDecimal = DataLabelValueApplicationRow.ValueCurrency; } else { // Default value if no Label data exists for the Partner TextBoxCurrencyEditor.NumberValueDecimal = null; } // enable save button in editor when cell contents have changed TextBoxCurrencyEditor.TextChanged += new EventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)TextBoxCurrencyEditor, new Position(ARowIndex, 1))); FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = TextBoxCurrencyEditor; } // Create boolean field else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_BOOLEAN) { CheckBoxEditor = new System.Windows.Forms.CheckBox(); cellControl = CheckBoxEditor; if (DataLabelValuePartnerRow != null) { CheckBoxEditor.Checked = DataLabelValuePartnerRow.ValueBool; } else if (DataLabelValueApplicationRow != null) { CheckBoxEditor.Checked = DataLabelValueApplicationRow.ValueBool; } else { // Default value if no Label data exists for the Partner CheckBoxEditor.Checked = false; } // enable save button in editor when cell contents have changed CheckBoxEditor.CheckedChanged += new EventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)CheckBoxEditor, new Position(ARowIndex, 1))); FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = CheckBoxEditor; } // Create partner key field else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_PARTNERKEY) { PartnerKeyEditor = new TtxtAutoPopulatedButtonLabel(); PartnerKeyEditor.ASpecialSetting = true; PartnerKeyEditor.ButtonText = ADataLabelRow.Text + ':'; PartnerKeyEditor.ButtonTextAlign = System.Drawing.ContentAlignment.MiddleRight; PartnerKeyEditor.ListTable = TtxtAutoPopulatedButtonLabel.TListTableEnum.PartnerKey; PartnerKeyEditor.TabStop = false; cellControl = PartnerKeyEditor; // AutomaticallyUpdateDataSource: very rare, but needed here PartnerKeyEditor.AutomaticallyUpdateDataSource = true; if (DataLabelValuePartnerRow != null) { PartnerKeyEditor.Text = StringHelper.PartnerKeyToStr(DataLabelValuePartnerRow.ValuePartnerKey); } else if (DataLabelValueApplicationRow != null) { PartnerKeyEditor.Text = StringHelper.PartnerKeyToStr(DataLabelValueApplicationRow.ValuePartnerKey); } else { // Default value if no Label data exists for the Partner PartnerKeyEditor.Text = StringHelper.PartnerKeyToStr(0); } // display partner name linked to partner key PartnerKeyEditor.ResetLabelText(); // enable save button in editor when cell contents have changed PartnerKeyEditor.ValueChanged += new TDelegatePartnerChanged(this.PartnerKeyControlValueHasChanged); PartnerKeyEditor.TextChanged += new System.EventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 0] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue(PartnerKeyEditor, new Position(ARowIndex, 0))); FLocalDataLabelValuesGrid[ARowIndex, 0].Tag = PartnerKeyEditor; FLocalDataLabelValuesGrid[ARowIndex, 0].ColumnSpan = 3; } // Create lookup field else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_LOOKUP) { // Get the instance of the combobox (created in the actual user interface class) LookupValueEditor = new TCmbAutoPopulated(); LookupValueEditor.Filter = PDataLabelLookupTable.GetCategoryCodeDBName() + " = '" + ADataLabelRow.LookupCategoryCode + "'"; LookupValueEditor.ListTable = TCmbAutoPopulated.TListTableEnum.DataLabelLookupList; LookupValueEditor.InitialiseUserControl(); cellControl = LookupValueEditor; if (DataLabelValuePartnerRow != null) { LookupValueEditor.SetSelectedString(DataLabelValuePartnerRow.ValueLookup); } else if (DataLabelValueApplicationRow != null) { LookupValueEditor.SetSelectedString(DataLabelValueApplicationRow.ValueLookup); } else { // Default value if no Label data exists for the Partner LookupValueEditor.Text = ""; } // enable save button in editor when cell contents have changed LookupValueEditor.SelectedValueChanged += new EventHandler(this.ControlValueHasChanged); LookupValueEditor.TextChanged += new EventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)LookupValueEditor, new Position(ARowIndex, 1))); FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = LookupValueEditor; FLocalDataLabelValuesGrid[ARowIndex, 1].ColumnSpan = 2; } // perform actions that need to be done for each control if (cellControl != null) { // remember the added control to get the value back lateron FGridRowInfo.SetControl(ARowIndex, cellControl); // handle focus change when field is entered cellControl.Enter += new EventHandler(this.UpdateGridFocusFromExternalControl); // set help text for control PetraUtilsObject.SetStatusBarText(cellControl, ADataLabelRow.Description); } // check if value is editable if (!ADataLabelRow.Editable) { FLocalDataLabelValuesGrid[ARowIndex, 1].Editor.EnableEdit = false; } }
public void TestDoubleValues() { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); TTxtNumericTextBox txtBox = new TTxtNumericTextBox(); txtBox.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.Decimal; txtBox.DecimalPlaces = 2; txtBox.NumberValueDouble = 1410.95; Assert.AreEqual(1410.95, txtBox.NumberValueDouble, "double value stored in british culture"); Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); txtBox.NumberValueDouble = 0.0; txtBox.NumberValueDouble = 1410.95; Assert.AreEqual(1410.95, txtBox.NumberValueDouble, "double value stored in german culture, switching culture, same txt object"); Assert.AreEqual("1,410.95", txtBox.Text, "text value stored in german culture, switching culture, same txt object, therefore still british format"); Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); TTxtNumericTextBox txtDEBox = new TTxtNumericTextBox(); txtDEBox.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.Decimal; txtDEBox.DecimalPlaces = 2; txtDEBox.NumberValueDouble = 0.0; txtDEBox.NumberValueDouble = 1410.95; Assert.AreEqual("1.410,95", txtDEBox.Text, "text value stored in german culture"); Assert.AreEqual(1410.95, txtDEBox.NumberValueDouble, "double value stored in german culture"); txtDEBox.NumberValueDouble = 1234410.95; Assert.AreEqual("1.234.410,95", txtDEBox.Text, "huge number text value stored in german culture"); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB"); txtBox.NumberValueDouble = 0.0; txtBox.NumberValueDouble = 30.00; Assert.AreEqual(30.00, txtBox.NumberValueDouble, "double value stored in english culture, with english UI"); Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB"); txtBox.NumberValueDouble = 0.0; txtBox.NumberValueDouble = 1410.95; Assert.AreEqual(1410.95, txtBox.NumberValueDouble, "double value stored in german culture, but english UI"); }
public void TestIntegerValues() { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); TTxtNumericTextBox txtBox = new TTxtNumericTextBox(); txtBox.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.Integer; txtBox.NumberValueInt = 1410; Assert.AreEqual(1410, txtBox.NumberValueInt, "integer value stored in british culture"); Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); txtBox.NumberValueInt = 0; txtBox.NumberValueInt = 1410; Assert.AreEqual(1410, txtBox.NumberValueInt, "integer value stored in german culture, switching culture, same txt object"); Assert.AreEqual("1410", txtBox.Text, "text value stored in german culture, switching culture, same txt object, therefore still british format"); Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); TTxtNumericTextBox txtDEBox = new TTxtNumericTextBox(); txtDEBox.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.Integer; txtDEBox.NumberValueInt = 0; txtDEBox.NumberValueInt = 1410; Assert.AreEqual("1410", txtDEBox.Text, "text value stored in german culture"); Assert.AreEqual(1410, txtDEBox.NumberValueInt, "integer value stored in german culture"); txtDEBox.NumberValueInt = 1234410; Assert.AreEqual("1234410", txtDEBox.Text, "huge number text value stored in german culture"); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB"); txtBox.NumberValueInt = 0; txtBox.NumberValueInt = 30; Assert.AreEqual(30, txtBox.NumberValueInt, "integer value stored in english culture, with english UI"); Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB"); txtBox.NumberValueInt = 0; txtBox.NumberValueInt = 1410; Assert.AreEqual(1410, txtBox.NumberValueInt, "integer value stored in german culture, but english UI"); }
/// <summary> /// Method to cancel a specified journal /// </summary> /// <param name="ACurrentJournalRow">The row to cancel</param> /// <param name="AJournalDescriptionTextBox">Pass a reference to a TextBox that is used to display the journal description text. This is required /// to ensure that validation passes when the cancelled journal is saved.</param> /// <param name="AExchangeRateToBaseTextBox">Pass a reference to a TextBox that is used to display the exchange rate to base. This is required /// to ensure that validation passes when the cancelled journal is saved.</param> /// <returns>True if the journal is cancelled.</returns> public bool CancelRow(GLBatchTDSAJournalRow ACurrentJournalRow, TextBox AJournalDescriptionTextBox, TTxtNumericTextBox AExchangeRateToBaseTextBox) { if ((ACurrentJournalRow == null) || !FMyForm.SaveChanges()) { return false; } int CurrentBatchNumber = ACurrentJournalRow.BatchNumber; int CurrentJournalNumber = ACurrentJournalRow.JournalNumber; if ((MessageBox.Show(String.Format(Catalog.GetString( "You have chosen to cancel this journal ({0}).\n\nDo you really want to cancel it?"), CurrentJournalNumber), Catalog.GetString("Confirm Cancel"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)) { try { //clear any transactions currently being editied in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(); //Load any new data FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransactionATransAnalAttrib(FLedgerNumber, CurrentBatchNumber, CurrentJournalNumber)); DataView dvAA = new DataView(FMainDS.ATransAnalAttrib); dvAA.RowFilter = String.Format("{0}={1} AND {2}={3}", ATransAnalAttribTable.GetBatchNumberDBName(), CurrentBatchNumber, ATransAnalAttribTable.GetJournalNumberDBName(), CurrentJournalNumber); //Delete Analysis Attribs foreach (DataRowView dvr in dvAA) { dvr.Delete(); } DataView dvTr = new DataView(FMainDS.ATransaction); dvTr.RowFilter = String.Format("{0}={1} AND {2}={3}", ATransactionTable.GetBatchNumberDBName(), CurrentBatchNumber, ATransactionTable.GetJournalNumberDBName(), CurrentJournalNumber); //Delete Transactions foreach (DataRowView dvr in dvTr) { dvr.Delete(); } ACurrentJournalRow.BeginEdit(); ACurrentJournalRow.JournalStatus = MFinanceConstants.BATCH_CANCELLED; //Ensure validation passes if (ACurrentJournalRow.JournalDescription.Length == 0) { AJournalDescriptionTextBox.Text = " "; } if (ACurrentJournalRow.ExchangeRateToBase == 0) { AExchangeRateToBaseTextBox.NumberValueDecimal = 1; } ABatchRow CurrentBatchRow = FMyForm.GetBatchControl().GetSelectedDetailRow(); CurrentBatchRow.BatchCreditTotal -= ACurrentJournalRow.JournalCreditTotal; CurrentBatchRow.BatchDebitTotal -= ACurrentJournalRow.JournalDebitTotal; if (CurrentBatchRow.BatchControlTotal != 0) { CurrentBatchRow.BatchControlTotal -= ACurrentJournalRow.JournalCreditTotal; } ACurrentJournalRow.JournalCreditTotal = 0; ACurrentJournalRow.JournalDebitTotal = 0; ACurrentJournalRow.EndEdit(); FPetraUtilsObject.SetChangedFlag(); //Need to call save if (FMyForm.SaveChanges()) { MessageBox.Show(Catalog.GetString("The journal has been cancelled successfully!"), Catalog.GetString("Success"), MessageBoxButtons.OK, MessageBoxIcon.Information); FMyForm.DisableTransactions(); } else { // saving failed, therefore do not try to post MessageBox.Show(Catalog.GetString( "The journal has been cancelled but there were problems during saving; ") + Environment.NewLine + Catalog.GetString("Please try and save the cancellation immediately."), Catalog.GetString("Failure"), MessageBoxButtons.OK, MessageBoxIcon.Error); } return true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } return false; }