Jump to content

Maximus

Active Members
  • Posts

    1481
  • Joined

  • Last visited

  • Days Won

    20

Posts posted by Maximus

  1.  

    Ceva de genu:

     

    Public Class Student
        Public firstName As String = String.Empty
        Public surname As String = String.Empty
        Public tel As String = String.Empty
        Public course As String = String.Empty
    End Class
    
    Public Class Form1
    
        Dim cursuri As New List(Of String)(New String() {"Computing Technology", "Grafician in caramida"})
        Dim dataBase As New Dictionary(Of String, List(Of Student))
        Dim dbDir = "cursuri"
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            If Not System.IO.Directory.Exists(dbDir) Then
                System.IO.Directory.CreateDirectory(dbDir)
            End If
    
            For Each curs As String In cursuri
                cbCourse.Items.Add(curs)
                createField(curs)
                If (System.IO.File.Exists(dbDir & "\" & curs & ".txt")) Then
                    For Each line As String In System.IO.File.ReadAllLines(dbDir & "\" & curs & ".txt")
                        If Not String.IsNullOrEmpty(line) AndAlso line.Contains(":") Then
                            Dim info() As String = line.Split(":")
                            Dim student As Student = New Student()
                            student.firstName = info(0).Trim
                            student.surname = info(1).Trim
                            student.tel = info(2).Trim
                            student.course = curs
                            addStudent(student)
                        End If
                    Next
                End If
            Next
        End Sub
    
        Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
            If Not String.IsNullOrEmpty(tbTel.Text) Then
                If searchForStudent(tbTel.Text) = True Then
                    Dim student As Student = getStudent(tbTel.Text)
                    tbFirstName.Text = student.firstName
                    tbSurname.Text = student.surname
                    tbTel.Text = student.tel
                    cbCourse.SelectedText = student.course
                Else
                    MessageBox.Show(Me, "Studentul nu exista in baza de date", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            Else
                MessageBox.Show(Me, "Studentii se cauta dupa numarul de telefon", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        End Sub
    
        Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
            If Not String.IsNullOrEmpty(tbTel.Text) Then
                If searchForStudent(tbTel.Text) = True Then
                    removeStudent(getStudent(tbTel.Text))
                    MessageBox.Show(Me, "Studentul a fost sters din baza de date", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Else
                    MessageBox.Show(Me, "Studentul nu exista in baza de date", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            Else
                MessageBox.Show(Me, "Studentii se sterg dupa numarul de telefon", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        End Sub
    
        Private Sub btnRegister_Click(sender As Object, e As EventArgs) Handles btnRegister.Click
            If Not String.IsNullOrEmpty(tbFirstName.Text) AndAlso Not String.IsNullOrEmpty(tbFirstName.Text) AndAlso Not String.IsNullOrEmpty(tbTel.Text) AndAlso cbCourse.SelectedIndex > -1 Then
                If searchForStudent(tbTel.Text) = False Then
                    Dim student As Student = New Student()
                    student.firstName = tbFirstName.Text
                    student.surname = tbSurname.Text
                    student.tel = tbTel.Text
                    student.course = cbCourse.SelectedItem.ToString
                    addStudent(student)
                    MessageBox.Show(Me, tbFirstName.Text & " " & tbSurname.Text & " a fost adaugat in baza de date", "Succes", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Else
                    MessageBox.Show(Me, "Acest student exista in baza de date", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            Else
                MessageBox.Show(Me, "Te rugam sa completezi toate campurile", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        End Sub
    
        Private Sub btnList_Click(sender As Object, e As EventArgs) Handles btnList.Click
            couseList.Items.Clear()
            listStudents(cbCourse.SelectedItem.ToString)
        End Sub
    
        Private Sub listStudents(ByVal course As String)
            MsgBox(course)
            If dataBase.ContainsKey(course) Then
                If dataBase(course).Count > 0 Then
                    For Each student As Student In dataBase(course)
                        couseList.Items.Add(student.firstName & " " & student.surname)
                    Next
                Else
                    MessageBox.Show(Me, "Nu exista studenti pentru cursul selectat", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error) ' ??
                End If
            Else
                MessageBox.Show(Me, "Nu exista cursul selectat", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error) ' ??
            End If
        End Sub
        Private Function searchForStudent(ByVal tel As String) As Boolean
            For Each pair In dataBase
                For Each student As Student In pair.Value
                    If student.tel = tel Then
                        Return True
                    End If
                Next
            Next
            Return False
        End Function
    
        Private Function getStudent(ByVal tel As String) As Student
            For Each pair In dataBase
                For Each student As Student In pair.Value
                    If student.tel = tel Then
                        Return student
                    End If
                Next
            Next
            Return Nothing
        End Function
    
        Private Function getStudentByIndex(ByVal course As String, ByVal index As Integer) As Student
            If dataBase.ContainsKey(course) Then
                If dataBase(course).Count >= index Then
                    Return dataBase(course).Item(index)
                End If
            End If
        End Function
    
        Private Sub removeStudent(ByVal student As Student)
            For index As Integer = 0 To dataBase(student.course).Count - 1
                If dataBase(student.course)(index).tel = student.tel Then
                    dataBase(student.course).RemoveAt(index)
                End If
            Next
        End Sub
        Private Sub addStudent(ByVal student As Student)
            If dataBase.ContainsKey(student.course) Then
                dataBase.Item(student.course).Add(student)
            Else
                createField(student.course)
                dataBase.Item(student.course).Add(student)
            End If
        End Sub
    
        Private Sub createField(ByVal fieldName As String)
            dataBase.Add(fieldName, New List(Of Student))
        End Sub
    
        Private Sub couseList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles couseList.SelectedIndexChanged
            If couseList.SelectedIndex > -1 Then
    
            End If
        End Sub
        Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
            For Each pair In dataBase
                Dim O As New System.IO.StreamWriter(dbDir & "\" & pair.Key & ".txt", False)
                For Each student As Student In pair.Value
                    O.WriteLine(student.firstName & ":" & student.surname & ":" & student.tel)
                Next
                O.Close()
            Next
        End Sub
    
    
    End Class
    

    A mai ramas putin de lucrat la el; si evident ca poate fi simplificat

  2. @MrGrj

    1 - Da

    2 - Cum vrei tu, fara base64; 3DES sau ceva mai complex !

    3 - Orice script vreau eu.

    4 - Unu singur, il faci tu

    5 - Este exact ca si vorba : In capul tau ; Nu de pe foaie ;

         Mai detaliat ar fi : Nu vreau sa fisierul decriptat sa fie scris pe disc, deci asta inseamna in memoria RAM nu?

    6 - Nu exista solutii existente , am cautat 2 zile.

     

    Prin umare, da, trebuie sa-mi dai si functia de decriptare , facuta in c# sau vb.net.

    • Upvote 1
  3. Cel mai bine e sa iti faci un live usb , exact asa : https://forums.kali.org/showthread.php?3450-How-to-make-a-PERSISTENT-live-usb-on-windows-using-ext2-filesystem&p=40812&viewfull=1#post40812

    1.

    Descarca imaginea de aici https://www.kali.org/downloads/

    Daca ai > 4GB ia x64 ; < 4GB x86

    2.

    Scrie imaginea cu Rufus (https://rufus.akeo.ie/) ; iti apare un dialog , dai Yes

    3.

    Download and install MiniTool Partition Wizard. Launch it, select the existing UUI partition on your USB drive then click "Move/Resize". Resize the partition leaving a "Unallocated Space After" of 1024MB, and click Apply. When completed, select the blank area you just created (after the UUI partition), and click Create. Select FileSystem: Ext2 , select Create As: Primary, and Partition Label: persistence. Then click Apply.

    Foarte important pasul asta !

    4.

    Boot de pe USB

    5.

    mkdir -p /mnt/usb
    mount /dev/sdb2 /mnt/usb
    echo "/ union" > /mnt/usb/persistence.conf
    umount /dev/sdb2

    (sdb2 poate fi sdb3 4 ....)

    reboot

    si apoi dai pe persitence ;) voila

  4. Ti-l cumpar !

    @Erase , tu pui la indoiala aptitudinile lui ? Uite ce design profesional.

    Uite ce viteza pe win32 @ ~2k threads, frate esti nebun.

    Vreau sa cumpar acest program , la pachet , cu tine si cu ma-ta !

    • Upvote 1
  5. Multithreading Log Writer

    Public Class mtLogWriter
        Implements IDisposable
    
        Private LogWriters As Dictionary(Of Integer, IO.StreamWriter)
        Public WritersCount As Integer = 0
    
        Public Sub New()
            LogWriters = New Dictionary(Of Integer, IO.StreamWriter)
            WritersCount = 0
        End Sub
    
        Public Function Add(ByVal path As String, ByVal append As Boolean) As Boolean
            Try
                LogWriters.Add(WritersCount, New IO.StreamWriter(path, append))
                WritersCount += 1
                Return True
            Catch ex As Exception
                Return False
            End Try
        End Function
    
        Public Sub Remove(ByVal intLogWriter As Integer)
            If LogWriters.ContainsKey(intLogWriter) Then
                SyncLock LogWriters.Item(intLogWriter)
                    LogWriters.Item(intLogWriter).Close()
                    LogWriters.Item(intLogWriter).Dispose()
                    LogWriters.Remove(intLogWriter)
                End SyncLock
            End If
        End Sub
    
        Public Sub WriteLine(ByVal intLogWriter As Integer, ByVal contents As String, Optional ByVal flush As Boolean = False)
            SyncLock LogWriters.Item(intLogWriter)
                LogWriters.Item(intLogWriter).WriteLine(contents)
                If flush = True Then LogWriters.Item(intLogWriter).Flush()
            End SyncLock
        End Sub
    
        Public Sub Write(ByVal intLogWriter As Integer, ByVal contents As String, Optional ByVal flush As Boolean = False)
            SyncLock LogWriters.Item(intLogWriter)
                LogWriters.Item(intLogWriter).Write(contents)
                If flush = True Then LogWriters.Item(intLogWriter).Flush()
            End SyncLock
        End Sub
    
        Public Sub Flush()
            For int As Integer = 0 To LogWriters.Count - 1
                SyncLock LogWriters.Item(int)
                    LogWriters.Item(int).Flush()
                End SyncLock
            Next
        End Sub
    
        Public Sub Flush(ByVal intLogWriter As Integer)
            SyncLock LogWriters.Item(intLogWriter)
                LogWriters.Item(intLogWriter).Flush()
            End SyncLock
        End Sub
    
        Public Sub Close()
            For int As Integer = 0 To LogWriters.Count - 1
                SyncLock LogWriters.Item(int)
                    LogWriters.Item(int).Close()
                    LogWriters.Item(int).Dispose()
                    LogWriters.Remove(int)
                End SyncLock
            Next
        End Sub
    
        Public Sub Close(ByVal intLogWriter As Integer)
            SyncLock LogWriters.Item(intLogWriter)
                LogWriters.Item(intLogWriter).Close()
                LogWriters.Item(intLogWriter).Dispose()
                LogWriters.Remove(intLogWriter)
            End SyncLock
        End Sub
    
    #Region "IDisposable Support"
        Private disposedValue As Boolean
    
        Protected Overridable Sub Dispose(disposing As Boolean)
            If Not disposedValue Then
                If disposing Then
                    For int As Integer = 0 To LogWriters.Count - 1
                        If LogWriters.Item(int) IsNot Nothing Then
                            LogWriters.Item(int).Close()
                            LogWriters.Item(int).Dispose()
                        End If
                    Next
                    LogWriters.Clear()
                    LogWriters = Nothing
                End If
            End If
            disposedValue = True
        End Sub
    
        Public Sub Dispose() Implements IDisposable.Dispose
            Dispose(True)
        End Sub
    #End Region
    
    End Class

    Test :

    Module Module1
        Private logw As LogWriter.mtLogWriter
        Private WaitMe As Boolean = True
        Sub Main()
            logw = New LogWriter.mtLogWriter
            For i As Integer = 0 To 20
                logw.Add("test/" & i & ".txt", False)
                logw.WriteLine(i, "First line")
                Dim th As New System.Threading.Thread(AddressOf WriteTest) ' Test
                th.IsBackground = True
                th.Start(i)
            Next
            'Generate error
            If logw.Add("test/2.txt", True) = False Then
                Console.WriteLine("Could not open writer")
            End If
            'End
            WaitMe = False
            Console.ReadLine()
            logw.Dispose()
            Console.ReadLine()
        End Sub
    
        Public Sub WriteTest(ByVal int As Object)
            While WaitMe = True
                System.Threading.Thread.Sleep(100)
            End While
            Dim Log_int As Integer = CInt(int)
            For i As Integer = 0 To 2000
                logw.WriteLine(Log_int, "MT line : " & i.ToString)
            Next
            logw.Flush(Log_int)
            Console.WriteLine("Thread " & Log_int & " finish !")
        End Sub
    End Module

    //Update

    • Upvote 2
×
×
  • Create New...