Skip to content

Commit

Permalink
Merge pull request #3 from mauryparra/ModificarEgresos
Browse files Browse the repository at this point in the history
Egresos Agregar/Modificar/Borrar
  • Loading branch information
mauryparra authored May 19, 2017
2 parents ff817a2 + 47c3dd4 commit b316f23
Show file tree
Hide file tree
Showing 19 changed files with 3,483 additions and 773 deletions.
205 changes: 200 additions & 5 deletions SireCu/Clases/Egreso.vb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ Module Egreso
ByVal fecha As Date, ByVal tipo_comp As String, ByVal secc As String, ByVal reintegro As Date, ByVal monto As Double,
ByVal comentario As String)
Principal.query = "INSERT INTO egresos (nro_comprobante, proveedor_id, categoria_gasto_id, persona_id, " &
"fecha, tipo_comprobante_id, seccional_id, mes_reintegro, monto, comentario)" &
"fecha, tipo_comprobante_id, seccional_id, mes_reintegro, monto, comentario, eliminado, seleccionado)" &
"VALUES (@nro_comprobante, @proveedor, @cat_gasto, @persona, @fecha, @t_comprobante, " &
"@seccional, @reintegro, @monto, @comentario)"
"@seccional, @reintegro, @monto, @comentario, 0, 0)"
Principal.command.Parameters.Clear()
Principal.command.Parameters.AddWithValue("@nro_comprobante", compro)
Principal.command.Parameters.AddWithValue("@proveedor", proveedor)
Principal.command.Parameters.AddWithValue("@cat_gasto", categoria)
Expand All @@ -23,15 +24,209 @@ Module Egreso
consultarNQ(Principal.query, Principal.command)
End Sub

Public Sub modificar_egreso()
Public Sub modificar_egreso(ByVal id As Integer, ByVal compro As String, ByVal proveedor As Integer, ByVal categoria As Integer,
ByVal persona As Integer, ByVal fecha As Date, ByVal tipo_comp As Integer, ByVal secc As Integer,
ByVal reintegro As Date, ByVal monto As Decimal, ByVal comentario As String)

Principal.query = "UPDATE Egresos SET nro_comprobante = @nro_comprobante, proveedor_id = @proveedor, categoria_gasto_id = @cat_gasto, " &
"persona_id = @persona, fecha = @fecha, tipo_comprobante_id = @t_comprobante, seccional_id = @seccional, " &
"mes_reintegro = @reintegro, monto = @monto, comentario = @comentario " &
"WHERE id = @id"
Principal.command.Parameters.Clear()
Principal.command.Parameters.AddWithValue("@nro_comprobante", compro)
Principal.command.Parameters.AddWithValue("@proveedor", proveedor)
Principal.command.Parameters.AddWithValue("@cat_gasto", categoria)
Principal.command.Parameters.AddWithValue("@persona", persona)
Principal.command.Parameters.AddWithValue("@fecha", fecha)
Principal.command.Parameters.AddWithValue("@t_comprobante", tipo_comp)
Principal.command.Parameters.AddWithValue("@seccional", secc)
Principal.command.Parameters.AddWithValue("@reintegro", reintegro)
Principal.command.Parameters.AddWithValue("@monto", monto)
Principal.command.Parameters.AddWithValue("@comentario", comentario)
Principal.command.Parameters.AddWithValue("@id", id)

If consultarNQ(Principal.query, Principal.command) > 0 Then
MsgBox("Egreso modificado exitosamente", MsgBoxStyle.OkOnly, "Guardar Cambios")
Else
MsgBox("Ocurrio un error al guardar los cambios", MsgBoxStyle.Exclamation, "Guardar Cambios")
End If
End Sub

Public Sub eliminar_egreso()
Public Sub eliminar_egreso_soft(ByVal id As Integer)
Principal.query = "UPDATE Egresos SET eliminado = 1 WHERE id = @id"
Principal.command.Parameters.Clear()
Principal.command.Parameters.AddWithValue("@id", id)

If consultarNQ(Principal.query, Principal.command) > 0 Then
MsgBox("Egreso eliminado exitosamente", MsgBoxStyle.OkOnly, "Eliminar Egreso")
Else
MsgBox("Ocurrio un error al eliminar el egreso", MsgBoxStyle.Exclamation, "Eliminar Egreso")
End If
End Sub

Public Function mostrar_egreso()
Public Sub restaurar_egreso(ByVal id As Integer)
Principal.query = "UPDATE Egresos SET eliminado = 0 WHERE id = @id"
Principal.command.Parameters.Clear()
Principal.command.Parameters.AddWithValue("@id", id)

If consultarNQ(Principal.query, Principal.command) > 0 Then
MsgBox("Egreso restaurado exitosamente", MsgBoxStyle.OkOnly, "Restaurar Egreso")
Else
MsgBox("Ocurrio un error al restaurar el egreso", MsgBoxStyle.Exclamation, "Restaurar Egreso")
End If
End Sub

Public Sub eliminar_egreso_hard(ByVal id As Integer)
Principal.query = "DELETE FROM Egresos WHERE id = @id"
Principal.command.Parameters.Clear()
Principal.command.Parameters.AddWithValue("@id", id)

If consultarNQ(Principal.query, Principal.command) > 0 Then
MsgBox("Egreso eliminado exitosamente", MsgBoxStyle.OkOnly, "Eliminar Egreso Permanentemente")
Else
MsgBox("Ocurrio un error al eliminar el egreso", MsgBoxStyle.Exclamation, "Eliminar Egreso Permanentemente")
End If
End Sub

Public Sub vaciar_papelera()
Principal.query = "DELETE FROM Egresos WHERE eliminado = 1"

If consultarNQ(Principal.query, Principal.command) > 0 Then
MsgBox("Papelera vaciada exitosamente", MsgBoxStyle.OkOnly, "Vaciar Papelera")
Else
MsgBox("Ocurrio un error al vaciar la papelera", MsgBoxStyle.Exclamation, "Vaciar Papelera")
End If
End Sub

Public Sub CargardDGV(ByRef dgv As DataGridView, Optional ByVal eliminado As Integer = 0, Optional ByVal nombreDataSet As String = "Egresos_Modificar")

'Creamos la tabla si no existe
If Not Principal.dataset.Tables.Contains(nombreDataSet) Then
Principal.dataset.Tables.Add(nombreDataSet)
End If
'Limpiamos la tabla
Principal.dataset.Tables(nombreDataSet).Clear()

'Creamos el query
Principal.command.CommandText = "SELECT TOP (500) E.id AS id,
E.nro_comprobante AS nro_comprobante,
E.tipo_comprobante_id AS tipo_comprobante_id,
Comp.nombre AS tipo_comprobante_nombre,
E.proveedor_id AS proveedor_id,
Pro.nombre AS proveedor_nombre,
E.categoria_gasto_id AS categoria_gasto_id,
Gastos.nombre AS categoria_nombre,
E.persona_id AS persona_id,
Per.nombre AS persona_nombre,
E.fecha AS fecha,
E.seccional_id AS seccional_id,
Secc.nombre AS seccional_nombre,
E.mes_reintegro AS mes_reintegro,
E.monto AS monto,
E.comentario AS comentario,
E.seleccionado AS seleccionado
FROM Egresos AS E
LEFT JOIN TiposComprobantes AS Comp ON E.tipo_comprobante_id = Comp.id
LEFT JOIN Proveedores AS Pro ON E.proveedor_id = Pro.id
LEFT JOIN CategoriasGastos AS Gastos ON E.categoria_gasto_id = Gastos.id
LEFT JOIN Personas AS Per ON E.persona_id = Per.id
LEFT JOIN Seccionales AS Secc ON E.seccional_id = Secc.id
WHERE E.eliminado = " & eliminado & " ORDER BY E.id DESC"

'Creamos el TableAdapter si no existe
If Not Principal.tableadapters.ContainsKey(nombreDataSet) Then
Principal.tableadapters.Add(nombreDataSet, New SqlCeDataAdapter(Principal.command))
End If

'Actualizamos el contenido de la tabla
Principal.tableadapters(nombreDataSet).Fill(Principal.dataset.Tables.Item(nombreDataSet))

'Asignamos el Bind
Dim mybinding = New BindingSource(Principal.dataset, nombreDataSet)

dgv.AutoGenerateColumns = False

dgv.Columns.Item(0).DataPropertyName = "id"
dgv.Columns.Item(1).DataPropertyName = "seleccionado"
dgv.Columns.Item(2).DataPropertyName = "nro_comprobante"
dgv.Columns.Item(3).DataPropertyName = "tipo_comprobante_id"
dgv.Columns.Item(4).DataPropertyName = "tipo_comprobante_nombre"
dgv.Columns.Item(5).DataPropertyName = "proveedor_id"
dgv.Columns.Item(6).DataPropertyName = "proveedor_nombre"
dgv.Columns.Item(7).DataPropertyName = "categoria_gasto_id"
dgv.Columns.Item(8).DataPropertyName = "categoria_nombre"
dgv.Columns.Item(9).DataPropertyName = "persona_id"
dgv.Columns.Item(10).DataPropertyName = "persona_nombre"
dgv.Columns.Item(11).DataPropertyName = "fecha"
dgv.Columns.Item(12).DataPropertyName = "seccional_id"
dgv.Columns.Item(13).DataPropertyName = "seccional_nombre"
dgv.Columns.Item(14).DataPropertyName = "mes_reintegro"
dgv.Columns.Item(15).DataPropertyName = "monto"
dgv.Columns.Item(16).DataPropertyName = "comentario"

dgv.DataSource = mybinding

End Sub

Public Sub FiltrarDGV(ByRef dgv As DataGridView, ByVal sql As String, Optional ByVal eliminado As Integer = 0, Optional ByVal nombreDataSet As String = "Egresos_Modificar")

'Creamos la tabla si no existe
If Not Principal.dataset.Tables.Contains(nombreDataSet) Then
Principal.dataset.Tables.Add(nombreDataSet)
End If
'Limpiamos la tabla
Principal.dataset.Tables(nombreDataSet).Clear()

'Creamos el query
Principal.command.CommandText = sql

'Creamos el TableAdapter si no existe
If Not Principal.tableadapters.ContainsKey(nombreDataSet) Then
Principal.tableadapters.Add(nombreDataSet, New SqlCeDataAdapter(Principal.command))
End If

'Actualizamos el contenido de la tabla
Principal.tableadapters(nombreDataSet).Fill(Principal.dataset.Tables.Item(nombreDataSet))

'Asignamos el Bind
Dim mybinding = New BindingSource(Principal.dataset, nombreDataSet)

dgv.AutoGenerateColumns = False

dgv.Columns.Item(0).DataPropertyName = "id"
dgv.Columns.Item(1).DataPropertyName = "seleccionado"
dgv.Columns.Item(2).DataPropertyName = "nro_comprobante"
dgv.Columns.Item(3).DataPropertyName = "tipo_comprobante_id"
dgv.Columns.Item(4).DataPropertyName = "tipo_comprobante_nombre"
dgv.Columns.Item(5).DataPropertyName = "proveedor_id"
dgv.Columns.Item(6).DataPropertyName = "proveedor_nombre"
dgv.Columns.Item(7).DataPropertyName = "categoria_gasto_id"
dgv.Columns.Item(8).DataPropertyName = "categoria_nombre"
dgv.Columns.Item(9).DataPropertyName = "persona_id"
dgv.Columns.Item(10).DataPropertyName = "persona_nombre"
dgv.Columns.Item(11).DataPropertyName = "fecha"
dgv.Columns.Item(12).DataPropertyName = "seccional_id"
dgv.Columns.Item(13).DataPropertyName = "seccional_nombre"
dgv.Columns.Item(14).DataPropertyName = "mes_reintegro"
dgv.Columns.Item(15).DataPropertyName = "monto"
dgv.Columns.Item(16).DataPropertyName = "comentario"

dgv.DataSource = mybinding

End Sub

Public Function comprobante_repetido(ByVal nComprobante As String, ByVal proveedorID As Integer)

Dim flag As Boolean = False

For i = 0 To Principal.dataset.Tables("Egresos").Rows.Count - 1
If (Principal.dataset.Tables("Egresos").Rows.Item(i).Item("nro_comprobante") = nComprobante) And
(Principal.dataset.Tables("Egresos").Rows.Item(i).Item("proveedor_id") = proveedorID) Then
flag = True
End If
Next

Return flag

End Function

Expand Down
35 changes: 7 additions & 28 deletions SireCu/Clases/Ingreso.vb
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,23 @@ Module Ingreso

End Sub

Public Function mostrar_ingreso(ByVal mes As Integer, ByVal año As Integer)
Public Function mostrar_ingreso(ByVal mes As Integer, ByVal año As Integer) As DataTable

Principal.query = "SELECT * from ingresos where DATEPART(month, fecha) = '" & mes & "'" &
" And DatePart(Year, fecha) = '" & año & "'"

consultarNQ(Principal.query, Principal.command)
Principal.adapter = New SqlCeDataAdapter(Principal.command)
ClearDataset(Principal.dataset)
Principal.adapter.Fill(Principal.dataset.Tables("ingresos"))

Dim array() As String
If (Principal.dataset.Tables("ingresos").Rows.Count = 0) Then
array = {0}
Return (array)
Else
array = {
Principal.dataset.Tables("ingresos").Rows.Item(0).Item("ingresos_prov"),
Principal.dataset.Tables("ingresos").Rows.Item(0).Item("ingresos_central"),
Principal.dataset.Tables("ingresos").Rows.Item(0).Item("ingresos_otros")
}
Return array
End If
Dim dt As DataTable = consultarReader(Principal.query)

Return dt

End Function

Public Function verificar_año(ByVal año As Integer)

Principal.query = "SELECT * from ingresos where DATEPART(Year, fecha) = '" & año & "'"
consultarNQ(Principal.query, Principal.command)
ClearDataset(Principal.dataset)
Principal.adapter = New SqlCeDataAdapter(Principal.command)
Principal.adapter.Fill(Principal.dataset.Tables("ingresos"))

If (Principal.dataset.Tables("ingresos").Rows.Count = 0) Then
Return (False)
Else
Return (True)
End If
Dim dt As DataTable = consultarReader(Principal.query)

Return IIf(dt.Rows.Count > 0, True, False)

End Function

Expand Down
45 changes: 44 additions & 1 deletion SireCu/Conexion.vb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Module Conexion

Private conexion As New SqlCeConnection(My.Settings.CadenaConexion)
Public conexion As New SqlCeConnection(My.Settings.CadenaConexion)

Private Sub conectar()

Expand Down Expand Up @@ -56,5 +56,48 @@ Module Conexion
Return resultado
End Function

Function consultarReader(ByVal sql As String) As DataTable

Dim reader As SqlCeDataReader
Dim dt As New DataTable

Try
conectar()
Principal.command.CommandText = sql
Principal.command.Connection = conexion
reader = Principal.command.ExecuteReader()
dt.Load(reader)
desconectar()
Catch ex As SqlCeException
MessageBox.Show(ex.Message)
reader = Nothing
End Try

Return dt
End Function

Sub cargarTablaEnDataSet(ByVal tabla As String)

Principal.command.Connection = conexion

' Crea tabla en dataset si no existe
If Not Principal.dataset.Tables.Contains(tabla) Then
Principal.dataset.Tables.Add(tabla)
End If
'Limpiamos la tabla
Principal.dataset.Tables(tabla).Clear()

Principal.command.CommandText = "Select * FROM " & tabla

' Crea tableadapter si no existe
If Not Principal.tableadapters.ContainsKey(tabla) Then
Principal.tableadapters.Add(tabla, New SqlCeDataAdapter(Principal.command))
End If

'Refrescamos el contenido
Principal.tableadapters(tabla).Fill(Principal.dataset.Tables.Item(tabla))

End Sub


End Module
Binary file modified SireCu/DBSireCu.sdf
Binary file not shown.
Loading

0 comments on commit b316f23

Please sign in to comment.