private void DgvDetalleCompra_SelectionChanged(object sender, EventArgs e) { try { if (isPedido) { cotPR = new DCotizacionPR(); Dgv2.DataSource = cotPR.SelectCotizacionesPRByCodStockAndCodPR((int)DgvDetalleCompra.SelectedRows[0].Cells[0].Value , (int)DgvPedidos.SelectedRows[0].Cells[0].Value); Dgv2.Refresh(); PersonalizarGridCotizacion(); } else { cotSC = new DCotizacionSC(); Dgv2.DataSource = cotSC.SelectCotizacionesSCByCodBienUsoAndCodSC((int)DgvDetalleCompra.SelectedRows[0].Cells[0].Value, (int)DgvSolicitudes.SelectedRows[0].Cells[0].Value); Dgv2.Refresh(); } } catch (Exception ex) { //MessageBox.Show($"Error: {ex.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
private void ConfirmarOrdenButton_Click(object sender, EventArgs e) { for (int i = 0; i < DgvDetalleCompra.RowCount; i++) { DataTable dtDetalle = (DataTable)DgvDetalleCompra.DataSource; var codProducto = 0; var codCotizacion = 0; decimal precioCot; // Comprobamos que todos los productos de la orden de compra tengan una cotización if (isPedido) { codProducto = (int)dtDetalle.Rows[i]["CodStock"]; cotPR = new DCotizacionPR(); var dtCot = cotPR.SelectCotizacionesPRByCodStockAndCodPR(codProducto , (int)DgvPedidos.SelectedRows[0].Cells[0].Value); codCotizacion = (int)dtCot.Rows[0]["CodCotizacion"]; precioCot = cotPR.GetPrecioCotizadoByCodCotizacionPR(codProducto, codCotizacion); if (precioCot <= 0) { MessageBox.Show("Alguno de los productos del detalle de orden de compra no tiene una cotización." + Environment.NewLine + "Revise las cotizaciones.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); CancelarButton_Click(sender, e); return; } } else { codProducto = (int)dtDetalle.Rows[i]["CodBienUso"]; cotSC = new DCotizacionSC(); var dtCot = cotPR.SelectCotizacionesPRByCodStockAndCodPR(codProducto , (int)DgvSolicitudes.SelectedRows[0].Cells[0].Value); codCotizacion = (int)dtCot.Rows[0]["CodCotizacion"]; precioCot = cotSC.GetPrecioCotizadoByCodBienUsoSC(codProducto, codCotizacion); if (precioCot <= 0) { MessageBox.Show("Alguno de los productos del detalle de orden de compra no tiene una cotización." + Environment.NewLine + "Revise las cotizaciones.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); CancelarButton_Click(sender, e); return; } } } var rta = MessageBox.Show("¿Realizar orden de compra?", "Confirmación", MessageBoxButtons.YesNo , MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (rta == DialogResult.No) { return; } string msg; try { int codOrdenCompra = ordenCompra.InsertOrdenCompra(false, isPedido ? "PR" : "SC"); if (isPedido) { cotPR.UpdateCotizacionPR((int)DgvPedidos.SelectedRows[0].Cells[0].Value, codOrdenCompra); } else { cotSC.UpdateCotizacionSC((int)DgvSolicitudes.SelectedRows[0].Cells[0].Value, codOrdenCompra); } msg = "Se ingresó la orden de compra correctamente"; } catch (Exception ex) { msg = "Error al ingresar la orden de compra"; MessageBox.Show($"ERROR: {ex.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } var popup1 = new PopupNotifier() { Image = msg == "Se ingresó la orden de compra correctamente" ? Properties.Resources.sql_success1 : Properties.Resources.sql_error, TitleText = "Mensaje", ContentText = msg, ContentFont = new Font("Segoe UI Bold", 11F), TitleFont = new Font("Segoe UI Bold", 10F), ImagePadding = new Padding(10) }; popup1.Popup(); HabilitarBotones(); LimpiarGridsDetalles(); CargarListados(); }
private void CargarCotizacionesPedido() { dCotizacionPR = new DCotizacionPR(); DgvCotizacionesPedidos.DataSource = dCotizacionPR.SelectCotizacionesPR(); DgvCotizacionesPedidos.Refresh(); }