예제 #1
0
        // Simple validation to check if new locale is an extension of a default locale
        private void CustomLocaleField_Validating(object sender, CancelEventArgs e)
        {
            String  newLocale = CustomLocaleField.Text.Trim();
            String  baseLocale;
            Boolean isValid = false;

            if (newLocale.Length > 0 && newLocale != TextHelper.GetString("Label.AddCustomLocale"))
            {
                foreach (ListItem locale in _defaultLocales)
                {
                    baseLocale = locale.Value + "-";
                    if (newLocale.StartsWithOrdinal(baseLocale) && newLocale.Length > baseLocale.Length)
                    {
                        isValid = true;
                        break;
                    }
                }
                if (!isValid)
                {
                    ValidationErrorProvider.SetError(CustomLocaleField, TextHelper.GetString("Validation.InvalidLocale"));
                    e.Cancel = true;
                }
                else
                {
                    ValidationErrorProvider.SetError(CustomLocaleField, "");
                }
            }
            else
            {
                ValidationErrorProvider.SetError(CustomLocaleField, "");
            }
            _customLocaleIsValid = isValid;
        }
예제 #2
0
        private bool ValidateControls( )
        {
            if (ImageRadioButton.Checked && ImageTextBox.Text.Length == 0)
            {
                ValidationErrorProvider.SetError(ImageRadioButton, "No image is selected.");

                return(false);
            }
            else
            {
                ValidationErrorProvider.SetError(ImageRadioButton, string.Empty);
            }

            if (CustomRadioButton.Checked && CustomTextBox.Text.Length == 0)
            {
                ValidationErrorProvider.SetError(CustomRadioButton, "Enter label text");

                return(false);
            }
            else
            {
                ValidationErrorProvider.SetError(CustomRadioButton, string.Empty);
            }

            return(true);
        }
 //Clear text boxes and errors, send focus back to Date
 private void ClearUserInput()
 {
     DatePicker.Value           = DateTime.Today;
     DepositRadioButton.Checked = true;
     AmountTextBox.Text         = "";
     PayeeTextBox.Text          = "";
     CheckTextBox.Text          = "";
     ValidationErrorProvider.Clear();
     DepositRadioButton.Focus();
 }
        //Collect user input, validate input, update balance if validation passed, clear form
        private void AddTransButton_Click(object sender, EventArgs e)
        {
            ValidationErrorProvider.Clear(); //Clear previous errors

            if (UserInputCompleted())        //User input is in correct format
            {
                decimal TempAmount = decimal.Parse(AmountTextBox.Text);
                if (Transaction.DecimalExcedeZero(TempAmount))//Amount is greater than Zero
                {
                    //Create Transaction
                    Transaction NewTransaction = new Transaction(DatePicker.Value, TempAmount, SelectedType, PayeeTextBox.Text,
                                                                 CheckTextBox.Text);
                    Transactions.Add(NewTransaction);                  //Add Transaction to TransactionList
                    UpdateBalanceLabel();                              //Display new balance

                    TransListBox.Items.Add(NewTransaction.ToString()); //Add transaction to listbox
                }
            }
        }
        //Check validity of important fields
        private bool UserInputCompleted()
        {
            bool InputComplete = true;                //Flag

            if (!Transaction.IsDate(DatePicker.Text)) //Date can be parsed
            {
                InputComplete = false;
                ValidationErrorProvider.SetError(DatePicker, string.Format(DATEINPUTERROR, DatePicker.Text));
            }
            if (!Transaction.IsDecimal(AmountTextBox.Text)) //Parsed as decimal
            {
                InputComplete = false;
                ValidationErrorProvider.SetError(AmountTextBox, AMOUNTINPUTERROR);
            }
            if (WithdrawRadioButton.Checked)//Payee entered if withdraw type selected
            {
                if (PayeeTextBox.Text == string.Empty)
                {
                    InputComplete = false;
                    ValidationErrorProvider.SetError(PayeeTextBox, PAYEEINPUTERROR);
                }
            }
            return(InputComplete);
        }