public void InsertarIngresoGastos(IngresosGastos ig) { using (SqlConnection conn = new SqlConnection(MasterConnection.connection)) { try { int resultado = 0; conn.Open(); string query = ig.idConcepto == 0 ? "[insertar_tb_Ingresos]" : "[insertar_tb_Gastos]"; SqlCommand sc = new SqlCommand(query, conn); sc.CommandType = CommandType.StoredProcedure; sc.Parameters.AddWithValue("@Caja_Id", ig.idCaja); if (ig.idConcepto != 0) { sc.Parameters.AddWithValue("@Concepto_Id", ig.idConcepto); } sc.Parameters.AddWithValue("@Fecha", ig.Fecha); sc.Parameters.AddWithValue("@Nro_Documento", ig.NoComprobante); sc.Parameters.AddWithValue("@Tipo_Comprobante", ig.TipoComprobante); sc.Parameters.AddWithValue("@Importe", ig.Importe); sc.Parameters.AddWithValue("@Descripcion", ig.Descripcion); resultado = sc.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { conn.Close(); throw ex; } } }
private void btnGuardar_Click(object sender, EventArgs e) { try { if (rbtnGastos.Checked && string.IsNullOrEmpty(txtBuscar.Text)) { MessageBox.Show("seleccione el concepto", "Campos obligatorios", MessageBoxButtons.OK, MessageBoxIcon.Information); txtBuscar.Focus(); return; } if (string.IsNullOrEmpty(txtMonto.Text) || string.IsNullOrEmpty(txtDetalle.Text)) { MessageBox.Show("Llene todos los campos por favor", "Campos obligatorios", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { IngresosGastos ig = new IngresosGastos(); ig.idCaja = _idCaja; ig.idConcepto = _idConcepto; ig.Importe = Convert.ToDecimal(txtMonto.Text); ig.Fecha = dtpFecha.Value; ig.Descripcion = txtDetalle.Text; ig.TipoComprobante = chkComprobante.Checked ? cboTipoComprobante.Text : "N/A"; ig.NoComprobante = chkComprobante.Checked ? "01" : "N/A"; new DatGastoIngreso().InsertarIngresoGastos(ig); MessageBox.Show("Se ha ingresado los datos de forma correcta", "ÉXITO", MessageBoxButtons.OK, MessageBoxIcon.Information); LimpiarCampos(); } } catch (Exception ex) { MessageBox.Show("Ocurrió un error al insertar los datos : " + ex.Message, "Error de inserción", MessageBoxButtons.OK, MessageBoxIcon.Error); } }