Sunteți pe pagina 1din 7

Public Partial Class FrmIngreso

Inherits Form

Public Idtrabajador As Integer


Private IsNuevo As Boolean
Private dtDetalle As DataTable
Private totalPagado As Decimal = 0
Private Shared _instancia As FrmIngreso

Public Shared Function GetInstancia() As FrmIngreso


If _instancia Is Nothing Then
_instancia = New FrmIngreso()
End If

Return _instancia
End Function

Public Sub setProveedor(ByVal idproveedor As String, ByVal nombre As String)


Me.txtIdproveedor.Text = idproveedor
Me.txtProveedor.Text = nombre
End Sub

Public Sub setArticulo(ByVal idarticulo As String, ByVal nombre As String)


Me.txtIdarticulo.Text = idarticulo
Me.txtArticulo.Text = nombre
End Sub

Public Sub New()


InitializeComponent()
Me.ttMensaje.SetToolTip(Me.txtProveedor, "Seleccione el Proveedor")
Me.ttMensaje.SetToolTip(Me.txtSerie, "Ingrese la serie del comprobante")
Me.ttMensaje.SetToolTip(Me.txtCorrelativo, "Ingrese el número del
comprobante")
Me.ttMensaje.SetToolTip(Me.txtStock, "Ingrese la cantidad de compra")
Me.ttMensaje.SetToolTip(Me.txtArticulo, "Seleccione el Artículo de compra")
Me.txtIdproveedor.Visible = False
Me.txtIdarticulo.Visible = False
Me.txtProveedor.[ReadOnly] = True
Me.txtArticulo.[ReadOnly] = True
End Sub

Private Sub MensajeOk(ByVal mensaje As String)


MessageBox.Show(mensaje, "Sistema de Ventas", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Sub

Private Sub MensajeError(ByVal mensaje As String)


MessageBox.Show(mensaje, "Sistema de Ventas", MessageBoxButtons.OK,
MessageBoxIcon.[Error])
End Sub

Private Sub Limpiar()


Me.txtIdingreso.Text = String.Empty
Me.txtIdproveedor.Text = String.Empty
Me.txtProveedor.Text = String.Empty
Me.txtSerie.Text = String.Empty
Me.txtCorrelativo.Text = String.Empty
Me.txtIgv.Text = String.Empty
Me.lblTotal_Pagado.Text = "0,0"
Me.txtIgv.Text = "18"
Me.crearTabla()
End Sub

Private Sub limpiarDetalle()


Me.txtIdarticulo.Text = String.Empty
Me.txtArticulo.Text = String.Empty
Me.txtStock.Text = String.Empty
Me.txtPrecio_Compra.Text = String.Empty
Me.txtPrecio_Venta.Text = String.Empty
End Sub

Private Sub Habilitar(ByVal valor As Boolean)


Me.txtIdingreso.[ReadOnly] = Not valor
Me.txtSerie.[ReadOnly] = Not valor
Me.txtCorrelativo.[ReadOnly] = Not valor
Me.txtIgv.[ReadOnly] = Not valor
Me.dtFecha.Enabled = valor
Me.cbTipo_Comprobante.Enabled = valor
Me.txtStock.[ReadOnly] = Not valor
Me.txtPrecio_Compra.[ReadOnly] = Not valor
Me.txtPrecio_Venta.[ReadOnly] = Not valor
Me.dtFecha_Produccion.Enabled = valor
Me.dtFecha_Vencimiento.Enabled = valor
Me.btnBuscarArticulo.Enabled = valor
Me.btnBuscarProveedor.Enabled = valor
Me.btnAgregar.Enabled = valor
Me.btnQuitar.Enabled = valor
End Sub

Private Sub Botones()


If Me.IsNuevo Then
Me.Habilitar(True)
Me.btnNuevo.Enabled = False
Me.btnGuardar.Enabled = True
Me.btnCancelar.Enabled = True
Else
Me.Habilitar(False)
Me.btnNuevo.Enabled = True
Me.btnGuardar.Enabled = False
Me.btnCancelar.Enabled = False
End If
End Sub

Private Sub OcultarColumnas()


Me.dataListado.Columns(0).Visible = False
Me.dataListado.Columns(1).Visible = False
End Sub

Private Sub Mostrar()


Me.dataListado.DataSource = NIngreso.Mostrar()
Me.OcultarColumnas()
lblTotal.Text = "Total de Registros: " &
Convert.ToString(dataListado.Rows.Count)
End Sub

Private Sub BuscarFechas()


Me.dataListado.DataSource =
NIngreso.BuscarFechas(Me.dtFecha1.Value.ToString("dd/MM/yyyy"),
Me.dtFecha2.Value.ToString("dd/MM/yyyy"))
Me.OcultarColumnas()
lblTotal.Text = "Total de Registros: " &
Convert.ToString(dataListado.Rows.Count)
End Sub

Private Sub MostrarDetalle()


Me.dataListadoDetalle.DataSource =
NIngreso.MostrarDetalle(Me.txtIdingreso.Text)
End Sub

Private Sub crearTabla()


Me.dtDetalle = New DataTable("Detalle")
Me.dtDetalle.Columns.Add("idarticulo", System.Type.[GetType]
("System.Int32"))
Me.dtDetalle.Columns.Add("articulo", System.Type.[GetType]
("System.String"))
Me.dtDetalle.Columns.Add("precio_compra", System.Type.[GetType]
("System.Decimal"))
Me.dtDetalle.Columns.Add("precio_venta", System.Type.[GetType]
("System.Decimal"))
Me.dtDetalle.Columns.Add("stock_inicial", System.Type.[GetType]
("System.Int32"))
Me.dtDetalle.Columns.Add("fecha_produccion", System.Type.[GetType]
("System.DateTime"))
Me.dtDetalle.Columns.Add("fecha_vencimiento", System.Type.[GetType]
("System.DateTime"))
Me.dtDetalle.Columns.Add("subtotal", System.Type.[GetType]
("System.Decimal"))
Me.dtDetalle.Columns.Add("Impuesto", System.Type.[GetType]
("System.Decimal"))
Me.dataListadoDetalle.DataSource = Me.dtDetalle
End Sub

Private Sub FrmIngreso_Load(ByVal sender As Object, ByVal e As EventArgs)


Me.Top = 0
Me.Left = 0
Me.Mostrar()
Me.Habilitar(False)
Me.Botones()
Me.crearTabla()
End Sub

Private Sub FrmIngreso_FormClosing(ByVal sender As Object, ByVal e As


FormClosingEventArgs)
_instancia = Nothing
End Sub

Private Sub btnBuscarProveedor_Click(ByVal sender As Object, ByVal e As


EventArgs)
Dim vista As FrmVistaProveedor_Ingreso = New FrmVistaProveedor_Ingreso()
vista.ShowDialog()
End Sub

Private Sub btnBuscarArticulo_Click(ByVal sender As Object, ByVal e As


EventArgs)
Dim vista As FrmVistaArticulo_Ingreso = New FrmVistaArticulo_Ingreso()
vista.ShowDialog()
End Sub
Private Sub btnBuscar_Click(ByVal sender As Object, ByVal e As EventArgs)
Me.BuscarFechas()
End Sub

Private Sub btnEliminar_Click(ByVal sender As Object, ByVal e As EventArgs)


Try
Dim Opcion As DialogResult
Opcion = MessageBox.Show("Realmente Desea Anular los Registros",
"Sistema de Ventas", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)

If Opcion = DialogResult.OK Then


Dim Codigo As String
Dim Rpta As String = ""

For Each row As DataGridViewRow In dataListado.Rows

If Convert.ToBoolean(row.Cells(0).Value) Then
Codigo = Convert.ToString(row.Cells(1).Value)
Rpta = NIngreso.Anular(Convert.ToInt32(Codigo))

If Rpta.Equals("OK") Then
Me.MensajeOk("Se Anuló Correctamente el Ingreso")
Else
Me.MensajeError(Rpta)
End If
End If
Next

Me.Mostrar()
End If

Catch ex As Exception
MessageBox.Show(ex.Message + ex.StackTrace)
End Try
End Sub

Private Sub chkEliminar_CheckedChanged(ByVal sender As Object, ByVal e As


EventArgs)
If chkEliminar.Checked Then
Me.dataListado.Columns(0).Visible = True
Else
Me.dataListado.Columns(0).Visible = False
End If
End Sub

Private Sub dataListado_CellContentClick(ByVal sender As Object, ByVal e As


DataGridViewCellEventArgs)
If e.ColumnIndex = dataListado.Columns("Eliminar").Index Then
Dim ChkEliminar As DataGridViewCheckBoxCell =
CType(dataListado.Rows(e.RowIndex).Cells("Eliminar"), DataGridViewCheckBoxCell)
ChkEliminar.Value = Not Convert.ToBoolean(ChkEliminar.Value)
End If
End Sub

Private Sub btnNuevo_Click(ByVal sender As Object, ByVal e As EventArgs)


Me.IsNuevo = True
Me.Botones()
Me.Limpiar()
Me.Habilitar(True)
Me.txtSerie.Focus()
Me.limpiarDetalle()
End Sub

Private Sub btnCancelar_Click(ByVal sender As Object, ByVal e As EventArgs)


Me.IsNuevo = False
Me.Botones()
Me.Limpiar()
Me.Habilitar(False)
Me.limpiarDetalle()
End Sub

Private Sub btnGuardar_Click(ByVal sender As Object, ByVal e As EventArgs)


Try
Dim rpta As String = ""

If Me.txtIdproveedor.Text = String.Empty OrElse Me.txtSerie.Text =


String.Empty OrElse Me.txtCorrelativo.Text = String.Empty OrElse Me.txtIgv.Text =
String.Empty Then
MensajeError("Falta ingresar algunos datos, serán remarcados")
errorIcono.SetError(txtIdproveedor, "Ingrese un Valor")
errorIcono.SetError(txtSerie, "Ingrese un Valor")
errorIcono.SetError(txtCorrelativo, "Ingrese un Valor")
errorIcono.SetError(txtIgv, "Ingrese un Valor")
Else

If Me.IsNuevo Then
rpta = NIngreso.Insertar(Idtrabajador,
Convert.ToInt32(Me.txtIdproveedor.Text), dtFecha.Value, cbTipo_Comprobante.Text,
txtSerie.Text, txtCorrelativo.Text, Convert.ToDecimal(txtIgv.Text), "EMITIDO",
dtDetalle)
End If

If rpta.Equals("OK") Then

If Me.IsNuevo Then
Me.MensajeOk("Se Insertó de forma correcta el registro")
End If
Else
Me.MensajeError(rpta)
End If

Me.IsNuevo = False
Me.Botones()
Me.Limpiar()
Me.limpiarDetalle()
Me.Mostrar()
End If

Catch ex As Exception
MessageBox.Show(ex.Message + ex.StackTrace)
End Try
End Sub

Private Sub btnAgregar_Click(ByVal sender As Object, ByVal e As EventArgs)


Try

If Me.txtIdarticulo.Text = String.Empty OrElse Me.txtStock.Text =


String.Empty OrElse Me.txtPrecio_Compra.Text = String.Empty OrElse
Me.txtPrecio_Venta.Text = String.Empty Then
MensajeError("Falta ingresar algunos datos, serán remarcados")
errorIcono.SetError(txtIdarticulo, "Ingrese un Valor")
errorIcono.SetError(txtStock, "Ingrese un Valor")
errorIcono.SetError(txtPrecio_Compra, "Ingrese un Valor")
errorIcono.SetError(txtPrecio_Venta, "Ingrese un Valor")
Else
Dim registrar As Boolean = True

For Each row As DataRow In dtDetalle.Rows

If Convert.ToInt32(row("idarticulo")) =
Convert.ToInt32(Me.txtIdarticulo.Text) Then
registrar = False
Me.MensajeError("YA se encuentra el artículo en el
detalle")
End If
Next

If registrar Then
Dim subTotal As Decimal = Convert.ToDecimal(Me.txtStock.Text) *
Convert.ToDecimal(Me.txtPrecio_Compra.Text)
totalPagado = totalPagado + subTotal
Me.lblTotal_Pagado.Text = totalPagado.ToString("#0.00#")
Dim row As DataRow = Me.dtDetalle.NewRow()
row("idarticulo") = Convert.ToInt32(Me.txtIdarticulo.Text)
row("articulo") = Me.txtArticulo.Text
row("precio_compra") =
Convert.ToDecimal(Me.txtPrecio_Compra.Text)
row("precio_venta") =
Convert.ToDecimal(Me.txtPrecio_Venta.Text)
row("stock_inicial") = Convert.ToInt32(Me.txtStock.Text)
row("fecha_produccion") = dtFecha_Produccion.Value
row("fecha_vencimiento") = dtFecha_Vencimiento.Value
row("subtotal") = subTotal
Me.dtDetalle.Rows.Add(row)
Me.limpiarDetalle()
End If
End If

Catch ex As Exception
MessageBox.Show(ex.Message + ex.StackTrace)
End Try
End Sub

Private Sub btnQuitar_Click(ByVal sender As Object, ByVal e As EventArgs)


Try
Dim indiceFila As Integer = Me.dataListadoDetalle.CurrentCell.RowIndex
Dim row As DataRow = Me.dtDetalle.Rows(indiceFila)
Me.totalPagado = Me.totalPagado -
Convert.ToDecimal(row("subtotal").ToString())
Me.lblTotal_Pagado.Text = totalPagado.ToString("#0.00#")
Me.dtDetalle.Rows.Remove(row)
Catch ex As Exception
MensajeError("No hay fila para remover")
End Try
End Sub
Private Sub dataListado_DoubleClick(ByVal sender As Object, ByVal e As
EventArgs)
Me.txtIdingreso.Text =
Convert.ToString(Me.dataListado.CurrentRow.Cells("idingreso").Value)
Me.txtProveedor.Text =
Convert.ToString(Me.dataListado.CurrentRow.Cells("proveedor").Value)
Me.dtFecha.Value =
Convert.ToDateTime(Me.dataListado.CurrentRow.Cells("fecha").Value)
Me.cbTipo_Comprobante.Text =
Convert.ToString(Me.dataListado.CurrentRow.Cells("tipo_comprobante").Value)
Me.txtSerie.Text =
Convert.ToString(Me.dataListado.CurrentRow.Cells("serie").Value)
Me.txtCorrelativo.Text =
Convert.ToString(Me.dataListado.CurrentRow.Cells("correlativo").Value)
Me.lblTotal_Pagado.Text =
Convert.ToString(Me.dataListado.CurrentRow.Cells("total").Value)
Me.txtIgv.Text =
Convert.ToString(Me.dataListado.CurrentRow.Cells("Impuesto").Value)
Me.MostrarDetalle()
Me.tabControl1.SelectedIndex = 1
End Sub

Private Sub btnImprimir_Click(ByVal sender As Object, ByVal e As EventArgs)


Dim frm As Reportes.FrmReporteCompras = New Reportes.FrmReporteCompras()
frm.Texto = Convert.ToString(dtFecha1.Value)
frm.Texto2 = Convert.ToString(dtFecha2.Value)
frm.ShowDialog()
End Sub
End Class

S-ar putea să vă placă și