Public Class Immobili

    Private Sub ImmobiliBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImmobiliBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.ImmobiliBindingSource.EndEdit()
        Me.ImmobiliTableAdapter.Update(Me.SmartEstateDataSet.Immobili)

    End Sub

    Private Sub Immobili_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'SmartEstateDataSet.Preventivi' table. You can move, or remove it, as needed.
        Me.PreventiviTableAdapter.Fill(Me.SmartEstateDataSet.Preventivi)
        'TODO: This line of code loads data into the 'SmartEstateDataSet.TipoImmobile' table. You can move, or remove it, as needed.
        Me.TipoImmobileTableAdapter.Fill(Me.SmartEstateDataSet.TipoImmobile)
        'TODO: This line of code loads data into the 'SmartEstateDataSet.Agenzie' table. You can move, or remove it, as needed.
        Me.AgenzieTableAdapter.Fill(Me.SmartEstateDataSet.Agenzie)
        'TODO: This line of code loads data into the 'SmartEstateDataSet.Immobili' table. You can move, or remove it, as needed.
        Me.ImmobiliTableAdapter.Fill(Me.SmartEstateDataSet.Immobili)

        Dim row As SmartEstateDataSet.TipoImmobileRow
        For Each row In SmartEstateDataSet.TipoImmobile
            comboFiltroTipoImmobile.Items.Add(row.CodiceTipoImmobile)
        Next
    End Sub

    Private Sub cmdCarica_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCarica.Click

        Dim openDialog As New OpenFileDialog

        openDialog.FileName = "*.jpg"
        openDialog.Filter = "Immagini|*.jpg"

        If (openDialog.ShowDialog() = Windows.Forms.DialogResult.OK) Then
            FotoPictureBox.Load(openDialog.FileName)

            Dim imgStream As New IO.MemoryStream

            Dim bm As Bitmap
            Using (imgStream)
                bm = New Bitmap(FotoPictureBox.Image)
                bm.Save(imgStream, System.Drawing.Imaging.ImageFormat.Gif)

                Dim rw As System.Data.DataRowView

                rw = DirectCast(ImmobiliBindingSource.Current, System.Data.DataRowView)
                Dim r As SmartEstateDataSet.ImmobiliRow

                r = rw.Row

                r.Foto = imgStream.ToArray()
            End Using
        End If


    End Sub

    Private Sub FiltraTipoImmobileToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FiltraTipoImmobileToolStripButton.Click
        Try
            Me.ImmobiliTableAdapter.FiltraTipoImmobile(Me.SmartEstateDataSet.Immobili, comboFiltroTipoImmobile.Text)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try

    End Sub


    Private Sub PreventiviDataGridView_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PreventiviDataGridView.DoubleClick
        Preventivi.MdiParent = Me.MdiParent
        Preventivi.PreventiviBindingSource.DataSource = Me.PreventiviBindingSource
        Main.stripFinestraCorrente.Items.Add("Preventivi")
        Preventivi.Show()
    End Sub

    Private Sub FillByToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Me.PreventiviTableAdapter.FillBy(Me.SmartEstateDataSet.Preventivi)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try

    End Sub
End Class