Commit inicial Ventas Productivo
This commit is contained in:
272
Bancos/CargarConciliacionesBancarias.aspx.vb
Normal file
272
Bancos/CargarConciliacionesBancarias.aspx.vb
Normal file
@@ -0,0 +1,272 @@
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
Imports System.Data
|
||||
Imports Extensiones
|
||||
Imports System.Xml
|
||||
Imports Microsoft.Reporting.WebForms
|
||||
Partial Class Bancos_CargarConciliacionesBancarias
|
||||
Inherits ClsPaginas
|
||||
|
||||
#Region "PROPIEDADES"
|
||||
|
||||
Private Property Modalidad As String
|
||||
Get
|
||||
Return CType(ViewState("Modalidad"), String)
|
||||
End Get
|
||||
Set(value As String)
|
||||
ViewState("Modalidad") = value
|
||||
End Set
|
||||
End Property
|
||||
Private Property CveIEEstadoCuenta As Integer
|
||||
Get
|
||||
Return CType(ViewState("CveIEEstadoCuenta"), Integer)
|
||||
End Get
|
||||
Set(value As Integer)
|
||||
ViewState("CveIEEstadoCuenta") = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
#End Region
|
||||
|
||||
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
||||
If Not IsPostBack Then
|
||||
InicializaValores()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
#Region "INICIALIZA VALORES / CONSULTA"
|
||||
|
||||
Private Sub InicializaValores()
|
||||
'Cargar Cuentas
|
||||
DdlCuenta.DataSource = GlobalDTBancosCuentas(UsuarioActual.CveUsuario)
|
||||
DdlCuenta.Items.Insert(0, New ListItem("Todos", "-1"))
|
||||
DdlCuenta.DataBind()
|
||||
|
||||
DdlCuentaModal.DataSource = GlobalDTBancosCuentas(UsuarioActual.CveUsuario)
|
||||
DdlCuentaModal.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
||||
DdlCuentaModal.DataBind()
|
||||
|
||||
txtFechaI.Text = Now.FirstDayOfMonth.ToShortDateString
|
||||
txtFechaF.Text = Now.ToShortDateString
|
||||
|
||||
Modalidad = ""
|
||||
End Sub
|
||||
|
||||
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
|
||||
ConsultaEstadoCuentaBancaria()
|
||||
End Sub
|
||||
|
||||
Private Sub ConsultaEstadoCuentaBancaria()
|
||||
Dim ObjBancos As New ClsBancos
|
||||
If ObjBancos.GetIEEstadoCuenta(-1, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, DdlConciliado.SelectedValue.ToEntero,
|
||||
DdlCuenta.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then
|
||||
GvEstadoCuentaBancaria.DataSource = ObjBancos.DtResultados
|
||||
End If
|
||||
ObjBancos.Dispose()
|
||||
GvEstadoCuentaBancaria.DataBind()
|
||||
UpEstadoCuentaBancaria.Update()
|
||||
End Sub
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "CARGA EXCEL"
|
||||
|
||||
Protected Sub BtnCargaExcel_Click(sender As Object, e As EventArgs)
|
||||
If TxtExcel.getfiles().Archivos.Count > 0 Then
|
||||
Dim file As Archivo = TxtExcel.getfiles().Archivos(0)
|
||||
Dim Directorio As String = AppDomain.CurrentDomain.BaseDirectory & file.patch
|
||||
Dim Tipo As String = If(file.Extencion.Contiene("xlsx", "xlsx", "xlsm", "xlsb"), "EXCEL", "CSV")
|
||||
CargaExcel(Directorio, file.filename, Tipo)
|
||||
Else
|
||||
Alert("No existe el archivo.Favor de subir un archivo csv o excel a la plataforma", TipoMensaje.MsgError)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub CargaExcel(Ruta As String, FileName As String, Tipo As String)
|
||||
If Not DdlCuenta.SelectedValue.ToEntero > 0 Then
|
||||
Alert("Tiene que seleccionar una cuenta", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
Dim dt As New DataTable
|
||||
Dim Conexion As Odbc.OdbcConnection = Nothing
|
||||
Dim ErrorArchivo = False
|
||||
Dim ErrorExcel = False
|
||||
Dim strConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + Ruta + FileName + ";Extended Properties=Excel 8.0;"
|
||||
Dim objDbFactory As Common.DbProviderFactory = Common.DbProviderFactories.GetFactory("System.Data.OleDb")
|
||||
Dim objDbAdapter As Common.DbDataAdapter = objDbFactory.CreateDataAdapter()
|
||||
Dim objDbConnection As Common.DbConnection = objDbFactory.CreateConnection()
|
||||
objDbConnection.ConnectionString = strConnString
|
||||
objDbConnection.Open()
|
||||
Dim objSheetNames As DataTable = objDbConnection.GetSchema("Tables")
|
||||
Dim HojaExcel As String = objSheetNames.FiltroPrimeroValor("TABLE_NAME")
|
||||
Try
|
||||
Select Case Tipo
|
||||
Case "CSV"
|
||||
Conexion = New Odbc.OdbcConnection("Driver={Microsoft Access Text Driver (*.txt, *.csv)};Dbq=" + Ruta + ";Extensions=asc,csv,tab,txt;")
|
||||
Conexion.Open()
|
||||
Dim cmd = Conexion.CreateCommand()
|
||||
cmd.CommandType = CommandType.Text
|
||||
cmd.CommandText = $"SELECT * FROM [{FileName}]"
|
||||
Dim DataAdapter = New Odbc.OdbcDataAdapter(cmd)
|
||||
DataAdapter.Fill(dt)
|
||||
Case "EXCEL"
|
||||
Conexion = New Odbc.OdbcConnection("Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + Ruta + FileName + ";")
|
||||
Conexion.Open()
|
||||
Dim cmd = Conexion.CreateCommand()
|
||||
cmd.CommandType = CommandType.Text
|
||||
cmd.CommandText = $"SELECT * FROM [{HojaExcel}]"
|
||||
Dim DataAdapter = New Odbc.OdbcDataAdapter(cmd)
|
||||
DataAdapter.Fill(dt)
|
||||
Case Else
|
||||
Alert("El archivo no tiene el formato correcto", TipoMensaje.MsgError)
|
||||
Exit Sub
|
||||
End Select
|
||||
Catch ex As Exception
|
||||
ErrorArchivo = True
|
||||
OnError("Ocurrio un error al leer el archivo <br/>" & ex.Message, ex)
|
||||
End Try
|
||||
Conexion.Close()
|
||||
If Not ErrorArchivo Then
|
||||
dt.Columns(0).ColumnName = "FechaDocumento"
|
||||
dt.Columns(1).ColumnName = "Referencia"
|
||||
dt.Columns(2).ColumnName = "Importe"
|
||||
dt.Columns(3).ColumnName = "Cargo"
|
||||
dt.Columns(4).ColumnName = "Abono"
|
||||
dt.Columns.Add("FueConciliado")
|
||||
dt.Columns.Add("Tipo")
|
||||
For Each Dr As DataRow In dt.Rows
|
||||
If Dr("Abono").ToString.ToDouble > 0 Then
|
||||
Dr("Importe") = Dr("Abono").ToString.FormatoNumero
|
||||
Dr("Tipo") = "Abono"
|
||||
Dr("Cargo") = 0
|
||||
ElseIf Dr("Cargo").ToString.ToDouble > 0 Then
|
||||
Dr("Importe") = Dr("Cargo").ToString.FormatoNumero
|
||||
Dr("Tipo") = "Cargo"
|
||||
Dr("Abono") = 0
|
||||
End If
|
||||
Next
|
||||
Dim ObjBancos As New ClsBancos
|
||||
Dim ErrorTrans As Boolean = False
|
||||
For Each Dr As DataRow In dt.Rows
|
||||
If Dr("Importe").ToString.ToDouble > 0 Then
|
||||
If Not ObjBancos.AddIEEstadoCuenta(Dr("Referencia").ToString, Dr("FechaDocumento").ToString.ToDate,
|
||||
Dr("Importe").ToString.ToDouble, DdlCuenta.SelectedValue.ToEntero,
|
||||
UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Dr("Tipo").ToString) Then
|
||||
ErrorTrans = True
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
If Not ErrorTrans Then
|
||||
ObjBancos.Commit()
|
||||
ConsultaEstadoCuentaBancaria()
|
||||
RegistraScript("$('#DivCargaExcel').modal('hide')")
|
||||
Alert("Cargado Correctamente")
|
||||
Else
|
||||
ObjBancos.RollBack()
|
||||
End If
|
||||
ObjBancos.Dispose()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "AGREGAR / EDITAR / ELIMINAR MOVIMIENTOS"
|
||||
|
||||
Protected Sub LnkEditar_Click(sender As Object, e As EventArgs)
|
||||
Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
|
||||
Modalidad = "U"
|
||||
CveIEEstadoCuenta = gvRow.DataKey("CveIEEstadoCuenta").ToEntero
|
||||
TxtReferencia.Text = gvRow.DataKey("Referencia").ToString
|
||||
TxtFecha.Text = gvRow.DataKey("FechaDocumento").ToDate.ToShortDateString
|
||||
TxtImporte.Text = gvRow.DataKey("Importe").ToString
|
||||
DdlTipo.SelectedValueExist(gvRow.DataKey("Tipo").ToString)
|
||||
DdlCuentaModal.SelectedValueExist(gvRow.DataKey("CveCuenta").ToString)
|
||||
BtnGuardarModal.Text = "Actualizar"
|
||||
UPModalEditar.Update()
|
||||
RegistraScript("$('#DModalEditar').modal()")
|
||||
End Sub
|
||||
|
||||
Protected Sub BtnGuardarModal_Click(sender As Object, e As EventArgs)
|
||||
Dim ObjBancos As New ClsBancos
|
||||
If Modalidad = "A" Then
|
||||
If ObjBancos.AddIEEstadoCuenta(TxtReferencia.Text, TxtFecha.Text.ToDate, TxtImporte.Text.ToDouble, DdlCuentaModal.SelectedValue.ToEntero,
|
||||
UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, DdlTipo.SelectedValue) Then
|
||||
ConsultaEstadoCuentaBancaria()
|
||||
Alert("Guardado Correctamente.", TipoMensaje.MsgInformacion, "1")
|
||||
RegistraScript("$('#DModalEditar').modal('hide')", "2")
|
||||
End If
|
||||
ElseIf Modalidad = "U" Then
|
||||
If ObjBancos.UpdateIEEstadoCuenta(CveIEEstadoCuenta, TxtImporte.Text.ToDouble, False, -1, TxtReferencia.Text,
|
||||
DdlTipo.SelectedValue, TxtFecha.Text.ToDate, DdlCuentaModal.SelectedValue.ToEntero) Then
|
||||
ConsultaEstadoCuentaBancaria()
|
||||
Alert("Actualizado Correctamente.", TipoMensaje.MsgInformacion, "1")
|
||||
RegistraScript("$('#DModalEditar').modal('hide')", "2")
|
||||
End If
|
||||
End If
|
||||
ObjBancos.Dispose()
|
||||
End Sub
|
||||
Protected Sub LnkEliminar_Click(sender As Object, e As EventArgs)
|
||||
Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
|
||||
Dim ObjBancos As New ClsBancos
|
||||
If ObjBancos.RemoveIEEstadoCuenta(gvRow.DataKey("CveIEEstadoCuenta").ToEntero) Then
|
||||
Alert("Eliminado Correctamente.")
|
||||
ConsultaEstadoCuentaBancaria()
|
||||
End If
|
||||
ObjBancos.Dispose()
|
||||
End Sub
|
||||
Protected Sub LnkAgregarMovimiento_Click(sender As Object, e As EventArgs)
|
||||
Modalidad = "A"
|
||||
TxtReferencia.Text = ""
|
||||
TxtFecha.Text = Now.ToShortDateString
|
||||
TxtImporte.Text = ""
|
||||
DdlTipo.SelectedIndex = 0
|
||||
DdlCuentaModal.SelectedIndex = 0
|
||||
BtnGuardarModal.Text = "Guardar"
|
||||
UPModalEditar.Update()
|
||||
RegistraScript("$('#DModalEditar').modal()")
|
||||
End Sub
|
||||
|
||||
Protected Sub LnkEliminarMovimientos_Click(sender As Object, e As EventArgs)
|
||||
Dim ObjBancos As New ClsBancos
|
||||
ObjBancos.IniciaTransacSQL()
|
||||
Dim ErrorTrans As Boolean = False
|
||||
For Each Gvr As GridViewRow In GvEstadoCuentaBancaria.Rows
|
||||
If Not CBool(Gvr.DataKey("FueConciliado")) Then
|
||||
If Not ObjBancos.RemoveIEEstadoCuenta(Gvr.DataKey("CveIEEstadoCuenta").ToEntero) Then
|
||||
ErrorTrans = True
|
||||
Exit For
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
|
||||
If Not ErrorTrans Then
|
||||
ObjBancos.Commit()
|
||||
Alert("Eliminado Correctamente.")
|
||||
ConsultaEstadoCuentaBancaria()
|
||||
Else
|
||||
ObjBancos.RollBack()
|
||||
End If
|
||||
ObjBancos.Dispose()
|
||||
End Sub
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "GRIDVIEW"
|
||||
|
||||
Protected Sub GvEstadoCuentaBancaria_RowDataBound(sender As Object, e As GridViewRowEventArgs)
|
||||
If e.Row.RowType = DataControlRowType.DataRow Then
|
||||
If e.Row.RowIndex = 0 Then
|
||||
e.Row.CssClass = "Totales"
|
||||
e.Row.Cells(0).Text = "Total"
|
||||
ElseIf Not CBool(e.Row.DBCampo("FueConciliado")) Then
|
||||
e.Row.FCLinkButton("LnkEditar").Visible = True
|
||||
e.Row.FCLinkButton("LnkEliminar").Visible = True
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
#End Region
|
||||
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user