Option Explicit On Option Strict On Imports System.Data Imports Extensiones Imports Microsoft.Reporting.WebForms Partial Class AF_OrdenTrabajoAsignacion Inherits ClsPaginas #Region " PROPIEDADES" Property DT_Cabeceras As DataTable Get If ViewState("DT_Cabeceras") Is Nothing Then Return New DataTable Else Return DirectCast(ViewState("DT_Cabeceras"), DataTable) End If End Get Set(value As DataTable) ViewState("DT_Cabeceras") = value End Set End Property Property DT_Datos As DataTable Get If ViewState("DT_Datos") Is Nothing Then Return New DataTable Else Return DirectCast(ViewState("DT_Datos"), DataTable) End If End Get Set(value As DataTable) ViewState("DT_Datos") = value End Set End Property #End Region Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then CargaCombos() CargaDatos() Dim FechaActual As Date = Now 'TxtFechaF.Text = $"{FechaActual.Day.ToString("00")}/{FechaActual.Month.ToString("00")}/{FechaActual.Year}" TxtFechaF.Text = "" FechaActual = FechaActual.AddDays(-30) TxtFechaI.Text = $"{FechaActual.Day.ToString("00")}/{FechaActual.Month.ToString("00")}/{FechaActual.Year}" End If End Sub #Region " CARGA PARAMETROS " #End Region #Region " CARGA COMBOS " Protected Sub CargaCombos() CargarCentrosDeCosto(Nothing, DdlSubProyecto, Nothing, LblSubProyecto) DdlAF.DataSource = GlobalDTActivoFijos(UsuarioActual.CveEmpresa, -1) DdlAF.DataBind() DdlAF.Items.Insert(0, New ListItem("Todos", "-1")) Dim ObjAF As New ClsAF If ObjAF.GetTiposServicios(-1, -1, -1, UsuarioActual.CveEmpresa) Then DdlTipoServicio.DataSource = ObjAF.DtResultados Else DdlTipoServicio.DataSource = Nothing End If ObjAF.Dispose() DdlTipoServicio.DataBind() DdlTipoServicio.Items.Insert(0, New ListItem("Todos", "-1")) UpFiltro.Update() End Sub #End Region #Region " CARGA DATOS " Protected Sub BtnFiltrar_Click(sender As Object, e As EventArgs) CargaDatos() End Sub #End Region #Region " GV DATOS " Private Sub CargaDatos() Dim FechaInicio, FechaFin As Date FechaInicio = TxtFechaI.Text.ToDate FechaFin = MaxFecha If TxtFechaF.Text.Length = 10 Then FechaFin = TxtFechaF.Text.ToDate End If Dim ObjAF As New ClsAF If ObjAF.GetOrdenesTrabajo(-1, DdlTipoServicio.SelectedValue.ToEntero, -1, DdlAF.SelectedValue.ToEntero, DdlSubProyecto.SelectedValue.ToEntero, DdlPrioridad.SelectedValue.ToEntero, FechaInicio, FechaFin, MaxFecha, -1, UsuarioActual.CveEmpresa) Then GvDatos.DataSource = ObjAF.DtResultados If ObjAF.DtResultados.Rows.Count > 0 Then BtnGuardar.Enabled = True Else BtnGuardar.Enabled = False End If Else GvDatos.DataSource = Nothing BtnGuardar.Enabled = False End If ObjAF.Dispose() GvDatos.DataBind() UpDatos.Update() End Sub Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatos.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then Dim CvePersonal As Integer = e.Row.DataKey("CvePersonal").ToEntero Dim DdlPersonal As DropDownList = e.Row.FCDropDownList("DdlPersonal") DdlPersonal.DataSource = GlobalDTRHPersonal(UsuarioActual.CveEmpresa, -1).FiltraParametros("CveEstatusPersonal = 1") DdlPersonal.DataBind() DdlPersonal.Items.Insert(0, New ListItem("Seleccione Uno", "-1")) DdlPersonal.SelectedValueExist(CvePersonal) End If End Sub #End Region Protected Sub LnkEliminarMetricaValor_Click(sender As Object, e As EventArgs) End Sub Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Dim ObjAf As New ClsAF Dim ErrorProceso As Boolean = False Dim CountAsiganados As Integer = 0 ObjAf.IniciaTransacSQL() For Each GvRow As GridViewRow In GvDatos.Rows If GvRow.RowType = DataControlRowType.DataRow Then Dim CvePersonal As Integer = GvRow.DataKey("CvePersonal").ToEntero Dim DdlPersonal As DropDownList = GvRow.FCDropDownList("DdlPersonal") Dim CveOrdenTrabajo As Integer = GvRow.DataKey("CveOrdenTrabajo").ToEntero If DdlPersonal.SelectedValue.ToEntero > 0 AndAlso (DdlPersonal.SelectedValue.ToEntero <> CvePersonal) Then If Not ObjAf.UpdateOrdenesTrabajo(CveOrdenTrabajo, -1, -1, "-1", -1, -1, MinFecha, MaxFecha, MaxFecha, -1, UsuarioActual.CveEmpresa, DdlPersonal.SelectedValue.ToEntero) Then ErrorProceso = True Else CountAsiganados = CountAsiganados + 1 End If End If End If Next If Not ErrorProceso Then ObjAf.Commit() If CountAsiganados > 0 Then Alert($"{CountAsiganados} ordenes de trabajo asignadas.") Else Alert($"No se asigno ninguna orden de trabajo.", TipoMensaje.MsgAdvertencia) End If Else ObjAf.RollBack() End If ObjAf.Dispose() End Sub End Class