martes, 27 de agosto de 2019
Extraer datos array
Dim dte() As String = array.Skip(2).ToArray
validar nombres de los nodos xml
Dim child As XmlElement = xml.CreateElement(XmlConvert.EncodeName(data(0)))
Etiquetas:
EncodeName,
xml,
XmlConvert
Buscar elementos repetidos en una columna
Dim query1 = (From i As DataGridViewRow In dg_captura.Rows Select i.Cells(0)).ToList()
Dim query2 = query1.GroupBy(Function(x) x.Value).Where(Function(g) g.Count > 1).Select(Function(y) y.Key).ToList()
fuente
Dim query2 = query1.GroupBy(Function(x) x.Value).Where(Function(g) g.Count > 1).Select(Function(y) y.Key).ToList()
fuente
obtener los valores de la columna datagrid
Dim query1 = (From i As DataGridViewRow In dg_captura.Rows Select i.Cells(0)).ToList()
Busca elemento repetido en una columna especifica
Dim query2 = query1.GroupBy(Function(x) x.Value).Where(Function(g) g.Count > 1).Select(Function(y) y.Key).ToList()
Busca elemento repetido en una columna especifica
Dim query2 = query1.GroupBy(Function(x) x.Value).Where(Function(g) g.Count > 1).Select(Function(y) y.Key).ToList()
Etiquetas:
DataGridView,
From,
Repetido
viernes, 23 de agosto de 2019
actualizar grid
Private Sub DataGridView1_CurrentCellDirtyStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DgvTareas.CurrentCellDirtyStateChanged
If DataGridView1.IsCurrentCellDirty Then
DataGridview1.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub
If DataGridView1.IsCurrentCellDirty Then
DataGridview1.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub
encriptar desencriptar
Public hash As String = "@H45H@"
Public Function encriptar(ByVal str As String) As String
Dim data As Byte() = UTF8Encoding.UTF8.GetBytes(str)
Dim transform As ICryptoTransform
Dim results As Byte()
Dim keys As Byte()
Using md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
keys = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash))
Using tripDes As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
tripDes.Key = keys
tripDes.Mode = CipherMode.ECB
tripDes.Padding = PaddingMode.PKCS7
transform = tripDes.CreateEncryptor
results = transform.TransformFinalBlock(data, 0, data.Length)
Return Convert.ToBase64String(results, 0, results.Length)
End Using
End Using
End Function
' Using tripDes As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider With {.Key = keys, .Mode = CipherMode.ECB, .Padding = PaddingMode.PKCS7}
Public Function desencriptar(ByVal str As String) As String
Dim data As Byte() = Convert.FromBase64String(str)
Dim transform As ICryptoTransform
Dim results As Byte()
Dim keys As Byte()
Using md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
keys = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash))
Using tripDes As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
tripDes.Key = keys
tripDes.Mode = CipherMode.ECB
tripDes.Padding = PaddingMode.PKCS7
transform = tripDes.CreateDecryptor
results = transform.TransformFinalBlock(data, 0, data.Length)
Return UTF8Encoding.UTF8.GetString(results)
End Using
End Using
End Function
fuente
Public Function encriptar(ByVal str As String) As String
Dim data As Byte() = UTF8Encoding.UTF8.GetBytes(str)
Dim transform As ICryptoTransform
Dim results As Byte()
Dim keys As Byte()
Using md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
keys = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash))
Using tripDes As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
tripDes.Key = keys
tripDes.Mode = CipherMode.ECB
tripDes.Padding = PaddingMode.PKCS7
transform = tripDes.CreateEncryptor
results = transform.TransformFinalBlock(data, 0, data.Length)
Return Convert.ToBase64String(results, 0, results.Length)
End Using
End Using
End Function
' Using tripDes As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider With {.Key = keys, .Mode = CipherMode.ECB, .Padding = PaddingMode.PKCS7}
Public Function desencriptar(ByVal str As String) As String
Dim data As Byte() = Convert.FromBase64String(str)
Dim transform As ICryptoTransform
Dim results As Byte()
Dim keys As Byte()
Using md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
keys = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash))
Using tripDes As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
tripDes.Key = keys
tripDes.Mode = CipherMode.ECB
tripDes.Padding = PaddingMode.PKCS7
transform = tripDes.CreateDecryptor
results = transform.TransformFinalBlock(data, 0, data.Length)
Return UTF8Encoding.UTF8.GetString(results)
End Using
End Using
End Function
fuente
Etiquetas:
encriptar,
md5,
MD5CryptoServiceProvider
martes, 13 de agosto de 2019
eliminar registros vacíos (Nothing) en un array
array = array.Where(Function(x) x IsNot Nothing).ToArray
Dim carpeta_xml() As String
carpeta_xml = carpeta_xml.Where(Function(x) Not String.IsNullOrEmpty(x)).ToArray
fuente
fuente1
fuente2
Dim carpeta_xml() As String
carpeta_xml = carpeta_xml.Where(Function(x) Not String.IsNullOrEmpty(x)).ToArray
fuente
fuente1
fuente2
TimeSpan mes,semana,día,hora,minuto,segundo
Dim total As TimeSpan = New TimeSpan((Now.AddMonths(nud_mes.Value).Date - Now.Date).TotalDays + (Now.AddDays(nud_semana.Value * 7).Date - Now.Date).TotalDays + nud_dia.Value, nud_hora.Value, nud_minuto.Value, nud_segundo.Value, 0)
Etiquetas:
AddMonths,
milisegundos,
Now,
TimeSpan,
TotalDays
consola
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Try
'Dim sr As New StreamReader("file.txt")
rtb_console.Text = File.ReadAllText("file.txt")
'rtb_console.AppendText(File.ReadAllText("file.txt"))
rtb_console.SelectionStart = rtb_console.TextLength
rtb_console.ScrollToCaret()
'rtb_console.Focus()
'rtb_console.Refresh()
Catch ex As Exception
End Try
' https://www.codeproject.com/Questions/430020/which-is-the-control-best-suited-for-displaying-th
End Sub
Try
'Dim sr As New StreamReader("file.txt")
rtb_console.Text = File.ReadAllText("file.txt")
'rtb_console.AppendText(File.ReadAllText("file.txt"))
rtb_console.SelectionStart = rtb_console.TextLength
rtb_console.ScrollToCaret()
'rtb_console.Focus()
'rtb_console.Refresh()
Catch ex As Exception
End Try
' https://www.codeproject.com/Questions/430020/which-is-the-control-best-suited-for-displaying-th
End Sub
timespan
Private Sub btn_ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ok.Click
Dim totalDia As Long = (Now.AddDays(1).Date - DateTime.Now).TotalMilliseconds
'Dim t As TimeSpan = TimeSpan.FromDays(31)
Dim cantidad_dias_mes As Integer = (Now.AddMonths(12).Date - DateTime.Now).TotalDays
Dim t1 As TimeSpan = TimeSpan.FromDays(cantidad_dias_mes)
Dim cantidad_dias_semana As Integer = (Now.AddDays(2 * 7).Date - DateTime.Now).TotalDays
Dim t2 As TimeSpan = TimeSpan.FromDays(cantidad_dias_semana)
Dim cantidad_dias_dia As Integer = (Now.AddDays(1).Date - DateTime.Now).TotalDays
Dim t3 As TimeSpan = TimeSpan.FromDays(cantidad_dias_dia)
End Sub
Dim totalDia As Long = (Now.AddDays(1).Date - DateTime.Now).TotalMilliseconds
'Dim t As TimeSpan = TimeSpan.FromDays(31)
Dim cantidad_dias_mes As Integer = (Now.AddMonths(12).Date - DateTime.Now).TotalDays
Dim t1 As TimeSpan = TimeSpan.FromDays(cantidad_dias_mes)
Dim cantidad_dias_semana As Integer = (Now.AddDays(2 * 7).Date - DateTime.Now).TotalDays
Dim t2 As TimeSpan = TimeSpan.FromDays(cantidad_dias_semana)
Dim cantidad_dias_dia As Integer = (Now.AddDays(1).Date - DateTime.Now).TotalDays
Dim t3 As TimeSpan = TimeSpan.FromDays(cantidad_dias_dia)
End Sub
viernes, 9 de agosto de 2019
Split string to array con vacíos
a.Split(';').Where(s => s.Length > 0).ToArray();
bloquear combobox
Private Sub cb_tareas_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cb_tareas.MouseDown
If e.Button = MouseButtons.Right Then
cb_tareas.DroppedDown = True
End If
End Sub
Private Sub cb_tareas_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cb_tareas.KeyDown
e.SuppressKeyPress = True
End Sub
Private Sub cb_tareas_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cb_tareas.KeyPress
e.Handled = True
End Sub
martes, 6 de agosto de 2019
Crear archivo xml
Dim xml As New XmlDocument
xml.AppendChild(xml.CreateXmlDeclaration("1.0", "UTF-8", Nothing))
Dim nodo As XmlNode = xml.CreateElement("DTE")
nodo.InnerXml = "<Documento>" &
"<TipoDTE></TipoDTE>" &
"<Folio></Folio>" &
"<EstadoSII></EstadoSII>" &
"<TrackID></TrackID>" &
"</Documento>"
xml.AppendChild(nodo)
xml.Save(archivo)
Fuente
xml.AppendChild(xml.CreateXmlDeclaration("1.0", "UTF-8", Nothing))
Dim nodo As XmlNode = xml.CreateElement("DTE")
nodo.InnerXml = "<Documento>" &
"<TipoDTE></TipoDTE>" &
"<Folio></Folio>" &
"<EstadoSII></EstadoSII>" &
"<TrackID></TrackID>" &
"</Documento>"
xml.AppendChild(nodo)
xml.Save(archivo)
Fuente
Etiquetas:
CreateXmlDeclaration,
xml,
XmlNode
lunes, 5 de agosto de 2019
hashset split
Dim t As New HashSet(Of String)
t.Add("33,45690;ruta xml")
t.Add("39,123;ruta txt")
Dim data As String = String.Join("@", t.Select(Function(x) x.Split(";")(0)).ToArray)
Dim path() As String = t.Select(Function(x) x.Split(";")(1)).ToArray
hashset to string separador
Dim enviar As New HashSet(Of String)
Dim str As String = ""
str = String.Join(@, enviar.ToArray)
fuente
Dim str As String = ""
str = String.Join(@, enviar.ToArray)
fuente
jueves, 1 de agosto de 2019
Tamaño de un archivo
Dim archivo As String = "xml_venta.xml"
Dim size_ As Long = New System.IO.FileInfo(archivo).Length
Dim p As String = size_.ToString("N0")
MessageBox.Show(p & " bytes")
Dim size_ As Long = New System.IO.FileInfo(archivo).Length
Dim p As String = size_.ToString("N0")
MessageBox.Show(p & " bytes")
servicio existe
Agregar referencia: System.ServiceProcess
Dim se As Boolean = ServiceExists("LanmanWorkstation")
Public Function ServiceExists(ByVal ServiceName As String)
Return ServiceController.GetServices.Any(Function(x) x.ServiceName.Equals(ServiceName))
End Function
Dim status As String = ServiceIsRunning("LanmanWorkstation")
Public Function ServiceIsRunning(ByVal ServiceName As String) As String
Dim sc As ServiceController = New ServiceController(ServiceName)
Select Case sc.Status
Case ServiceControllerStatus.Running ' Iniciado
Return "Running"
Case ServiceControllerStatus.Stopped ' Detenido
Return "Stopped"
Case ServiceControllerStatus.Paused ' Pausado
Return "Paused"
Case ServiceControllerStatus.StopPending ' Deteniendose
Return "Stopping"
Case ServiceControllerStatus.StartPending ' Iniciando
Return "Starting"
Case Else
Return "Status Changing" ' Desconocido
End Select
End Function
fuente
buscar string regex
Dim rx As Regex = New Regex("[a-z]")
If rx.IsMatch("string") Then
Return True
End If
If rx.IsMatch("string") Then
Return True
End If
Crear archivo
File.Create("nombre_archivo").Dispose
Suscribirse a:
Entradas (Atom)