예제 #1
0
        private void comboDestDir_TextChanged(object sender, System.EventArgs e)
        {
            buttonCheck.Enabled = buttonGo.Enabled = false;

            // check
            if (!System.IO.Directory.Exists(comboDestDir.Text))
            {
                // directory not found
                errorProvider.SetError(comboDestDir, "保存先フォルダが見つかりません。");
            }
            else if (!FileUtility.IsNTFS(comboDestDir.Text))
            {
                // not ntfs
                errorProvider.SetError(comboDestDir, "バックアップ保存先がNTFSボリュームではありません。");
            }
            else
            {
                // ok
                errorProvider.SetError(comboDestDir, "");
                labelPrevDir.Text = "前回バックアップ: " + Dumper.GetPreviousSnap(
                    comboDestDir.Text, DateTime.Now, (Int32)numericLimitDay.Value);
                if (errorProvider.GetError(comboBackupDir) == "")
                {
                    buttonCheck.Enabled = buttonGo.Enabled = true;
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Resets all of the errorproviders when anything succeeds
 /// </summary>
 private void ResetAllErrProviders()
 {
     foreach (Control ctl in this.Controls)
     {
         if (errorProvider.GetError(ctl) != "")
         {
             errorProvider.SetError(ctl, "");
         }
     }
 }
예제 #3
0
        private void butLeft_Click(object sender, System.EventArgs e)
        {
            if (errorProvider1.GetError(textDateFrom) != "" ||
                errorProvider1.GetError(textDateTo) != "")
            {
                MessageBox.Show(Lan.g(this, "Please fix data entry errors first."));
                return;
            }
            DateTime dateFrom  = PIn.PDate(textDateFrom.Text);
            DateTime dateTo    = PIn.PDate(textDateTo.Text);
            bool     toLastDay = false;

            if (CultureInfo.CurrentCulture.Calendar.GetDaysInMonth(dateTo.Year, dateTo.Month) == dateTo.Day)
            {
                toLastDay = true;
            }
            textDateFrom.Text = dateFrom.AddMonths(-1).ToString(Lan.g(this, "MM/dd"));
            textDateTo.Text   = dateTo.AddMonths(-1).ToString(Lan.g(this, "MM/dd"));
            if (toLastDay)
            {
                dateTo          = PIn.PDate(textDateTo.Text);
                textDateTo.Text = new DateTime(dateTo.Year, dateTo.Month,
                                               CultureInfo.CurrentCulture.Calendar.GetDaysInMonth(dateTo.Year, dateTo.Month))
                                  .ToString(Lan.g(this, "MM/dd"));
            }
        }
예제 #4
0
 // This method demonstrates using the ErrorProvider.GetError method
 // to check for an error before opening the dialog box.
 private void button1_Click(System.Object sender, System.EventArgs e)
 {
     //If there is no error, then open the dialog box.
     if (errorProvider1.GetError(textBox1) == "")
     {
         DialogResult dialogResult = openFileDialog1.ShowDialog();
     }
 }
예제 #5
0
 public static void GetErrorMessages(Control parentControl, ICollection<string> errorList, ErrorProvider errorProvider )
 {
     string error = errorProvider.GetError(parentControl);
     if (!string.IsNullOrWhiteSpace(error) && !errorList.Contains(error))
         errorList.Add(error);
     foreach (Control control in parentControl.Controls)
         GetErrorMessages(control, errorList, errorProvider);
 }
예제 #6
0
 public static bool TryFocusInvalidInput(ErrorProvider errorProvider, Control control)
 {
     if (!string.IsNullOrEmpty(errorProvider.GetError(control)))
     {
         control.Focus();
         return true;
     }
     return false;
 }
예제 #7
0
		public void GetandSetErrorTest ()
		{
			Form myForm = new Form ();
			myForm.ShowInTaskbar = false;
			Label label1 = new Label ();
			Label label2 = new Label ();
			ErrorProvider myErrorProvider = new ErrorProvider ();
			Assert.AreEqual (string.Empty, myErrorProvider.GetError (label1), "#1");
			myErrorProvider.SetError (label1, "ErrorMsg1");
			Assert.AreEqual ("ErrorMsg1", myErrorProvider.GetError (label1), "#2");
			Assert.AreEqual (string.Empty, myErrorProvider.GetError (label2), "#3");
			myErrorProvider.SetError (label2, "ErrorMsg2");
			Assert.AreEqual ("ErrorMsg2", myErrorProvider.GetError (label2), "#4");
			myErrorProvider.SetError (label2, null);
			Assert.AreEqual ("ErrorMsg1", myErrorProvider.GetError (label1), "#5");
			Assert.AreEqual (string.Empty, myErrorProvider.GetError (label2), "#6");
			myForm.Dispose ();
		}
예제 #8
0
        /// <summary>
        /// Event handler for the X coordinte text box.
        /// If an invalid character is entered, the event handler does not accept it.
        /// The event handler also enables/disables the Add Point button.
        /// </summary>
        private void txt_TextChanged(object sender, EventArgs e)
        {
            double garbage;

            if (!double.TryParse(((TextBox)sender).Text, out garbage))
            {
                ErrorProvider1.SetError((TextBox)sender, "Please only enter valid numeric coordinates");
            }
            // Added by Lailin Chen 6/2/2005 start1
            else if (ErrorProvider1.GetError((TextBox)sender) != null)
            {
                ErrorProvider1.SetError((TextBox)sender, null);
            }
            // Added by Lailin Chen 6/2/2005 end1
            btnAddPoint.Enabled = ValidateText();
        }
예제 #9
0
        public void SetError(ErrorProvider provider , Control control, string message)
        {
            if (!string.IsNullOrEmpty(message))
            {
                if (provider.GetError(control) != "")
                {
                    provider.Clear();
                    Counter--;

                }
                else
                {
                    provider.SetError(control,message);
                    Counter ++;
                }
            }
        }
        public void ValidationIsClearedForControlWhenControlPropertyIsSetAndErrorIsCleared()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "StringProperty");
            ValidatedControlItem controlItem1 = validationProvider.GetExistingValidatedControlItem(control1);
            MockControl control2 = new MockControl();
            validationProvider.SetSourcePropertyName(control2, "StringProperty");
            ValidatedControlItem controlItem2 = validationProvider.GetExistingValidatedControlItem(control2);
            ErrorProvider errorProvider = new ErrorProvider();
            validationProvider.ErrorProvider = errorProvider;

            control1.Text = "000000000001";
            control2.Text = "000000000001";

            validationProvider.PerformValidation(control1);
            validationProvider.PerformValidation(control2);

            Assert.IsFalse(validationProvider.IsValid);
            Assert.IsFalse(controlItem1.IsValid);
            Assert.IsFalse(controlItem2.IsValid);
            Assert.AreEqual("string property", errorProvider.GetError(control1));
            Assert.AreEqual("string property", errorProvider.GetError(control2));

            validationProvider.ValidationPerformed += OnValidationPerformed;
            validationProvider.SetSourcePropertyName(control2, "IntProperty");

            Assert.IsFalse(validationProvider.IsValid);
            Assert.IsFalse(controlItem1.IsValid);
            Assert.IsTrue(controlItem2.IsValid);
            Assert.AreEqual("string property", errorProvider.GetError(control1));
            Assert.AreEqual(string.Empty, errorProvider.GetError(control2));
            Assert.IsNull(validationPerformedEventArgs);

            validationProvider.PerformValidation(control2);

            Assert.IsFalse(validationProvider.IsValid);
            Assert.IsFalse(controlItem1.IsValid);
            Assert.IsFalse(controlItem2.IsValid);
            Assert.AreEqual("string property", errorProvider.GetError(control1));
            Assert.AreEqual("int property", errorProvider.GetError(control2));
            Assert.IsNotNull(validationPerformedEventArgs);
        }
        public void ValueConvertingCallbackSettingConversionErrorMessageWillUseMessageOnErrorProviderIfExists()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.ValueConvert += OnValueConvertFailing;
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "IntProperty");
            ErrorProvider errorProvider = new ErrorProvider();
            validationProvider.ErrorProvider = errorProvider;

            control1.Text = "5";

            validationProvider.PerformValidation(control1);

            Assert.IsNotNull(valueConvertEventArgs); // callback was called
            Assert.AreEqual(0,
                            MockValidator<object>.CreatedValidators[0].ValidatedTargets.Count); // nothing got validated
            Assert.IsFalse(validationProvider.IsValid); // but the provider is invalid
            Assert.AreEqual("failed conversion", errorProvider.GetError(control1)); // and the error was set on the error provider
        }
        public void ExistingValidationErrorsAreClearedWhenDisablingValidationProviderButNotSetAgainWhenEnablingTheValidationProvider()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            MockControl control1 = new MockControl();
            validationProvider.SetSourcePropertyName(control1, "StringProperty");
            ErrorProvider errorProvider = new ErrorProvider();
            validationProvider.ErrorProvider = errorProvider;

            control1.Text = "too long";

            validationProvider.PerformValidation(control1);

            Assert.AreEqual("validation", errorProvider.GetError(control1));

            validationProvider.Enabled = false; // set validation provider to disabled

            Assert.AreEqual("", errorProvider.GetError(control1));

            validationProvider.Enabled = true; // set validation provider to enabled

            Assert.AreEqual("", errorProvider.GetError(control1));
        }
        public void ErrorsInErrorProviderForValidatedControlsAreClearedByValidatorProviderDispose()
        {
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            ErrorProvider errorProvider = new ErrorProvider();
            validationProvider.ErrorProvider = errorProvider;

            MockControl controlWithoutError = new MockControl();
            controlWithoutError.Text = "short";
            validationProvider.SetSourcePropertyName(controlWithoutError, "StringProperty");
            MockControl controlWithError = new MockControl();
            controlWithError.Text = "too long";
            validationProvider.SetSourcePropertyName(controlWithError, "StringProperty");
            MockControl controlWithoutValidation = new MockControl();
            controlWithoutValidation.Text = "too long";

            validationProvider.PerformValidation(controlWithoutError);
            validationProvider.PerformValidation(controlWithError);
            errorProvider.SetError(controlWithoutValidation, "an unmanaged error");

            Assert.AreEqual(string.Empty, errorProvider.GetError(controlWithoutError));
            Assert.AreEqual("validation", errorProvider.GetError(controlWithError));
            Assert.AreEqual("an unmanaged error", errorProvider.GetError(controlWithoutValidation));

            validationProvider.Dispose();

            Assert.AreEqual(string.Empty, errorProvider.GetError(controlWithoutError));
            Assert.AreEqual(string.Empty, errorProvider.GetError(controlWithError));
            Assert.AreEqual("an unmanaged error", errorProvider.GetError(controlWithoutValidation));
        }
        public void ErrorProviderErrorForControlIsClearedAfterPerformingSuccessfulValidation()
        {
            ErrorProvider errorProvider = new ErrorProvider();
            ValidationProvider validationProvider = new ValidationProvider();
            validationProvider.SourceTypeName = typeof(ValidationProviderFixtureTestClass).AssemblyQualifiedName;
            validationProvider.RulesetName = "validation";
            validationProvider.ErrorProvider = errorProvider;
            MockControl control = new MockControl();
            ValidatedControlItem validatedControlItem
                = new ValidatedControlItem(validationProvider, control);
            validatedControlItem.SourcePropertyName = "StringProperty";

            control.Text = "too long";
            validationProvider.PerformValidation(validatedControlItem);

            Assert.AreNotEqual(string.Empty, errorProvider.GetError(control));
        }
예제 #15
0
        /// <summary>
        /// Validate controls in form using supplied error provider.
        /// </summary>
        /// <param name="erPr"></param>
        /// <param name="ctrl"></param>
        /// <returns></returns>
        public static bool ValidateForm(ErrorProvider erPr, Control ctrl)
        {
            bool isValid = true;

            foreach (Control control in ctrl.Controls)
            {
                control.Focus();
                ctrl.Focus();

                string msg = erPr.GetError(control);

                if (msg != "")
                    isValid = false;
            }

            return isValid;
        }
예제 #16
0
		public void txtPageBottom_ValidatedBL(object sender, EventArgs e)
		{
			try
			{
				bool result = Common.AssignValuePageUnit(cTool.TxtPageBottom, null);
				_errProvider = Common._errProvider;
				if (_errProvider.GetError(cTool.TxtPageBottom) != "")
				{
					_errProvider.SetError(cTool.TxtPageBottom, _errProvider.GetError(cTool.TxtPageBottom));
				}
				else
				{
					ValidatePageHeightMargins(sender, e);
				}
			}
			catch { }
		}
		/// <summary>
		/// Shows error message for the given control
		/// </summary>
		/// <param name="control">Control</param>
		/// <param name="errorProvider">Error provider</param>
		/// <param name="error">Error message</param>
		public static void ShowError(Control control, ErrorProvider errorProvider, string error)
		{
			// Current error
			error = (error ?? string.Empty).Trim();
			error = (error.Length == 0) ? null : error;

			// Previous error
			string existingError = errorProvider.GetError(control);
			existingError = (existingError ?? string.Empty).Trim();
			existingError = (existingError.Length == 0) ? null : existingError;

			// Apply
			if (error != null)
			{
				if (existingError == null)
				{
					control.Width -= 32;
				}
				errorProvider.SetError(control, error);
			}
			else
			{
				errorProvider.SetError(control, null);
				if (existingError != null)
				{
					control.Width += 32;
				}
			}
		}
 /// <summary>
 /// Gets the warning.
 /// </summary>
 /// <param name="control">The control.</param>
 /// <returns></returns>
 public string GetWarning(Control control)
 {
     return(_errorProviderWarn.GetError(control));
 }
 /// <summary>
 /// Gets the information.
 /// </summary>
 /// <param name="control">The control.</param>
 /// <returns></returns>
 public string GetInformation(Control control)
 {
     return(_errorProviderInfo.GetError(control));
 }