Files
SIG/General/ColectivasDetalle.aspx.vb
JORGE LUIS CAUDILLO ESPARZA c35cf91883 Commit inicial Ventas Productivo
2019-08-14 16:40:54 -07:00

342 lines
16 KiB
VB.net

Option Explicit On
Option Strict On
Imports System.Data
Imports Extensiones
Imports System.Xml
Imports System.Linq
Partial Class General_ColectivasDetalle
Inherits ClsPaginas
'Configuración
#Region "P R O P I E D A D E S"
Private Property DtCuentasContables As Data.DataTable
Get
Return CType(ViewState("DtCuentasContables"), DataTable)
End Get
Set(value As Data.DataTable)
ViewState("DtCuentasContables") = value
End Set
End Property
Private ReadOnly Property CveColectiva As Integer
Get
Return ViewState("CveColectiva").ToString.ToEntero
End Get
End Property
Private Property DTCuentasBancos As DataTable
Get
Return CType(ViewState("DTCuentasBancos"), DataTable)
End Get
Set(value As DataTable)
ViewState("DTCuentasBancos") = value
End Set
End Property
Private Property TempDTCuentasBancos As DataTable
Get
Return CType(ViewState("TempDTCuentasBancos"), DataTable)
End Get
Set(value As DataTable)
ViewState("TempDTCuentasBancos") = value
End Set
End Property
#End Region
Private Sub CargaCuentasContables()
Dim ObjContabilidad As New ClsContPAQi(UsuarioActual.Empresa)
If ObjContabilidad.GetCuentas(-1, "-1", -1) Then
DtCuentasContables = ObjContabilidad.DtResultados
DdlCtaContColectivas.DataSource = ObjContabilidad.DtResultados
DdlCtaContColectivas.DataBind()
Else
DtCuentasContables = Nothing
End If
ObjContabilidad.Dispose()
End Sub
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
If UsuarioActual.Empresa.UsaContabilidad Then CargaCuentasContables()
If Request("CveColectiva") IsNot Nothing AndAlso IsNumeric(Request("CveColectiva")) AndAlso Request("CveColectiva").ToEntero > 0 Then
ViewState("CveColectiva") = Request("CveColectiva")
CargarDatos()
'Configuración de Modalidad Update
BtnGuardar.Text = "Guardar Cambios"
LtlTitulo.Text = "Consulta del Colectiva:"
Else
'Configuración de Modalidad Insertf
LblFechaCaptura.Text = Now.ToShortDateString()
LblUsuarioCapturo.Text = UsuarioActual.Usuario
ViewState("CveColectiva") = -1
End If
CargaCuentasBancarias()
End If
End Sub
Private Sub CargarDatos()
Dim ObjColectivasDetalle As New ClsGenerales
If ObjColectivasDetalle.GetColectivas(CveColectiva, "-1", "-1", "-1", UsuarioActual.CveEmpresa) Then
If ObjColectivasDetalle.DtResultados.Rows.Count > 0 Then
TxtColectiva.Text = ObjColectivasDetalle.Colectiva
TxtCodigo.Text = ObjColectivasDetalle.Codigo
TxtRFC.Text = ObjColectivasDetalle.RFC
TxtDireccion.Text = ObjColectivasDetalle.Direccion
TxtTelefono.Text = ObjColectivasDetalle.Telefono
TxtCorreo.Text = ObjColectivasDetalle.Correo
DdlTipo.SelectedValue = ObjColectivasDetalle.Tipo.ToString
DdlCtaContColectivas.SelectedValue = ObjColectivasDetalle.IdCtaContable.ToString
ChkEstado.Checked = ObjColectivasDetalle.Estatus
LblFechaCaptura.Text = ObjColectivasDetalle.FechaIng.ToString
LblUsuarioCapturo.Text = ObjColectivasDetalle.Usuario
End If
End If
End Sub
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click
Dim ObjColectivasDetalle As New ClsGenerales
Dim ObjCuentasDeposito As New ClsGenerales(ObjColectivasDetalle.IniciaTransacSQL())
Dim ErrorBancos = False
If CveColectiva = -1 Then
If ObjColectivasDetalle.AddColectivas(TxtColectiva.Text.Trim, TxtCodigo.Text.Trim, TxtRFC.Text.Trim, TxtDireccion.Text.Trim, TxtTelefono.Text.Trim, TxtCorreo.Text.Trim, DdlCtaContColectivas.SelectedValue.ToEntero, DdlCtaContColectivas.SelectedItem.ToString, DdlTipo.SelectedValue.ToEntero.ToString, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then
Dim NuevoCveColectiva = ObjColectivasDetalle.CveColectiva
''Agregar Cuentas Bancarias
If TempDTCuentasBancos.Rows.Count > 0 Then
For Each row As DataRow In TempDTCuentasBancos.Rows
If Not ObjCuentasDeposito.AddCuentasDepositos(row("BancoNombre").ToString, row("Plaza").ToString, row("Sucursal").ToString, row("Cuenta").ToString, row("CLABE").ToString, row("CIE").ToString, row("SWIFT").ToString, row("Referencia").ToString, "", UsuarioActual.CveUsuario, 1, CveColectiva:=NuevoCveColectiva) Then
ErrorBancos = True
End If
Next
End If
If ObjColectivasDetalle.GetColectivas(CveColectiva, "-1", "-1", "-1", -1) Then
GlobalDTGralColectivas(-1) = ObjColectivasDetalle.DtResultados
Else
ErrorBancos = True
End If
If ErrorBancos Then
ObjColectivasDetalle.RollBack()
Alert("Ocurrió un error al registrar las Cuentas Bancarias", TipoMensaje.MsgError)
Else
ObjColectivasDetalle.Commit()
Alert("Se guardó correctamente.", TipoMensaje.MsgInformacion, If(Request("CveFactura") Is Nothing, "document.location.href=""/General/Colectivas.aspx""", "window.opener.location.href = window.opener.location.href; window.close();"))
End If
Alert("El Registro se guardó correctamente.", TipoMensaje.MsgInformacion, If(Request("CveColectiva") Is Nothing, "document.location.href=""/General/Colectivas.aspx""", "window.opener.location.href = window.opener.location.href; window.close();"))
End If
Else
If ObjColectivasDetalle.UpdateColectivas(TxtColectiva.Text.Trim, TxtCodigo.Text.Trim, TxtRFC.Text.Trim, TxtDireccion.Text.Trim, TxtTelefono.Text.Trim, TxtCorreo.Text.Trim, DdlCtaContColectivas.SelectedValue.ToEntero, DdlCtaContColectivas.SelectedItem.ToString, DdlTipo.SelectedValue.ToEntero.ToString, ChkEstado.Checked, CveColectiva) Then
Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion, "document.location.href=""/General/Colectivas.aspx""")
End If
End If
ObjColectivasDetalle.Dispose()
ObjCuentasDeposito.Dispose()
End Sub
#Region "TAB BANCOS"
Protected Sub LbOrden_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim Tipo As Integer = 1
Dim Orden As String = ""
Dim Campo As String = ""
Dim gvi As Integer = 0
Dim ImgButon As ImageButton = Nothing
Const OrdenInicial As String = ""
Select Case sender.GetType().Name
Case "LinkButton"
Tipo = 1
Campo = CType(sender, LinkButton).CommandArgument().ToString
ImgButon = CType(CType(sender, LinkButton).BindingContainer.FindControl("Img" & Campo.Replace(",", "_")), ImageButton)
Case "ImageButton"
Tipo = 2
ImgButon = CType(sender, ImageButton)
Campo = CType(sender, ImageButton).CommandArgument().ToString
End Select
If ViewState(String.Format("O{0}", Campo)) IsNot Nothing AndAlso ViewState(String.Format("O{0}", Campo)).ToString = String.Format("{0} DESC", Campo) Then
ViewState(String.Format("O{0}", Campo)) = String.Format("{0} ASC", Campo)
RegistraScript(String.Format("$get('{0}').src='{1}'", ImgButon.ClientID, "/Imagenes/FlechasArriba.gif"))
Else
ViewState(String.Format("O{0}", Campo)) = String.Format("{0} DESC", Campo)
RegistraScript(String.Format("$get({0}).src='{1}'", ImgButon.ClientID, "/Imagenes/FlechasAbajo.gif"))
End If
Orden = OrdenInicial & ViewState(String.Format("O{0}", Campo)).ToString
ViewState("OrdenCuentasBancos") = Orden
CargaGridCuentasBancos(Orden)
End Sub
Protected Sub LbAgregarCuentaBanco_Click(sender As Object, e As EventArgs)
AgregarCuentaBanco(TxtNombreBanco.Text.Trim, TxtNumeroSucursal.Text.Trim, TxtCLABE.Text.Trim, TxtSWIFT.Text.Trim, TxtPlaza.Text.Trim, TxtNumeroCuenta.Text.Trim, TxtConvenioCIE.Text.Trim, TxtReferencia.Text.Trim)
End Sub
Private Sub CargaGridCuentasBancos(Orden As String)
If CveColectiva > 0 Then
If Orden <> String.Empty Then
Dim DV As New DataView(DTCuentasBancos, "", Orden, DataViewRowState.CurrentRows)
GvBancosCuentas.DataSource = DV.ToTable()
DV.Dispose()
Else
GvBancosCuentas.DataSource = DTCuentasBancos
End If
Else
If Orden <> String.Empty Then
Dim DV As New DataView(TempDTCuentasBancos, "", Orden, DataViewRowState.CurrentRows)
GvBancosCuentas.DataSource = DV.ToTable()
DV.Dispose()
Else
GvBancosCuentas.DataSource = TempDTCuentasBancos
End If
End If
GvBancosCuentas.DataBind()
UpCuentasBancos.Update()
End Sub
Private Sub AgregarCuentaBanco(NombreBanco As String, NumeroSucursal As String, CLABE As String, SWIFT As String, Plaza As String, NumeroCuenta As String, ConvenioCIE As String, Referencia As String)
Dim ObjCuentasBancos As New ClsGenerales
Dim Row As DataRow
If CveColectiva > 0 Then
If ObjCuentasBancos.AddCuentasDepositos(NombreBanco, Plaza, NumeroSucursal, NumeroCuenta, CLABE, ConvenioCIE, SWIFT, Referencia, "", UsuarioActual.CveUsuario, 1, CveColectiva:=CveColectiva) Then
DTCuentasBancos.Clear()
DTCuentasBancos.Merge(ObjCuentasBancos.DtResultados.FiltraParametros(String.Format("CveColectiva = {0}", CveColectiva)))
Alert("Cuenta Bancaria agregada con éxito.", TipoMensaje.MsgInformacion)
End If
Else
Row = TempDTCuentasBancos.NewRow
Row("BancoNombre") = NombreBanco
Row("Sucursal") = NumeroSucursal
Row("CLABE") = CLABE
Row("SWIFT") = SWIFT
Row("Plaza") = Plaza
Row("Cuenta") = NumeroCuenta
Row("CIE") = ConvenioCIE
Row("Referencia") = Referencia
TempDTCuentasBancos.Rows.Add(Row)
End If
ObjCuentasBancos.Dispose()
LimpiaCuentasBancarias()
CargaGridCuentasBancos(ViewState("OrdenCuentasBancos").ToString)
End Sub
Private Sub LimpiaCuentasBancarias()
TxtNombreBanco.Text = ""
TxtNumeroSucursal.Text = ""
TxtCLABE.Text = ""
TxtSWIFT.Text = ""
TxtPlaza.Text = ""
TxtNumeroCuenta.Text = ""
TxtConvenioCIE.Text = ""
TxtReferencia.Text = ""
End Sub
Private Sub CargaCuentasBancarias()
Dim ObjCuentasBancos As New ClsGenerales
ViewState("OrdenCuentasBancos") = ""
DTCuentasBancos = New DataTable
TempDTCuentasBancos = New DataTable
If ObjCuentasBancos.GetCuentasDepositos(CveColectiva:=CveColectiva) Then
DTCuentasBancos.Merge(ObjCuentasBancos.DtResultados)
Else
Alert("No se pudieron cargar las cuentas bancarias. Por favor intente nuevamente.", TipoMensaje.MsgAdvertencia)
End If
If CveColectiva < 0 Then
TempDTCuentasBancos = DTCuentasBancos.Clone
End If
ObjCuentasBancos.Dispose()
CargaGridCuentasBancos(ViewState("OrdenCuentasBancos").ToString)
End Sub
#Region "GRIDVIEW - CUENTAS BANCARIAS"
Protected Sub GvBancosCuentas_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvBancosCuentas.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If CveColectiva < 0 Then
For index = 1 To TempDTCuentasBancos.Rows.Count
TempDTCuentasBancos.Rows(index - 1)("CveCuentaDeposito") = index
Next
TempDTCuentasBancos.AcceptChanges()
End If
End If
End Sub
Protected Sub GvBancosCuentas_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GvBancosCuentas.RowEditing
GvBancosCuentas.EditIndex = e.NewEditIndex
CargaGridCuentasBancos(ViewState("OrdenCuentasBancos").ToString)
End Sub
Protected Sub GvBancosCuentas_RowCancelingEdit(sender As Object, e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GvBancosCuentas.RowCancelingEdit
GvBancosCuentas.EditIndex = -1
CargaGridCuentasBancos(ViewState("OrdenCuentasBancos").ToString)
End Sub
Protected Sub GvBancosCuentas_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GvBancosCuentas.RowUpdating
Dim NombreBanco = GvBancosCuentas.Rows(e.RowIndex).FCTextBox("TxtNombreBanco").Text.Trim
Dim NumeroSucursal = GvBancosCuentas.Rows(e.RowIndex).FCTextBox("TxtNumeroSucursal").Text.Trim
Dim CLABE = GvBancosCuentas.Rows(e.RowIndex).FCTextBox("TxtCLABE").Text.Trim
Dim SWIFT = GvBancosCuentas.Rows(e.RowIndex).FCTextBox("TxtSWIFT").Text.Trim
Dim Plaza = GvBancosCuentas.Rows(e.RowIndex).FCTextBox("TxtPlaza").Text.Trim
Dim NumeroCuenta = GvBancosCuentas.Rows(e.RowIndex).FCTextBox("TxtNumeroCuenta").Text.Trim
Dim ConvenioCIE = GvBancosCuentas.Rows(e.RowIndex).FCTextBox("TxtConvenioCIE").Text.Trim
Dim Referencia = GvBancosCuentas.Rows(e.RowIndex).FCTextBox("TxtReferencia").Text.Trim
Dim ObjCuentasBancos As New ClsGenerales
If CveColectiva > 0 Then
If ObjCuentasBancos.UpdateCuentasDepositos(GvBancosCuentas.DataKeys(e.RowIndex)("CveCuentaDeposito").ToString.ToEntero, NombreBanco, Plaza, NumeroSucursal, NumeroCuenta, CLABE, ConvenioCIE, SWIFT, Referencia, "", False, True, 1) Then
DTCuentasBancos.Clear()
DTCuentasBancos.Merge(ObjCuentasBancos.DtResultados.FiltraParametros(String.Format("CveColectiva = {0}", CveColectiva)))
Alert("Cuenta actualizada con éxito.", TipoMensaje.MsgInformacion)
End If
Else
Dim index = GvBancosCuentas.Rows(e.RowIndex).DataKey("CveCuentaDeposito").ToString.ToEntero - 1
Dim Row As DataRow = TempDTCuentasBancos.Rows(index)
Row("BancoNombre") = NombreBanco
Row("Sucursal") = NumeroSucursal
Row("CLABE") = CLABE
Row("SWIFT") = SWIFT
Row("Plaza") = Plaza
Row("Cuenta") = NumeroCuenta
Row("CIE") = ConvenioCIE
Row("Referencia") = Referencia
TempDTCuentasBancos.AcceptChanges()
End If
GvBancosCuentas.EditIndex = -1
ObjCuentasBancos.Dispose()
CargaGridCuentasBancos(ViewState("OrdenCuentasBancos").ToString)
End Sub
Protected Sub GvBancosCuentas_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvBancosCuentas.RowDeleting
Dim ObjCuentasBancos As New ClsGenerales
If CveColectiva > 0 Then
If ObjCuentasBancos.RemoveCuentasDepositos(GvBancosCuentas.DataKeys(e.RowIndex)("CveCuentaDeposito").ToString.ToEntero) Then
DTCuentasBancos.Clear()
DTCuentasBancos.Merge(ObjCuentasBancos.DtResultados.FiltraParametros(String.Format("CveColectiva = {0}", CveColectiva)))
Alert("Cuenta Bancaria borrada con éxito.", TipoMensaje.MsgInformacion)
End If
Else
Dim index = GvBancosCuentas.Rows(e.RowIndex).DataKey("CveCuentaDeposito").ToString.ToEntero - 1
TempDTCuentasBancos.Rows.RemoveAt(index)
End If
CargaGridCuentasBancos(ViewState("OrdenCuentasBancos").ToString)
ObjCuentasBancos.Dispose()
End Sub
#End Region
#End Region
End Class