Imports System.Data Imports System.Globalization Imports System.IO Imports Extensiones Imports Microsoft.Reporting.WebForms Partial Class OI_Normatividad Inherits ClsPaginas #Region "Propiedades" Private Property DtDatos As DataTable Get Return CType(ViewState("DtDatos"), DataTable) End Get Set(value As DataTable) ViewState("DtDatos") = value End Set End Property Private Property IDSelected As Integer Get Return ViewState("idsel").ToString.ToEntero End Get Set(value As Integer) ViewState("idsel") = 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 CargaDatos() If DtDatos.Rows.Count = 0 Then 'Agregar los titulos Padres necesarios para que el usuario comience agregar los suyos Dim ObjOIEventos As New ClsOIEventos If ObjOIEventos.AddEventoNormatividad("PADRE", "PADRE DE TODOS", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, "".ToEntero) Then If ObjOIEventos.GetEventoNormatividad(UsuarioActual.CveEmpresa) Then IDSelected = ObjOIEventos.DtResultados(0)("CveEvento").ToString.ToEntero ObjOIEventos.AddEventoNormatividad("Título 1", "", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, IDSelected) End If End If ObjOIEventos.Dispose() CargaDatos() End If CargaTitulosPadre() RegistraScript("expandir();") End If End Sub Private Sub CargaDatos() Dim ObjOIEventos As New ClsOIEventos If ObjOIEventos.GetEventoNormatividad(UsuarioActual.CveEmpresa) Then DtDatos = ObjOIEventos.DtResultados.FiltraParametros("", "CveEvento") End If ArbolCuentas.DataSource = DtDatos ArbolCuentas.nivel = "CtaInicial" ArbolCuentas.nodoid = "CveEvento" ArbolCuentas.padre = "CveEventoPadre" ArbolCuentas.titulo = "Asunto" updatos.Update() ObjOIEventos.Dispose() End Sub Private Sub CargaTitulosPadre() DdlSubtitulo.Items.Clear() DdlSubtitulo.DataSource = DtDatos.FiltraParametros("CveEventoPadre IS NOT NULL") DdlSubtitulo.DataBind() DdlSubtitulo.Items.Insert(0, New ListItem("-", "-1")) End Sub Private Function getNodospadreHijos(nodo As Integer) As DataTable Return DtDatos.FiltraParametros(String.Format("CveEvento = {0}", nodo)) End Function Protected Sub agregar_Click(sender As Object, e As EventArgs) Handles ArbolCuentas.addclick RegistraScript("$('#DvModalTitulos').modal();") ModalTitulo.Text = "Nuevo Título" LimpiarCampos() Dim obj As ADServerControl.DragableItem = DirectCast(sender, ADServerControl.DragableItem) IDSelected = obj.Cve DdlSubtitulo.SelectedValueExist(IDSelected) nuevacuenta.Visible = True updatos.Visible = True updatos.Update() End Sub Protected Sub editar_Click(sender As Object, e As EventArgs) Handles ArbolCuentas.editclick RegistraScript("$('#DvModalTitulos').modal();") ModalTitulo.Text = "Modificar Título" LimpiarCampos() Dim dt As DataTable Dim obj As ADServerControl.DragableItem = DirectCast(sender, ADServerControl.DragableItem) IDSelected = obj.Cve dt = getNodospadreHijos(IDSelected) If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then Dim dr As DataRow = dt.Rows(0) Ttitulo.Text = dr("Asunto").ToString() DdlSubtitulo.SelectedValueExist(dr("CveEventoPadre").ToString()) TxtObservaciones.Text = dr("Descripcion").ToString DdlSubtitulo.Enabled = False If dr("Archivo").ToString() <> "" Then ImgDownLoadFormato.Visible = True ImgDownLoadFormato.CommandArgument = String.Format("OI\{0}", dr("Archivo").ToString()) End If Dim Hijos As Integer = DtDatos.FiltraParametros(String.Format("CveEventoPadre = {0}", IDSelected)).Rows.Count If (Hijos = 0 And DtDatos.Rows.Count > 2) Then BtnEliminar.Visible = True End If Guardar.Visible = True updatos.Visible = True updatos.Update() End Sub Protected Sub Guardar_Click(sender As Object, e As EventArgs) Handles Guardar.Click Dim ObjOIEventos As New ClsOIEventos 'ARCHIVO Dim FileExtension As String = "-1" Dim filesgral As List(Of Archivo) = Anexo.getfiles().Archivos Dim filemove As String = "" For Each fileItem As Archivo In filesgral FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") filemove = fileItem.filename Next If ObjOIEventos.UpdateEventoNormatividad(Ttitulo.Text.Trim, TxtObservaciones.Text.Trim, String.Format(".{0}", FileExtension), IDSelected) Then If filemove <> "" Then Dim ruta = UsuarioActual.Empresa.Ruta & String.Format("OI\{0}", String.Format("OI{0}.{1}", IDSelected.ToString, FileExtension)) If File.Exists(ruta) Then File.Delete(ruta) End If filemove.FilesMove(String.Format("OI{0}", IDSelected.ToString), String.Format("Empresas\{0}\OI", UsuarioActual.CveEmpresa)) End If Dim customerRow As Data.DataRow customerRow = DtDatos.Select(String.Format("CveEvento = {0}", IDSelected))(0) customerRow("Asunto") = Ttitulo.Text.Trim DtDatos.AcceptChanges() 'CargaDatos() ArbolCuentas.DataSource = DtDatos ArbolCuentas.DataBind() Dim item As CheckBox = DirectCast(ArbolCuentas.FindControl(String.Format("chk{0}", IDSelected)), CheckBox) item.Text = Ttitulo.Text.Trim 'Dim btnAdd As Button = DirectCast(ArbolCuentas.FindControl(String.Format("aradd{0}", IDSelected)), Button) 'btnAdd.Visible = False Anexo.Text = "[]" LimpiarCampos() RegistraScript("expandir();") CargaDatos() RegistraScript("$get('BtnCambiaTitulos').click();") updatos.Update() Alert("El título se guardó correctamente") End If ObjOIEventos.Dispose() End Sub Protected Sub nuevacuenta_Click(sender As Object, e As EventArgs) Handles nuevacuenta.Click Dim ObjOIEventos As New ClsOIEventos 'ARCHIVO Dim FileExtension As String = "-1" Dim filesgral As List(Of Archivo) = Anexo.getfiles().Archivos Dim filemove As String = "" For Each fileItem As Archivo In filesgral FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") filemove = fileItem.filename Next If ObjOIEventos.AddEventoNormatividad(Ttitulo.Text.Trim, TxtObservaciones.Text.Trim, String.Format(".{0}", FileExtension), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, DdlSubtitulo.SelectedValue.ToEntero) Then CargaDatos() Dim Idnew As Integer = 0 Dim row As DataRow = DtDatos.FiltraParametros("", "CveEvento DESC").Rows(0) Idnew = row("CveEvento").ToString().ToEntero If filemove <> "" Then filemove.FilesMove(String.Format("OI{0}", Idnew.ToString), String.Format("Empresas\{0}\OI", UsuarioActual.CveEmpresa)) End If ArbolCuentas.DataSource = DtDatos Dim item As ADServerControl.DragableItem = DirectCast(ArbolCuentas.FindControl(String.Format("{0}", DdlSubtitulo.SelectedValue.ToEntero)), ADServerControl.DragableItem) item.Attributes.Item("data-hijos") = item.Attributes.Item("data-hijos").ToEntero + 1 Dim objul As ADServerControl.DragableUL = DirectCast(ArbolCuentas.FindControl(String.Format("ul{0}", DdlSubtitulo.SelectedValue.ToEntero)), ADServerControl.DragableUL) If (IsNothing(objul)) Then objul = New ADServerControl.DragableUL objul.ID = String.Format("ul{0}", item.Cve) item.Controls.Add(objul) End If ArbolCuentas.additem(objul, Idnew, DdlSubtitulo.SelectedValue.ToEntero, String.Format("{0}", Ttitulo.Text)) Anexo.Text = "[]" LimpiarCampos() CargaDatos() RegistraScript("$get('BtnCambiaTitulos').click();") updatos.Update() RegistraScript("expandir();") Alert("El título se guardó correctamente") End If ObjOIEventos.Dispose() End Sub Private Sub LimpiarCampos() Ttitulo.Text = "" DdlSubtitulo.SelectedValue = -1 TxtObservaciones.Text = "" Guardar.Visible = False nuevacuenta.Visible = False BtnEliminar.Visible = False DdlSubtitulo.Enabled = True ImgDownLoadFormato.Visible = False End Sub Protected Sub BtnEliminar_Click(sender As Object, e As EventArgs) Handles BtnEliminar.Click Dim ObjOIEventos As New ClsOIEventos If ObjOIEventos.RemoveEvento(IDSelected.ToEntero, UsuarioActual.CveEmpresa) Then Dim customerRow As Data.DataRow customerRow = DtDatos.Select(String.Format("CveEvento = {0}", IDSelected))(0) customerRow("CveEventoPadre") = "-5" DtDatos.AcceptChanges() Dim dt As DataTable = getNodospadreHijos(IDSelected) Dim ruta = UsuarioActual.Empresa.Ruta & String.Format("OI\{0}", dt(0)("Archivo").ToString()) If File.Exists(ruta) Then File.Delete(ruta) End If ArbolCuentas.DataSource = DtDatos Dim item As ADServerControl.DragableItem = DirectCast(ArbolCuentas.FindControl(String.Format("{0}", IDSelected)), ADServerControl.DragableItem) Dim padre As ADServerControl.DragableItem = DirectCast(ArbolCuentas.FindControl(String.Format("{0}", item.CvePadre)), ADServerControl.DragableItem) padre.Attributes.Item("data-hijos") = padre.Attributes.Item("data-hijos").ToEntero - 1 ArbolCuentas.Controls.Remove(item) 'RegistraScript(String.Format("$('#{0}').click();", editar.ClientID)) dt.Rows(0).Delete() RegistraScript(String.Format("$('li#{0}').remove();", IDSelected)) LimpiarCampos() Alert("El título ha sido eliminado", TipoMensaje.MsgInformacion) CargaDatos() RegistraScript("$get('BtnCambiaTitulos').click();") Else Alert("El título no pudo ser eliminado", TipoMensaje.MsgError) ObjOIEventos.RollBack() End If ObjOIEventos.Dispose() End Sub Protected Sub ImgDownLoadFormato_Click(sender As Object, e As EventArgs) Dim filePath As String = String.Format("{0}{1}", UsuarioActual.Empresa.Ruta, CType(sender, LinkButton).CommandArgument) Dim Archivo As New System.IO.FileInfo(filePath) HttpContext.Current.Response.Clear() HttpContext.Current.Response.ClearContent() HttpContext.Current.Response.ContentType = "application/octet-stream" HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment; filename=" + Path.GetFileName(filePath)) HttpContext.Current.Response.AddHeader("Content-Length", Archivo.Length.ToString()) HttpContext.Current.Response.TransmitFile(filePath) HttpContext.Current.Response.Flush() HttpContext.Current.Response.End() Archivo = Nothing End Sub Protected Sub BtnCambiaTitulos_Click(sender As Object, e As EventArgs) CargaTitulosPadre() End Sub Protected Sub LnkNuevo_Click(sender As Object, e As EventArgs) RegistraScript("$('#DvModalTitulos').modal();") ModalTitulo.Text = "Nuevo Título" LimpiarCampos() nuevacuenta.Visible = True updatos.Visible = True updatos.Update() End Sub End Class