private void dgvOfertas_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (inputCantidadUnidades.Text == "") { MessageBoxUtil.ShowError("Ingrese la cantidad de unidades a comprar"); } else if (!TextFieldUtil.IsDigitsOnly(inputCantidadUnidades.Text)) { MessageBoxUtil.ShowError("La cantidad de unidades debe ser un numero natural"); } else { if (MessageBox.Show("¿Desea comprar " + inputCantidadUnidades.Text + " unidades de " + dgvOfertas.CurrentRow.Cells["descripcion"].Value.ToString() + "?", "Atención", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { StoredProcedureParameters inputParameters = new StoredProcedureParameters() .AddParameter("@id_cliente_comprador", new RepositorioClientes().ObtenerIdClienteDeUsuario(Session.Instance.IdUsuario)) .AddParameter("@codigo_oferta", dgvOfertas.CurrentRow.Cells["codigo_oferta"].Value.ToString()) .AddParameter("@cant_unidades", Int32.Parse(inputCantidadUnidades.Text)) .AddParameter("@fecha", DateTime.Parse(ConfigurationManager.AppSettings["FechaSistema"])); try { new Conexion().ExecDataTableStoredProcedure(StoredProcedures.ComprarOferta, inputParameters); MessageBoxUtil.ShowInfo("Compra exitosa!"); this.LlenarTablaOfertas(); } catch (SqlException ex) { MessageBoxUtil.ShowError(ex.Message); } } } }
private Boolean ValidarInputs() { string errores = ""; // Validacion monto if (inputMonto.Text == "") { errores += "El monto es obligatorio\n"; } else if (!TextFieldUtil.IsDigitsOnly(inputMonto.Text)) { errores += "El monto debe ser un número entero positivo\n"; } // Validacion tarjeta if (cmbTipoPago.SelectedItem == null) { errores += "El tipo de pago es obligatorio\n"; } else if (cmbTipoPago.Text == "Efectivo" && cmbTarjeta.SelectedItem != null) { errores += "No seleccione una tarjeta si el pago es en efectivo\n"; } else if ((cmbTipoPago.Text == "Débito" || cmbTipoPago.Text == "Crédito") && cmbTarjeta.SelectedItem == null) { errores += "Seleccione la tarjeta asociada al pago\n"; } else if ((cmbTipoPago.Text == "Débito" || cmbTipoPago.Text == "Crédito") && !cmbTarjeta.Text.Contains(cmbTipoPago.Text)) { errores += "El tipo de la tarjeta seleccionada no coincide con el indicado en el formulario\n"; } if (errores != "") { MessageBoxUtil.ShowError(errores); return(false); } else { return(true); } }
private Boolean ValidarInputs() { string errores = ""; double precioOferta, precioLista; DateTime fechaSistema = DateTime.Parse(ConfigurationManager.AppSettings["FechaSistema"]); // Validacion fecha publicacion if (dateTimePickerFechaPublicacion.Value.CompareTo(fechaSistema) < 0) { errores += "La fecha de publicacion no puede ser anterior a la fecha actual (" + fechaSistema + ")\n"; } // Validacion fecha vencimiento if (dateTimePickerFechaVencimiento.Value.CompareTo(fechaSistema) < 0) { errores += "La fecha de publicacion no puede ser anterior a la fecha actual (" + fechaSistema + ")\n"; } // Validacion fecha publicacion y vencimiento if (dateTimePickerFechaVencimiento.Value.CompareTo(dateTimePickerFechaPublicacion.Value) < 0) { errores += "La fecha de vencimiento no puede ser anterior a la fecha de publicacion\n"; } // Validacion precio oferta if (inputPrecioOferta.Text == "") { errores += "El precio de oferta es obligatorio\n"; } else if (!double.TryParse(inputPrecioOferta.Text, out precioOferta)) { errores += "El precio de oferta debe ser un número flotante\n"; } else if (precioOferta <= 0) { errores += "El precio de oferta debe ser mayor que cero\n"; } // Validacion precio lista if (inputPrecioLista.Text == "") { errores += "El precio de lista es obligatorio\n"; } else if (!double.TryParse(inputPrecioLista.Text, out precioLista)) { errores += "El precio de lista debe ser un número flotante\n"; } else if (precioLista <= 0) { errores += "El precio de lista debe ser mayor que cero\n"; } // Validacion precio oferta y precio lista if (double.TryParse(inputPrecioOferta.Text, out precioOferta) && double.TryParse(inputPrecioLista.Text, out precioLista) && precioOferta >= precioLista) { errores += "El precio de oferta debe ser menor que el precio de lista\n"; } // Validacion stock disponible if (inputStockDisponible.Text == "") { errores += "El stock disponible es obligatorio\n"; } else if (!TextFieldUtil.IsDigitsOnly(inputStockDisponible.Text)) { errores += "El stock disponible debe ser un número entero positivo\n"; } // Validacion max unidades por cliente if (inputMaxUnidadesPorCliente.Text == "") { errores += "El maximo de unidades por cliente es obligatorio\n"; } else if (!TextFieldUtil.IsDigitsOnly(inputMaxUnidadesPorCliente.Text)) { errores += "El maximo de unidades por cliente debe ser un número entero positivo\n"; } // Validacion codigo if (inputCodigo.Text == "") { errores += "El codigo es obligatorio\n"; } else if (inputCodigo.Text.Length > 50) { errores += "El codigo es muy largo\n"; } else if (inputCodigo.Text.Length < 4) { errores += "El codigo es muy corto\n"; } // Validacion descripcion if (inputDescripcion.Text == "") { errores += "La descripcion es obligatoria\n"; } if (errores != "") { MessageBoxUtil.ShowError(errores); return(false); } else { return(true); } }