Files
SIG/Planeacion/CatSubProyectos.aspx.vb

1000 lines
42 KiB
VB.net

Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.OleDb
Imports System.IO
Imports Extensiones
Partial Class CatSubProyectos
Inherits ClsPaginas
#Region "P R O P I E D A D E S"
Public Property DtSegmentosNegocio As Data.DataTable
Get
Return CType((ViewState("DtSegmentosNegocio")), Data.DataTable)
End Get
Set(value As Data.DataTable)
ViewState("DtSegmentosNegocio") = value
End Set
End Property
Public Property DTSubProyectos As Data.DataTable
Get
Return CType((ViewState("DTSubProyectos")), Data.DataTable)
End Get
Set(value As Data.DataTable)
ViewState("DTSubProyectos") = value
End Set
End Property
Private Property CveCentroCosto As Integer
Get
Return ViewState("CveCentroCosto").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveCentroCosto") = 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
ViewState("Orden") = ""
If Not UsuarioActual.Empresa.UsaRH Then
GvDatos.Columns(2).Visible = False
End If
'Dim objsubproyecto As New ClsSubProyectos
''If objsubproyecto.GetSubProyectosexcel(9, UsuarioActual.CveEmpresa) Then
'' 'DatatableToExcel(objsubproyecto.DtResultados)
'' objsubproyecto.DtResultados.ExportToExcel("subproyecto")
''End If
'objsubproyecto.Dispose()
If Not UsuarioActual.Empresa.Tipo_CentroCosto = 3 Then
'GvDatos.Columns(0).Visible = False
'TdTituloProyecto.Visible = False
'TdProyecto.Visible = False
'LbSubProyecto.Text = "Proyecto"
GvDatos.Columns(2).Visible = False
End If
If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then
DivCodigoSucursal.Visible = True
End If
If UsuarioActual.Empresa.Funcionalidad(381).Trim() <> "" Then
DivDeshabilitaAutorizaciones.Visible = True
End If
If UsuarioActual.CveEmpresa = 119 Then
divNoVerificaAlmacen.Visible = True
End If
CargaProyecto()
CargaSegmentosNegocio()
'COMERCIO EXTERIOR
CargaPais()
CargaEstado()
CargaMunicipio()
CargaColonia()
CargaLocalidad()
CargaPrecioLista()
CargaDatos()
If UsuarioActual.Empresa.UsaContabilidad Then
GvDatos.Columns(1).Visible = True
DivSegmentoNegocio.Visible = True
End If
BtnGuardar.OnClientClick = $"ValidaGuardar();"
If UsuarioActual.Empresa.Funcionalidad(404) = "20" Then
DVModalPrecioLista.Visible = True
End If
End If
End Sub
Private Sub RecargaGlobal()
GlobalDTSubProyectos(-1, CveEmpresa:=UsuarioActual.CveEmpresa) = Nothing
GlobalDTSubProyectosUsuarios(-1, -1, UsuarioActual.CveEmpresa) = Nothing
GlobalDTOCEstatusUsuarios(UsuarioActual.CveEmpresa) = Nothing
End Sub
#Region "O R D E N A M I E N T O"
Protected Sub LbOrden_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim Orden As String = ""
Dim Campo As String = ""
Dim Literal As Literal = Nothing
Const OrdenInicial As String = ""
Dim Arg(2) As String
Arg = CType(sender, LinkButton).CommandArgument().ToString.Split(";"c)
Campo = Arg(0)
Literal = CType(CType(sender, LinkButton).NamingContainer.FindControl("Img" & Campo.Replace(",", "_")), Literal)
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)
Literal.Text = String.Format("<i class='fa fa-sort-asc' style='color:#999' ></i>")
Else
ViewState(String.Format("O{0}", Campo)) = String.Format("{0} DESC", Campo)
Literal.Text = String.Format("<i class='fa fa-sort-desc' style='color:#999' ></i>")
End If
Orden = OrdenInicial & ViewState(String.Format("O{0}", Campo)).ToString
ViewState("Orden") = Orden
CargaDatos()
End Sub
#End Region
#Region "C A R G A S"
Public Sub CargaDatos()
Dim ObjSub As New ClsSubProyectos
If ObjSub.GetSubProyectos(UsuarioActual.CveEmpresa) Then
GvDatos.DataSource = ObjSub.DtResultados
GvDatos.DataBind()
End If
ObjSub.Dispose()
UpDatos.Update()
End Sub
Private Sub CargaProyecto()
DdlProyecto.DataSource = GlobalDTProyectos(UsuarioActual.CveEmpresa).FiltraParametros("", "", {"CveProyecto", "Proyecto"})
DdlProyecto.DataBind()
End Sub
Private Sub CargaPrecioLista()
DdlPrecioLista.DataSource = GlobalDTPrecioListas(UsuarioActual.CveEmpresa)
DdlPrecioLista.Items.Insert(0, New ListItem("Seleccione", "-1"))
DdlPrecioLista.DataBind()
End Sub
Private Sub CargaSegmentosNegocio()
DdlSegmentoNegocio.Items.Clear()
If UsuarioActual.Empresa.TipoContabilidad = 2 Then
Dim Cuenta As New ClsContPAQi(UsuarioActual.Empresa)
If Cuenta.GetSegmentosNegocio(-1, "-1") Then
DtSegmentosNegocio = Cuenta.DtResultados.FiltraParametros("Id > 0")
DtSegmentosNegocio.Rows.Add(New Object() {0, 0, " - ", "", ""})
Dim dataView As New DataView(DtSegmentosNegocio)
dataView.Sort = "Id ASC"
DtSegmentosNegocio = dataView.ToTable
End If
Cuenta.Dispose()
DdlSegmentoNegocio.DataSource = DtSegmentosNegocio : DdlSegmentoNegocio.DataBind()
DdlSegmentoNegocio.Items.Insert(0, New ListItem("-", "-1"))
End If
'For Each Gvr As GridViewRow In GvDatos.Rows
' 'If Gvr.DataKey("IdSegNeg").ToEntero > 0 Then
' ' 'COMENTADO PORQUE TRUENA | IPP - 17 AGOSTO 2017
' ' 'Dim Cuenta2 As New ClsContPAQi(UsuarioActual.Empresa)
' ' 'If Cuenta2.GetSegmentosNegocio(Gvr.DataKey("IdSegNeg").ToEntero, "-1") Then
' ' ' Dim DRES2 As DataRow
' ' ' DRES2 = Cuenta2.DtResultados(0)
' ' ' Gvr.Cells(1).Text = DRES2("Nombre").ToString
' ' 'Else
' ' ' Gvr.Cells(1).Text = "-"
' ' 'End If
' ' 'Cuenta2.Dispose()
' ' 'If DtSegmentosNegocio IsNot Nothing AndAlso DtSegmentosNegocio.Rows.Count > 0 Then
' ' ' Dim dr As DataRow
' ' ' dr = DtSegmentosNegocio.FiltroPrimero(String.Format("Id ={0}", Gvr.DataKey("IdSegNeg")))
' ' ' Gvr.Cells(1).Text = dr("Nombre").ToString
' ' 'End If
' 'Else
' ' Gvr.Cells(1).Text = "0"
' 'End If
'Next
End Sub
#End Region
#Region "GV"
Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatos.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
ScriptManager.GetCurrent(Me).RegisterPostBackControl(e.Row.FCLinkButton("downExcel"))
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Left
If e.Row.RowIndex > 0 AndAlso e.Row.Cells(1).Visible Then
e.Row.Cells(1).Text = DtSegmentosNegocio.FiltroPrimeroValor("Nombre", $"Id = {e.Row.DataKey("IdSegNeg")}")
End If
End If
End Sub
Protected Sub GvDatos_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatos.RowDeleting
Dim ObjSubProyectos As New ClsSubProyectos
ObjSubProyectos.IniciaTransacSQL()
If ObjSubProyectos.RemoveSubProyecto(GvDatos.DataKeys(e.RowIndex).Value.ToString.ToEntero) Then
ObjSubProyectos.Commit()
GvDatos.EditIndex = -1
ViewState("DTSubProyectos") = ObjSubProyectos.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa)
GlobalDTSubProyectos(UsuarioActual.CveEmpresa) = ObjSubProyectos.DtResultados
Alert("El SubProyecto se eliminó correctamente.", TipoMensaje.MsgInformacion)
Else
ObjSubProyectos.RollBack()
End If
ObjSubProyectos.Dispose()
CargaDatos()
End Sub
Protected Sub GvDatos_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
If (e.CommandName = "AgregarSubProyecto") Then
Dim ObjContpaQ As New ClsContPAQi(UsuarioActual.Empresa)
ObjContpaQ.IniciaTransacSQL()
Dim ObjSubProyectos As New ClsSubProyectos
ObjSubProyectos.IniciaTransacSQL()
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = GvDatos.Rows(index)
Dim SubProyecto As String = GvDatos.Rows(index).DataKey("SubProyecto").ToString
Dim CveSegmento As Integer = ObjContpaQ.AddSegmentosNegocio(SubProyecto)
Dim CveSubProyecto As Integer = GvDatos.DataKeys(index).Value.ToString.ToEntero
Dim ErrorSubProyecto As Boolean = False
If ObjSubProyectos.UpdateSubProyectoSegNeg(CveSubProyecto, CveSegmento, UsuarioActual.CveEmpresa) Then
GvDatos.EditIndex = -1
ViewState("DTSubProyectos") = ObjSubProyectos.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa)
GlobalDTSubProyectos(UsuarioActual.CveEmpresa) = ObjSubProyectos.DtResultados
Alert("Los cambios se guardaron correctamente.", TipoMensaje.MsgInformacion)
Else
ErrorSubProyecto = True
End If
If CveSegmento > 0 AndAlso Not ErrorSubProyecto Then
ObjContpaQ.Commit()
ObjSubProyectos.Commit()
If ObjContpaQ.GetSegmentosNegocio(-1, "-1") Then
DtSegmentosNegocio = ObjContpaQ.DtResultados.FiltraParametros("Id > 1")
End If
CargaDatos()
Else
ObjContpaQ.RollBack()
ObjSubProyectos.RollBack()
End If
ObjSubProyectos.Dispose()
ObjContpaQ.Dispose()
End If
End Sub
Public Sub Edit_Click(sender As Object, e As EventArgs)
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
Tab.ActiveTabIndex = 0
CveCentroCosto = (GvRow.DataKey("CveSubProyecto")).ToEntero
HdnModalidad.Value = "U"
TxtCentroCosto.Text = (GvRow.DataKey("SubProyecto"))
DdlSegmentoNegocio.SelectedValueExist(GvRow.DataKey("IdSegNeg"))
ChkEstatus.Checked = If(GvRow.DataKey("Estatus").ToString = "Activo", True, False)
DdlProyecto.SelectedValueExist(GvRow.DataKey("CveProyecto"))
TxtSerie.Text = (GvRow.DataKey("Serie"))
TxtIVA.Text = (GvRow.DataKey("IVA"))
TxtCalle.Text = (GvRow.DataKey("Calle"))
TxtNoExt.Text = (GvRow.DataKey("NoExt"))
TxtNoInt.Text = (GvRow.DataKey("NoInt"))
TxtColonia.Text = (GvRow.DataKey("Colonia"))
TxtLocalidad.Text = (GvRow.DataKey("Localidad"))
TxtMunicipio.Text = (GvRow.DataKey("Municipio"))
TxtEstado.Text = (GvRow.DataKey("Estado"))
TxtPais.Text = (GvRow.DataKey("Pais"))
TxtCP.Text = (GvRow.DataKey("CP"))
ChkEsMatriz.Checked = If(GvRow.DataKey("TipoSucursal").ToString.ToEntero = 1, True, False)
ChkEsSucursal.Checked = If(GvRow.DataKey("EsSucursal").ToString.ToEntero = 1, True, False)
DdlPrecioLista.SelectedIndex = 0
DdlPrecioLista.SelectedValueExist(GvRow.DataKey("CvePrecioLista"))
TxtCorreo.Text = (GvRow.DataKey("Correo"))
TxtTelefono.Text = (GvRow.DataKey("Telefono"))
TxtHorarioVerano.Text = (GvRow.DataKey("UTCOffsetVerano"))
TxtHorarioInvierno.Text = (GvRow.DataKey("UTCOffsetInvierno"))
'COMERCIO EXTERIOR
ChkAplicaComercioExterior.Checked = If(GvRow.DataKey("AplicaComercioExterior").ToString = "True", True, False)
DdlPais.SelectedValueExist(GvRow.DataKey("CvePais"))
CargaEstado()
DdlEstado.SelectedValueExist(GvRow.DataKey("CveEstado"))
CargaMunicipio()
DdlMunicipio.SelectedValueExist(GvRow.DataKey("CveMunicipio"))
CargaColonia()
DdlColonia.SelectedValueExist(GvRow.DataKey("CveColonia"))
CargaLocalidad()
DdlLocalidad.SelectedValueExist(GvRow.DataKey("CveLocalidad"))
'AplicaComercio()
ChkNoVerificaAlmacen.Checked = If(GvRow.DataKey("NoVerificaAlmacen").ToString = "True", True, False)
TxtCodigoSucursal.Text = (GvRow.DataKey("CodigoSucursal"))
ChkDeshabilitaAutorizaciones.Checked = CBool(GvRow.DataKey("DeshabilitaAutorizacion"))
BtnGuardar.Text = "Actualizar"
CargaRequired()
UpAddCentroEstatus.Update()
RegistraScript(String.Format("$('#{0}').modal();", "DivAgregarCentroCosto"))
End Sub
#End Region
#Region "G U A R D A R"
Private Function ValidaComercioExterior() As Boolean
If ChkAplicaComercioExterior.Checked Then
If Not DdlPais.SelectedValue.ToEntero > 0 Then
Alert("Tiene que seleccionar un pais para comercio exterior.", TipoMensaje.MsgAdvertencia)
Return False
End If
If Not DdlPais.SelectedValue.ToEntero > 0 Then
Alert("Tiene que seleccionar un pais para comercio exterior.", TipoMensaje.MsgAdvertencia)
Return False
End If
If Not DdlEstado.SelectedValue.ToEntero > 0 Then
Alert("Tiene que seleccionar un estado para comercio exterior.", TipoMensaje.MsgAdvertencia)
Return False
End If
If DdlPais.SelectedValue.ToEntero = 151 Then
If Not DdlMunicipio.SelectedValue.ToEntero > 0 Then
Alert("Tiene que seleccionar un municipio para comercio exterior si el pais es mexico.", TipoMensaje.MsgAdvertencia)
Return False
End If
If Not DdlColonia.SelectedValue.ToEntero > 0 Then
Alert("Tiene que seleccionar una colonia para comercio exterior si el pais es mexico.", TipoMensaje.MsgAdvertencia)
Return False
End If
End If
End If
Return True
End Function
Private Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click
If Not ValidaComercioExterior() Then
Exit Sub
End If
CreaProyectoSubProyectoSucursal()
End Sub
Private Sub CreaProyectoSubProyectoSucursal()
Dim ObjSubproyectos As New ClsSubProyectos
Dim CveUsuarioNomina As Integer = Nothing
Dim CveSubProyecto = -1
Dim TieneError = False
Dim TipoSucursal As Integer
Dim EsSucursal As Integer
Dim HorarioVerano As Integer = TxtHorarioVerano.Text.ToEntero
Dim HorarioInvierno As Integer = TxtHorarioInvierno.Text.ToEntero
If ChkEsMatriz.Checked = True Then TipoSucursal = 1 Else TipoSucursal = 0
If ChkEsSucursal.Checked = True Then EsSucursal = 1 Else EsSucursal = 0
'GlobalDTProyectos(-1) = ObjSubproyectos.DtResultados
ObjSubproyectos.IniciaTransacSQL()
Dim IdSeg As Integer
If DdlSegmentoNegocio.Visible = True Then IdSeg = DdlSegmentoNegocio.SelectedValue.ToEntero Else IdSeg = 0
Dim StrPais As String = ""
Dim StrEstado As String = ""
Dim StrMunicipio As String = ""
Dim StrLocalidad As String = ""
Dim StrColonia As String = ""
If DdlPais.SelectedValue.ToEntero > 0 Then
StrPais = DdlPais.SelectedItem.Text
Else
StrPais = TxtPais.Text
End If
If DdlEstado.SelectedValue.ToEntero > 0 Then
StrEstado = DdlEstado.SelectedItem.Text
Else
StrEstado = TxtEstado.Text
End If
If DdlMunicipio.SelectedValue.ToEntero > 0 Then
StrMunicipio = DdlMunicipio.SelectedItem.Text
Else
StrMunicipio = TxtMunicipio.Text
End If
If DdlLocalidad.SelectedValue.ToEntero > 0 Then
StrLocalidad = DdlLocalidad.SelectedItem.Text
Else
StrLocalidad = TxtLocalidad.Text
End If
If DdlColonia.SelectedValue.ToEntero > 0 Then
StrColonia = DdlColonia.SelectedItem.Text
Else
StrColonia = TxtColonia.Text
End If
'CREA SUBPROYECTO
If HdnModalidad.Value = "I" Then
If Not ObjSubproyectos.AddCentroCosto(TxtCentroCosto.Text.Trim, IdSeg, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, DdlProyecto.SelectedValue.ToEntero, Serie:=TxtSerie.Text.Trim, IVA:=TxtIVA.Text.ToDecimal, Calle:=TxtCalle.Text.Trim, NoExt:=TxtNoExt.Text.Trim,
NoInt:=TxtNoInt.Text.Trim, Colonia:=StrColonia, Localidad:=StrLocalidad, Municipio:=StrMunicipio, Estado:=StrEstado, Pais:=StrPais, CP:=TxtCP.Text.Trim, TipoSucursal:=TipoSucursal, EsSucursal:=EsSucursal,
CvePais:=DdlPais.SelectedValue.ToEntero, CveEstado:=DdlEstado.SelectedValue.ToEntero, CveMunicipio:=DdlMunicipio.SelectedValue.ToEntero, CveColonia:=DdlColonia.SelectedValue.ToEntero, AplicaComercioExterior:=ChkAplicaComercioExterior.Checked, Correo:=TxtCorreo.Text, CvePrecioLista:=DdlPrecioLista.SelectedValue.ToEntero,
Telefono:=TxtTelefono.Text, NoVerificaAlmacen:=ChkNoVerificaAlmacen.Checked, CodigoSucursal:=TxtCodigoSucursal.Text.Trim, CveLocalidad:=DdlLocalidad.SelectedValue.ToEntero, DeshabilitaAutorizacion:=ChkDeshabilitaAutorizaciones.Checked) Then
TieneError = True
Else
CveSubProyecto = ObjSubproyectos.CveSubProyecto
End If
Else
If (HorarioVerano > -13 And HorarioVerano < 13) And (HorarioInvierno > -13 And HorarioInvierno < 13) Then
If Not ObjSubproyectos.UpdateCentroCosto(CveCentroCosto, TxtCentroCosto.Text.Trim, IdSeg, If(ChkEstatus.Checked = True, 1, 0), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, DdlProyecto.SelectedValue.ToEntero, Serie:=TxtSerie.Text.Trim, IVA:=TxtIVA.Text.ToDecimal, Calle:=TxtCalle.Text.Trim, NoExt:=TxtNoExt.Text.Trim,
NoInt:=TxtNoInt.Text.Trim, Colonia:=StrColonia, Localidad:=TxtLocalidad.Text.Trim, Municipio:=StrMunicipio, Estado:=StrEstado, Pais:=StrPais, CP:=TxtCP.Text.Trim, TipoSucursal:=TipoSucursal, EsSucursal:=EsSucursal,
CvePais:=DdlPais.SelectedValue.ToEntero, CveEstado:=DdlEstado.SelectedValue.ToEntero, CveMunicipio:=DdlMunicipio.SelectedValue.ToEntero, CveColonia:=DdlColonia.SelectedValue.ToEntero, AplicaComercioExterior:=ChkAplicaComercioExterior.Checked, Correo:=TxtCorreo.Text, CvePrecioLista:=DdlPrecioLista.SelectedValue.ToEntero,
Telefono:=TxtTelefono.Text, HorarioVerano:=TxtHorarioVerano.Text.ToEntero, HorarioInvierno:=TxtHorarioInvierno.Text.ToEntero, NoVerificaAlmacen:=ChkNoVerificaAlmacen.Checked, CodigoSucursal:=TxtCodigoSucursal.Text.Trim, CveLocalidad:=DdlLocalidad.SelectedValue.ToEntero, DeshabilitaAutorizacion:=ChkDeshabilitaAutorizaciones.Checked) Then
TieneError = True
End If
Else
Alert("Los valores de horario no deben ser superiores a '12' o menor a '-12'", TipoMensaje.MsgAdvertencia)
TieneError = True
End If
End If
If Not TieneError Then
ObjSubproyectos.Commit()
If HdnModalidad.Value = "I" Then
Alert("La nueva sucursal se guardó correctamente.", TipoMensaje.MsgInformacion)
Else
Alert("La sucursal se actualizo correctamente.", TipoMensaje.MsgInformacion)
End If
RegistraScript(String.Format("$('#{0}').modal('hide');", "DivAgregarCentroCosto"))
CargaDatos()
RecargaGlobal()
Else
ObjSubproyectos.RollBack()
RecargaGlobal()
End If
If DdlSegmentoNegocio.Visible = True Then
CargaSegmentosNegocio()
End If
ObjSubproyectos.Dispose()
If HdnModalidad.Value = "I" AndAlso Not TieneError Then
If UsuarioActual.Empresa.Funcionalidad(523) <> "" Then
Dim ObjOC As New ClsOC
ObjOC.IniciaTransacSQL()
Dim CveUsuario As Integer
Dim CveEstatus As Integer
Dim ArregloUsuarios As String() = UsuarioActual.Empresa.Funcionalidad(523).ToString.Split(","c)
Dim YaExiste As Boolean = False
Dim DTEstatus As DataTable = GlobalDTOCEstatus(UsuarioActual.CveEmpresa).FiltraParametros("TipoTermino IN (1, 2)")
For Each item In ArregloUsuarios
CveUsuario = item.ToString.ToEntero
For Each row As DataRow In DTEstatus.Rows
CveEstatus = row("CveEstatus").ToString.ToEntero
If Not ObjOC.AddEstatusUsuarios(CveEstatus, CveSubProyecto, CveUsuario, True, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then
YaExiste = True
End If
Next
Next
If YaExiste Then
ObjOC.RollBack()
Else
ObjOC.Commit()
End If
ObjOC.Dispose()
End If
End If
End Sub
#End Region
#Region "E X C E L"
Protected Sub downExcel_Click(sender As Object, e As EventArgs)
Dim Gvr As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
'TxtApellidoPaterno.Text = Gvr.DataKey("APaterno")
Dim subproyecto As Integer
Try
subproyecto = Gvr.DataKey("CveSubProyecto").ToEntero
Catch ex As Exception
subproyecto = 0
End Try
If subproyecto > 0 Then
Dim objsubproyecto As New ClsSubProyectos
If objsubproyecto.GetSubProyectosexcel(subproyecto, UsuarioActual.CveEmpresa) Then
'DatatableToExcel(objsubproyecto.DtResultados)
objsubproyecto.DtResultados.ExportToExcel("subproyecto")
End If
objsubproyecto.Dispose()
End If
End Sub
Protected Sub UpExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpExcel.Click
If (FileUpload1.HasFile AndAlso IO.Path.GetExtension(FileUpload1.FileName) = ".xlsx") Then
Dim FileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
Dim Extension As String = Path.GetExtension(FileUpload1.PostedFile.FileName)
Dim FolderPath As String = Request.ApplicationPath + "Temp\"
Dim FilePath As String = Server.MapPath(FolderPath + FileName)
FileUpload1.SaveAs(FilePath)
Dim DTExcel As New Data.DataTable
Dim conn As Odbc.OdbcConnection = Nothing
Dim ErrorExcel As Boolean = False
Try
conn = New Odbc.OdbcConnection("Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & FilePath & ";")
conn.Open()
Dim cmd = conn.CreateCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT * FROM [subproyecto$]"
Dim da = New Odbc.OdbcDataAdapter(cmd)
da.Fill(DTExcel)
Dim objsubproyectos As New ClsSubProyectos
Dim objcontpaqi As New ClsContPAQi(UsuarioActual.Empresa)
Dim resultado As Boolean = False
Dim DTError As New DataTable
'COLUMNAS DEL REPORTE (GRID)
DTError.Columns.Add("Fila", GetType(String))
DTError.Columns.Add("Clasificacion", GetType(String))
DTError.Columns.Add("SubProyecto", GetType(String))
DTError.Columns.Add("CuentaGasto", GetType(String))
DTError.Columns.Add("CuentaAnticipo", GetType(String))
DTError.Columns.Add("CuentaInventario", GetType(String))
Dim hayerrorcol As Boolean = False
Dim errores As String = "<table> <tr style=""color:#FFFFCC;background-color:orange;font-weight:bold;""><td style='width:250px'>Clasificación</td><td style='width:250px'>SubProyecto</td><td>CuentaGasto</td><td>CuentaAnticipo</td><td>CuentaInventario</td></tr>"
Dim mensajea As String = "el Archivo se cargado Correctamente"
For index As Integer = 0 To DTExcel.Rows.Count - 1
Dim CveClasificacion As Integer = DTExcel.Rows(index)("CveClasificacion").ToString.ToEntero
Dim CveSubProyecto As Integer = DTExcel.Rows(index)("CveSubProyecto").ToString.ToEntero
Dim idcuentagasto As Integer = -1
Dim idcuentaanticipo As Integer = -1
Dim idcuentaInventario As Integer = -1
Dim namecuentagasto As String = ""
Dim namecuentaanticipo As String = ""
Dim namecuentaInventario As String = ""
Dim cuentagasto As String = DTExcel.Rows(index)("CuentaGasto").ToString
cuentagasto = (cuentagasto.ToString.Trim.Replace("-", ""))
Dim cuentaanticipo As String = DTExcel.Rows(index)("CuentaAnticipo").ToString
cuentaanticipo = (cuentaanticipo.ToString.Trim.Replace("-", ""))
Dim cuentaInventario As String = DTExcel.Rows(index)("CuentaInventario").ToString
cuentaInventario = (cuentaInventario.ToString.Trim.Replace("-", ""))
Dim NEcuentagasto As Boolean = False
Dim NEcuentaanticipo As Boolean = False
Dim NEcuentaInventario As Boolean = False
If (Not (cuentagasto Is Nothing)) AndAlso cuentagasto.Length > 4 Then
If objcontpaqi.GetCuentas(-1, cuentagasto, -1, 1) Then
If objcontpaqi.DtResultados.Rows.Count > 0 Then
idcuentagasto = objcontpaqi.DtResultados.Rows(0)("Id").ToString.ToEntero
namecuentagasto = cuentagasto & " - " & objcontpaqi.DtResultados.Rows(0)("Nombre").ToString
Else
NEcuentagasto = True
End If
Else
NEcuentagasto = True
End If
End If
If (Not (cuentaanticipo Is Nothing)) AndAlso cuentaanticipo.Length > 4 Then
If objcontpaqi.GetCuentas(-1, cuentaanticipo, -1, 1) Then
If objcontpaqi.DtResultados.Rows.Count > 0 Then
idcuentaanticipo = objcontpaqi.DtResultados.Rows(0)("Id").ToString.ToEntero
namecuentaanticipo = cuentaanticipo & " - " & objcontpaqi.DtResultados.Rows(0)("Nombre").ToString
Else
NEcuentaanticipo = True
End If
Else
NEcuentaanticipo = True
End If
End If
If (Not (cuentaInventario Is Nothing)) AndAlso cuentaInventario.Length > 4 Then
If objcontpaqi.GetCuentas(-1, cuentaInventario, -1, 1) Then
If objcontpaqi.DtResultados.Rows.Count > 0 Then
idcuentaInventario = objcontpaqi.DtResultados.Rows(0)("Id").ToString.ToEntero
namecuentaInventario = cuentaInventario.ToString & " - " & objcontpaqi.DtResultados.Rows(0)("Nombre").ToString
Else
NEcuentaInventario = True
End If
Else
NEcuentaInventario = True
End If
End If
'If (idcuentagasto > 0 Or idcuentaanticipo > 0 Or idcuentaInventario > 0) Then
' If objsubproyectos.UpdateSubProyectoExcel(UsuarioActual.CveEmpresa, CveClasificacion, CveSubProyecto, idcuentagasto, idcuentaanticipo, idcuentaInventario, namecuentagasto, namecuentaanticipo, namecuentaInventario) Then
' Else
' resultado = True
' End If
'End If
If NEcuentagasto Or NEcuentaanticipo Or NEcuentaInventario Then
hayerrorcol = True
Dim Row As DataRow = Nothing
Row = DTError.NewRow
Row("Fila") = (index + 1).ToString
Row("Clasificacion") = DTExcel.Rows(index)("Clasificacion").ToString
Row("SubProyecto") = DTExcel.Rows(index)("SubProyecto").ToString
Row("CuentaGasto") = If(NEcuentagasto, cuentagasto, "")
Row("CuentaAnticipo") = If(NEcuentaanticipo, cuentaanticipo, "")
Row("CuentaInventario") = If(NEcuentaInventario, cuentaInventario, "")
DTError.Rows.Add(Row)
mensajea = "<br/><br/> El Archivo ha sido Cargado Correctamente <br/><br/> se han omitido los Siguientes Registros"
errores = String.Format("{0}<tr><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>", errores, Row("Clasificacion").ToString, Row("SubProyecto").ToString, Row("CuentaGasto").ToString, Row("CuentaAnticipo").ToString, Row("CuentaInventario").ToString)
End If
Next
objcontpaqi.Dispose()
objsubproyectos.Dispose()
If resultado Then
Alert("ocurrio un error al guardar los datos")
Else
Alert(mensajea & " <div style=""width:350px;height:200px;overflow:scroll"">" & errores & " </div>")
End If
'GridView1.Caption = Path.GetFileName("Lista de errores en carga")
'GridView1.DataSource = DTError
'GridView1.DataBind()
Catch ex As Exception
ErrorExcel = True
Alert("Ocurrio un error al leer el Excel: " + ex.ToString, TipoMensaje.MsgError)
End Try
conn.Close()
Else
Alert("No es un archivo de excel valido")
End If
End Sub
Private Sub Import_To_Grid(ByVal FilePath As String, ByVal Extension As String, ByVal isHDR As String)
Dim conStr As String = ""
Select Case Extension
Case ".xls"
'Excel 97-03
conStr = ConfigurationManager.ConnectionStrings("Excel03ConString") _
.ConnectionString
Exit Select
Case ".xlsx"
'Excel 07
conStr = ConfigurationManager.ConnectionStrings("Excel07ConString") _
.ConnectionString
Exit Select
End Select
conStr = String.Format(conStr, FilePath, isHDR)
Dim connExcel As New OleDbConnection(conStr)
Dim cmdExcel As New OleDbCommand()
Dim oda As New OleDbDataAdapter()
Dim dt As New DataTable()
cmdExcel.Connection = connExcel
'Get the name of First Sheet
connExcel.Open()
Dim dtExcelSchema As DataTable
dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
Dim SheetName As String = dtExcelSchema.Rows(0)("TABLE_NAME").ToString()
connExcel.Close()
'Read Data from First Sheet
connExcel.Open()
cmdExcel.CommandText = "SELECT * From [" & SheetName & "]"
oda.SelectCommand = cmdExcel
oda.Fill(dt)
connExcel.Close()
''Bind Data to GridView
'GridView1.Caption = Path.GetFileName(FilePath)
'GridView1.DataSource = dt
'GridView1.DataBind()
End Sub
Public Sub BtnAgregarCentroCosto_Click(sender As Object, e As EventArgs)
CveCentroCosto = -1
HdnModalidad.Value = "I"
TxtCentroCosto.Text = ""
ChkEstatus.Checked = True
ChkEsMatriz.Checked = False
ChkEsSucursal.Checked = False
ChkAplicaComercioExterior.Checked = False
'TabComercioExterior.Visible = False
TxtSerie.Text = ""
TxtIVA.Text = "0.16"
TxtCalle.Text = ""
TxtNoExt.Text = ""
TxtNoInt.Text = ""
TxtColonia.Text = ""
TxtLocalidad.Text = ""
TxtMunicipio.Text = ""
TxtEstado.Text = ""
TxtPais.Text = ""
TxtCP.Text = ""
TxtCorreo.Text = ""
TxtTelefono.Text = ""
DdlPais.SelectedValueExist("-1")
DdlPrecioLista.SelectedValueExist("-1")
CargaEstado()
CargaMunicipio()
CargaColonia()
CargaLocalidad()
If UsuarioActual.Empresa.UsaContabilidad Then
CargaSegmentosNegocio()
End If
BtnGuardar.Text = "Agregar"
UpAddCentroEstatus.Update()
RegistraScript(String.Format("$('#{0}').modal();", "DivAgregarCentroCosto"))
End Sub
Private Sub CargaRequired()
If ChkEsSucursal.Checked = True Then
RFVSerie.Enabled = True
RFVIVA.Enabled = True
RFVCalle.Enabled = True
RFVNoExt.Enabled = True
RFVColonia.Enabled = True
RFVLocalidad.Enabled = True
RFVMunicipio.Enabled = True
RFVEstado.Enabled = True
RFVPais.Enabled = True
RFVCP.Enabled = True
RFVSerie.Visible = True
RFVIVA.Visible = True
RFVCalle.Visible = True
RFVNoExt.Visible = True
RFVColonia.Visible = True
RFVLocalidad.Visible = True
RFVMunicipio.Visible = True
RFVEstado.Visible = True
RFVPais.Visible = True
RFVCP.Visible = True
RFVCP.Visible = True
RFVDdlPais.Visible = True
RFVDdlEstado.Visible = True
RFVMunicipio.Visible = True
RFVLocalidad.Visible = True
RFVColonia.Visible = True
Else
RFVSerie.Enabled = False
RFVIVA.Enabled = False
RFVCalle.Enabled = False
RFVNoExt.Enabled = False
RFVColonia.Enabled = False
RFVLocalidad.Enabled = False
RFVMunicipio.Enabled = False
RFVEstado.Enabled = False
RFVPais.Enabled = False
RFVCP.Enabled = False
RFVSerie.Visible = False
RFVIVA.Visible = False
RFVCalle.Visible = False
RFVNoExt.Visible = False
RFVColonia.Visible = False
RFVLocalidad.Visible = False
RFVMunicipio.Visible = False
RFVEstado.Visible = False
RFVPais.Visible = False
RFVCP.Visible = False
RFVCP.Visible = False
RFVDdlPais.Visible = False
RFVDdlEstado.Visible = False
RFVMunicipio.Visible = False
RFVLocalidad.Visible = False
RFVColonia.Visible = False
End If
End Sub
Private Sub ChkEsSucursal_CheckedChanged(sender As Object, e As EventArgs) Handles ChkEsSucursal.CheckedChanged
CargaRequired()
End Sub
#End Region
#Region "COMERCIO EXTERIOR"
Private Sub CargaPais()
DdlPais.DataSource = GlobalDTGralPaises()
DdlPais.DataBind()
DdlPais.SelectedValueExist("151")
End Sub
Private Sub CargaEstado()
DdlEstado.Items.Clear()
If DdlPais.SelectedValue.ToEntero > 0 Then
DdlEstado.DataSource = GlobalDTGralEstados("-1", DdlPais.SelectedValue.ToEntero)
End If
DdlEstado.Items.Insert(0, New ListItem("Seleccione", "-1"))
DdlEstado.DataBind()
End Sub
Private Sub CargaMunicipio()
DdlMunicipio.Items.Clear()
If DdlEstado.SelectedValue.ToEntero > 0 Then
DdlMunicipio.DataSource = GlobalDTGralMunicipios("-1", DdlEstado.SelectedValue.ToEntero)
End If
DdlMunicipio.Items.Insert(0, New ListItem("Seleccione", "-1"))
DdlMunicipio.DataBind()
End Sub
Private Sub CargaColonia()
DdlColonia.Items.Clear()
If DdlMunicipio.SelectedValue.ToEntero > 0 Then
DdlColonia.DataSource = GlobalDTGralColonias("-1", "-1", "-1", DdlMunicipio.SelectedValue.ToEntero, CodigoPostal:=If(TxtCP.Text.Trim.Length > 0, TxtCP.Text.ToEntero, -1))
End If
DdlColonia.Items.Insert(0, New ListItem("Seleccione", "-1"))
DdlColonia.DataBind()
End Sub
Protected Sub CargaLocalidad()
DdlLocalidad.Items.Clear()
If DdlEstado.SelectedValue.ToEntero > 0 Then
DdlLocalidad.DataSource = GlobalDTLocalidad(DdlEstado.SelectedValue.ToEntero, DdlMunicipio.SelectedValue.ToEntero)
DdlLocalidad.DataBind()
End If
DdlLocalidad.Items.Insert(0, New ListItem("Seleccione una", "-1"))
End Sub
Protected Sub DdlPais_SelectedIndexChanged(sender As Object, e As EventArgs)
CargaEstado()
CargaMunicipio()
' CargaColonia()
' CargaLocalidad()
End Sub
Protected Sub DdlEstado_SelectedIndexChanged(sender As Object, e As EventArgs)
CargaMunicipio()
'CargaColonia()
'CargaLocalidad()
End Sub
Protected Sub DdlMunicipio_SelectedIndexChanged(sender As Object, e As EventArgs)
CargaColonia()
CargaLocalidad()
End Sub
'Protected Sub ChkAplicaComercioExterior_CheckedChanged(sender As Object, e As EventArgs)
' AplicaComercio()
'End Sub
'Private Sub AplicaComercio()
' If ChkAplicaComercioExterior.Checked Then
' TabComercioExterior.Visible = True
' Else
' TabComercioExterior.Visible = False
' End If
' UpBodyCentroCosto.Update()
'End Sub
#End Region
Protected Sub BtnValidar_Click(sender As Object, e As EventArgs)
validaCodigoPostal()
End Sub
Protected Sub DdlColonia_SelectedIndexChanged(sender As Object, e As EventArgs)
validaCodigoPostal()
End Sub
Private Sub validaCodigoPostal()
Dim CPTxt As Integer = TxtCP.Text.ToEntero()
Dim CveColonia As Integer = DdlColonia.SelectedValue.ToEntero
If CPTxt > 0 And CveColonia > 0 Then
Dim CP As Integer = GlobalDTGralColonias("-1", "-1", "-1", CveColonia:=CveColonia).FiltroPrimeroValor("CP", "").ToEntero
If CPTxt <> CP Then
Alert("El código postal selecionado es diferente del codigo postal de la Colonia.", TipoMensaje.MsgAdvertencia)
End If
End If
End Sub
Protected Sub LnkusuariosAsignados_Click(sender As Object, e As EventArgs)
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
Dim CveSubProyectoUsuarios As Integer = GvRow.DataKey("CveSubProyecto").ToEntero
LblUsuariosProyectoTitulo.Text = $"Centro de Costos: {GvRow.DataKey("SubProyecto")}"
CargaUsuariosAsignados(CveSubProyectoUsuarios)
RegistraScript("$('#DivUsuariosProyecto').modal('show');")
End Sub
Private Sub CargaUsuariosAsignados(CveSubProyectoUsuarios As Integer)
Dim ObjUsuarios As New ClsSisUsuarios
If ObjUsuarios.GetSubProyectos(-1, CveSubProyectoUsuarios) Then
GvUsuariosProyectos.DataSource = ObjUsuarios.DtResultados
Else
GvUsuariosProyectos.DataSource = Nothing
End If
ObjUsuarios.Dispose()
GvUsuariosProyectos.DataBind()
UpModalUsuariosProyectos.Update()
End Sub
Protected Sub LnkEliminarUsuarioSubProyecto_Click(sender As Object, e As EventArgs)
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
Dim CveUsuario As Integer = GvRow.DataKey("CveUsuario").ToEntero
Dim CveSubProyectoUsuarios As Integer = GvRow.DataKey("CveSubProyecto").ToEntero
Dim SubProyecto As String = GvRow.DataKey("SubProyecto")
Dim Erroreliminacion As Boolean = False
Dim ObjUsuarios As New ClsSisUsuarios()
Dim ObjGenerales As New ClsGenerales(ObjUsuarios.IniciaTransacSQL)
If ObjUsuarios.RemoveSubProyectos(CveUsuario, CveSubProyectoUsuarios, UsuarioActual.CveUsuario) Then
If Not ObjGenerales.AddHistorialBitacora(406, -1, -1, -1, -1, -1, -1, -1, "", SubProyecto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, "-1", "-1", "-1", CveUsuarioTabla:=CveUsuario) Then
Erroreliminacion = True
ObjUsuarios.Commit()
End If
Else
Erroreliminacion = True
ObjUsuarios.RollBack()
End If
ObjUsuarios.Dispose()
If Not ErrorEliminacion Then
CargaUsuariosAsignados(CveSubProyectoUsuarios)
Alert("Centro de Costo desasignado.")
End If
End Sub
End Class