Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
295 lines (185 sloc) 9.19 KB
Imports System.Data
Imports System.Configuration.ConfigurationManager
Imports MySql.Data.MySqlClient
Partial Class RegTransferencia
Inherits cBase
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim Control As New cRegistroTransferencia
Dim dsDatos As New DataSet
Me.finSession()
If Me.IsPostBack = False Then
If String.IsNullOrEmpty(Me.Request("Transferencia")) = True Then
Me.MsgBox1.ShowAlert("Ocurrio un problema al cargar los datos, debe seleccionar una transferencia pendiente de registrar.", "", Cooperator.Framework.Web.Controls.AlertOption.NoAction)
Else
LlenarTransfencia(Control.RecuperarTransferenciaporIdGenerado(Request("Transferencia")))
End If
Iniciar()
'DeshabilitarForm()
'llenar desechos
llenarDesechos()
End If
Me.lblPuntoTransferencia.Text = Me.Session.Item("PuntoTransferencia")
Me.hdPuntoTransferencia.Value = Me.Session.Item("idPuntoTransferencia")
End Sub
Function LlenarTransfencia(ByVal dsDatos As DataSet) As Integer
Dim control As New cTransporte
If dsDatos.Tables(0).Rows.Count > 0 Then
Me.txtIdTransferencia.Text = Request("Transferencia")
Me.txtFechaIngreso.Text = dsDatos.Tables(0).Rows(0).Item("FechaRegistro")
Me.txtCliente.Text = dsDatos.Tables(0).Rows(0).Item("NombreCliente")
Me.txtTipoIngreso.Text = dsDatos.Tables(0).Rows(0).Item("NombreTipo")
Me.txtTransporte.Text = dsDatos.Tables(0).Rows(0).Item("Transporte_IdTransporte")
Me.txtPesoBruto.Text = dsDatos.Tables(0).Rows(0).Item("PesoBruto")
dsDatos = control.RecuperarTransportePorId(dsDatos.Tables(0).Rows(0).Item("Transporte_IdTransporte"))
If dsDatos.Tables(0).Rows.Count > 0 Then
Me.hdPesoTara.Value = dsDatos.Tables(0).Rows(0).Item("PesoTara")
End If
Me.txtPesoNeto.Text = Me.txtPesoBruto.Text - Me.hdPesoTara.Value
End If
End Function
Function llenarDesechos() As Integer
Dim cControl As New cDesecho
Dim dsDatos As New DataSet
dsDatos = cControl.RecuperarDesechos
If dsDatos.Tables(0).Rows.Count > 0 Then
chkDesechos.DataSource = dsDatos.Tables(0)
chkDesechos.DataTextField = "NombreDesecho"
chkDesechos.DataValueField = "IdDesecho"
End If
chkDesechos.DataBind()
End Function
Function IniciarConClienteAsignado() As Integer
Me.btnModificar.Visible = False
Me.btnDeschabilitar.Visible = False
Me.btnBuscar.Visible = False
Me.btnAgregar.Visible = False
End Function
Function Iniciar() As Integer
Me.btnAgregar.Visible = False
Me.btnCancelar.Visible = False
Me.btnModificar.Visible = False
Me.btnDeschabilitar.Visible = False
Me.btnBuscarCliente.Visible = False
Me.btnVerComprobante.Visible = False
Me.btnBuscar.Visible = False
End Function
Function HabilitaForm() As Integer
Me.txtIdTransferencia.ReadOnly = True
Me.txtPesoBruto.Enabled = True
Me.txtTipoIngreso.Enabled = True
Me.txtTransporte.Enabled = True
Me.txtPesoBruto.Enabled = True
Me.txtFechaIngreso.Enabled = True
Me.chkDesechos.Enabled = True
End Function
Function DeshabilitarForm() As Integer
Me.txtIdTransferencia.ReadOnly = True
Me.txtTipoIngreso.Enabled = False
Me.txtTransporte.Enabled = False
Me.txtPesoBruto.Enabled = False
Me.txtFechaIngreso.Enabled = False
Me.chkDesechos.Enabled = False
End Function
Function LimpiarForm() As Integer
Me.txtIdTransferencia.Text = ""
Me.txtPesoBruto.Text = ""
End Function
Protected Sub btnAgregar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAgregar.Click
Me.Session.Item("Accion") = "Agregar"
Me.btnAgregar.Visible = False
Me.btnGuardar.Visible = True
Me.btnCancelar.Visible = True
Me.btnBuscarCliente.Visible = True
Me.btnBuscar.Visible = False
HabilitaForm()
End Sub
Protected Sub btnGuardar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGuardar.Click
Dim control As New cRegistroTransferencia
Dim eRegistro As New RegistroTransferencia
Dim eBitacora As New Bitacora
Dim i As Integer
Dim flag As Boolean = False
For i = 0 To Me.chkDesechos.Items.Count - 1
If Me.chkDesechos.Items(i).Selected = True Then
flag = True
End If
Next
If flag = False Then
Me.MsgBox1.ShowAlert("Favor seleccionar algun desecho", "", Cooperator.Framework.Web.Controls.AlertOption.NoAction)
Else
eRegistro.IdRegistroTransferencia = Request("Transferencia")
eRegistro.TiempoIngreso = CDate(Now)
eRegistro.PesoNeto = Me.txtPesoNeto.Text
LlenarDesechosPorTransferencia(Request("Transferencia"))
If control.CompletarRegistroTransferencia(eRegistro) > 0 Then
Me.hdTransferencia.Value = Request("Transferencia")
Me.MsgBox1.ShowAlert("Registro Transferencia Guardado Satisfactoriamente", "", Cooperator.Framework.Web.Controls.AlertOption.NoAction, Cooperator.Framework.Web.Controls.AlertType.Information)
Me.btnVerComprobante.Visible = True
Me.btnVerComprobante.Attributes.Add("onclick", "javascript:verComprobante();")
Me.btnGuardar.Visible = False
Me.DeshabilitarForm()
'estaba aqui el llenado de desechos por transferencia
eBitacora.IdUsuario = Me.Session.Item("IdUsuario")
eBitacora.Fecha = CDate(Now)
eBitacora.IdEvento = Evento_Guardar
eBitacora.Detalle = "Nuevo Registro de Tranferencia numero " & Me.hdTransferencia.Value
Me.GuardarAccionEnBitacora(eBitacora)
Else
Me.MsgBox1.ShowAlert("Ocurriio un problema al guardar la transferencia", "", Cooperator.Framework.Web.Controls.AlertOption.NoAction, Cooperator.Framework.Web.Controls.AlertType.Stop)
End If
End If
End Sub
Function LlenarDesechosPorTransferencia(ByVal IdRegistroTransferencia As Integer) As Integer
Dim myCnnString As New String(AppSettings("cnnString"))
Dim myConnection = New MySqlConnection(myCnnString)
Dim ds As New DataSet
Dim i As Integer
Try
myConnection.Open()
Dim miCommandoSelect As String = "SELECT desechosportransferencia.idDesechosPorTransferencia, desechosportransferencia.Desecho_idDesecho, desechosportransferencia.RegistroTransferencia_idRegistroTransferencia FROM desechosportransferencia WHERE desechosportransferencia.RegistroTransferencia_idRegistroTransferencia =" & IdRegistroTransferencia
Dim adp As New MySqlDataAdapter(miCommandoSelect, myCnnString)
Dim cb As New MySqlCommandBuilder(adp)
Dim dt As DataTable = New DataTable("desechosportransferencia")
ds.Tables.Add(dt)
adp.Fill(ds, "desechosportransferencia")
Dim dsTemp As New DataSet
adp.Fill(dsTemp, "desechosportransferencia")
Dim dr As DataRow
Dim j As Integer = 0
Dim agregar As Boolean = True
For i = 0 To Me.chkDesechos.Items.Count - 1
agregar = True
For j = 0 To dsTemp.Tables(0).Rows.Count - 1
If Me.chkDesechos.Items(i).Value = dsTemp.Tables(0).Rows(j).Item("RegistroTransferencia_idRegistroTransferencia") Then
agregar = False
If Me.chkDesechos.Items(i).Selected = False Then
ds.Tables("desechosportransferencia").Rows(j).Delete()
End If
End If
Next
If agregar = True Then
If Me.chkDesechos.Items(i).Selected = True Then
dr = ds.Tables("desechosportransferencia").NewRow()
dr(1) = Trim(Me.chkDesechos.Items(i).Value)
dr(2) = IdRegistroTransferencia
ds.Tables("desechosportransferencia").Rows.Add(dr)
End If
End If
Next
If ds.HasChanges() Then
Dim ds2 As DataSet = ds.GetChanges()
adp.Update(ds2, "desechosportransferencia")
End If
myConnection.Close()
Catch ex As Exception
End Try
End Function
Protected Sub txtPesoBruto_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPesoBruto.TextChanged
Me.txtPesoNeto.Text = Me.txtPesoBruto.Text - Me.hdPesoTara.Value
End Sub
Protected Sub btnCancelar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
Iniciar()
DeshabilitarForm()
LimpiarForm()
End Sub
End Class