Public Class frmBuilding
  Inherits System.Windows.Forms.Form
  Dim MyApartment As New Apartment()
  Dim MyBuilding As New Commercial()
  Dim MyHome As New Home()

  ' Kod generowany przez Windows Form Designer

  Private Sub frmBuilding_Load(ByVal sender As System.Object, ByVal e As _
                System.EventArgs) Handles MyBase.Load

    ' dodajemy dane do pola kombi
    cmbPropertyType.Items.Add("Apartment") 
    cmbPropertyType.Items.Add("Commercial")
    cmbPropertyType.Items.Add("Home")
    cmbPropertyType.SelectedIndex = 0
    ' ustalamy niewidoczność grup
    grbApt.Visible = False
    grbCom.Visible = False
    grbHome.Visible = False

  End Sub

  Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As _
                 System.EventArgs) Handles btnExit.Click
    MyApartment = Nothing   ' Zwalniamy zasoby pamięci 
    MyBuilding = Nothing
    MyHome = Nothing
    Me.Dispose()
  End Sub

  Private Sub cmbPropertyType_Leave(ByVal sender As Object, ByVal e As _
                System.EventArgs) Handles cmbPropertyType.Leave

    Select Case cmbPropertyType.SelectedIndex
      Case 0  ' Blok mieszkalny
        grbApt.Visible = True
        txtAUnits.Focus()

      Case 1  ' Komercyjny
        grbCom.Visible = True
        txtCSqFt.Focus()
      Case 2  ' Dom
        grbHome.Visible = True
        txtHSqFt.Focus()
    End Select
  End Sub

  Private Sub cmbPropertyType_Enter(ByVal sender As Object, ByVal e As _
                System.EventArgs) Handles cmbPropertyType.Enter

    grbApt.Visible = False  ' Ukryj pola grupy
    grbCom.Visible = False
    grbHome.Visible = False

  End Sub

  Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As _
                 System.EventArgs) Handles btnAdd.Click


    Select Case cmbPropertyType.SelectedIndex

      Case 0              ' Blok mieszkalny
        MyApartment.BuildingType = 0
        MyApartment.Address = txtAddress.Text
        MyApartment.PurchasePrice = CDbl(txtPrice.Text)
        MyApartment.MonthlyPayment = CDbl(txtMonthlyPay.Text)
        MyApartment.Taxes = CDbl(txtTaxes.Text)
        MyApartment.DisplayBuilding()

      Case 1              ' Komercyjny
        MyBuilding.BuildingType = 1
        MyBuilding.Address = txtAddress.Text
        MyBuilding.PurchasePrice = CDbl(txtPrice.Text)
        MyBuilding.MonthlyPayment = CDbl(txtMonthlyPay.Text)
        MyBuilding.Taxes = CDbl(txtTaxes.Text)
        MyBuilding.DisplayBuilding()

      Case 2              ' Dom
        MyHome.BuildingType = 2
        MyHome.Address = txtAddress.Text
        MyHome.PurchasePrice = CDbl(txtPrice.Text)
        MyHome.MonthlyPayment = CDbl(txtMonthlyPay.Text)
        MyHome.Taxes = CDbl(txtTaxes.Text)
        MyHome.DisplayBuilding()

    End Select

  End Sub

  ' ============= Pola edycji dla budynków mieszkalnych ==============
  Private Sub txtAUnits_Leave(ByVal sender As Object, ByVal e As _
                  System.EventArgs) Handles txtAUnits.Leave
    MyApartment.Units = CInt(txtAUnits.Text)
  End Sub
  Private Sub txtARent_Leave(ByVal sender As Object, ByVal e As _
                  System.EventArgs) Handles txtARent.Leave
    MyApartment.Rents = CDbl(txtARent.Text)
  End Sub

  Private Sub txtAOccup_Leave(ByVal sender As Object, ByVal e As _
                  System.EventArgs) Handles txtAOccup.Leave
    MyApartment.OccupancyRate = CDbl(txtAOccup.Text)
  End Sub

  ' ============ Pola edycji dla budynków komercyjnych ==================

  Private Sub txtCSqFt_Leave(ByVal sender As Object, ByVal e As _
                  System.EventArgs) Handles txtCSqFt.Leave
    MyBuilding.SquareFeet = CInt(txtCSqFt.Text)
  End Sub

  Private Sub txtCRent_Leave(ByVal sender As Object, ByVal e As _
                  System.EventArgs) Handles txtCRent.Leave
    MyBuilding.RentPerSF = CDbl(txtCRent.Text)
  End Sub

  Private Sub txtCPark_Leave(ByVal sender As Object, ByVal e As _
                  System.EventArgs) Handles txtCPark.Leave
    MyBuilding.ParkingSpots = CInt(txtCPark.Text)
  End Sub

  ' =============== Pola edycji dla domów =================

  Private Sub txtHSqFt_Leave(ByVal sender As Object, ByVal e As _
                  System.EventArgs) Handles txtHSqFt.Leave
    MyHome.SquareFeet = CInt(txtHSqFt.Text)
  End Sub

  Private Sub txtHRent_Leave(ByVal sender As Object, ByVal e As _
                  System.EventArgs) Handles txtHRent.Leave
    MyHome.Rent = CDbl(txtHRent.Text)
  End Sub

  Private Sub txtBedrooms_Leave(ByVal sender As Object, ByVal e As _
                   System.EventArgs) Handles txtBedrooms.Leave
    MyHome.Bedrooms = CInt(txtBedrooms.Text)
  End Sub

  Private Sub txtBaths_Leave(ByVal sender As Object, ByVal e As _
                  System.EventArgs) Handles txtBaths.Leave
    MyHome.Baths = CInt(txtBaths.Text)
  End Sub

End Class
