Option Strict On Option Explicit On Imports Extensiones Imports System.Data Partial Class RH_ActualizacionMasiva Inherits ClsPaginas Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not IsPostBack Then SetPermisos() DdlCliente.Attributes.Add("onclick", "CargaClientes();") CargaProyecto() CargaTurnos() CargaSupervisores() End If End Sub Private Sub SetPermisos() End Sub #Region "Propiedades" Private ReadOnly Property DTUsuarios As DataTable Get Return DirectCast(ViewState("DTUsuarios"), DataTable) End Get End Property Private ReadOnly Property DTTurno As DataTable Get Return DirectCast(ViewState("DTTurno"), DataTable) End Get End Property Private ReadOnly Property DTSubProyectos As DataTable Get Return DirectCast(ViewState("DTSubProyectos"), DataTable) End Get End Property Private ReadOnly Property DTProyectos As DataTable Get Return DirectCast(ViewState("DTProyectos"), DataTable) End Get End Property #End Region #Region "CargaCombos" Private Sub CargaClientes() Dim ObjClientes As New ClsClientes If ObjClientes.GetClientes(-1, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa) Then DdlCliente.DataSource = ObjClientes.DtResultados Else DdlCliente.DataSource = Nothing End If ObjClientes.Dispose() 'Application("GlobalDTResponsable") DdlCliente.DataBind() End Sub Protected Sub BtnCargarClientes_Click(sender As Object, e As System.EventArgs) Handles BtnCargarClientes.Click CargaClientes() DdlCliente.Attributes.Remove("onclick") End Sub Private Sub CargaProyecto() ViewState("DTProyectos") = GlobalDTProyectos(UsuarioActual.Empresa.CveEmpresa) Dim Row As DataRow = DirectCast(ViewState("DTProyectos"), DataTable).NewRow() Row("CveProyecto") = -1 : Row("Proyecto") = "Sin Proyecto asignado" DirectCast(ViewState("DTProyectos"), DataTable).Rows.InsertAt(Row, 0) DdlProyecto.DataSource = GlobalDTProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, 1) DdlProyecto.DataBind() End Sub Private Sub CargaSubProyecto() ViewState("DTSubProyectos") = GlobalDTSubProyectos(DdlProyecto.SelectedValue.ToEntero) DdlSubProyecto.Items.Clear() DdlSubProyecto.DataSource = GlobalDTSubProyectos(DdlProyecto.SelectedValue.ToEntero) DdlSubProyecto.DataBind() DdlSubProyecto.Items.Insert(0, New ListItem("Todos", "-1")) End Sub Private Sub CargaTurnos() ViewState("DTTurno") = GlobalDTTurno.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) DdlTurno.DataSource = GlobalDTTurno.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) DdlTurno.DataBind() End Sub Private Sub CargaSupervisores() ViewState("DTUsuarios") = GlobalDTUsuarios.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa & " AND EsSupervisorRH = 1 ") Dim Row As DataRow = DirectCast(ViewState("DTUsuarios"), DataTable).NewRow() Row("CveUsuario") = -1 : Row("Nombre") = "Sin Supervisor Asignado" DirectCast(ViewState("DTUsuarios"), DataTable).Rows.InsertAt(Row, 0) DdlSupervisor.DataSource = GlobalDTUsuarios.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa & " AND EsSupervisorRH = 1 ") DdlSupervisor.DataBind() End Sub #End Region Protected Sub DdlProyecto_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlProyecto.SelectedIndexChanged CargaSubProyecto() End Sub Protected Sub BtnConsultar_Click(sender As Object, e As System.EventArgs) Handles BtnConsultar.Click Dim ObjPersonal As New ClsRH If ObjPersonal.GetPersonalMasivo(DdlTurno.SelectedValue.ToEntero, DdlProyecto.SelectedValue.ToEntero, DdlSubProyecto.SelectedValue.ToEntero, DdlSupervisor.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then GvDatos.DataSource = ObjPersonal.DtResultados Else GvDatos.DataSource = Nothing End If ObjPersonal.Dispose() GvDatos.DataBind() UPDatos.Update() End Sub Protected Sub GvDatos_RowCreated(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatos.RowCreated If e.Row.RowType = DataControlRowType.DataRow AndAlso (e.Row.RowState = DataControlRowState.Alternate OrElse e.Row.RowState = DataControlRowState.Normal) Then e.Row.FCDropDownList("DdlGVProyecto").DataSource = DTProyectos e.Row.FCDropDownList("DdlGVProyecto").DataBind() 'e.Row.FCDropDownList("DdlGVProyecto").Items.Insert(0, New ListItem("Sin Proyecto asignado", "-1")) e.Row.FCDropDownList("DdlGVSubProyecto").DataSource = DTSubProyectos e.Row.FCDropDownList("DdlGVSubProyecto").DataBind() 'e.Row.FCDropDownList("DdlGVSubProyecto").Items.Insert(0, New ListItem("Sin SubProyecto asignado", "-1")) e.Row.FCDropDownList("DdlTurno").DataSource = DTTurno e.Row.FCDropDownList("DdlTurno").DataBind() e.Row.FCDropDownList("DdlSupervisor").DataSource = DTUsuarios e.Row.FCDropDownList("DdlSupervisor").DataBind() 'e.Row.FCDropDownList("DdlSupervisor").Items.Insert(0, New ListItem("Sin Supervisor Asignado", "-1")) End If 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 If e.Row.DBCampo("Turno") = "" AndAlso e.Row.DBCampo("Nombre") = "" Then e.Row.FCLiteral("LtlNombre").Text = "Sub Proyecto: " & If(e.Row.DBCampo("SubProyecto") = String.Empty, "Sin Proyecto Asignado", e.Row.DBCampo("SubProyecto")) e.Row.Cells(0).ColumnSpan = 8 For i As Integer = 1 To 7 e.Row.Cells(i).Visible = False Next e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left ElseIf e.Row.DBCampo("Turno") <> "" AndAlso e.Row.DBCampo("Nombre") = "" Then e.Row.FCLiteral("LtlNombre").Text = "Turno: " & e.Row.DBCampo("Turno") e.Row.Cells(0).ColumnSpan = 8 For i As Integer = 1 To 7 e.Row.Cells(i).Visible = False Next e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left Else If e.Row.DBCampo("CveProyecto") <> String.Empty Then e.Row.FCDropDownList("DdlGVProyecto").SelectedValue = e.Row.DBCampo("CveProyecto") CargaSubProyectoGV(e.Row.FCDropDownList("DdlGVProyecto"), e.Row.FCDropDownList("DdlGVSubProyecto")) If e.Row.DBCampo("CveSubProyecto") <> String.Empty Then e.Row.FCDropDownList("DdlGVSubProyecto").SelectedValue = e.Row.DBCampo("CveSubProyecto") e.Row.FCDropDownList("DdlGVSubProyecto").Attributes.Add("onChange", "F(this, " & e.Row.FCDropDownList("DdlGVProyecto").ClientID & ")") If e.Row.DBCampo("CveTurno") <> String.Empty Then e.Row.FCDropDownList("DdlTurno").SelectedValue = e.Row.DBCampo("CveTurno") If e.Row.DBCampo("CveSupervisor") <> String.Empty Then e.Row.FCDropDownList("DdlSupervisor").SelectedValue = e.Row.DBCampo("CveSupervisor") e.Row.FCTextBox("TxtSalarioCotizado").Text = e.Row.FCTextBox("TxtSalarioCotizado").Text.Replace(",", "") ''Deshabilita todo 'e.Row.Cells(1).Enabled = True : e.Row.Cells(2).Enabled = True : e.Row.Cells(3).Enabled = True : e.Row.Cells(4).Enabled = True 'e.Row.Cells(5).Enabled = True : e.Row.Cells(6).Enabled = True : e.Row.Cells(7).Enabled = True '25: CargaMasiva-Proy,Sup,Tur If Not UsuarioActual.TienePermisoProceso(25) Then e.Row.Cells(1).Enabled = False : e.Row.Cells(2).Enabled = False : e.Row.Cells(3).Enabled = False : e.Row.Cells(4).Enabled = False '26: CargaMasiva-Salarios If Not UsuarioActual.TienePermisoProceso(26) Then e.Row.Cells(5).Enabled = False : e.Row.Cells(6).Enabled = False : e.Row.Cells(7).Enabled = False End If End If End Sub Protected Sub BtnGuardar_Click(sender As Object, e As System.EventArgs) Handles BtnGuardar.Click Dim ObjPersonal As New ClsRH ObjPersonal.IniciaTransacSQL() Dim OcurrioError As Boolean = False For Each Row As GridViewRow In GvDatos.Rows If Row.DataKey("CvePersonal") <> "" Then If Not ObjPersonal.UpdatePersonalMasivo(Row.FCDropDownList("DdlTurno").SelectedValue.ToEntero, Row.FCDropDownList("DdlGVSubProyecto").SelectedValue.ToEntero, Row.FCDropDownList("DdlSupervisor").SelectedValue.ToEntero, Row.FCTextBox("TxtSalarioDiario").Text.ToDouble, Row.FCTextBox("TxtSDI").Text.ToDouble, Row.FCTextBox("TxtSalarioCotizado").Text.ToDouble, Row.DataKey("CvePersonal").ToEntero, UsuarioActual.CveEmpresa) Then OcurrioError = True ObjPersonal.RollBack() Exit For End If End If Next If Not OcurrioError Then ObjPersonal.Commit() Alert("La información se guardó correctamente.", TipoMensaje.MsgInformacion) Else Alert("Ocurrió un error al guardar la información.", TipoMensaje.MsgError) End If ObjPersonal.Dispose() End Sub Private Sub CargaSubProyectoGV(DdlProyecto As DropDownList, DdlSubProyecto As DropDownList) DdlSubProyecto.Items.Clear() DdlSubProyecto.DataSource = GlobalDTSubProyectos(DdlProyecto.SelectedValue.ToEntero) DdlSubProyecto.DataBind() DdlSubProyecto.Items.Insert(0, New ListItem("Sin SubProyecto asignado", "-1")) End Sub Protected Sub DdlGVProyecto_SelectedIndexChanged(sender As Object, e As System.EventArgs) Dim Array() As String = Nothing Dim DdlGVSubProyecto As DropDownList = Nothing Array = DirectCast(sender, DropDownList).ClientID.Split("_"c) If Array.Length > 0 Then DdlGVSubProyecto = DirectCast(GvDatos.Rows(Array(3).ToEntero).Controls(2).Controls(1), DropDownList) End If If DdlGVSubProyecto IsNot Nothing Then CargaSubProyectoGV(DirectCast(sender, DropDownList), DdlGVSubProyecto) End Sub End Class