Option Explicit On Option Strict On Imports System Imports System.Data Imports Extensiones Partial Class Contabilidad_CatBloqueoDiario Inherits ClsPaginas Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then txtFechaI.Text = Now.AddMonths(-1).ToShortDateString() txtFechaF.Text = Now.AddMonths(1).ToShortDateString() End If End Sub Protected Sub BtnConsulta_Click(sender As Object, e As EventArgs) CargaDatos() End Sub Private Sub CargaDatos() Dim FechaI = txtFechaI.Text.ToDate() Dim FechaF = txtFechaF.Text.ToDate() GvDatos.DataSource = GenerateDTBloqueos(FechaI, FechaF) GvDatos.DataBind() UpDatos.Update() End Sub Function GenerateDTBloqueos(FechaI As DateTime, FechaF As DateTime) As DataTable Dim DtDatos As New DataTable() DtDatos.Columns.Add(New DataColumn("CveBloqueoDiario", GetType(Integer))) DtDatos.Columns.Add(New DataColumn("Fecha", GetType(DateTime))) DtDatos.Columns.Add(New DataColumn("Bloqueado", GetType(Boolean))) Dim TieneError As Boolean = False Try Dim DtBloqueos As DataTable = Nothing Using ObjConta As New ClsContabilidad If ObjConta.GetBloqueoDiario(-1, FechaI, FechaF, UsuarioActual.CveEmpresa) Then DtBloqueos = ObjConta.DtResultados.Copy() Else TieneError = True End If End Using If Not TieneError Then Dim dateList As List(Of DateTime) = GenerateDateList(FechaI, FechaF) 'GENERA EL LISTADO DE FECHAS For Each dateValue As DateTime In dateList Dim Row As DataRow = DtDatos.NewRow() Row("CveBloqueoDiario") = -1 Row("Fecha") = dateValue Row("Bloqueado") = False DtDatos.Rows.Add(Row) Next 'ASIGNA LOS QUE TIENEN VALORES For Each RowValores As DataRow In DtBloqueos.Rows Dim RowsFechas As DataRow() = DtDatos.Select($"Fecha = '{RowValores("Fecha").ToString().ToDate().ToString("dd/MM/yyyy")}'") If RowsFechas IsNot Nothing AndAlso RowsFechas.Count() > 0 Then RowsFechas(0)("CveBloqueoDiario") = RowValores("CveBloqueoDiario") RowsFechas(0)("Bloqueado") = RowValores("Bloqueado") End If Next End If Catch ex As Exception OnError("Ocurrió un error generar la tabla", ex) DtDatos.Rows.Clear() TieneError = True End Try If TieneError Then DtDatos.Rows.Clear() End If Return DtDatos End Function Function GenerateDateList(startDate As DateTime, endDate As DateTime) As List(Of DateTime) Dim dates As New List(Of DateTime)() Dim dateValue As DateTime = startDate While dateValue <= endDate dates.Add(dateValue) dateValue = dateValue.AddDays(1) End While Return dates End Function Protected Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.DBCampo("CveBloqueoDiario").ToEntero() > 0 Then If CBool(e.Row.DBCampo("Bloqueado")) Then e.Row.CssClass = "SubTotales2" Else e.Row.CssClass = "Totales" End If End If End If End Sub Protected Sub ChkBloqueo_CheckedChanged(sender As Object, e As EventArgs) Dim ChkBloqueo = DirectCast(sender, CheckBox) Dim GvRow As GridViewRow = DirectCast(ChkBloqueo.NamingContainer, GridViewRow) Dim CveBloqueoDiario As Integer = GvRow.DataKey("CveBloqueoDiario").ToEntero() Dim Fecha As DateTime = GvRow.DataKey("Fecha").ToDate() Using ObjConta As New ClsContabilidad If ObjConta.AddUpdateBloqueoDiario(CveBloqueoDiario, Fecha, ChkBloqueo.Checked, UsuarioActual.CveEmpresa) Then Alert($"Se actualizó el estatus de bloqueo en el dia {Fecha.ToString("dd/MM/yyyy")}") End If End Using CargaDatos() End Sub End Class