Example #1
0
 private void agregar()
 {
     bool result = false;
     string mensaje = string.Empty;
     if (txtNombre.Text != string.Empty && txtPrecio.Text != string.Empty && numExistencia.Value >= 0 && cbUnMed.SelectedItem != null && cbIva.SelectedItem != null)
     {
         if (validacion.validarNombre(txtNombre.Text) == true)
         {
             if (validacion.validarCantidadDecimal(txtPrecio.Text))
             {
                 if (this.tipo == 1)
                 {
                     this.productoActual = new producto(txtClave.Text, txtNombre.Text, Convert.ToDecimal(txtPrecio.Text), numExistencia.Value, cbUnMed.SelectedItem.ToString(), Convert.ToInt32(cbIva.SelectedItem.ToString().Trim('%')), dtpProducto.Value.ToString("dd-MM-yy"), txtDesc.Text);
                     result = productoActual.RegistroProducto();
                     if (result == true)
                     {
                         mensaje = "El Producto Se Ha Agregado";
                     }
                     else
                     {
                         mensaje = "El Producto No Se Ha Podido Agregar, Intenta Mas Tarde";
                     }
                 }
                 else
                 {
                     this.productoActual = new producto(txtClave.Text, txtNombre.Text, Convert.ToDecimal(txtPrecio.Text), numExistencia.Value, cbUnMed.SelectedItem.ToString(), Convert.ToInt32(cbIva.SelectedItem.ToString().Trim('%')),txtDesc.Text);
                     result = productoActual.modificarProducto();
                     if (result == true)
                     {
                         mensaje = "El Producto Se Ha modificado";
                     }
                     else
                     {
                         mensaje = "El Producto No Se Ha Podido modificar, Intenta Mas Tarde";
                     }
                 }
             }
             else
             {
                 mensaje = "El precio no tiene un formato correcto";
             }
         }
         else
         {
             mensaje = "El nombre no tiene un formato valido";
         }
     }
     else
     {
         mensaje = "Llena todos los campos";
     }
     MessageBox.Show(mensaje);
     if (result == true) { this.Close(); }
 }