apo-bankomat/WindowsApp1/Form2.vb
2021-10-11 08:42:17 +02:00

86 lines
3.1 KiB
VB.net

Public Class Form2
Public card As card
Public parent As Form1
Public Sub New(karta As card, form As Form1)
' To wywołanie jest wymagane przez projektanta.
InitializeComponent()
' Dodaj inicjowanie po wywołaniu funkcji InitializeComponent().
card = karta
parent = form
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
MsgBox("your card balance is:" + vbNewLine + card.ammound.ToString)
Me.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If card.ammound >= Int(TextBox1.Text) Then
card.ammound = card.ammound - Int(TextBox1.Text)
MsgBox("succesfully withdrawed: " + TextBox1.Text)
Me.Close()
Else
MsgBox("not sufficient balanse")
Me.Close()
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
card.ammound = card.ammound + Int(TextBox2.Text)
MsgBox("succesfully deposited: " + TextBox2.Text)
Me.Close()
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim cardl = TextBox4.Text
Dim ammound = Int(TextBox5.Text)
If card.ammound >= ammound Then
Dim found As Integer = -1
For i = 0 To parent.karty.Length - 1
If cardl = parent.karty(i).numer Then
found = i
End If
Next
If found = -1 Then
MsgBox("target card not exists")
Me.Close()
Return
End If
card.ammound = card.ammound - ammound
parent.karty(found).ammound = parent.karty(found).ammound + ammound
MsgBox("succesfully transfered to card: " + cardl + vbNewLine + "amound: " + ammound.ToString)
Me.Close()
Else
MsgBox("not sufficient balanse")
Me.Close()
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If card.ammound >= Int(TextBox3.Text) Then
card.ammound = card.ammound - Int(TextBox3.Text)
MsgBox("succesfully topupped: " + TextBox3.Text + vbNewLine + "your code: " + GenerateRandomString(8, False))
Me.Close()
Else
MsgBox("not sufficient balanse")
Me.Close()
End If
End Sub
Public Function GenerateRandomString(ByRef len As Integer, ByRef upper As Boolean) As String
Dim rand As New Random()
Dim allowableChars() As Char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ0123456789".ToCharArray()
Dim final As String = String.Empty
For i As Integer = 0 To len - 1
final += allowableChars(rand.Next(allowableChars.Length - 1))
Next
Return IIf(upper, final.ToUpper(), final)
End Function
End Class