public frmNuevaFactura() { InitializeComponent(); dtpEmision.Value = DateTime.Now; cboEstadoPagar.DataSource = estado; pedidoSeleccionado = new PedidoWS.pedido(); daoFactura = new FacturaWS.FacturaWSClient(); if (frmVentanaPrincipal.nBtn == 1) { frmGestionarFacturas.facturaSeleccionada = (FacturaWS.factura)frmGestionarFacturas.dgv.CurrentRow.DataBoundItem; FacturaWS.factura miFactura = frmGestionarFacturas.facturaSeleccionada; txtIdFactura.Text = miFactura.idFactura.ToString(); txtIdPedido.Text = miFactura.pedido.idPedido.ToString(); txtMontoPendiente.Text = miFactura.pedido.montoPagar.ToString(); txtMonto.Text = miFactura.monto.ToString(); if (miFactura.estadoPagar) { cboEstadoPagar.SelectedIndex = 0; cboEstadoPagar.Enabled = false; } else { cboEstadoPagar.SelectedIndex = 1; } txtObservacion.Text = miFactura.observacion; dtpEmision.Value = miFactura.fechaEmision; dtpVencimiento.Value = miFactura.fechaVencimiento; txtImpuestos.Text = miFactura.impuestos.ToString(); btnBuscarPedido.Enabled = false; } }
private void dgvFacturas_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { try { FacturaWS.factura factura = dgvFacturas.Rows[e.RowIndex].DataBoundItem as FacturaWS.factura; dgvFacturas.Rows[e.RowIndex].Cells["ID_PEDIDO"].Value = factura.pedido.idPedido; dgvFacturas.Rows[e.RowIndex].Cells["RUC"].Value = factura.pedido.cliente.ruc; dgvFacturas.Rows[e.RowIndex].Cells["RAZON_SOCIAL"].Value = factura.pedido.cliente.razonSocial; dgvFacturas.Rows[e.RowIndex].Cells["GRUPO"].Value = factura.pedido.cliente.grupo; dgvFacturas.Rows[e.RowIndex].Cells["TIPO_CLIENTE"].Value = factura.pedido.cliente.tipoEmpresa; dgvFacturas.Rows[e.RowIndex].Cells["NOMBRE"].Value = factura.pedido.empleado.nombre; dgvFacturas.Rows[e.RowIndex].Cells["APELLIDO_PATERNO"].Value = factura.pedido.empleado.apellidoPaterno; dgvFacturas.Rows[e.RowIndex].Cells["APELLIDO_MATERNO"].Value = factura.pedido.empleado.apellidoMaterno; String anulado = ""; if (factura.anulado) { anulado = "SI"; } else { anulado = "NO"; } String estadoPagar = ""; if (factura.estadoPagar) { estadoPagar = "SI"; } else { estadoPagar = "NO"; } dgvFacturas.Rows[e.RowIndex].Cells["ANULADO"].Value = anulado; dgvFacturas.Rows[e.RowIndex].Cells["ESTADO_PAGAR"].Value = estadoPagar; } catch (Exception) {} }
public static void eliminar() { facturaSeleccionada = (FacturaWS.factura)dgv.CurrentRow.DataBoundItem; daoFactura.eliminarFactura(facturaSeleccionada); }
private void btnGuardar_Click(object sender, EventArgs e) { if (txtIdPedido.Text == "") { MessageBox.Show("Debe indicar un pedido", "Mensaje de advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } foreach (Control c in this.Controls) { if (c is TextBox) { TextBox textBox = c as TextBox; if (textBox.Text == string.Empty && textBox.Name != "txtIdPedido" && textBox.Name != "txtMontoPendiente" && textBox.Name != "txtIdFactura" && textBox.Name != "txtImpuestos") { MessageBox.Show("Falta llenar los datos de " + textBox.Name.Substring(3), "Mensaje de advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { try { double monto = Convert.ToDouble(txtMonto.Text); } catch (Exception) { MessageBox.Show("Los datos del monto de la factura solo pueden contener dígitos", "Mensaje de advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } } if (dtpVencimiento.Value < DateTime.Now) { MessageBox.Show("Fecha de vencimiento inválida", "Mensaje de advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (dtpEmision.Value > dtpVencimiento.Value) { MessageBox.Show("Rango de fechas inválido", "Mensaje de advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (Convert.ToDouble(txtMonto.Text) < 0) { MessageBox.Show("El monto debe ser positivo", "Mensaje de advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (Convert.ToDouble(txtMonto.Text) > Convert.ToDouble(txtMontoPendiente.Text)) { MessageBox.Show("Monto de pago excede el monto pendiente", "Mensaje de advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } frmConfirmarInsertar formInsertar = new frmConfirmarInsertar(); if (formInsertar.ShowDialog() == DialogResult.OK) { FacturaWS.factura factura = new FacturaWS.factura(); factura.pedido = new FacturaWS.pedido(); factura.pedido.idPedido = pedidoSeleccionado.idPedido; factura.monto = Convert.ToDouble(txtMonto.Text); factura.observacion = txtObservacion.Text; factura.fechaVencimiento = dtpVencimiento.Value; factura.fechaVencimientoSpecified = true; factura.impuestos = Math.Round(factura.monto * 0.18, 2); txtImpuestos.Text = factura.impuestos.ToString("n2"); if (cboEstadoPagar.Text == "PAGADO") { factura.estadoPagar = true; } else { factura.estadoPagar = false; } if (frmVentanaPrincipal.nBtn == 0) { int resultado = daoFactura.insertarFactura(factura); if (resultado == 0) { MessageBox.Show("No se insertó correctamente", "Mensaje de error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { ((frmGestionarFacturas)Program.pantallas[Program.pantallas.Count - 2].Formulario).recargarDGV(); MessageBox.Show("Se insertó correctamente", "Mensaje de confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information); txtIdFactura.Text = resultado.ToString(); txtMontoPendiente.Text = (Convert.ToDouble(txtMontoPendiente.Text) - Convert.ToDouble(txtMonto.Text)).ToString("n2"); } } else if (frmVentanaPrincipal.nBtn == 1) { factura.idFactura = Convert.ToInt32(txtIdFactura.Text); int resultado = daoFactura.actualizarFactura(factura); if (resultado == 0) { MessageBox.Show("No se actualizó correctamente", "Mensaje de error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { ((frmGestionarFacturas)Program.pantallas[Program.pantallas.Count - 2].Formulario).recargarDGV(); MessageBox.Show("Se actualizó correctamente", "Mensaje de confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information); txtIdFactura.Text = resultado.ToString(); txtMontoPendiente.Text = (frmGestionarFacturas.facturaSeleccionada.pedido.montoPagar - Convert.ToDouble(txtMonto.Text)).ToString(); } } } }