private void AgregarTerritorio() { string id = txtID.Text; if (string.IsNullOrWhiteSpace(id)) { errorProvider.SetError(txtID, "Ingrese Id correcta."); } bool existeID = db.Territories.Where(t => t.TerritoryID.Equals(id)).Any(); if (existeID) { errorProvider.SetError(txtID, "El ID ya está registrado."); } string nombre = txtTerritorio.Text; if (string.IsNullOrWhiteSpace(nombre)) { errorProvider.SetError(txtTerritorio, "Ingrese nombre de territorio."); } bool existeTerritorio = db.Territories.Where(t => t.TerritoryDescription.Equals(nombre)).Any(); if (existeTerritorio) { errorProvider.SetError(txtTerritorio, "El nombre del territorio ya está registrado."); } if (errorProvider.GetError()) { this.DialogResult = DialogResult.None;//Impide que la ventana se cierre por causa del botón aceptar. return; } int regionid = (int)cboRegión.SelectedValue; Territories territorio = new Territories { TerritoryID = id, TerritoryDescription = nombre, RegionID = regionid, bitHabilitado = true }; //Agregar territorio nuevo al datacontext. db.Territories.InsertOnSubmit(territorio); try { //Actualizar la base de datos. db.SubmitChanges(); MessageBox.Show("Territorio agregado correctectamente."); } catch { MessageBox.Show("Ocurrió un error."); } }
public void ValidarCampoVacio(TextBox caja) { if (caja.Text.Length == 0) { ErrorProv.SetError(caja, "Campo requerido"); } else { ErrorProv.SetError(caja, ""); } }
private void Correotxt_TextChanged(object sender, EventArgs e) { ValidarCampoVacio(Correotxt); if (verificar.RevisarCorreo(Correotxt) == true) { ErrorProv.SetError(Correotxt, ""); } else { ErrorProv.SetError(Correotxt, "Ingrese el formato correcto"); } }
private void contactotxt_TextChanged(object sender, EventArgs e) { ValidarCampoVacio(contactotxt); FormatoNumero(contactotxt); if (verificar.VerificarNumero(contactotxt) == true) { ErrorProv.SetError(contactotxt, ""); } else { ErrorProv.SetError(contactotxt, "Ingrese los 8 digitos"); } }
private void Calculations() { try { var values = from DataGridViewRow row in dgwRates.Rows where row.Cells[2].FormattedValue.ToString() != string.Empty select Convert.ToDecimal(row.Cells[2].FormattedValue); var minValue = values.Min(); var avgValue = values.Average(); var maxValue = values.Max(); labelMin.Text = Math.Round(minValue, 2).ToString() + " HUF"; labelAvg.Text = Math.Round(avgValue, 2).ToString() + " HUF"; labelMax.Text = Math.Round(maxValue, 2).ToString() + " HUF"; foreach (DataGridViewRow row in dgwRates.Rows) { if (Convert.ToDecimal(row.Cells[2].Value) == minValue) { row.DefaultCellStyle.BackColor = Color.Lime; } else if (Convert.ToDecimal(row.Cells[2].Value) == maxValue) { row.DefaultCellStyle.BackColor = Color.Red; } if (dgwRates.Rows.Count == 1 || Convert.ToDecimal(row.Cells[2].Value) == 0) { row.DefaultCellStyle.BackColor = Color.White; } } } catch (Exception) { if (dtpFrom.Value > dtpTo.Value) { ErrorProv.SetError(labelError, "A kezdő dátum nem lehet a záró dátumnál későbbi időpont!"); } else if (dgwRates.Rows.Count == 0) { ErrorProv.SetError(labelError, "Az adott szűrési feltételek mellett nem léteznek adatok!"); } labelMin.Text = "N/A"; labelAvg.Text = "N/A"; labelMax.Text = "N/A"; } }
private bool VerificarIdSeleccionado() { errorProvider.InitializeError();//Limpia los errores pasados. if (String.IsNullOrWhiteSpace(id)) { errorProvider.SetError(dgvTerritorios, "Seleccionar ID dando clic en fila."); } if (errorProvider.GetError()) { MessageBox.Show("Seleccionar un ID primero"); return(true); } return(false); }
private void btnAceptar_Click(object sender, EventArgs e) { errorProvider.InitializeError();//Lia errores pasados. if (string.IsNullOrWhiteSpace(txtCódigo.Text)) { errorProvider.SetError(txtCódigo, "Ingrese código"); } if (!int.TryParse(txtCódigo.Text, out var n)) { errorProvider.SetError(txtCódigo, "Ingrese código númerico de maximo 10 dígitos."); } if (string.IsNullOrWhiteSpace(txtNombre.Text)) { errorProvider.SetError(txtNombre, "Ingrese nombre del empleado"); } if (string.IsNullOrWhiteSpace(txtApellidos.Text)) { errorProvider.SetError(txtApellidos, "Ingrese apellidos del empleado"); } if (string.IsNullOrWhiteSpace(txtTitulo.Text)) { errorProvider.SetError(txtTitulo, "Ingrese título del empleado"); } if (errorProvider.GetError()) { this.DialogResult = DialogResult.None; return; } //Insertar un nuevo dato. int Código = Convert.ToInt32(txtCódigo.Text); string Nombre = txtNombre.Text; string Apellidos = txtApellidos.Text; string Dirección = txtDirección.Text; string Título = txtTitulo.Text; DateTime Fecha = txtFecha.Value; if (accion.Equals("Nuevo")) { Employees empleado = new Employees { EmployeeID = Código, FirstName = Nombre, LastName = Apellidos, Address = Dirección, BirthDate = Fecha, Title = Título, bitHabilitado = true }; try { //Agregar db.Employees.InsertOnSubmit(empleado); //Actualizar en base de datos db.SubmitChanges(); MessageBox.Show("Empleado agregado correctamente.", "Insertar", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("Ocurrió un error.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { var empleado = db.Employees.Where(em => em.EmployeeID.Equals(id)).Single(); empleado.FirstName = Nombre; empleado.LastName = Apellidos; empleado.Address = Dirección; empleado.BirthDate = Fecha; empleado.Title = Título; try { //Actualizar en base de datos db.SubmitChanges(); MessageBox.Show("Empleado actualizado correctamente.", "Actualizar", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("Ocurrió un error.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }