public static bool lengthMin(ErrorProvider errorProvider1, Control control1, string value, int minlength, string message = "Invalid Length") { if (value.Length < minlength) { errorProvider1.SetError(control1, message); return false; } return true; }
public static bool numberOnly(ErrorProvider errorProvider1, Control control1, string value, string message = "Number Only") { if (!numberchk.IsMatch(value)) { errorProvider1.SetError(control1, message); return false; } return true; }
public static bool email(ErrorProvider errorProvider1, Control control1, string value, string message = "Invalid Email") { if (!emailchk.IsMatch(value)) { errorProvider1.SetError(control1, message); return false; } return true; }
protected bool _TBTel_Validating(object sender, CancelEventArgs e, ErrorProvider errorProvider, string msg) { TextBox boxName = sender as TextBox; bool isTel = isFormat(boxName.Text); if (!isTel) { e.Cancel = true; errorProvider3?.SetError(boxName, ""); errorProvider2?.SetError(boxName, ""); errorProvider.SetError(boxName, msg); return(false); } else { e.Cancel = false; errorProvider.SetError(boxName, ""); return(true); } }
private Boolean ValidateUserInput() { bool bool_Test = true; if (cbx_Product.Text.Length == 0 || cbx_Product.SelectedValue == null) { bool_Test = false; ErrorProvider.SetError(cbx_Product, "Please Select Product"); string str_error = ErrorProvider.GetError(cbx_Product); MessageBox.Show(str_error); } else if (txt_Quantity.Text.Trim().Length == 0) { bool_Test = false; ErrorProvider.SetError(txt_Quantity, "Enter Quantity"); string str_error = ErrorProvider.GetError(txt_Quantity); MessageBox.Show(str_error); } ErrorProvider.Clear(); return(bool_Test); }
private void deEndDate_Validating(object sender, CancelEventArgs e) { if (deStartDate.EditValue != null) { if (deEndDate.EditValue != null && (DateTime)deEndDate.EditValue < (DateTime)deStartDate.EditValue) { ErrorProvider.SetError(deEndDate, "Financial period date to should be greater than from date."); } else if (!IsSaving) { ErrorProvider.SetError(deEndDate, ""); if (!IsSaving) { txtFinPerName.Text = ((DateTime)deStartDate.EditValue).Date.Year.ToString() + " - " + (deEndDate.EditValue == null ? "*" : ((DateTime)deEndDate.EditValue).Date.Year.ToString()); } } } else { ErrorProvider.SetError(deEndDate, "Please select financial period from date."); } }
private void button1_Click(object sender, EventArgs e) { string url = textBox1.Text.StartsWith("http://") ? textBox1.Text.Substring(6) : textBox1.Text; url = url.StartsWith("https://") ? url : "https://" + url; url = url.EndsWith("/") ? url.Remove(url.Length - 1) : url; Regex reg = new Regex(@"https\:\/\/\w+\.\w+"); Match m = reg.Match(url); if (m.Success) { Properties.Settings.Default.serverURL = url; Properties.Settings.Default.Save(); softwareClose = true; Close(); } else { ErrorProvider error = new ErrorProvider(); error.SetError(textBox1, "Invalid Url"); error.SetIconPadding(textBox1, -20); } }
public void NextTab() { if (IsNextAvailable) { _errorProvider.Clear(); var res = ((MyTabPage)this.SelectedTab).OnPageLeaving(new Components.PageLeavingEventArgs()); if (!res.Cancel) { this.SelectedIndex = getNextShowablePageIndex(); ((MyTabPage)this.SelectedTab).OnPageEntering(new Components.PageEnteringEventArgs()); } else { foreach (PageError pe in res.PageErrors) { _errorProvider.SetIconAlignment(pe.Control, ErrorIconAlignment.MiddleLeft); _errorProvider.SetError(pe.Control, !string.IsNullOrEmpty(pe.ErrorMessage) ? pe.ErrorMessage : "Error"); } } //MessageBox.Show(res.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// PublicKey, PublicKeyToken, Hash validation /// </summary> /// <param name="sender">object to validate</param> /// <param name="e">parameters</param> private void StringToByte_Validating(object sender, CancelEventArgs e) { try { var textBox = sender as TextBox; if (textBox != null) { var input = textBox.Text; if (input.Length % 2 != 0) { return; } ByteHelper.StringToByte(input); ErrorProvider.SetError(sender as Control, string.Empty); } } catch (Exception) { ErrorProvider.SetError((Control)sender, "Incorrect byte sequence"); e.Cancel = true; } }
private void btnSave_Click(object sender, EventArgs e) { try { if (Static.ToLong(numRefreshTime.EditValue) >= 5) { _core.CacheSet("fmrIssue_ReadDay", numReadDay.EditValue); _core.CacheSet("fmrIssue_UnReadDay", numUnReadDay.EditValue); _core.CacheSet("fmrIssue_RefreshTime", numRefreshTime.EditValue); _core.CacheSave(); MessageBox.Show("Амжилттай хадгалагдлаа"); this.Close(); } else { ErrorProvider.SetError(numRefreshTime, "5-с их утга оруулна уу."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Buscarbutton_Click(object sender, EventArgs e) { RepositorioBase <Inscripciones> repositorio = new RepositorioBase <Inscripciones>(); Inscripciones inscripcion = new Inscripciones(); Estudiantes estudiante = new Estudiantes(); Asignaturas asignatura = new Asignaturas(); int.TryParse(IdnumericUpDown.Text, out int id); inscripcion = repositorio.Buscar(id); if (inscripcion != null) { ErrorProvider.Clear(); LlenaCampo(inscripcion); //todo: llenar datos de la inscripcion LLenarEstudiante(BuscarEstudiante(inscripcion.EstudianteId)); //todo: llena id & nombre del estudiante LlenarAsignatura(BuscarAsignatura(inscripcion.AsignaturaId)); // todo: llenar id & descripcion de la asignatura } else { ErrorProvider.SetError(IdnumericUpDown, "Inscripcion no encontrada"); } }
public static bool TexBoxTypeValidation(TextBox control, string controlLable, ErrorProvider errorProvider, Type NumberType) { if (NumberType == typeof(int)) { int result; if (int.TryParse(control.Text, out result) && result > 0) { return(true); } } else if (NumberType == typeof(double)) { double result; var value = control.Text.Replace(',', '.'); if (double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out result) && result > 0) { return(true); } } errorProvider.SetError(control, $"Wrong {controlLable} value."); return(false); }
public static bool ObaveznoPolje(Control control, ErrorProvider err, string poruka) { bool validno = true; if (control is TextBox && string.IsNullOrEmpty((control as TextBox).Text)) { validno = false; } else if (control is ComboBox && (control as ComboBox).SelectedIndex == -1) { validno = false; } if (!validno) { err.SetError(control, poruka); return(false); } err.Clear(); return(true); }
private void Register_Click(object sender, EventArgs e) { if (textBox1.Text == "") { errorProvider1.SetError(textBox1, "This Field Must Be Filled"); } else if (textBox2.Text == "") { errorProvider1.SetError(textBox2, "This Field Must Be Filled"); } else if (textBox3.Text == "") { errorProvider1.SetError(textBox3, "This Field Must Be Filled"); } else if (textBox7.Text == "") { errorProvider1.SetError(textBox4, "This Field Must Be Filled"); } else if (textBox7.TextLength != 13) { errorProvider1.SetError(textBox4, "CNIC MUST BE 13 DIGItS"); } else if (textBox4.Text == "") { errorProvider1.SetError(textBox4, "This Field Must Be Filled"); } //PASSWORD VERIFICATION NEEDS TO BE IMPLEMENTED TOO// else { { connection1.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = connection1; string query = "insert into customers(Username,FirstName,LastName,Type,ContactNumber,Email,[PASSWORD],CNIC) values ('" + textBox8.Text + "','" + textBox1.Text + "','" + textBox2.Text + "','" + comboBox1.SelectedItem + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox7.Text + "') "; command.CommandText = query; command.ExecuteNonQuery(); MessageBox.Show("Congratulations!"); connection1.Close(); } } }
//------------------------------------------------------------------------------------------------------------------- private void btnbuscar_Click(object sender, EventArgs e) { //------------------------------------------------------------------------------------------------------------------- // vamos a buscar a un alumno por el codigo ------------------------------------------ // valido que no este vacia --------------------------------------------------------- if (!validacion.Vacio(txtcodigo, ErrorProvider, "Para buscar debe haber un codigo")) { if (validacion.TipoNumero(txtcodigo, ErrorProvider, "El Codigo es numerico")) { // validar que existe if (ExisteCodigo(Convert.ToInt32(txtcodigo.Text))) { Alumno myAlumno = obtenerDatos(Convert.ToInt32(txtcodigo.Text)); txtnombre.Text = myAlumno.Nombre; txtcorreo.Text = myAlumno.Correo; txtnota1.Text = myAlumno.Nota1.ToString(); txtnota2.Text = myAlumno.Nota2.ToString(); txtnota3.Text = myAlumno.Nota3.ToString(); txtnota4.Text = myAlumno.Nota4.ToString(); // activar los botones btneditar.Enabled = true; btneliminar.Enabled = true; txtcodigo.Enabled = false; } else { ErrorProvider.SetError(txtcodigo, "El Codigo no existe en la lineas"); txtcodigo.Focus(); LimpiarCajar2(); return; } } } }
public void TextBoxString(object sender, CancelEventArgs e, String message = "") { TextBox controle = (TextBox)sender; if (message == "") { message = "La saisie de ce champs est oblégatoir"; } if (controle.Text.Trim() == String.Empty) { errorProvider.SetError(controle, message); e.Cancel = true; } else { errorProvider.SetError(controle, ""); } }
private void CalculoPVP(TextBox cost, TextBox percentage, TextBox price, TextBox pvp) { decimal priceDecimal; decimal percentageDecimal; _ = decimal.TryParse(cost.Text, out decimal costDecimal); _ = decimal.TryParse(pvp.Text, out decimal pvpDecimal); if (ivaRateComboBox.Text.Trim() == "12%") { priceDecimal = pvpDecimal / Convert.ToDecimal(1.12); } else { priceDecimal = pvpDecimal; } price.Text = decimal.Round(priceDecimal, 4).ToString(); if (costDecimal == 0) { ErrorProvider.SetError(cost, "Costo es igual a 0"); ErrorStatus = false; percentageDecimal = 0; } else { ErrorProvider.SetError(cost, ""); if (priceDecimal == 0) { percentageDecimal = 0; } else { percentageDecimal = Math.Abs(((costDecimal / priceDecimal) - 1) * 100); //percentageDecimal = ((priceDecimal - costDecimal) * 100) / costDecimal; } } percentage.Text = decimal.Round(percentageDecimal, 4).ToString(); }
private void btnSaveupdate_Click(object sender, EventArgs e) { HFMS.Controls.StudentController update = new HFMS.Controls.StudentController(); Student obj = new Student(); obj.Ptype = 0; obj.FirstName = txtname.Text; error.BlinkRate = 0; if (string.IsNullOrEmpty(txtname.Text)) { error.SetError(txtname, ""); //check = false; obj.LastName = txtlname.Text; obj.RollNo = txtroll.Text; obj.CNIC = txtnic.Text; obj.RoomNo = txtroom.Text; obj.Email = txtemaill.Text; obj.Address = txtadd.Text; obj.contact = txtcontactno.Text; obj.GuardianName = txtgnamee.Text; obj.GuardianEmail = txtgemaill.Text; obj.GuardianContact = txtgcontactt.Text; obj.Relation = txtrelationn.Text; int result = update.updateStudent(obj); if (result > 0) { pnlUpdate.Visible = false; MessageBox.Show("Done Successfully."); } else { pnlUpdate.Refresh(); MessageBox.Show("Error Occured."); } } }
private void btn_FinalizarParcial_Click(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(lblCodigo_Cliente.Text)) { if (valorAbatido > 0) { if (cbFormaPagamento.SelectedIndex == -1) { MessageBox.Show("Informe qual o tipo de pagamento em espécie!", "Biblioteca Fácil", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); errorProvider.SetError(cbFormaPagamento, "Selecione O tipo em espécie!"); cbFormaPagamento.Focus(); return; } TipoPagamento = cbFormaPagamento.Text; } vendaConfirmada = true; if (valorAbatido == 0.00m) { valorRestante = valorTotal - descontoDinheiro; } id_Cliente = lblCodigo_Cliente.Text; this.Close(); } else { MessageBox.Show("Informe o cliente!", "Biblioteca Fácil", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Biblioteca Fácil", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void phone_number_Leave(object sender, EventArgs e) { // בודקים אם הנתונים בשדה לא תקינים ופעם ראשונה פונקציה phone_number_leave מופעלת if (check_phoneNumber() == false && count == 0) { // מקדמים מונה כניסות/הפעלות של פונקציה phone_number_leave count++; // מגדירים שגאיה בהתאם idErrorProvider = new ErrorProvider(); idErrorProvider.SetError(phone_number, "מספר פלאפון חייב להכיל 10 ספרות"); } // לא פעם ראשונה phone_number_leave מופעלת else { // פעם ראשונה מפעילים phone_number_leave ונתונים בשדה תקינים if (check_phoneNumber() == true && count == 0) { //לא מבצעים פעולות // נשאר count=0 } else { // לא פעם ראשונה מפעילים phone_number_leave // אם מגיעים לתנאי הזה יישארו שתי אןפציות // 1) נתונים תקינים בשדה if (check_phoneNumber() == true) { idErrorProvider.SetError(phone_number, ""); } // 2) נתונים שגויים else { idErrorProvider.SetError(phone_number, "מספר פלאפון חייב להכיל 10 ספרות"); } } } }
public static bool ValidateControl <T>(this Control container, T instance, ErrorProvider errorProvider, out ICollection <ValidationResult> validationResults) where T : class, new() { var innerControls = new Dictionary <string, Control>(); container.GetAllInnerControls <T>(ref innerControls); errorProvider.Clear(); var validationContext = new ValidationContext(instance, null, null); validationResults = new List <ValidationResult>(); var isValid = Validator.TryValidateObject(instance, validationContext, validationResults, true); if (isValid) { return(isValid); } foreach (var validationResult in validationResults) { foreach (var member in validationResult.MemberNames) { if (!innerControls.ContainsKey(member)) { continue; } var control = innerControls[member]; errorProvider.SetError(control, validationResult.ErrorMessage); } } return(isValid); }
private void amountTextBox_Validating(object sender, CancelEventArgs e) { double testAmount = -1; string textError = StringConstant.IncorrectInput; try { testAmount = double.Parse(amountTextBox.Text); } catch (Exception) { e.Cancel = true; } if (!e.Cancel) { if (testAmount < 0 || testAmount > 1000000) { e.Cancel = true; textError = StringConstant.OutOfBounds; } } if (!e.Cancel) { textError = StringConstant.NotInteger; int n; bool notInteger = !int.TryParse(amountTextBox.Text, out n); if (measureComboBox.SelectedIndex == 0 && notInteger) { e.Cancel = true; } } if (e.Cancel) { ErrorProvider errorProvider = new ErrorProvider(); errorProvider.SetError(amountTextBox, textError); } }
private void button1_Click(object sender, EventArgs e) { if (tbNama.Text == "" || tbAlamat.Text == "" || tbTelepon.Text == "" || radioButtonTemp.Text == "") { errorProvider.SetError(tbNama, "Tidak boleh kosong"); errorProvider.SetError(tbAlamat, "Tidak boleh kosong"); errorProvider.SetError(tbTelepon, "Tidak boleh kosong"); errorProvider.SetError(radioButtonTemp, "Tidak boleh kosong"); } else { errorProvider.SetError(tbNama, ""); errorProvider.SetError(tbAlamat, ""); errorProvider.SetError(tbTelepon, ""); } if (tbNama.Text == "" || tbAlamat.Text == "" || tbTelepon.Text == "" || radioButtonTemp.Text == "") { MessageBox.Show("Field tidak boleh kosong", "Isi data", MessageBoxButtons.OK, MessageBoxIcon.Information); tbNama.Text = ""; tbAlamat.Text = ""; tbTelepon.Text = ""; } else { listBox2.Items.Clear(); listBox2.Items.Add("Nama\t\t\t: " + tbNama.Text); listBox2.Items.Add("Jenis Kelamin\t\t: " + radioButtonTemp.Text); listBox2.Items.Add("Alamat\t\t\t: " + tbAlamat.Text); listBox2.Items.Add("Telepon\t\t\t: " + tbTelepon.Text); listBox2.Items.Add("Kode Produk\t\t: " + comboBoxKode.Text); listBox2.Items.Add("Qty\t\t\t: " + comboBoxQty.Text); listBox2.Items.Add("Harga Total\t\t: " + tbHargaTotal.Text); for (int i = 1; i <= x; i++) { listBox2.Items.Add("VOUCHER " + i + "\t\t: " + RandomString(12)); } MessageBox.Show("Nama: " + tbNama.Text + "\nJenis Kelamin: " + radioButtonTemp.Text + "\nALamat: " + tbAlamat.Text + "\nTelepon: " + tbTelepon.Text + "\nKode: " + comboBoxKode.Text + "\nQty: " + comboBoxQty.Text + "\nHarga Total: " + tbHargaTotal.Text, "Detail", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void SurNameTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) { string namePattern = @"[а-я]"; var surNameIsMatch = Regex.IsMatch(SurNameTextBox.Text, namePattern); if (String.IsNullOrEmpty(SurNameTextBox.Text)) { e.Cancel = true; SurNameTextBox.Focus(); ErrorProvider.SetError(SurNameTextBox, "Укажите фамилию"); } else if (surNameIsMatch == false) { e.Cancel = true; SurNameTextBox.Focus(); ErrorProvider.SetError(SurNameTextBox, "Недопустимый формат"); } else { e.Cancel = false; ErrorProvider.SetError(SurNameTextBox, null); } }
private void PositionTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) { string namePattern = @"[а-я]"; var positionIsMatch = Regex.IsMatch(PositionTextBox.Text, namePattern); if (String.IsNullOrEmpty(PositionTextBox.Text)) { e.Cancel = true; PositionTextBox.Focus(); ErrorProvider.SetError(PositionTextBox, "Укажите должность"); } else if (positionIsMatch == false) { e.Cancel = true; PositionTextBox.Focus(); ErrorProvider.SetError(PositionTextBox, "Неверный формат"); } else { e.Cancel = false; ErrorProvider.SetError(PositionTextBox, null); } }
private void TypeSpecificationEditor_Validating(object sender, CancelEventArgs e) { bool validated; var typeSpecification = TypeSpecificationEditor.SelectedTypeReference as TypeSpecification; if (typeSpecification != null) { validated = typeSpecification.ElementType != null; } else { validated = TypeSpecificationEditor.SelectedTypeReference != null; } if (!validated) { ErrorProvider.SetError(TypeSpecificationEditor, "Type is mandatory"); e.Cancel = true; } else { ErrorProvider.SetError(TypeSpecificationEditor, string.Empty); } }
private void button1_Click(object sender, EventArgs e) { String ProductName = textBox1.Text; if (ProductName.Length == 0 || ProductName.Length > 30) { errorProvider1.SetError(textBox1, " Please Enter Valid ProductName "); errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink; } else { con.Open(); errorProvider1.Clear(); cmd.Connection = con; SqlCommand myCommand = new SqlCommand("Delete From Supply Where ProductName ='" + ProductName.ToString() + "'", con); int success = myCommand.ExecuteNonQuery(); if (success == 1) { MessageBox.Show(success + " row has been Deleted "); } con.Close(); } }
private void MpBarLoag() {/* * MPBarColorPictureBox.BackColor = BarSetting.StringToColor(BarSetting.GetData("GeneralDataHero", "MPBarColor")); * EnergyBarColorPictureBox.BackColor = BarSetting.StringToColor(BarSetting.GetData("GeneralDataHero", "EnergyBarColor")); * ShieldBarColorPictureBox.BackColor = BarSetting.StringToColor(BarSetting.GetData("GeneralDataHero", "ShieldBarColor")); * OtherBarColorPictureBox.BackColor = BarSetting.StringToColor(BarSetting.GetData("GeneralDataHero", "OtherBarColor")); * * MPFadeColorPictureBox.BackColor = BarSetting.StringToColor(BarSetting.GetData("GeneralDataHero", "MPFadeColor")); * EnergyFadeColorPictureBox.BackColor = BarSetting.StringToColor(BarSetting.GetData("GeneralDataHero", "EnergyFadeColor")); * ShieldFadeColorPictureBox.BackColor = BarSetting.StringToColor(BarSetting.GetData("GeneralDataHero", "ShieldFadeColor")); * OtherFadeColorPictureBox.BackColor = BarSetting.StringToColor(BarSetting.GetData("GeneralDataHero", "OtherFadeColor")); * * MPBarColorLabel.Text = MPBarColorPictureBox.BackColor.ToString().Substring(6); * EnergyBarColorLabel.Text = EnergyBarColorPictureBox.BackColor.ToString().Substring(6); * ShieldBarColorLabel.Text = ShieldBarColorPictureBox.BackColor.ToString().Substring(6); * OtherBarColorLabel.Text = OtherBarColorPictureBox.BackColor.ToString().Substring(6); * * MPFadeColorLabel.Text = MPFadeColorPictureBox.BackColor.ToString().Substring(6); * EnergyFadeColorLabel.Text = EnergyFadeColorPictureBox.BackColor.ToString().Substring(6); * ShieldFadeColorLabel.Text = ShieldFadeColorPictureBox.BackColor.ToString().Substring(6); * OtherFadeColorLabel.Text = OtherFadeColorPictureBox.BackColor.ToString().Substring(6); */ ErrorProvider.SetError(HealthBarSaveButton, ""); }
private void btnOk_Click(object sender, EventArgs e) { var txtContentErrorProvider = new ErrorProvider(); if (String.IsNullOrEmpty(tbContent.Text.Trim())) { txtContentErrorProvider.SetError(tbContent, "You need to type something here"); //TODO: Localize tbContent.Focus(); return; } #region Save The Used Font and Color InsertText_FormClosing(null, null); #endregion //Insert content in owner form using delegate method InsertTextDelegate insertTextMethod; if (_isLegacy) { insertTextMethod = ((Legacy)Owner).InsertText; } else { insertTextMethod = ((Modern)Owner).InsertText; } insertTextMethod(tbContent.Text.Trim()); _okClicked = true; this.Close(); }
public static bool RequiredField(Control control, ErrorProvider err) { bool valid = true; if (control is TextBox && string.IsNullOrEmpty((control as TextBox).Text)) { valid = false; } else if (control is ComboBox && (control as ComboBox).SelectedIndex == -1) { valid = false; } if (!valid) { err.SetError(control, message); return(false); } else { err.Clear(); return(true); } }
private void deBreak3End_Validating(object sender, CancelEventArgs e) { if (deBreak3Start.EditValue != null && deBreak3End.EditValue == null) { ErrorProvider.SetError(deBreak3End, "Pleae enter second tea break end time."); } else { ErrorProvider.SetError(deBreak3End, ""); } //if (deBreak3End.EditValue != null && (deShiftEnd.EditValue != null && deBreak3End.DateTime > deShiftEnd.DateTime)) //{ // ErrorProvider.SetError(deBreak3End, "Second Tea Break end time must be less than shift end time."); //} //else //if (deBreak3Start.EditValue != null && deBreak3End.EditValue != null && deBreak3End.DateTime < deBreak3Start.DateTime) //{ // ErrorProvider.SetError(deBreak3End, "Second Tea Break end time must be greater then start time."); //} //else //{ // ErrorProvider.SetError(deBreak3End, ""); //} }
public static bool ValidirajPolje(Control control, ErrorProvider err, string message) { bool validno = true; if (control is TextBox && string.IsNullOrEmpty((control as TextBox).Text)) { validno = false; } else if (control is PictureBox && (control as PictureBox).Image == null) { validno = false; } else if (control is DateTimePicker && (control as DateTimePicker).Value == null) { validno = false; } else if (control is RadioButton && (control as RadioButton).Checked == false) { validno = false; } else if (control is ComboBox && (control as ComboBox).SelectedIndex == -1) { validno = false; } if (!validno) { err.SetError(control, message); return(false); } else { err.Clear(); return(true); } }
private void BtnEliminar_Click(object sender, EventArgs e) { RepositorioBase <Usuarios> UsuarioBLL = new RepositorioBase <Usuarios>(new Contexto()); try { ErrorProvider.Clear(); int id; int.TryParse(UsarioId.Text, out id); Limpiar(); if (UsuarioBLL.Eliminar(id)) { MessageBox.Show("Eliminado"); } else { ErrorProvider.SetError(UsarioId, "No se puede eliminar una persona que no existe"); } } catch (Exception) { MessageBox.Show("No fue posible eliminar", "Imformation", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static bool requireField(ErrorProvider errorProvider1,Control control1,string value,string message ="Field Is Required") { if (value == string.Empty) { errorProvider1.SetError(control1, message); return false; } return true; }