lunes, 30 de diciembre de 2019

detalle facturador

dgv(cantidad, e.RowIndex).Value = Double.Parse(dgv(cantidad, e.RowIndex).Value)

martes, 24 de diciembre de 2019

crud vista

 Dim nombre_vista As String = "vista_estado_sii"
        Dim query_vista_existe As String = "SELECT 1 FROM sys.views WHERE name=" & "'" & nombre_vista & "'"
        Dim query_vista_crear As String = "CREATE VIEW " & nombre_vista & " AS " & My.Resources.ejemplo_vista
        Dim vista_existe As Integer = get_vista_crud(conex, query_vista_existe)


        If vista_existe = 1 Then ' Vista existe; eliminar y crear
            Dim query_vista_eliminar As String = "DROP VIEW " & nombre_vista
            Dim eliminar_vista As Integer = get_vista_crud(conex, query_vista_eliminar)

            If eliminar_vista = 0 Then
                Dim crear_vista As Integer = get_vista_crud(conex, query_vista_crear)
                If crear_vista = 0 Then
                    MessageBox.Show("La vista se ha creado correctamente", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If
            End If

        Else ' Vista no existe; crear

            Dim crear_vista As Integer = get_vista_crud(conex, query_vista_crear)
            If crear_vista = 0 Then
                MessageBox.Show("La vista se ha creado correctamente", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If

        End If

        '1 Preguntar si existe
        '2 Si existe, borrar y crear vista
        '3 Si no existe, crear vista


Public Function get_vista_crud(ByVal conex As String, ByVal query As String) As Integer
        Dim return_value As Integer = 0
        Dim con As New SqlConnection(conex)
        con.Open()
        Using cmd As New SqlCommand(query, con)
            return_value = cmd.ExecuteScalar()
        End Using
        con.Close()
        Return return_value
    End Function

viernes, 20 de diciembre de 2019

sql recursion

WITH miCTE AS (
   
     SELECT MIN(idcaf_activo) as n,(select max(idcaf_activo) from caf_activos) as maxid from caf_activos
     UNION all
     SELECT n+1,maxid from miCTE where n < maxid
)
SELECT n FROM miCTE  t1 left join (select * from caf_activos)t2 on t2.idcaf_activo=t1.n
where t2.idcaf_activo is null
OPTION (MAXRECURSION 0)

fuente

fuente2

fuente3

fuente4

jueves, 19 de diciembre de 2019

listado de ultimos registros

select top 10 * from hist_DTE order by id_DTE desc

array trim y elementos no vacíos

Dim str As String = "|1|2|5|7|8|9|122   |0| 9   9|"

Dim array() As String = str.Split("|").Select(Function(w) w.Trim).Where(Function(w) w.Length > 0).ToArray

Existe elemento en un array



System.Array.Exists(array, Function(w) w = "6")

Fuente

martes, 17 de diciembre de 2019

check boolean data


Dim c As String = "  true"

If Boolean.TryParse(c, flag) Then
            MessageBox.Show("True")
        Else
            MessageBox.Show("False")
        End If


Fuente

validar formato hora

Dim time As DateTime
        Dim valid As Boolean = DateTime.TryParseExact("00:05:00", "hh:mm:ss", CultureInfo.InvariantCulture, Globalization.DateTimeStyles.None, time)


fuente

lunes, 16 de diciembre de 2019

close and open application, restart

Private Sub btn_restart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_restart.Click
        Application.Restart()
        Environment.Exit(0)
    End Sub

fuente

sábado, 7 de diciembre de 2019

caf vencidos

select DATEDIFF(MONTH,CAST(fecha_autorizacion as DATE), GETDATE()) from caf_activos


select DATEADD(MONTH,6,CAST(fecha_autorizacion as DATE)) from caf_activos

viernes, 6 de diciembre de 2019

socket timeout


 Dim send As New Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
            send.SendTimeout = 1000
            send.ReceiveTimeout = 1000
            send.Connect(remoteEP)


fuente

jueves, 5 de diciembre de 2019

timer windows service

Public Class custom_timer
        Inherits Timer
        Private id As String
        Public Property Tag As String
            Get
                Return id
            End Get
            Set(ByVal value As String)
                id = value
            End Set
        End Property
    End Class



Dim t As New custom_timer
        xt1.rut(len) = rut
        t.AutoReset = False
        t.Interval = TimeSpan.Parse(elem("Intervalo").InnerXml).TotalMilliseconds
        t.Enabled = elem("Activar").InnerXml
        t.Tag = rut & "|" & elem("Id").InnerXml & "|" & elem("Config").OuterXml
        AddHandler t.Elapsed, New ElapsedEventHandler(AddressOf Timer_Elapsed1)
        xt1.tareas(len) = t
        Dim x As String = ""

network address changed

fuente

cerrar procesos form al salir aplicación

System.Diagnostics.Process.GetCurrentProcess().Kill()
fuente

seleccionar algunas columnas al hacer clic

 dgv.Rows(e.RowIndex).Selected = True
 dgv.Rows(e.RowIndex).Cells(4).Selected = False


lunes, 2 de diciembre de 2019