Enable Javascript


Last Arduino/ESP8266 project (click to open)

User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

Article Index

frmNAW

frmNAW:
Een suggestie als voorbeeld met code om na te doen, maar misschien maak je er liever gelijk iets zinnigs van.
(afbeelding en tekst kan wat meer naar onder staan)


De Cotrol-namen zijn opgebouwd uit 3-letters voor het type control en de bijbehorende teksten/labels.
pnl, lsb, dvg, txb, lbl, btn, chb, rbn, nud
Let op bij rbn's; in Groep Relatie: rbnAllen, rbnFamilie,... in Groep Selecteer op Relatie: rbnSelectAllen, rbnSelectFamilie,.
..
In het rood wat voorbeelden, spaties en vraagteken worden niet meegenomen.
GroupBoxes en, op één na, alle Labels behouden de standaardbenaming.
Anchor gaat heel snel als je het op een selectie toepast, dat scheelt nogal wat klik of schrijfwerk.

Project NAW - frmNAW.vb


Imports System.Drawing

Public Class frmNAW

' ''####### voorbeeld met Event uit MODULE
'Private WithEvents BindingSourcesEvents As New BindingSourcesClass
'Private Sub BindingSourceTblPassword_CurrentChanged(ByVal count As Integer) _
'           Handles BindingSourcesEvents.BSPasswordCurrentChanged
'  ' ' Event-code hier
'End Sub
' ''######

Private WithEvents DB As NawDB = New NawDB ' BindingSourceTblPassword_CurrentChanged-Event
Private RelatieVlag As Integer = 0 ' RadioButtons Selectie-Realtiesoort

Private Sub frmBinding_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim i As Integer
Me.Size = New Size(660, 397)
Me.MinimumSize = New Size(660, 397)
Me.MaximumSize = New Size(855, 567)
Me.pnlData.Visible = False
Me.txbEncrypt.ReadOnly = True
Me.txbRealatie.ReadOnly = True
Me.txbGeheim.PasswordChar = "*"
Me.rbnAllen.Tag = 0
Me.rbnSelectAllen.Tag = 0
Me.rbnFamilie.Tag = 1
Me.rbnSelectFamilie.Tag = 1
Me.rbnVrienden.Tag = 2
Me.rbnSelectVrienden.Tag = 2
Me.rbnZakelijk.Tag = 3
Me.rbnSelectZakelijk.Tag = 3
If Not InitDB() Then
MsgBox("Geen tblPassword-record gevonden: EINDE")
Me.Close()
End If
i = DB.InitDB()
    i = DB.NAWSelectSQL(-1)
    i = PasswordSelectSQL()
Me.LinkLabel1.Text = "www.kendziorra.nl"
' '' Inplaats van onderstaande DataBindingen kun je er ook voor kiezen om de Contols te 
' ''  vullen/updaten via het BindingSourceTblNAW_CurrentChanged-Event
Me.lsbLijst.DataSource = DB.BindingSourceTblNAW ' lijst om snel naar "Naam" zoeken
Me.lsbLijst.DisplayMember = "Naam" 'herhaal eertste letter van "Naam" tot het gezocht voor staat
Me.dgvGrid.DataSource = DB.BindingSourceTblNAW ' eerst datagridview binden, dan aanpassen
' '' Decrypt-TextBoxColomn voor ontsleutelde Geheim invoegen
Dim dataGridViewColumn As New DataGridViewTextBoxColumn()
    dataGridViewColumn.HeaderText = "Decrypt"
dataGridViewColumn.Name = "Decrypt"
Me.dgvGrid.Columns.Insert(4, dataGridViewColumn)
' '' Relatie-ComboBoxColomn voor Relatiesoort in tekst
Dim dataGridViewComboBoxColumn As New DataGridViewComboBoxColumn
    dataGridViewComboBoxColumn.HeaderText = "Relatie"
dataGridViewComboBoxColumn.Name = "Relatie"
dataGridViewComboBoxColumn.Items.AddRange("Allen", "Familie", "Vrienden", "Zakelijk")
Me.dgvGrid.Columns.Insert(8, dataGridViewComboBoxColumn)
' '' ReadOnly = True: Edit kan hier via textboxes, anders voor het Updaten
' ''  de kolommen "Decrypt"->"Geheim" en "Relatie"->"Relatiesoort" verwerken
Me.dgvGrid.ReadOnly = True
Me.dgvGrid.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader
Me.dgvGrid.Columns(7).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader
' '' Textboxes binden
Me.txbNaam.DataBindings.Add(New Binding("Text", DB.BindingSourceTblNAW, _
"Naam", True))
Me.txbAdres.DataBindings.Add(New Binding("Text", DB.BindingSourceTblNAW, _
"Adres", True))
Me.txbPlaats.DataBindings.Add(New Binding("Text", DB.BindingSourceTblNAW, _
"Woonplaats", True))
Me.txbEncrypt.DataBindings.Add(New Binding("Text", DB.BindingSourceTblNAW, _
"Geheim", True))
' '' Me.txbGeheim.Text in BindingSourceTblNAW_CurrentChanged-Event 
Me.txbHomepage.DataBindings.Add(New Binding("Text", DB.BindingSourceTblNAW, _
"Homepage", True))
Me.txbRealatie.DataBindings.Add(New Binding("Text", DB.BindingSourceTblNAW, _
"Relatiesoort", True))
' '' Realatie-RadioButtons in BindingSourceTblNAW_CurrentChanged-Event
End Sub

Private Sub frmBinding_FormClosing(ByVal sender As Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    OpslaanVervers(False)
    DB.CloseDB()
    CloseDB()
End Sub

Private Sub OpslaanVervers(ByVal Ververs As Boolean)
Dim i As Integer
' '' Update tabel uit TextBoxes
Dim Pos As Integer = DB.BindingSourceTblNAW.Position ' bewaar Position
DB.BindingSourceTblNAW.MovePrevious() ' wijzig Position
i = DB.AdapterTblNAWUpdate() ' Opslaan
If Ververs Then i = DB.NAWSelectSQL(RelatieVlag) ' verversen
DB.BindingSourceTblNAW.Position = Pos ' zet Position terug  
End Sub

Public Sub BindingSourceTblNAW_CurrentChanged(ByVal Records) _
Handles DB.BindingSourceTblNAWChanged
If Records > 0 Then
Me.lblRecNr.Text = (DB.BindingSourceTblNAW.Position + 1) & "/" & Records
Me.lblRecNr.Left = 193 - Me.lblRecNr.Width ' in r-bovenhoek van lijst houden
Me.rbnAllen.Checked = False
Me.rbnFamilie.Checked = False
Me.rbnVrienden.Checked = False
Me.rbnZakelijk.Checked = False
Select Case DB.RowTblNAW("Relatiesoort")
Case 0 : Me.rbnAllen.Checked = True
Case 1 : Me.rbnFamilie.Checked = True
Case 2 : Me.rbnVrienden.Checked = True
Case 3 : Me.rbnZakelijk.Checked = True
End Select
If DB.RowTblNAW("Geheim").ToString.Length Then
Me.txbGeheim.Text = Decrypt(DB.RowTblNAW("Geheim"), w4(RowTblPassword("Subkey")))
Else
Me.txbGeheim.Text = ""
End If
End If
End Sub

Private Sub txbHomepage_DragEnter(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) Handles txbHomepage.DragEnter
If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.Link
Else
e.Effect = DragDropEffects.None
End If
End Sub

Private Sub txbHomepage_DragDrop(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) Handles txbHomepage.DragDrop
' '' Zowel een applicatie als een url kan hier worden ingesleept
' '' URL of EXE is met dubbelklik te openen
Me.txbHomepage.Text = e.Data.GetData(DataFormats.FileDrop)(0)
End Sub

Private Sub txbHomepage_DoubleClick(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles txbHomepage.DoubleClick
Try
Dim Link As String = Me.txbHomepage.Text
If Link.IndexOf("/") <> -1 AndAlso Link.IndexOf("http://", 0) = -1 Then _
                  Link = "http://" & Link ' Is het een url?
System.Diagnostics.Process.Start(Link)
Catch ex As Exception
End Try
End Sub

Private Sub textbox_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles txbWachtwoord.KeyPress, txbNaam.KeyPress, txbAdres.KeyPress, _
            txbPlaats.KeyPress, txbGeheim.KeyPress, txbHomepage.KeyPress, _
            txbNieuwWW.KeyPress, txbHerhaalWW.KeyPress
' '' Test op toegestane tekens
Dim i As Boolean = (Lettertekens & Chr(8)).IndexOf(e.KeyChar) >= 0
If i Then Exit Sub
e.KeyChar = Nothing
Beep()
End Sub

Private Sub textbox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles txbWachtwoord.TextChanged, txbNaam.TextChanged, txbNieuwWW.TextChanged, _
              txbHerhaalWW.TextChanged
' '' Minimale lengte = 4
' '' CType() tegen Late Binding Error in Mobile
If CType(sender, TextBox).Text.Length AndAlso CType(sender, TextBox).Text.Length < 4 Then
CType(sender, TextBox).BackColor = Color.OrangeRed
Else
CType(sender, TextBox).BackColor = Color.White
End If
If CType(sender, TextBox).Name = "txbNieuwWW" Then Me.nudTekensWW.Value = _
Me.txbNieuwWW.Text.Length
End Sub

Private Sub btnWachtwoord_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnWachtwoord.Click
If Me.btnWachtwoord.Text = "OK" Then
If Me.txbWachtwoord.Text.Length < 4 Then Exit Sub
w1 = Encrypt(Me.txbWachtwoord.Text, w2) ' bewaar wachtwoord verstopt
If PasswordOk(RowTblPassword("Password"), Me.txbWachtwoord.Text) Then
Me.pnlData.Visible = True
Me.txbWachtwoord.Enabled = False
Me.btnWachtwoord.Text = "Bescherm"
End If
Else
Me.pnlData.Visible = False
Me.txbWachtwoord.Enabled = True
Me.btnWachtwoord.Text = "OK"
End If
Me.txbWachtwoord.Text = ""
End Sub

Private Sub btnGenereerWW_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
Me.txbNieuwWW.Text = GenerateStrongPW(nudTekensWW.Value)
Me.txbHerhaalWW.Text = Me.txbNieuwWW.Text()
End Sub

Private Sub btnNieuwRec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnNieuwRec.Click
    DB.BindingSourceTblNAW.AddNew()
End Sub

Private Sub btnWisRec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnWisRec.Click
If MsgBox("Naam: " & DB.RowTblNAW("Naam"), MsgBoxStyle.Exclamation Or _
              MsgBoxStyle.OkCancel, "RECORD WISSEN") = MsgBoxResult.Ok Then _
      DB.BindingSourceTblNAW.Remove(DB.BindingSourceTblNAW.Current)
End Sub

Private Sub btnOpslaanVerversenRec_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnOpslaan.Click, btnVervers.Click
If Me.txbGeheim.Text.Length Then
Me.txbEncrypt.Text = Encrypt(Me.txbGeheim.Text, w4(RowTblPassword("Subkey")))
Else
Me.txbGeheim.Text = ""
Me.txbEncrypt.Text = ""
End If
OpslaanVervers(True)
End Sub

Private Sub btnCompactDB_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnCompactDB.Click
    MsgBox("-" & CompactDB() & " KB", MsgBoxStyle.Information, "Compact DB")
End Sub

Private Sub rbnSelectRelatie_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles rbnSelectAllen.CheckedChanged, _
              rbnSelectFamilie.CheckedChanged, rbnSelectVrienden.CheckedChanged, _
              rbnSelectZakelijk.CheckedChanged
' '' de RelatieVlag bepaald welke records er worden geselecteerd
If Not Me.CanFocus Then Exit Sub ' eerst Form opmaken, daarna is DB pas beschikbaar
' '' CType() tegen Late Binding Error in Mobile
RelatieVlag = CType(sender, RadioButton).Tag
Dim i As Integer = DB.NAWSelectSQL(RelatieVlag)
End Sub

Private Sub rbnRelatie_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles rbnAllen.CheckedChanged, _
              rbnFamilie.CheckedChanged, rbnVrienden.CheckedChanged, rbnZakelijk.CheckedChanged
' '' CType() tegen Late Binding Error in Mobile
' '' Plaats de waarden 0 t/m 3 in het Tag-propertie van de betreffende RadioButtons
Me.txbRealatie.Text = CType(sender, RadioButton).Tag
End Sub

Private Sub chbToonGeheim_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles chbToonGeheim.CheckedChanged
If Me.chbToonGeheim.Checked Then
Me.txbGeheim.PasswordChar = ""
Else
Me.txbGeheim.PasswordChar = "*"
End If
dgvGrid.Refresh()
End Sub

Private Sub chbToonWW_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles chbToonWW.CheckedChanged
If Me.chbToonWW.Checked Then
Me.txbNieuwWW.PasswordChar = ""
Else
Me.txbNieuwWW.PasswordChar = "*"
End If
Me.txbHerhaalWW.PasswordChar = Me.txbNieuwWW.PasswordChar
End Sub

Private Sub btnOpslaanWW_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnOpslaanWW.Click
' '' Test nieuw wachtwoord 
' '' Decrypt SubKey met oude WW en Encrypt het met nieuw WW
' '' Sla WW op
If Me.txbNieuwWW.Text.Length < 4 Then Exit Sub
If Me.txbNieuwWW.Text <> Me.txbHerhaalWW.Text Then
MsgBox("Ongelijk", MsgBoxStyle.Information)
Exit Sub
End If
MsgBox("Wachtwoord: " & Me.txbNieuwWW.Text & vbCrLf & _
"Noteer wachtwoord en berg het veilig op!", MsgBoxStyle.Exclamation)
Dim SubKeyDecrypt As String = w4(RowTblPassword("Subkey")) ' ontsleutel SubKey
Dim SubKeyEncrypt As String = Encrypt(SubKeyDecrypt, Me.txbNieuwWW.Text) ' versleutel SubKey
Dim PasswordEncrypt As String = Encrypt(Me.txbNieuwWW.Text, Me.txbNieuwWW.Text)
If PasswordUpdate(RowTblPassword("ID"), PasswordEncrypt, SubKeyEncrypt) Then
AdapterTblPasswordUpdate() ' gelijk in DB opslaan
w1 = Encrypt(Me.txbNieuwWW.Text, w2) ' bewaar wachtwoord als w1 versleuteld in geheugen
Else
MsgBox("Wachtwoor en SubKey opslaan is mislukt!", MsgBoxStyle.Critical)
End If
Me.txbNieuwWW.Text = ""
Me.txbHerhaalWW.Text = ""
Me.chbToonWW.Checked = False
End Sub

Private Sub btnGenereerWW_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnGenereerWW.Click
Me.txbNieuwWW.Text = GenerateStrongPW(Me.nudTekensWW.Value)
Me.txbHerhaalWW.Text = Me.txbNieuwWW.Text
End Sub

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) _
Handles LinkLabel1.LinkClicked
    System.Diagnostics.Process.Start("http://www.kendziorra.nl")
End Sub

Private Sub dgvGrid_CellFormatting(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) _
Handles dgvGrid.CellFormatting
If e.Value Is Nothing Then Exit Sub
Select Case e.ColumnIndex
Case 5
If Me.dgvGrid("Geheim", e.RowIndex).Value.length Then
Me.dgvGrid("Decrypt", e.RowIndex).Value = Decrypt(Me.dgvGrid("Geheim", _
                                                            e.RowIndex).Value, w4(RowTblPassword("Subkey")))
If Not Me.chbToonGeheim.Checked Then Me.dgvGrid("Decrypt", e.RowIndex).Value = _
New String("*"c, Me.dgvGrid("Decrypt", e.RowIndex).Value.Length)
End If
Case 8
Me.dgvGrid("Relatie", e.RowIndex).Value = _
                    Choose(e.Value + 1, "Allen", "Familie", "Vrienden", "Zakelijk")
End Select
End Sub

End Class