private void Limpiar() { errorProvider1.Clear(); CategoriaidnumericUpDown1.Value = 0; EstudiantetextBox.Text = string.Empty; ServiciocomboBox.ResetText(); CantidadtextBox.Text = string.Empty; PreciotextBox.Text = string.Empty; ImportetextBox.Text = string.Empty; TotaltextBox.Text = string.Empty; this.Detalle = new List <CategoriaDetalle>(); CargarGrid(); }
private bool ValidarDetalle() { errorProvider1.Clear(); bool paso = true; if (string.IsNullOrWhiteSpace(CantidadtextBox.Text)) { errorProvider1.SetError(CantidadtextBox, "El campo cantidad no puede estar vacio"); CantidadtextBox.Focus(); paso = false; } if (string.IsNullOrWhiteSpace(PreciotextBox.Text)) { errorProvider1.SetError(PreciotextBox, "El campo precio no puede estar vacio"); PreciotextBox.Focus(); paso = false; } if (string.IsNullOrWhiteSpace(ServiciocomboBox.Text)) { errorProvider1.SetError(ServiciocomboBox, "El campo categoria no puede estar vacio, debe de seleccionar una categoria"); ServiciocomboBox.Focus(); paso = false; } if (Convert.ToInt32(CantidadtextBox.Text) < 0) { errorProvider1.SetError(CantidadtextBox, "El campo cantidad no puede ser menor a 0"); CantidadtextBox.Focus(); paso = false; } if (Convert.ToDouble(PreciotextBox.Text) < 0) { errorProvider1.SetError(PreciotextBox, "El campo precio no puede ser negativo"); PreciotextBox.Focus(); paso = false; } return(paso); }
private void Agregarbutton_Click(object sender, EventArgs e) { double total = 0; if (!ValidarDetalle()) { return; } if (DetalledataGridView.DataSource != null) { this.Detalle = (List <CategoriaDetalle>)DetalledataGridView.DataSource; } this.Detalle.Add( new CategoriaDetalle( categoriaId: 0, cantidad: Convert.ToInt32(CantidadtextBox.Text), precio: Convert.ToDouble(PreciotextBox.Text), importe: Convert.ToDouble(ImportetextBox.Text), facturaId: Convert.ToInt32(CategoriaidnumericUpDown1.Value) ) ); CargarGrid(); ServiciocomboBox.Focus(); ServiciocomboBox.ResetText(); CantidadtextBox.Text = string.Empty; PreciotextBox.Text = string.Empty; ImportetextBox.Text = string.Empty; foreach (var item in this.Detalle) { total += Convert.ToDouble(item.Importe); } TotaltextBox.Text = Convert.ToString(total); }